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 org.jpox.util.StringUtils;
020:
021: /**
022: * Representation of the MetaData of a named Sequence (JDO, or JPA).
023: *
024: * @since 1.1
025: * @version $Revision: 1.12 $
026: */
027: public class SequenceMetaData extends MetaData {
028: /** Name under which this sequence generator is known. */
029: protected final String name;
030:
031: /** Datastore Sequence name */
032: protected String datastoreSequence;
033:
034: /** factory class name (JDO). */
035: protected String factoryClass;
036:
037: /** Strategy for this sequence (JDO). */
038: protected SequenceStrategy strategy;
039:
040: /** Initial value of the sequence. */
041: protected long initialValue = -1;
042:
043: /** Allocation size for the sequence. */
044: protected long allocationSize = -1;
045:
046: /**
047: * Constructor.
048: * @param parent The parent of this element
049: * @param name The sequence name
050: * @param datastoreSequence The datastore sequence
051: * @param factoryClass The factory class
052: * @param strategyValue The strategy value
053: * @param initialValue Initial value
054: * @param allocationSize Allocation size
055: */
056: public SequenceMetaData(final MetaData parent, final String name,
057: final String datastoreSequence, final String factoryClass,
058: final String strategyValue, final String initialValue,
059: final String allocationSize) {
060: super (parent);
061:
062: this .name = name;
063: if (StringUtils.isWhitespace(name)) {
064: throw new InvalidMetaDataException(LOCALISER, "044155");
065: }
066:
067: this .datastoreSequence = (StringUtils
068: .isWhitespace(datastoreSequence) ? null
069: : datastoreSequence);
070: this .factoryClass = factoryClass;
071:
072: // strategy
073: this .strategy = SequenceStrategy.getStrategy(strategyValue);
074:
075: if (!StringUtils.isWhitespace(initialValue)) {
076: this .initialValue = new Long(initialValue).longValue();
077: }
078: if (!StringUtils.isWhitespace(allocationSize)) {
079: this .allocationSize = new Long(allocationSize).longValue();
080: }
081: }
082:
083: /**
084: * Convenience accessor for the fully-qualified name of the sequence.
085: * @return Fully qualfiied name of the sequence (including the package name).
086: */
087: public String getFullyQualifiedName() {
088: PackageMetaData pmd = (PackageMetaData) getParent();
089: return pmd.getName() + "." + name;
090: }
091:
092: /**
093: * Accessor for the class name.
094: * @return class name
095: */
096: public String getName() {
097: return name;
098: }
099:
100: /**
101: * Accessor for the strategy
102: * @return strategy tag value
103: */
104: public SequenceStrategy getStrategy() {
105: return strategy;
106: }
107:
108: /**
109: * Accessor for the sequence name
110: * @return The sequence name
111: */
112: public String getDatastoreSequence() {
113: return datastoreSequence;
114: }
115:
116: /**
117: * Accessor for the factory class
118: * @return factory class
119: */
120: public String getFactoryClass() {
121: return factoryClass;
122: }
123:
124: /**
125: * Accessor for the initial value of the sequence.
126: * @return The initial value
127: */
128: public long getInitialValue() {
129: return initialValue;
130: }
131:
132: /**
133: * Accessor for the allocation size of the sequence.
134: * @return The allocation size
135: */
136: public long getAllocationSize() {
137: return allocationSize;
138: }
139:
140: /**
141: * Returns a string representation of the object.
142: * @param prefix prefix string
143: * @param indent indent string
144: * @return a string representation of the object.
145: */
146: public String toString(String prefix, String indent) {
147: StringBuffer sb = new StringBuffer();
148: sb.append(prefix).append("<sequence name=\"" + name + "\"\n");
149: if (datastoreSequence != null) {
150: sb.append(prefix).append(
151: " datastore-sequence=\"" + datastoreSequence
152: + "\"\n");
153: }
154: if (factoryClass != null) {
155: sb.append(prefix).append(
156: " factory-class=\"" + factoryClass + "\"\n");
157: }
158: if (strategy != null) {
159: sb.append(prefix).append(
160: " strategy=\"" + strategy.toString()
161: + "\">\n");
162: }
163:
164: // Add extensions
165: sb.append(super .toString(prefix + indent, indent));
166:
167: sb.append(prefix + "</sequence>\n");
168: return sb.toString();
169: }
170: }
|