001: /**********************************************************************
002: Copyright (c) 2005 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:
016: Contributors:
017: ...
018: **********************************************************************/package org.jpox.metadata;
019:
020: import java.io.Serializable;
021:
022: /**
023: * Representation of strategy of a Sequence.
024: *
025: * @since 1.1
026: * @version $Revision: 1.5 $
027: */
028: public class SequenceStrategy implements Serializable {
029: /**
030: * language="nontransactional"
031: */
032: public static final SequenceStrategy NONTRANSACTIONAL = new SequenceStrategy(
033: 1);
034:
035: /**
036: * language="continguous"
037: */
038: public static final SequenceStrategy CONTIGUOUS = new SequenceStrategy(
039: 2);
040:
041: /**
042: * language="noncontiguous"
043: */
044: public static final SequenceStrategy NONCONTIGUOUS = new SequenceStrategy(
045: 3);
046:
047: private final int typeId;
048:
049: private SequenceStrategy(int i) {
050: this .typeId = i;
051: }
052:
053: /**
054: * Indicates whether some other object is "equal to" this one.
055: * @param o the reference object with which to compare.
056: * @return true if this object is the same as the obj argument; false otherwise.
057: */
058: public boolean equals(Object o) {
059: if (o instanceof SequenceStrategy) {
060: return ((SequenceStrategy) o).typeId == typeId;
061: }
062: return false;
063: }
064:
065: /**
066: * Returns a string representation of the object.
067: * @return a string representation of the object.
068: */
069: public String toString() {
070: switch (typeId) {
071: case 1:
072: return "nontransactional";
073: case 2:
074: return "contiguous";
075: case 3:
076: return "noncontiguous";
077: }
078: return "";
079: }
080:
081: /**
082: * Accessor to the sequence strategy type
083: * @return the type
084: */
085: public int getType() {
086: return typeId;
087: }
088:
089: /**
090: * Return Sequence strategy from String.
091: * @param value sequence strategy
092: * @return Instance of SequenceStrategy. If parse failed, return null.
093: */
094: public static SequenceStrategy getStrategy(final String value) {
095: if (value == null) {
096: return null;
097: } else if (SequenceStrategy.NONTRANSACTIONAL.toString()
098: .equalsIgnoreCase(value)) {
099: return SequenceStrategy.NONTRANSACTIONAL;
100: } else if (SequenceStrategy.CONTIGUOUS.toString()
101: .equalsIgnoreCase(value)) {
102: return SequenceStrategy.CONTIGUOUS;
103: } else if (SequenceStrategy.NONCONTIGUOUS.toString()
104: .equalsIgnoreCase(value)) {
105: return SequenceStrategy.NONCONTIGUOUS;
106: }
107: return null;
108: }
109: }
|