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