1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * ident "%Z%%M% %I% %E% SMI"
24 *
25 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28
29 package com.sun.dhcpmgr.data.qualifier;
30
31 /**
32 * This qualifier type allows the logical and of two qualifier types. Care
33 * must be taken that the two qualifier types are suitable. For instance
34 * if 'and'ing two integer ranges together that do not overlap will ensure
35 * that no legal values are ever parsed by parseValue().
36 */
37 public class QualifierAnd extends QualifierTypeImpl {
38
39 protected QualifierType typeA;
40
41 protected QualifierType typeB;
42
43 public QualifierAnd(QualifierType typeA, QualifierType typeB) {
44 this.typeA = typeA;
45 this.typeB = typeB;
46 }
47
48 public void setQualifierTypeA(QualifierType typeA) {
49 this.typeA = typeA;
50 }
51
52 public void setQualifierTypeB(QualifierType typeB) {
53 this.typeB = typeB;
54 }
55
56 public QualifierType getQualifierTypeA() {
57 return typeA;
58 }
59
60 public QualifierType getQualifierTypeB() {
61 return typeB;
62 }
63
64 public Object parseValue(String value) {
65 if (!typeA.getJavaType().equals(typeB.getJavaType())) {
66 return null;
67 }
68
69 Object objectA = typeA.parseValue(value);
70 Object objectB = typeB.parseValue(value);
71
72 if (objectA != null && objectB != null) {
73 return (objectA.equals(objectB)) ? objectA : null;
74 } else {
75 return null;
76 }
77 }
78
79 public String formatValue(String value) {
80 if (!typeA.getJavaType().equals(typeB.getJavaType())) {
81 return null;
82 }
83
84 String stringA = typeA.formatValue(value);
85 String stringB = typeB.formatValue(value);
86
87 if (stringA != null && stringB != null) {
88 return (stringA.equals(stringB)) ? stringA : null;
89 } else {
90 return null;
91 }
92 }
93
94 public Class getJavaType() {
95 return typeA.getJavaType();
96 }
97
98 public String toString() {
99 return "(" + typeA + " && " + typeB + ")";
100 }
101
102 }