|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jpox.metadata.MetaDataManager
Manager of MetaData information in JPOX.
Acts as a registry of JDO metadata so that metadata files don't need to be parsed multiple times. MetaData is stored as a FileMetaData, which contains PackageMetaData, which contains ClassMetaData, and so on. This maps exactly to the users model of their metadata. The users access point is getMetaDataForClass() which will check the known classes without metadata, then check the existing registered metdata, then check the valid locations for metdata files. This way, the metadata is managed from this single point.
When the MetaData is requested for a class, if it isnt already found, the valid file locations are checked for that class and the file containing it will be read. The MetaData for all classes, queries, sequences etc in that file are loaded at that point. In addition, all classes will be "populated" (meaning that their superclasses are assigned, and unspecified fields are added, and any related objects are linked). The MetaData of these classes are only initialised when they are absolutely needed - to avoid generating circular references in the initialisation process.
Maintains a list of all classes that have been checked for MetaData and don't have any available. This avoids the needs to look up MetaData multiple times finding the same result. Currently this list is for all ClassMetaData objects keyed by the class name. If necessary we could store them keyed by file name, but not currently necessary.
Each PMFContext typically will have its own MetaDataManager so allowing Meta-Data to be for different datastores. In addition, each PMF can allow MetaData files to use a particular suffix, hence we allow the JDO/ORM file suffices to be specifiable at construction.
TODO Add a cache of MetaDataManagers and add a check of the other managers when a class is required and we don't have the file (to save the parse).
Field Summary | |
static int |
ALL_JDO_LOCATIONS
MetaData files will be searched in all possible locations defined in JDO 1.0, JDO 1.0.1, JDO 2.0 or later |
protected java.util.Collection |
classesWithoutMetaData
Classes without MetaData. |
protected java.util.Map |
classMetaDataByClass
Map of ClassMetaData, keyed by the class name. |
protected java.util.Map |
classMetaDataByInterface
Map of ClassMetaData, keyed by the interface class name. |
protected java.lang.String |
defaultInheritanceStrategy
Default for the inheritance strategy to use. |
protected boolean |
enhancing
Indicator for whether this manager is managing the enhancement process, else it's runtime. |
protected java.util.Map |
fileMetaDataByURL
MetaData for the files parsed, keyed by the URL. |
static int |
JDO_1_0_0_LOCATIONS
MetaData files will be searched in all locations defined in JDO 1.0 |
static int |
JDO_1_0_1_LOCATIONS
MetaData files will be searched in all locations defined in JDO 1.0.1 |
protected java.lang.String |
jdoFileSuffix
Suffix for JDO MetaData files. |
protected java.lang.String |
jdoqueryFileSuffix
Suffix for query MetaData files. |
protected int |
locationDefinition
Definition of which locations we accept for MetaData files. |
protected java.util.Map |
ormClassMetaDataByClass
Map of ClassMetaData from ORM files, keyed by the class name. |
protected java.lang.String |
ormFileSuffix
Suffix for ORM MetaData files. |
protected java.lang.String |
ormMappingName
Name for the ORM mapping (used to define the filename of the ORM files). |
protected PMFContext |
pmfContext
The PMF Context that this metadata manager is operating in. |
protected java.util.Map |
queryMetaDataByName
Map of QueryMetaData, keyed by the (class name + query name). |
protected java.util.Map |
sequenceMetaDataByPackageSequence
Map of SequenceMetaData, keyed by the package name and sequence name. |
protected boolean |
validateMetaData
Flag whether we should validate the metadata files. |
Constructor Summary | |
MetaDataManager(PMFContext pmfContext)
Constructor, allowing specification of the suffix used for JDO files. |
Method Summary | |
protected void |
addClassWithoutMetaData(java.lang.String class_name)
Method to add a class that doesn't have MetaData. |
void |
addORMDataToClass(java.lang.Class c,
ClassLoaderResolver clr)
Load up and add the O/R mapping info for the specified class to the stored JDO ClassMetaData. |
void |
close()
Clear resources |
java.lang.String[] |
getClassesImplementingInterface(java.lang.String interfaceName,
ClassLoaderResolver clr)
Accessor for the list of names of classes that are declared to implement the specified interface (using <implements> in the MetaData). |
java.lang.String |
getDefaultInheritanceStrategy()
Accessor for the default inheritance strategy to use. |
java.lang.String |
getJdoFileSuffix()
Accessor for the suffix used when looking for JDO MetaData files. |
java.lang.String |
getJdoqueryFileSuffix()
Accessor for the suffix used when looking for Query MetaData files. |
AbstractClassMetaData |
getMetaDataForClass(java.lang.Class c,
ClassLoaderResolver clr)
Accessor for the MetaData for a class. |
AbstractClassMetaData |
getMetaDataForClass(java.lang.String class_name,
ClassLoaderResolver clr)
Accessor for the MetaData for a class given the name and a loader. |
protected AbstractClassMetaData |
getMetaDataForClassOrInterface(java.lang.Class c,
ClassLoaderResolver clr)
Accessor for the MetaData for a class. |
AbstractPropertyMetaData |
getMetaDataForField(java.lang.Class c,
ClassLoaderResolver clr,
java.lang.String field_name)
Accessor for the MetaData for a field of a class. |
AbstractPropertyMetaData |
getMetaDataForField(java.lang.String class_name,
java.lang.String field_name,
ClassLoaderResolver clr)
Accessor for the MetaData for a field of a class. |
ClassMetaData |
getMetaDataForImplementationOfReference(java.lang.Class referenceClass,
java.lang.Object implValue,
ClassLoaderResolver clr)
Accessor for the MetaData for an implementation of a reference type. |
InterfaceMetaData |
getMetaDataForInterface(java.lang.Class c,
ClassLoaderResolver clr)
Accessor for the MetaData for an interface. |
QueryMetaData |
getMetaDataForQuery(java.lang.Class cls,
ClassLoaderResolver clr,
java.lang.String queryName)
Accessor for the MetaData for a named query for a class. |
SequenceMetaData |
getMetaDataForSequence(ClassLoaderResolver clr,
java.lang.String packageSequenceName)
Accessor for the MetaData for a Sequence in a package. |
java.lang.String |
getOrmFileSuffix()
Accessor for the suffix used when looking for ORM MetaData files. |
PMFContext |
getPMFContext()
Accessor for the PMF Context that this manager is running in. |
java.util.List |
getReferencedClassMetaData(AbstractClassMetaData cmd,
java.lang.String dba_vendor_id,
ClassLoaderResolver clr)
Utility to return all ClassMetaData that is referenced from the supplier class. |
java.lang.String[] |
getSubclassesForClass(java.lang.String className,
boolean includeDescendents)
Accessor for the subclasses of a particular class |
boolean |
hasMetaDataForClass(java.lang.String class_name)
Convenience method to check if the metadataq for the specified class is already registered. |
protected void |
initialiseClassMetaData(ClassMetaData cmd,
java.lang.Class cls,
ClassLoaderResolver clr)
Utility to initialise the MetaData for a class, using the specified class. |
protected void |
initialiseInterfaceMetaData(InterfaceMetaData imd,
ClassLoaderResolver clr)
Utility to initialise the MetaData for a interface, using the specified class. |
protected void |
initialiseMetaDataFileSuffixes(java.lang.String jdo_file_suffix,
java.lang.String orm_file_suffix,
java.lang.String orm_mapping_name,
java.lang.String jdoquery_file_suffix)
Initialise suffixes that will be in the search path |
protected boolean |
isClassWithoutMetaData(java.lang.String class_name)
Accessor for whether a class doesn't have MetaData. |
boolean |
isEnhancing()
Accessor for whether we are managing the enhancement process. |
boolean |
isPersistentInterface(java.lang.String name)
Convenience method to return if the passed class name is a "persistent-interface". |
boolean |
isPersistentInterfaceImplementation(java.lang.String interfaceName,
java.lang.String implName)
Convenience method to return if the passed class name is an implementation of the passed "persistent-interface". |
protected FileMetaData |
loadMetaDataForClass(java.lang.Class pc_class,
ClassLoaderResolver clr,
java.lang.String metadata_file_modifier,
java.lang.String metadata_file_extension,
boolean populate)
Method to find the Meta-Data file for a specified class. |
protected FileMetaData |
parseFile(java.net.URL file_url,
boolean validate)
Utility to parse a file. |
protected void |
populateClassesInterfacesInFile(FileMetaData filemd,
ClassLoaderResolver clr)
Convenience method to populate all classes in a Meta-Data file. |
ClassMetaData |
readMetaDataForClass(java.lang.String className)
Method to access the (already known) metadata for the specified class. |
AbstractPropertyMetaData |
readMetaDataForField(java.lang.String className,
java.lang.String fieldName)
Method to access the (already known) metadata for the field of the specified class. |
protected void |
registerFile(java.net.URL file_url,
FileMetaData filemd)
Method to take the FileMetaData and register the relevant parts of it with the various convenience collections/maps that we use for access. |
void |
registerPersistentInterface(InterfaceMetaData imd,
java.lang.Class implClass,
ClassLoaderResolver clr)
Method to register a persistent interface and its implementation with the MetaData system. |
protected void |
registerQueriesForFile(FileMetaData filemd)
Convenience method to register all queries found in the passed file. |
protected void |
registerSequencesForFile(FileMetaData filemd)
Convenience method to register all sequences found in the passed file. |
void |
setLocationDefinition(int definition)
Mutator for the definition of locations of MetaData accepted. |
void |
setValidate(boolean validate)
Mutator for whether to validate the MetaData files for XML compliance. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int ALL_JDO_LOCATIONS
public static final int JDO_1_0_0_LOCATIONS
public static final int JDO_1_0_1_LOCATIONS
protected PMFContext pmfContext
protected int locationDefinition
protected boolean validateMetaData
protected java.lang.String jdoFileSuffix
protected java.lang.String ormFileSuffix
protected java.lang.String jdoqueryFileSuffix
protected java.lang.String ormMappingName
protected java.lang.String defaultInheritanceStrategy
protected java.util.Map classMetaDataByClass
protected java.util.Map queryMetaDataByName
protected java.util.Map classMetaDataByInterface
protected java.util.Map sequenceMetaDataByPackageSequence
protected java.util.Map ormClassMetaDataByClass
protected java.util.Collection classesWithoutMetaData
protected java.util.Map fileMetaDataByURL
protected boolean enhancing
Constructor Detail |
public MetaDataManager(PMFContext pmfContext)
pmfContext
- PMF Context that this metadata manager operates inMethod Detail |
public void setValidate(boolean validate)
validate
- Whether to validatepublic PMFContext getPMFContext()
protected void initialiseMetaDataFileSuffixes(java.lang.String jdo_file_suffix, java.lang.String orm_file_suffix, java.lang.String orm_mapping_name, java.lang.String jdoquery_file_suffix)
jdo_file_suffix
- Suffix to be used on all JDO MetaData files.orm_file_suffix
- Suffix to be used on all ORM MetaData files.orm_mapping_name
- Name of the ORM mappingjdoquery_file_suffix
- Suffix to be used on all JDOQuery MetaData files.public void close()
public void setLocationDefinition(int definition)
definition
- The definitionpublic boolean isEnhancing()
public java.lang.String getJdoFileSuffix()
public java.lang.String getOrmFileSuffix()
public java.lang.String getJdoqueryFileSuffix()
public java.lang.String getDefaultInheritanceStrategy()
public boolean hasMetaDataForClass(java.lang.String class_name)
class_name
- The name of the class to check
public AbstractClassMetaData getMetaDataForClass(java.lang.String class_name, ClassLoaderResolver clr)
class_name
- Name of the class to find MetaData forclr
- ClassLoaderResolver resolver for use in loading the class.
public AbstractClassMetaData getMetaDataForClass(java.lang.Class c, ClassLoaderResolver clr)
c
- The class to find MetaData forclr
- the ClassLoaderResolver
public InterfaceMetaData getMetaDataForInterface(java.lang.Class c, ClassLoaderResolver clr)
c
- The interface to find MetaData forclr
- the ClassLoaderResolver
public ClassMetaData readMetaDataForClass(java.lang.String className)
className
- Name of the class
public AbstractPropertyMetaData readMetaDataForField(java.lang.String className, java.lang.String fieldName)
className
- Name of the classfieldName
- Name of the field
protected AbstractClassMetaData getMetaDataForClassOrInterface(java.lang.Class c, ClassLoaderResolver clr)
c
- The class to find MetaData for
public java.lang.String[] getSubclassesForClass(java.lang.String className, boolean includeDescendents)
className
- Name of the class that we want the known subclasses for.includeDescendents
- Whether to include subclasses of subclasses etc
public java.lang.String[] getClassesImplementingInterface(java.lang.String interfaceName, ClassLoaderResolver clr)
interfaceName
- Name of the interfaceclr
- The ClassLoaderResolver
public void addORMDataToClass(java.lang.Class c, ClassLoaderResolver clr)
c
- The classclr
- the ClassLoaderResolverpublic ClassMetaData getMetaDataForImplementationOfReference(java.lang.Class referenceClass, java.lang.Object implValue, ClassLoaderResolver clr)
referenceClass
- The reference class to find MetaData forimplValue
- Object of an implementation class, to return if possible (null=ignore)
public AbstractPropertyMetaData getMetaDataForField(java.lang.String class_name, java.lang.String field_name, ClassLoaderResolver clr)
class_name
- The name of the class owning the fieldfield_name
- The name of the field to find MetaData forclr
- ClassLoaderResolver resolver for any loading of classes
public AbstractPropertyMetaData getMetaDataForField(java.lang.Class c, ClassLoaderResolver clr, java.lang.String field_name)
c
- The class owning the fieldclr
- the ClassLoaderResolverfield_name
- The name of the field to find MetaData for
public QueryMetaData getMetaDataForQuery(java.lang.Class cls, ClassLoaderResolver clr, java.lang.String queryName)
cls
- The class which has the query defined for itclr
- the ClassLoaderResolverqueryName
- Name of the query
public boolean isPersistentInterface(java.lang.String name)
name
- Name if the interface
public boolean isPersistentInterfaceImplementation(java.lang.String interfaceName, java.lang.String implName)
interfaceName
- Name of the persistent interfaceimplName
- The implementation name
public void registerPersistentInterface(InterfaceMetaData imd, java.lang.Class implClass, ClassLoaderResolver clr)
imd
- MetaData for the interfaceimplClass
- The implementation classclr
- ClassLoader Resolver to usepublic SequenceMetaData getMetaDataForSequence(ClassLoaderResolver clr, java.lang.String packageSequenceName)
clr
- the ClassLoaderResolverpackageSequenceName
- Fully qualified name of the sequence (inc package name)
protected void initialiseClassMetaData(ClassMetaData cmd, java.lang.Class cls, ClassLoaderResolver clr)
cmd
- The classes metadatacls
- The class to use as a basis for initialisationprotected void initialiseInterfaceMetaData(InterfaceMetaData imd, ClassLoaderResolver clr)
imd
- The interface metadataclr
- The loader of the interfaceprotected boolean isClassWithoutMetaData(java.lang.String class_name)
class_name
- Name of the class
protected void addClassWithoutMetaData(java.lang.String class_name)
class_name
- Name of class that has no metadata.protected FileMetaData parseFile(java.net.URL file_url, boolean validate)
file_url
- URL of the filevalidate
- Whether to validate the file
protected void registerSequencesForFile(FileMetaData filemd)
filemd
- MetaData for the fileprotected void registerQueriesForFile(FileMetaData filemd)
filemd
- MetaData for the fileprotected void populateClassesInterfacesInFile(FileMetaData filemd, ClassLoaderResolver clr)
filemd
- The MetaData fileclr
- Class Loader to use in populationprotected void registerFile(java.net.URL file_url, FileMetaData filemd)
file_url
- URL of the metadata filefilemd
- The File MetaDataprotected FileMetaData loadMetaDataForClass(java.lang.Class pc_class, ClassLoaderResolver clr, java.lang.String metadata_file_modifier, java.lang.String metadata_file_extension, boolean populate)
Allows 2 variations on the naming above. The first is a modifier which caters for a JDO 2.0 requirement whereby the user can specify a modifier such as "mysql", which would mean that this should search for filenames "package-mysql.jdo". The second variation is the suffix of the file. This is "jdo" by default, but JDO 2.0 has situations where "orm", or "jdoquery" are required as a suffix.
pc_class
- The class/interface to retrieve the Meta-Data file forclr
- the ClassLoaderResolvermetadata_file_modifier
- Any modifier for the filenamemetadata_file_extension
- File extension of MetaData files (e.g "jdo")populate
- Whether to populate any loaded MetaData classes
public java.util.List getReferencedClassMetaData(AbstractClassMetaData cmd, java.lang.String dba_vendor_id, ClassLoaderResolver clr)
cmd
- The origin class's MetaData.dba_vendor_id
- The Vendor id of the database adapter in use.
(Used in handling "views" support)clr
- ClassLoaderResolver resolver for loading any classes.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |