FileDocCategorySizeDatePackage
MetadataAccessor.javaAPI DocGlassfish v2 API21571Tue May 22 16:54:26 BST 2007oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors

MetadataAccessor

public abstract class MetadataAccessor extends Object
Top level metatata accessor.
author
Guy Pelletier
since
TopLink EJB 3.0 Reference Implementation

Fields Summary
private boolean
m_isProcessed
private Boolean
m_isRelationship
protected MetadataLogger
m_logger
protected MetadataProject
m_project
protected MetadataProcessor
m_processor
protected MetadataValidator
m_validator
protected MetadataDescriptor
m_descriptor
protected MetadataAccessibleObject
m_accessibleObject
Constructors Summary
public MetadataAccessor(MetadataAccessibleObject accessibleObject, ClassAccessor classAccessor)
INTERNAL:

        this(accessibleObject, classAccessor.getProcessor(), classAccessor.getDescriptor());
    
public MetadataAccessor(MetadataAccessibleObject accessibleObject, MetadataProcessor processor, MetadataDescriptor descriptor)
INTERNAL:

        m_isProcessed = false;
        
        m_processor = processor;
        m_descriptor = descriptor;
        m_logger = processor.getLogger();
        m_project = processor.getProject();
        m_validator = processor.getValidator();
        
        m_accessibleObject = accessibleObject;
    
Methods Summary
public java.lang.reflect.AnnotatedElementgetAnnotatedElement()
INTERNAL: Return the annotated element for this accessor.

        return m_accessibleObject.getAnnotatedElement();
    
protected TgetAnnotation(java.lang.Class annotation)
INTERNAL: Return the annotated element for this accessor.

        return (T) getAnnotation(annotation, getAnnotatedElement());
    
protected TgetAnnotation(java.lang.Class annotation, java.lang.reflect.AnnotatedElement annotatedElement)
INTERNAL: Return the annotated element for this accessor.

        return (T) MetadataHelper.getAnnotation(annotation, annotatedElement, m_descriptor);
    
public java.lang.StringgetAttributeName()
INTERNAL: Return the attribute name for this accessor.

        return m_accessibleObject.getAttributeName();
    
public oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptorgetDescriptor()
INTERNAL: Return the MetadataDescriptor for this accessor.

        return m_descriptor;
    
public java.lang.StringgetFetchType()
INTERNAL: Subclasses that support processing a fetch type should override this method, otherwise a runtime development exception is thrown for those accessors who call this method and don't implement it themselves.

        throw new RuntimeException("Development exception. The accessor: [" + this + "] should not call the getFetchType method unless it overrides it.");
    
public java.lang.ClassgetJavaClass()
INTERNAL: (Overridden in ClassAccessor) Return the java class associated with this accessor's descriptor.

        return m_descriptor.getJavaClass();
    
protected java.lang.StringgetJavaClassName()
INTERNAL: Return the java class that defines this accessor.

        return getJavaClass().getName();
    
public oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataLoggergetLogger()
INTERNAL: Return the metadata validator.

        return m_logger;
    
protected java.lang.ClassgetMapKeyClass()
INTERNAL: Return the map key class from a generic Map type. If it is not generic, then null is returned.

        return m_accessibleObject.getMapKeyClass();
    
public java.lang.StringgetName()
INTERNAL: Returns the name of this accessor. If it is a field, it will return the field name. For a method it will return the method name.

        return m_accessibleObject.getName();
    
protected java.lang.StringgetName(oracle.toplink.essentials.internal.helper.DatabaseField field, java.lang.String defaultName, java.lang.String context)
INTERNAL: Helper method to return a field name from a candidate field name and a default field name. Requires the context from where this method is called to output the correct logging message when defaulting the field name.

        return getName(field.getName(), defaultName, context);
    
protected java.lang.StringgetName(java.lang.String name, java.lang.String defaultName, java.lang.String context)
INTERNAL: Helper method to return a field name from a candidate field name and a default field name. Requires the context from where this method is called to output the correct logging message when defaulting the field name. In some cases, both the name and defaultName could be "" or null, therefore, don't log any message and return name.

        // Check if a candidate was specified otherwise use the default.
        if (name != null && !name.equals("")) {
            return name;
        } else if (defaultName == null || defaultName.equals("")) {
            return "";
        } else {
            // Log the defaulting field name based on the given context.
            m_logger.logConfigMessage(context, getAnnotatedElement(), defaultName);
            return defaultName;
        }
	
protected oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataPrimaryKeyJoinColumnsgetPrimaryKeyJoinColumns(java.lang.String sourceTableName, java.lang.String targetTableName)
INTERNAL: (Overridden in XMLClassAccessor and XMLOneToOneAccessor) Process the @PrimaryKeyJoinColumns and @PrimaryKeyJoinColumn.

        PrimaryKeyJoinColumn primaryKeyJoinColumn = getAnnotation(PrimaryKeyJoinColumn.class);
        PrimaryKeyJoinColumns primaryKeyJoinColumns = getAnnotation(PrimaryKeyJoinColumns.class);
        
        return new MetadataPrimaryKeyJoinColumns(primaryKeyJoinColumns, primaryKeyJoinColumn, sourceTableName, targetTableName);
    
public oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessorgetProcessor()
INTERNAL: Return the MetadataProcessor.

        return m_processor;
    
public oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProjectgetProject()
INTERNAL: Return the MetadataProject.

        return m_project;
    
public java.lang.ClassgetRawClass()
INTERNAL: Return the raw class for this accessor. Eg. For an accessor with a type of java.util.Collection, this method will return java.util.Collection

        return m_accessibleObject.getRawClass();   
    
public java.lang.ClassgetReferenceClass()
INTERNAL: (Overridden in CollectionAccessor and ObjectAccessor) Return the reference class for this accessor. By default the reference class is the raw class. Some accessors, namely relationship accessors, will need to override this behavior to extract a reference class from generics or a target entity specification.

        return m_accessibleObject.getRawClass();
    
public java.lang.StringgetReferenceClassName()
INTERNAL: Return the reference class name for this accessor.

        return getReferenceClass().getName();
    
public oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptorgetReferenceDescriptor()
INTERNAL: Return the reference metadata descriptor for this accessor.

        return m_project.getDescriptor(getReferenceClass());
    
protected java.lang.reflect.TypegetRelationType()
INTERNAL: Return the relation type of this accessor.

        return m_accessibleObject.getRelationType();
    
protected java.lang.StringgetSetMethodName()
INTERNAL: Returns the set method name of a method accessor. Note, this method should not be called when processing field access.

        return ((MetadataMethod) m_accessibleObject).getSetMethodName();
    
protected java.lang.StringgetUpperCaseAttributeName()
INTERNAL: Return the upper cased attribute name for this accessor. Used when defaulting.

        return getAttributeName().toUpperCase();
    
protected java.lang.StringgetUpperCaseShortJavaClassName()
INTERNAL: Return the upper case java class that defines this accessor.

        return Helper.getShortClassName(getJavaClassName()).toUpperCase();
    
public oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataValidatorgetValidator()
INTERNAL: Return the metadata validator.

        return m_validator;
    
protected booleanhasColumn()
INTERNAL: Method to check if an annotated element has a @Column.

		return isAnnotationPresent(Column.class);
    
protected booleanhasPrimaryKeyJoinColumns()
INTERNAL: Method to check if this accessor has @PrimaryKeyJoinColumns.

		return isAnnotationPresent(PrimaryKeyJoinColumns.class);
    
protected booleanisAnnotationPresent(java.lang.Class annotation)
INTERNAL: Indicates whether the specified annotation is present on the annotated element for this accessor. Method checks against the metadata complete flag.

        return isAnnotationPresent(annotation, getAnnotatedElement());
    
protected booleanisAnnotationPresent(java.lang.Class annotation, java.lang.reflect.AnnotatedElement annotatedElement)
INTERNAL: Indicates whether the specified annotation is present on the annotated element for this accessor. Method checks against the metadata complete flag.

        return MetadataHelper.isAnnotationPresent(annotation, annotatedElement, m_descriptor);
    
public booleanisBasic()
INTERNAL: Return true if this accessor represents a basic mapping.

        return false;
    
public booleanisClass()
INTERNAL: Return true if this accessor represents a class.

        return false;
    
public booleanisEmbedded()
INTERNAL: Return true if this accessor represents an aggregate mapping.

        return false;
    
public booleanisEmbeddedId()
INTERNAL: Return true if this accessor represents an aggregate id mapping.

        return false;
    
public booleanisManyToMany()
INTERNAL: Return true if this accessor represents a m-m relationship.

        return false;
    
public booleanisManyToOne()
INTERNAL: Return true if this accessor represents a m-1 relationship.

        return false;
    
public booleanisOneToMany()
INTERNAL: Return true if this accessor represents a 1-m relationship.

        return false;
    
public booleanisOneToOne()
INTERNAL: Return true if this accessor represents a 1-1 relationship.

        return false;
    
public booleanisOptional()
INTERNAL: Subclasses that support processing an optional setting should override this method, otherwise a runtime development exception is thrown for those accessors who call this method and don't implement it themselves.

        throw new RuntimeException("Development exception. The accessor: [" + this + "] should not call the isOptional method unless it overrides it.");
    
public booleanisProcessed()
INTERNAL: Return true if this accessor has already been processed.

        return m_isProcessed;    
    
public booleanisRelationship()
INTERNAL: Return true if this accessor method represents a relationship. It will cache the boolean value to avoid multiple checks and validation.

        if (m_isRelationship == null) {
            m_isRelationship = new Boolean(isManyToOne() || isManyToMany() || isOneToMany() || isOneToOne());
        }
        
        return m_isRelationship.booleanValue(); 
    
public booleanisXMLAccessor()
INTERNAL: Return true if this is an XML processing accessor.

        return false;
    
public abstract voidprocess()
INTERNAL: Every accessor knows how to process themselves since they have all the information they need.

protected oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ClassAccessorprocessAccessor(oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptor descriptor)
INTERNAL: (Overidden in XMLClassAccessor and XMLEmbeddedAccessor) Fast track processing a ClassAccessor for the given descriptor. Inheritance root classes and embeddables may be fast tracked.

        ClassAccessor accessor = new ClassAccessor(new MetadataClass(descriptor.getJavaClass()), getProcessor(), descriptor);
        descriptor.setClassAccessor(accessor);
        accessor.process();
        return accessor;
    
protected java.util.ListprocessPrimaryKeyJoinColumns(oracle.toplink.essentials.internal.ejb.cmp3.metadata.columns.MetadataPrimaryKeyJoinColumns primaryKeyJoinColumns)
INTERNAL: Process the primary key join columms for this accessors annotated element.

        // This call will add any defaulted columns as necessary.
        List<MetadataPrimaryKeyJoinColumn> pkJoinColumns = primaryKeyJoinColumns.values(m_descriptor);
        
        if (m_descriptor.hasCompositePrimaryKey()) {
            // Validate the number of primary key fields defined.
            if (pkJoinColumns.size() != m_descriptor.getPrimaryKeyFields().size()) {
                m_validator.throwIncompletePrimaryKeyJoinColumnsSpecified(getJavaClass(), getAnnotatedElement());
            }
            
            // All the primary and foreign key field names should be specified.
            for (MetadataPrimaryKeyJoinColumn pkJoinColumn : pkJoinColumns) {
                if (pkJoinColumn.isPrimaryKeyFieldNotSpecified() || pkJoinColumn.isForeignKeyFieldNotSpecified()) {
                    m_validator.throwIncompletePrimaryKeyJoinColumnsSpecified(getJavaClass(), getAnnotatedElement());
                }
            }
        } else {
            if (pkJoinColumns.size() > 1) {
                m_validator.throwExcessivePrimaryKeyJoinColumnsSpecified(getJavaClass(), getAnnotatedElement());
            }
        }
        
        return pkJoinColumns;
    
protected voidprocessTable(oracle.toplink.essentials.internal.ejb.cmp3.metadata.tables.MetadataTable table, java.lang.String defaultName)
INTERNAL: Common table processing for table, secondary table, join table and collection table.

        // Name could be "", need to check against the default name.
		String name = getName(table.getName(), defaultName, table.getNameContext());
        
        // Catalog could be "", need to check for an XML default.
        String catalog = getName(table.getCatalog(), m_descriptor.getCatalog(), table.getCatalogContext());
        
        // Schema could be "", need to check for an XML default.
        String schema = getName(table.getSchema(), m_descriptor.getSchema(), table.getSchemaContext());
        
        // Build a fully qualified name and set it on the table.
        table.setName(MetadataHelper.getFullyQualifiedTableName(name, catalog, schema));
    
protected voidsetAccessorMethods(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: Set the getter and setter access methods for this accessor.

        if (m_descriptor.usesPropertyAccess()) {
            mapping.setGetMethodName(getName());
            mapping.setSetMethodName(getSetMethodName());
        }
    
public voidsetAnnotatedElement(java.lang.reflect.AnnotatedElement annotatedElement)
INTERNAL: Return the annotated element for this accessor.

        m_accessibleObject.setAnnotatedElement(annotatedElement);
    
protected voidsetIndirectionPolicy(oracle.toplink.essentials.mappings.CollectionMapping mapping, java.lang.String mapKey)
INTERNAL: Set the correct indirection policy on a collection mapping. Method assume that the reference class has been set on the mapping before calling this method.

        Class rawClass = getRawClass();
        
        if (usesIndirection()) {            
            if (rawClass == Map.class) {
                mapping.useTransparentMap(mapKey);
            } else if (rawClass == List.class) {
                mapping.useTransparentList();
            } else if (rawClass == Collection.class) {
                mapping.useTransparentCollection();
                mapping.setContainerPolicy(new CollectionContainerPolicy(ClassConstants.IndirectList_Class));
            } else if (rawClass == Set.class) {
                mapping.useTransparentSet();
            } else {
                // Because of validation we should never get this far.
            }
        } else {
            mapping.dontUseIndirection();
            
            if (rawClass == Map.class) {
                mapping.useMapClass(java.util.Hashtable.class, mapKey);
            } else if (rawClass == Set.class) {
                mapping.useCollectionClass(java.util.HashSet.class);
            } else {
                mapping.useCollectionClass(java.util.Vector.class);
            }
        }
    
public voidsetIsProcessed()
INTERNAL:

        m_isProcessed = true;	
	
public booleanusesIndirection()
INTERNAL:

        return getFetchType().equals(MetadataConstants.LAZY);