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.ObjectManager;
020: import org.jpox.exceptions.JPOXUserException;
021: import org.jpox.metadata.AbstractClassMetaData;
022: import org.jpox.util.Localiser;
023:
024: /**
025: * Abstract representation of a JDO Extent.
026: * Suitable for use with all datastores.
027: *
028: * @version $Revision: 1.5 $
029: */
030: public abstract class AbstractExtent implements org.jpox.store.Extent {
031: /** Localised messages source */
032: protected static final Localiser LOCALISER = Localiser
033: .getInstance("org.jpox.store.Localisation");
034:
035: /** ObjectManager for the Extent. */
036: protected final ObjectManager om;
037:
038: /** The candidate class. We store the class since we need to retain it for class loading. */
039: protected final Class candidateClass;
040:
041: /** Whether to include subclasses. */
042: protected final boolean subclasses;
043:
044: /** ClassMetaData for the candidate class. */
045: protected final AbstractClassMetaData cmd;
046:
047: /** Manager for the Store. */
048: protected final StoreManager storeMgr;
049:
050: /**
051: * Constructor.
052: * @param om Object Manager
053: * @param cls candidate class
054: * @param subclasses Whether to include subclasses
055: * @param cmd MetaData for the candidate class
056: */
057: public AbstractExtent(ObjectManager om, Class cls,
058: boolean subclasses, AbstractClassMetaData cmd) {
059: if (cls == null) {
060: throw new JPOXUserException(LOCALISER.msg("033000"))
061: .setFatal();
062: }
063:
064: // Find the MetaData for this class
065: storeMgr = om.getStoreManager();
066: this .cmd = cmd;
067: if (cmd == null) {
068: throw new JPOXUserException(LOCALISER.msg("033001", cls
069: .getName())).setFatal();
070: }
071:
072: this .om = om;
073: this .candidateClass = cls;
074: this .subclasses = subclasses;
075: }
076:
077: /**
078: * Returns whether this Extent was defined to contain subclasses.
079: * @return true if this Extent was defined to include subclasses.
080: */
081: public boolean hasSubclasses() {
082: return subclasses;
083: }
084:
085: /**
086: * Accessor for the class of instances in this Extent.
087: * @return the Class of instances of this Extent
088: */
089: public Class getCandidateClass() {
090: return candidateClass;
091: }
092:
093: /**
094: * Accessor for the owning PersistenceManager.
095: * @return the owning PersistenceManager
096: */
097: public ObjectManager getObjectManager() {
098: // TODO Relies on ObjectManager being a PersistenceManager!
099: return om;
100: }
101:
102: /**
103: * Stringifier method.
104: * @return Stringified form of this object
105: */
106: public String toString() {
107: return LOCALISER.msg("033002", candidateClass.getName(), ""
108: + subclasses);
109: }
110: }
|