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: * Class defining the possibilities for persistence, in terms of the type of
023: * persistence, and the types that are capable to be supported.
024: * @since 1.1
025: * @version $Revision: 1.4 $
026: */
027: public class FieldPersistenceModifier implements Serializable {
028: /**
029: * persistence-modifier="persistent"
030: */
031: public static final FieldPersistenceModifier PERSISTENT = new FieldPersistenceModifier(
032: 1);
033:
034: /**
035: * persistence-modifier="transactional"
036: */
037: public static final FieldPersistenceModifier TRANSACTIONAL = new FieldPersistenceModifier(
038: 2);
039:
040: /**
041: * persistence-modifier="none"
042: */
043: public static final FieldPersistenceModifier NONE = new FieldPersistenceModifier(
044: 3);
045:
046: /**
047: * default persistence modifier
048: */
049: public static final FieldPersistenceModifier DEFAULT = new FieldPersistenceModifier(
050: -1);
051:
052: /**
053: * persistent|transactional|none id
054: */
055: private final int typeId;
056:
057: /**
058: * constructor
059: * @param i type id
060: */
061: private FieldPersistenceModifier(int i) {
062: this .typeId = i;
063: }
064:
065: /**
066: * Indicates whether some other object is "equal to" this one.
067: * @param o the reference object with which to compare.
068: * @return true if this object is the same as the obj argument; false otherwise.
069: */
070: public boolean equals(Object o) {
071: if (o instanceof FieldPersistenceModifier) {
072: return ((FieldPersistenceModifier) o).typeId == typeId;
073: }
074: return false;
075: }
076:
077: /**
078: * Returns a string representation of the object.
079: * @return a string representation of the object.
080: */
081: public String toString() {
082: switch (typeId) {
083: case 1:
084: return "persistent";
085: case 2:
086: return "transactional";
087: case 3:
088: return "none";
089: }
090: return "";
091: }
092:
093: protected int getType() {
094: return typeId;
095: }
096:
097: /**
098: * Return FieldPersistenceModifier from String.
099: * @param value persistence-modifier attribute value
100: * @return Instance of FieldPersistenceModifier.
101: * If value invalid, return null.
102: */
103: public static FieldPersistenceModifier getFieldPersistenceModifier(
104: final String value) {
105: if (value == null) {
106: return null;
107: } else if (FieldPersistenceModifier.PERSISTENT.toString()
108: .equalsIgnoreCase(value)) {
109: return FieldPersistenceModifier.PERSISTENT;
110: } else if (FieldPersistenceModifier.TRANSACTIONAL.toString()
111: .equalsIgnoreCase(value)) {
112: return FieldPersistenceModifier.TRANSACTIONAL;
113: } else if (FieldPersistenceModifier.NONE.toString()
114: .equalsIgnoreCase(value)) {
115: return FieldPersistenceModifier.NONE;
116: }
117: return null;
118: }
119: }
|