001: /**********************************************************************
002: Copyright (c) 2006 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.store;
018:
019: import org.jpox.metadata.AbstractMemberMetaData;
020: import org.jpox.metadata.ClassMetaData;
021: import org.jpox.metadata.MetaData;
022: import org.jpox.util.Localiser;
023:
024: /**
025: * Basic store information about an object that is stored in a datastore.
026: * Can be a class or field.
027: *
028: * @version $Revision: 1.15 $
029: */
030: public class StoreData {
031: /** Localiser for messages. */
032: protected static final Localiser LOCALISER = Localiser
033: .getInstance("org.jpox.store.Localisation");
034:
035: /** First class object (FCO) type */
036: public static final int FCO_TYPE = 1;
037:
038: /** Second class object (SCO) type */
039: public static final int SCO_TYPE = 2;
040:
041: /** Name of the class/field. */
042: protected final String name;
043:
044: /** MetaData for this object. */
045: protected MetaData metadata;
046:
047: /** Type of data being stored (FCO, SCO). */
048: protected final int type;
049:
050: /** If this class is an implementation of a persistent interface, this attribute will hold the name of the interface. */
051: protected final String interfaceName;
052:
053: /**
054: * Constructor.
055: * @param name Name of the class/field
056: * @param metadata MetaData for the class or field (if available)
057: * @param type Type of data (FCO/SCO)
058: * @param interfaceName Name of persistent-interface being implemented
059: */
060: public StoreData(String name, MetaData metadata, int type,
061: String interfaceName) {
062: this .name = name;
063: this .metadata = metadata;
064: this .type = type;
065: this .interfaceName = interfaceName;
066: }
067:
068: /**
069: * Accessor for class/field name.
070: * @return Returns the class/field name.
071: */
072: public String getName() {
073: return name;
074: }
075:
076: /**
077: * Accessor for class/field meta data.
078: * @return Returns the class/field meta data.
079: */
080: public MetaData getMetaData() {
081: return metadata;
082: }
083:
084: /**
085: * Method to set the MetaData for this class.
086: * @param md MetaData
087: */
088: public void setMetaData(MetaData md) {
089: metadata = md;
090: }
091:
092: /**
093: * Accessor for any superclass for this class, if this is a class.
094: * @return The superclass (if exists). If this is a field, just return null.
095: **/
096: public String getSuperclass() {
097: if (metadata instanceof ClassMetaData) {
098: return ((ClassMetaData) metadata)
099: .getPersistenceCapableSuperclass();
100: } else {
101: return null;
102: }
103: }
104:
105: /**
106: * Accessor for whether this represents FCO data
107: * @return Whether it is FCO
108: */
109: public boolean isFCO() {
110: return type == FCO_TYPE;
111: }
112:
113: /**
114: * Accessor for whether this represents SCO data.
115: * @return Whether it is SCO.
116: */
117: public boolean isSCO() {
118: return type == SCO_TYPE;
119: }
120:
121: /**
122: * Accessor for type.
123: * @return Returns the type.
124: */
125: public int getType() {
126: return type;
127: }
128:
129: /**
130: * Accessor for the persistent interface name
131: * @return Returns the persistent interface name
132: */
133: public String getInterfaceName() {
134: return interfaceName;
135: }
136:
137: /**
138: * Method to return this class/field managed object as a string.
139: * @return String version of this class/field managed object.
140: **/
141: public String toString() {
142: if (metadata instanceof ClassMetaData) {
143: ClassMetaData cmd = (ClassMetaData) metadata;
144: return LOCALISER.msg("035002", name, "(none)", cmd
145: .getInheritanceMetaData().getStrategyValue()
146: .toString());
147: } else if (metadata instanceof AbstractMemberMetaData) {
148: return LOCALISER.msg("035003", name, null);
149: } else {
150: return LOCALISER.msg("035002", name, null);
151: }
152: }
153: }
|