org.apache.jdo.impl.enhancer.meta.prop
Class MetaDataProperties

java.lang.Object
  extended byorg.apache.jdo.impl.enhancer.meta.prop.MetaDataProperties

final class MetaDataProperties
extends java.lang.Object

This class parses properties containing meta data information about classes. The syntax of the properties is the following:

This class is not thread safe.


Nested Class Summary
private static interface MetaDataProperties.Msg
          Holds all unformatted error messages.
private static class MetaDataProperties.Property
          The holder-class for the name and the value of a property.
 
Field Summary
(package private) static java.lang.String ACCESS_PACKAGE_LOCAL
           
(package private) static java.lang.String ACCESS_PRIVATE
           
(package private) static java.lang.String ACCESS_PROTECTED
           
(package private) static java.lang.String ACCESS_PUBLIC
           
(package private) static java.lang.String ANNOTATION_TYPE_DFG
           
(package private) static java.lang.String ANNOTATION_TYPE_KEY
           
(package private) static java.lang.String ANNOTATION_TYPE_MEDIATED
           
private  java.util.Map cachedJDOClasses
          A map of already read class properties.
(package private) static char FIELD_DELIMITER
          The delimiter of a property key between the class- and fieldname.
(package private) static java.lang.String JDO_PERSISTENT
           
(package private) static java.lang.String JDO_TRANSACTIONAL
           
(package private) static java.lang.String JDO_TRANSIENT
           
private static JDOClass NULL
          A constant for the cache indicating that a given classname if not specified in the properties.
private  java.util.Properties properties
          The properties to parse.
(package private) static java.lang.String PROPERTY_ACCESS_MODIFIER
           
(package private) static java.lang.String PROPERTY_ANNOTATION_TYPE
           
(package private) static char PROPERTY_ASSIGNER
          A delimiter character between attribute name and attribute value
(package private) static java.lang.String PROPERTY_DELIMITERS
          A string of delimiter characters between attributes.
(package private) static java.lang.String PROPERTY_JDO_MODIFIER
           
(package private) static java.lang.String PROPERTY_OID_CLASSNAME
           
(package private) static java.lang.String PROPERTY_SUPER_CLASSNAME
           
(package private) static java.lang.String PROPERTY_TYPE
           
private  java.util.List tmpTokens
          A temporary vector (this is the reason why the implementation is not thread safe).
 
Constructor Summary
MetaDataProperties(java.util.Properties props)
          Creates a new object with the given properties.
 
Method Summary
private static void checkForDuplicateProperties(java.util.List props, java.lang.String entry)
          Checks if an attribute-property was entered twice for a class or field.
private static void checkPropertyName(java.lang.String name, java.lang.String[] validnames, java.lang.String entry)
          Checks if an attribute name is recognized by the parser.
private static void checkPropertyValue(MetaDataProperties.Property prop, java.lang.String[] validvalues, java.lang.String name, java.lang.String entry)
          Checks if the given value of an attribute-property is recognized by by the parser if that value belongs to a given attribute name.
 JDOClass getJDOClass(java.lang.String classname)
          Get the information about the class with the given name.
 JDOField getJDOField(java.lang.String fieldname, java.lang.String classname)
          Gets the information about the specified field.
 java.lang.String[] getKnownClassNames()
          Gets all classnames in the properties.
private static int getModifiers(java.lang.String modifier)
          Returns the modifier value for a Java modifier name.
(package private) static java.lang.String getMsg(java.lang.String msg, java.lang.String[] params)
          Formats an error message with the given parameters.
static void main(java.lang.String[] argv)
          A simple test to run from the command line.
private  JDOClass parseJDOClass(java.lang.String classname, java.lang.String attributes)
          Parses the attributes-string of a class and puts them into a JDOClass-object.
private  JDOField parseJDOField(java.lang.String attributes, java.lang.String fieldname, JDOClass clazz)
          Parses the attribute-string of a field.
private  void parseJDOFields(JDOClass clazz)
          Parses all fields of a given class.
(package private)  java.util.List parseProperties(java.lang.String attributes)
          Parses the attribute-string of a class- or fieldname.
private  MetaDataProperties.Property parseProperty(java.lang.String attribute)
          Parses the given attribute and splits it into name and value.
private static void validateClassProperty(MetaDataProperties.Property prop, java.lang.String classname)
          Checks if the given attribute-property of a class is valid.
private  void validateDependencies(JDOClass clazz)
          Validates dependencies between a class and its fields and between.
private static void validateFieldName(java.lang.String fieldname, java.lang.String classname)
          Checks if a given fieldname is a valid Java identifier.
private  void validateFieldProperty(MetaDataProperties.Property prop, java.lang.String fieldname, java.lang.String classname)
          Checks if the given attribute-property if valid for a field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELD_DELIMITER

static final char FIELD_DELIMITER
The delimiter of a property key between the class- and fieldname.

See Also:
Constant Field Values

PROPERTY_DELIMITERS

static final java.lang.String PROPERTY_DELIMITERS
A string of delimiter characters between attributes.

See Also:
Constant Field Values

PROPERTY_ASSIGNER

static final char PROPERTY_ASSIGNER
A delimiter character between attribute name and attribute value

See Also:
Constant Field Values

PROPERTY_ACCESS_MODIFIER

static final java.lang.String PROPERTY_ACCESS_MODIFIER
See Also:
Constant Field Values

PROPERTY_JDO_MODIFIER

static final java.lang.String PROPERTY_JDO_MODIFIER
See Also:
Constant Field Values

PROPERTY_SUPER_CLASSNAME

static final java.lang.String PROPERTY_SUPER_CLASSNAME
See Also:
Constant Field Values

PROPERTY_OID_CLASSNAME

static final java.lang.String PROPERTY_OID_CLASSNAME
See Also:
Constant Field Values

PROPERTY_TYPE

static final java.lang.String PROPERTY_TYPE
See Also:
Constant Field Values

PROPERTY_ANNOTATION_TYPE

static final java.lang.String PROPERTY_ANNOTATION_TYPE
See Also:
Constant Field Values

ACCESS_PRIVATE

static final java.lang.String ACCESS_PRIVATE
See Also:
Constant Field Values

ACCESS_PACKAGE_LOCAL

static final java.lang.String ACCESS_PACKAGE_LOCAL
See Also:
Constant Field Values

ACCESS_PROTECTED

static final java.lang.String ACCESS_PROTECTED
See Also:
Constant Field Values

ACCESS_PUBLIC

static final java.lang.String ACCESS_PUBLIC
See Also:
Constant Field Values

JDO_TRANSIENT

static final java.lang.String JDO_TRANSIENT
See Also:
Constant Field Values

JDO_PERSISTENT

static final java.lang.String JDO_PERSISTENT
See Also:
Constant Field Values

JDO_TRANSACTIONAL

static final java.lang.String JDO_TRANSACTIONAL
See Also:
Constant Field Values

ANNOTATION_TYPE_KEY

static final java.lang.String ANNOTATION_TYPE_KEY
See Also:
Constant Field Values

ANNOTATION_TYPE_DFG

static final java.lang.String ANNOTATION_TYPE_DFG
See Also:
Constant Field Values

ANNOTATION_TYPE_MEDIATED

static final java.lang.String ANNOTATION_TYPE_MEDIATED
See Also:
Constant Field Values

properties

private java.util.Properties properties
The properties to parse.


cachedJDOClasses

private final java.util.Map cachedJDOClasses
A map of already read class properties. The keys are the classnames, the values are the appropriate JDOClass-object.


NULL

private static final JDOClass NULL
A constant for the cache indicating that a given classname if not specified in the properties.


tmpTokens

private final java.util.List tmpTokens
A temporary vector (this is the reason why the implementation is not thread safe).

Constructor Detail

MetaDataProperties

public MetaDataProperties(java.util.Properties props)
Creates a new object with the given properties.

Parameters:
props - The properties.
Method Detail

getJDOClass

public final JDOClass getJDOClass(java.lang.String classname)
                           throws EnhancerMetaDataUserException
Get the information about the class with the given name.

Parameters:
classname - The classname.
Returns:
The information about the class or null if no information is given.
Throws:
EnhancerMetaDataUserException - If something went wrong parsing the properties.

getJDOField

public final JDOField getJDOField(java.lang.String fieldname,
                                  java.lang.String classname)
                           throws EnhancerMetaDataUserException
Gets the information about the specified field.

Parameters:
classname - The name of the class.
fieldname - The name of the field of the class.
Returns:
The information about the field or null if no information could be found.
Throws:
EnhancerMetaDataUserException - If something went wrong parsing the properties.

getKnownClassNames

public final java.lang.String[] getKnownClassNames()
Gets all classnames in the properties.

Returns:
All classnames in the properties.

parseJDOClass

private final JDOClass parseJDOClass(java.lang.String classname,
                                     java.lang.String attributes)
                              throws EnhancerMetaDataUserException
Parses the attributes-string of a class and puts them into a JDOClass-object.

Parameters:
classname - The name of the class.
attributes - The attribute-string as specified in the properties.
Returns:
The create JDOClass-object.
Throws:
EnhancerMetaDataUserException - If something went wrong parsing the attributes.

validateClassProperty

private static void validateClassProperty(MetaDataProperties.Property prop,
                                          java.lang.String classname)
                                   throws EnhancerMetaDataUserException
Checks if the given attribute-property of a class is valid.

Parameters:
prop - The attribute-property.
classname - The classname.
Throws:
EnhancerMetaDataUserException - If the validation failed.

parseJDOFields

private final void parseJDOFields(JDOClass clazz)
                           throws EnhancerMetaDataUserException
Parses all fields of a given class.

Parameters:
clazz - the representation of the class
Throws:
EnhancerMetaDataUserException - on parse errors

parseJDOField

private final JDOField parseJDOField(java.lang.String attributes,
                                     java.lang.String fieldname,
                                     JDOClass clazz)
                              throws EnhancerMetaDataUserException
Parses the attribute-string of a field.

Parameters:
attributes - The attribute-string.
fieldname - The fieldname.
clazz - The class to field belongs to.
Throws:
EnhancerMetaDataUserException - on parse errors

validateFieldProperty

private final void validateFieldProperty(MetaDataProperties.Property prop,
                                         java.lang.String fieldname,
                                         java.lang.String classname)
                                  throws EnhancerMetaDataUserException
Checks if the given attribute-property if valid for a field.

Parameters:
prop - The attribute-property.
fieldname - The fieldname.
classname - The classname.
Throws:
EnhancerMetaDataUserException - If the check fails.

validateDependencies

private final void validateDependencies(JDOClass clazz)
                                 throws EnhancerMetaDataUserException
Validates dependencies between a class and its fields and between.

Parameters:
clazz - the class
Throws:
EnhancerMetaDataUserException - if the validation fails

validateFieldName

private static void validateFieldName(java.lang.String fieldname,
                                      java.lang.String classname)
                               throws EnhancerMetaDataUserException
Checks if a given fieldname is a valid Java identifier.

Parameters:
fieldname - The fieldname.
classname - The corresponding classname.
Throws:
EnhancerMetaDataUserException - If the check fails.

checkForDuplicateProperties

private static void checkForDuplicateProperties(java.util.List props,
                                                java.lang.String entry)
                                         throws EnhancerMetaDataUserException
Checks if an attribute-property was entered twice for a class or field.

Parameters:
props - The properties.
entry - The class- or fieldname.
Throws:
EnhancerMetaDataUserException - If the check fails.

checkPropertyName

private static void checkPropertyName(java.lang.String name,
                                      java.lang.String[] validnames,
                                      java.lang.String entry)
                               throws EnhancerMetaDataUserException
Checks if an attribute name is recognized by the parser.

Parameters:
name - The name of the attribute.
validnames - A list of valid names(the attribute name has to be in this list).
entry - The class- or fieldname.
Throws:
EnhancerMetaDataUserException - If the check fails.

checkPropertyValue

private static void checkPropertyValue(MetaDataProperties.Property prop,
                                       java.lang.String[] validvalues,
                                       java.lang.String name,
                                       java.lang.String entry)
                                throws EnhancerMetaDataUserException
Checks if the given value of an attribute-property is recognized by by the parser if that value belongs to a given attribute name.

Parameters:
prop - The attribute-property(with name and value).
validvalues - A list of valid values.
name - The name of the attribute-property to check.
entry - The class- or fieldname.
Throws:
EnhancerMetaDataUserException - If the check fails.

getMsg

static final java.lang.String getMsg(java.lang.String msg,
                                     java.lang.String[] params)
Formats an error message with the given parameters.

Parameters:
msg - The message with format strings.
params - The params to format the message with.
Returns:
The formatted error message.

parseProperties

final java.util.List parseProperties(java.lang.String attributes)
                              throws EnhancerMetaDataUserException
Parses the attribute-string of a class- or fieldname.

Parameters:
attributes - The attribute-string.
Returns:
A list of Propert<-objects for the attributes.
Throws:
EnhancerMetaDataUserException - If the parsing fails.

parseProperty

private final MetaDataProperties.Property parseProperty(java.lang.String attribute)
                                                 throws EnhancerMetaDataUserException
Parses the given attribute and splits it into name and value.

Parameters:
attribute - The attribute-string.
Returns:
The Propert-object.
Throws:
EnhancerMetaDataUserException - If the parsing fails.

getModifiers

private static int getModifiers(java.lang.String modifier)
Returns the modifier value for a Java modifier name.


main

public static void main(java.lang.String[] argv)
A simple test to run from the command line.

Parameters:
argv - The command line arguments.