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: ...
017: **********************************************************************/package org.jpox.metadata;
018:
019: import java.io.Serializable;
020:
021: /**
022: * Representation of the values for discriminator "strategy".
023: *
024: * @since 1.1
025: * @version $Revision: 1.4 $
026: */
027: public class DiscriminatorStrategy implements Serializable {
028: /** strategy="none" */
029: public static final DiscriminatorStrategy NONE = new DiscriminatorStrategy(
030: 0);
031:
032: /** strategy="value-map" */
033: public static final DiscriminatorStrategy VALUE_MAP = new DiscriminatorStrategy(
034: 1);
035:
036: /** strategy="class-name" */
037: public static final DiscriminatorStrategy CLASS_NAME = new DiscriminatorStrategy(
038: 2);
039:
040: /** The type id. */
041: private final int typeId;
042:
043: /**
044: * Constructor
045: * @param id type id
046: */
047: private DiscriminatorStrategy(int id) {
048: this .typeId = id;
049: }
050:
051: /**
052: * Indicates whether some other object is "equal to" this one.
053: * @param o the reference object with which to compare.
054: * @return true if this object is the same as the obj argument; false otherwise.
055: */
056: public boolean equals(Object o) {
057: if (o instanceof DiscriminatorStrategy) {
058: return ((DiscriminatorStrategy) o).typeId == typeId;
059: }
060: return false;
061: }
062:
063: /**
064: * Returns a string representation of the object.
065: * @return a string representation of the object.
066: */
067: public String toString() {
068: switch (typeId) {
069: case 0:
070: return "none";
071: case 1:
072: return "value-map";
073: case 2:
074: return "class-name";
075: }
076: return "";
077: }
078:
079: /**
080: * Accessor for the type.
081: * @return Type
082: **/
083: public int getType() {
084: return typeId;
085: }
086:
087: /**
088: * Accessor for the strategy
089: * @param value The string form
090: * @return The strategy
091: */
092: public static DiscriminatorStrategy getDiscriminatorStrategy(
093: final String value) {
094: if (value == null) {
095: return null;
096: } else if (DiscriminatorStrategy.NONE.toString().equals(value)) {
097: return DiscriminatorStrategy.NONE;
098: } else if (DiscriminatorStrategy.VALUE_MAP.toString().equals(
099: value)) {
100: return DiscriminatorStrategy.VALUE_MAP;
101: } else if (DiscriminatorStrategy.CLASS_NAME.toString().equals(
102: value)) {
103: return DiscriminatorStrategy.CLASS_NAME;
104: }
105: return null;
106: }
107: }
|