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 inheritance "strategy".
023: * A brief description of the strategies
024: * <ul>
025: * <li><b>subclass-table</b> - the fields of this class are persisted into the table(s) of subclasses.</li>
026: * <li><b>new-table</b> - the fields of this class are persisted into its own table.</li>
027: * <li><b>superclass-table</b> - the fields of this class are persisted into the table of its superclass</li>
028: * <li><b>complete-table</b> - the fields of this class and all fields of superclasses are persisted into its own table.</li>
029: * </ul>
030: *
031: * @since 1.1
032: * @version $Revision: 1.7 $
033: */
034: public class InheritanceStrategy implements Serializable {
035: /** strategy="subclass-table" */
036: public static final InheritanceStrategy SUBCLASS_TABLE = new InheritanceStrategy(
037: 1);
038:
039: /** strategy="new-table" */
040: public static final InheritanceStrategy NEW_TABLE = new InheritanceStrategy(
041: 2);
042:
043: /** strategy="superclass-table" */
044: public static final InheritanceStrategy SUPERCLASS_TABLE = new InheritanceStrategy(
045: 3);
046:
047: /** strategy="complete-table" (from JPA "TABLE_PER_CLASS") */
048: public static final InheritanceStrategy COMPLETE_TABLE = new InheritanceStrategy(
049: 4);
050:
051: /**
052: * The type id.
053: */
054: private final int typeId;
055:
056: /**
057: * constructor
058: * @param i type id
059: */
060: private InheritanceStrategy(int i) {
061: this .typeId = i;
062: }
063:
064: /**
065: * Indicates whether some other object is "equal to" this one.
066: * @param o the reference object with which to compare.
067: * @return true if this object is the same as the obj argument; false otherwise.
068: */
069: public boolean equals(Object o) {
070: if (o instanceof InheritanceStrategy) {
071: return ((InheritanceStrategy) o).typeId == typeId;
072: }
073: return false;
074: }
075:
076: /**
077: * Returns a string representation of the object.
078: * @return a string representation of the object.
079: */
080: public String toString() {
081: switch (typeId) {
082: case 1:
083: return "subclass-table";
084: case 2:
085: return "new-table";
086: case 3:
087: return "superclass-table";
088: case 4:
089: return "complete-table";
090: }
091: return "";
092: }
093:
094: /**
095: * Accessor for the type.
096: * @return Type
097: **/
098: public int getType() {
099: return typeId;
100: }
101:
102: /**
103: * Obtain a InheritanceStrategy for the given name by <code>value</code>
104: * @param value the name
105: * @return the InheritanceStrategy found or InheritanceStrategy.NEW_TABLE if not found.
106: * Nothing specified returns null
107: */
108: public static InheritanceStrategy getInheritanceStrategy(
109: final String value) {
110: if (value == null) {
111: return null;
112: } else if (InheritanceStrategy.SUBCLASS_TABLE.toString()
113: .equals(value)) {
114: return InheritanceStrategy.SUBCLASS_TABLE;
115: } else if (InheritanceStrategy.NEW_TABLE.toString().equals(
116: value)) {
117: return InheritanceStrategy.NEW_TABLE;
118: } else if (InheritanceStrategy.SUPERCLASS_TABLE.toString()
119: .equals(value)) {
120: return InheritanceStrategy.SUPERCLASS_TABLE;
121: } else if (InheritanceStrategy.COMPLETE_TABLE.toString()
122: .equals(value)) {
123: return InheritanceStrategy.COMPLETE_TABLE;
124: }
125: return InheritanceStrategy.NEW_TABLE;
126: }
127: }
|