001: /*
002: * Copyright 2005 Ralf Joachim
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.castor.mapping;
017:
018: import java.io.Serializable;
019: import java.util.HashMap;
020: import java.util.Iterator;
021: import java.util.Map;
022:
023: /**
024: * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
025: * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
026: */
027: public final class BindingType implements Cloneable, Comparable,
028: Serializable {
029: //------------------------------------------------------------------------
030:
031: /** SerialVersionUID */
032: private static final long serialVersionUID = -2116844968191798202L;
033:
034: private static final Map TYPES = new HashMap();
035:
036: public static final BindingType JDO = new BindingType("jdo");
037: public static final BindingType XML = new BindingType("xml");
038:
039: private final String _type;
040:
041: //------------------------------------------------------------------------
042:
043: private BindingType(final String kind) {
044: _type = kind;
045: TYPES.put(kind, this );
046: }
047:
048: public static BindingType valueOf(final String kind) {
049: return (BindingType) TYPES.get(kind);
050: }
051:
052: public static Iterator iterator() {
053: return TYPES.values().iterator();
054: }
055:
056: //------------------------------------------------------------------------
057:
058: /**
059: * Returns the String representation of this kind.
060: *
061: * @return String representation of this kind.
062: */
063: public String toString() {
064: return _type;
065: }
066:
067: /**
068: * Clone only returns the one and only instance of this kind.
069: *
070: * @return The original instance.
071: */
072: public Object clone() {
073: return this ;
074: }
075:
076: /**
077: * Returns if the specified object and this are one and the same instance.
078: *
079: * @param other Object to be compared with this instance.
080: * @return <code>true</code> if other equals this else <code>false</code>.
081: */
082: public boolean equals(final Object other) {
083: return (this == other);
084: }
085:
086: /**
087: * Returns the hash code of this object.
088: *
089: * @return Hash code of this object.
090: */
091: public int hashCode() {
092: return _type.hashCode();
093: }
094:
095: /**
096: * Compares {@link #_type} against {@link #_type} of the specified
097: * object. So this method is inconsistent with {@link #equals}.
098: *
099: * @param other Object to be compared with this instance.
100: * @return A negative integer, zero, or a positive integer as this object
101: * is less than, equal to, or greater than the specified object.
102: */
103: public int compareTo(final Object other) {
104: return _type.compareTo(((BindingType) other)._type);
105: }
106:
107: /**
108: * Called during deserialization.
109: *
110: * @return The existing instance of the enum. <br>So you can use '=='
111: * like 'equals' even if you use a deserialized Enum.
112: */
113: protected Object readResolve() {
114: return TYPES.get(_type);
115: }
116:
117: //------------------------------------------------------------------------
118: }
|