QualifierOr.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff/*
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * CDDL HEADER START
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * The contents of this file are subject to the terms of the
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * Common Development and Distribution License, Version 1.0 only
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * (the "License"). You may not use this file except in compliance
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * with the License.
15a44745412679c30a6d022733925af70a38b715David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
15a44745412679c30a6d022733925af70a38b715David Lawrence * or http://www.opensolaris.org/os/licensing.
15a44745412679c30a6d022733925af70a38b715David Lawrence * See the License for the specific language governing permissions
15a44745412679c30a6d022733925af70a38b715David Lawrence * and limitations under the License.
15a44745412679c30a6d022733925af70a38b715David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * When distributing Covered Code, include this CDDL HEADER in each
15a44745412679c30a6d022733925af70a38b715David Lawrence * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * If applicable, add the following below this CDDL HEADER, with the
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * fields enclosed by brackets "[]" replaced with your own identifying
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * information: Portions Copyright [yyyy] [name of copyright owner]
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence *
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * CDDL HEADER END
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff/*
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * ident "%Z%%M% %I% %E% SMI"
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff *
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * Use is subject to license terms.
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff */
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graffpackage com.sun.dhcpmgr.data.qualifier;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff/**
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * This qualifier type allows the logical or of two qualifier types. Care
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * must be taken that the two qualifier types are suitable. For instance
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * if 'or'ing a string and an integer may result in parseValue() returning
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff * either a String or an Integer.
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff */
f9fdb43a912a53c44627449ace57921b143eef60Michael Graffpublic class QualifierOr extends QualifierTypeImpl {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff protected QualifierType typeA;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff protected QualifierType typeB;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff public QualifierOr(QualifierType typeA, QualifierType typeB) {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff this.typeA = typeA;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff this.typeB = typeB;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff public void setQualifierTypeA(QualifierType typeA) {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff this.typeA = typeA;
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence }
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence public void setQualifierTypeB(QualifierType typeB) {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff this.typeB = typeB;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff public QualifierType getQualifierTypeA() {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff return typeA;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff public QualifierType getQualifierTypeB() {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff return typeB;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff public Object parseValue(String value) {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff if (!typeA.getJavaType().equals(typeB.getJavaType())) {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff return null;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff Object objectA = typeA.parseValue(value);
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff Object objectB = typeB.parseValue(value);
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff if (objectA != null && objectB != null) {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff return (objectA.equals(objectB)) ? objectA : null;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff } else {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff return (objectA == null) ? objectB : objectA;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff public String formatValue(String value) {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff if (!typeA.getJavaType().equals(typeB.getJavaType())) {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff return null;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff String stringA = typeA.formatValue(value);
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff String stringB = typeB.formatValue(value);
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff if (stringA != null && stringB != null) {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff return (stringA.equals(stringB)) ? stringA : null;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff } else {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff return (stringA == null) ? stringB : stringA;
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff public Class getJavaType() {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff return typeA.getJavaType();
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff public String toString() {
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff return "(" + typeA + " || " + typeB + ")";
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff }
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff}
f9fdb43a912a53c44627449ace57921b143eef60Michael Graff