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: 2004 Andy Jefferson - added initialise() method
017: ...
018: **********************************************************************/package org.jpox.metadata;
019:
020: /**
021: * Representation of the Meta-Data defining inherited classes.
022: *
023: * @since 1.1
024: * @version $Revision: 1.9 $
025: */
026: public class InheritanceMetaData extends MetaData {
027: /** strategy tag value. */
028: protected InheritanceStrategy strategy = null;
029:
030: /** JoinMetaData element. */
031: protected JoinMetaData joinMetaData;
032:
033: /** DiscriminatorMetaData element. */
034: protected DiscriminatorMetaData discriminatorMetaData;
035:
036: /**
037: * Constructor.AbstractClassMetaData
038: * @param parent parent ClassMetaData instance
039: * @param strategy Inheritance strategy
040: */
041: public InheritanceMetaData(AbstractClassMetaData parent,
042: final String strategy) {
043: super (parent);
044:
045: this .strategy = InheritanceStrategy
046: .getInheritanceStrategy(strategy);
047: }
048:
049: /**
050: * Method to initialise the object, creating internal convenience arrays.
051: * Initialises all sub-objects.
052: */
053: public void initialise() {
054: if (joinMetaData != null) {
055: joinMetaData.initialise();
056: }
057:
058: if (discriminatorMetaData != null) {
059: discriminatorMetaData.initialise();
060: }
061:
062: setInitialised();
063: }
064:
065: // ----------------------------- Accessors ---------------------------------
066:
067: /**
068: * Accessor for the strategy tag value
069: * @return strategy tag value
070: */
071: public InheritanceStrategy getStrategyValue() {
072: return strategy;
073: }
074:
075: /**
076: * Accessor for the Join MetaData.
077: * @return Returns the joinMetaData.
078: */
079: public JoinMetaData getJoinMetaData() {
080: return joinMetaData;
081: }
082:
083: /**
084: * Mutator for the Join MetaData.
085: * @param joinMetaData The joinMetaData to set.
086: */
087: public void setJoinMetaData(JoinMetaData joinMetaData) {
088: this .joinMetaData = joinMetaData;
089: if (this .joinMetaData != null) {
090: this .joinMetaData.parent = this ;
091: }
092: }
093:
094: /**
095: * Accessor for the Discrimintor MetaData.
096: * @return Returns the Discrimintor MetaData.
097: */
098: public DiscriminatorMetaData getDiscriminatorMetaData() {
099: return discriminatorMetaData;
100: }
101:
102: /**
103: * Mutator for the Discriminator MetaData.
104: * @param discriminatorMetaData The discriminatorMetaData to set.
105: */
106: public void setDiscriminatorMetaData(
107: DiscriminatorMetaData discriminatorMetaData) {
108: this .discriminatorMetaData = discriminatorMetaData;
109: this .discriminatorMetaData.parent = this ;
110: }
111:
112: // ----------------------------- Utilities ---------------------------------
113:
114: /**
115: * Returns a string representation of the object using a prefix
116: * @param prefix prefix string
117: * @param indent indent string
118: * @return a string representation of the object.
119: */
120: public String toString(String prefix, String indent) {
121: StringBuffer sb = new StringBuffer();
122: sb.append(prefix).append(
123: "<inheritance strategy=\"" + strategy + "\">\n");
124:
125: // Add join
126: if (joinMetaData != null) {
127: sb.append(joinMetaData.toString(prefix + indent, indent));
128: }
129:
130: // Add discriminator
131: if (discriminatorMetaData != null) {
132: sb.append(discriminatorMetaData.toString(prefix + indent,
133: indent));
134: }
135:
136: // Add extensions
137: sb.append(super .toString(prefix + indent, indent));
138:
139: sb.append(prefix).append("</inheritance>\n");
140:
141: return sb.toString();
142: }
143: }
|