001: /**********************************************************************
002: Copyright (c) 2004 Andy Jefferson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: Kikuchi Kousuke - org.jpox.enhancer.conf.NullValue
017: ...
018: **********************************************************************/package org.jpox.metadata;
019:
020: import java.io.Serializable;
021:
022: import org.jpox.util.StringUtils;
023:
024: /**
025: * jdo config null-value class.
026: * <br>
027: * <!ATTLIST field null-value (exception|default|none) 'none'>
028: *
029: * @since 1.1
030: * @version $Revision: 1.5 $
031: */
032: public class NullValue implements Serializable {
033: /**
034: * null-value="exception"
035: */
036: public static final NullValue EXCEPTION = new NullValue(1);
037:
038: /**
039: * null-value="default"
040: */
041: public static final NullValue DEFAULT = new NullValue(2);
042:
043: /**
044: * null-value="none"
045: */
046: public static final NullValue NONE = new NullValue(3);
047:
048: /**
049: * The type id
050: */
051: private final int typeId;
052:
053: /**
054: * constructor
055: * @param i type id
056: */
057: private NullValue(int i) {
058: this .typeId = i;
059: }
060:
061: /**
062: * Indicates whether some other object is "equal to" this one.
063: * @param o the reference object with which to compare.
064: * @return true if this object is the same as the obj argument; false otherwise.
065: */
066: public boolean equals(Object o) {
067: if (o instanceof NullValue) {
068: return ((NullValue) o).typeId == typeId;
069: }
070: return false;
071: }
072:
073: /**
074: * Returns a string representation of the object.
075: * @return a string representation of the object.
076: */
077: public String toString() {
078: switch (typeId) {
079: case 1:
080: return "exception";
081: case 2:
082: return "default";
083: case 3:
084: return "none";
085: }
086: return "";
087: }
088:
089: /**
090: * Accessor for the type.
091: * @return Type
092: **/
093: public int getType() {
094: return typeId;
095: }
096:
097: /**
098: * Obtain a NullValue for the given name by <code>value</code>
099: * @param value the name
100: * @return the NullValue found or NullValue.NONE if not found. If <code>value</code> is null, returns NullValue.NONE.
101: */
102: public static NullValue getNullValue(final String value) {
103: if (StringUtils.isWhitespace(value)) {
104: return NullValue.NONE;
105: } else if (NullValue.DEFAULT.toString().equals(value)) {
106: return NullValue.DEFAULT;
107: } else if (NullValue.EXCEPTION.toString().equals(value)) {
108: return NullValue.EXCEPTION;
109: } else if (NullValue.NONE.toString().equals(value)) {
110: return NullValue.NONE;
111: }
112: return NullValue.NONE;
113: }
114: }
|