FileDocCategorySizeDatePackage
JDOMetaDataModelImpl.javaAPI DocGlassfish v2 API11171Fri May 04 22:34:38 BST 2007com.sun.jdo.api.persistence.enhancer.meta

JDOMetaDataModelImpl

public class JDOMetaDataModelImpl extends com.sun.jdo.api.persistence.enhancer.util.Support implements JDOMetaData
Provides the JDO meta information based on a JDO meta model.

Fields Summary
protected final PrintWriter
out
protected com.sun.jdo.api.persistence.model.Model
model
Constructors Summary
public JDOMetaDataModelImpl(com.sun.jdo.api.persistence.model.Model model)
Creates an instance.

        this(model, null);
    
public JDOMetaDataModelImpl(com.sun.jdo.api.persistence.model.Model model, PrintWriter out)

        // check arguments
        if (model == null) {
            final String msg
                = "Initializing meta data: model == null";//NOI18N
            throw new JDOMetaDataFatalError(msg);
        }
        this.model = model;
        this.out = out;
    
Methods Summary
public intgetFieldNo(java.lang.String classPath, java.lang.String fieldName)
Returns the unique field index of a declared, persistent field of a class.

        final String className = pathToName(classPath);
        final PersistenceFieldElement pfe
            = model.getPersistenceField(className, fieldName);
        if (pfe == null
            || pfe.getPersistenceType() != PersistenceFieldElement.PERSISTENT)
            return -1;

        return pfe.getFieldNumber();
    
public java.lang.String[]getManagedFields(java.lang.String classPath)
Returns an array of field names of all declared persistent and transactional fields of a class.

        return getPersistentFields(classPath);
    
public java.lang.StringgetPersistenceCapableRootClass(java.lang.String classPath)
Returns the name of the persistence-capable root class of a class.

        //^olsen: exchange dummy implementation once supported by Model
        return (isPersistenceCapableClass(classPath) ? classPath : null);
    
private final java.lang.String[]getPersistentFields(java.lang.String classPath)
Returns an array of field names of all declared, persistent fields of a class.

        final String className = pathToName(classPath);
        final PersistenceClassElement pce
            = model.getPersistenceClass(className);
        if (pce == null)
            return new String[]{};

        // exctract field names into result array
        final PersistenceFieldElement[] pfes = pce.getFields();
        final int nofFields = (pfes != null  ?  pfes.length  :  0);
        final String[] names = new String[nofFields];
        for (int i = 0; i < nofFields; i++) {
            final PersistenceFieldElement pfe = pfes[i];
            names[i] = pfe.getName();

            //@olsen: debugging check
            if (false) {
                if (pfe.getPersistenceType()
                    != PersistenceFieldElement.PERSISTENT) {
                    final String msg
                        = ("Getting persistent field names: " //NOI18N
                           + "Encountered non-persistent field '"//NOI18N
                           + names[i] + "' for class " + classPath);//NOI18N
                    throw new JDOMetaDataFatalError(msg);
                    //out.println(msg);
                    //names[i] = null;
                }
            }
        }
        return names;
    
public java.lang.StringgetSuperClass(java.lang.String classPath)
Returns the name of the superclass of a class.

param
classPath the JVM-qualified name of the class
return
the name of the superclass.

        //throw new UnsupportedOperationException ("not implemented yet");
        return null;
    
public booleanisDefaultFetchGroupField(java.lang.String classPath, java.lang.String fieldName)
Tests whether a field of a class is known to be part of the Default Fetch Group. Please note that for a relationship field, this method always returns false.

        final String className = pathToName(classPath);
        boolean isdfgField = model.isDefaultFetchGroup(className, fieldName);
        if(isdfgField) {
            final PersistenceFieldElement pfe
                = model.getPersistenceField(className, fieldName);
            if (pfe instanceof RelationshipElement) {
                // This is a relationship field. Flag it as not belonging
                // to dfg.
                // Relationship fields are always flaged as not belonging to dfg
                // This assures that access to a relationship fields is always
                // mediated.
                // Please see call to this method from following for more details.
                // 1. EJBMetaDataModelImpl#getFieldFlags()
                // 2. MethodAnnotater#notePutFieldAnnotation()
                // 3. MethodAnnotater#noteGetFieldAnnotation()
                isdfgField = false;
            }
        }
        return isdfgField;
    
public booleanisMutableSecondClassObjectType(java.lang.String classPath)
Tests whether a type is known for Mutable Second Class Objects.

        final String className = pathToName(classPath);
        return model.isMutableSecondClassObject(className);
    
public booleanisPersistenceCapableClass(java.lang.String classPath)
Tests whether a class is known to be persistence-capable.

        //^olsen: delegate to Model once supported
        if (isTransientClass(classPath))
            return false;
        final String className = pathToName(classPath);
        return model.isPersistent(className);
    
public booleanisPersistenceCapableRootClass(java.lang.String classPath)
Tests whether a class is known as a persistence-capable root class.

        //@olsen: 4631388 - do not attempt to support inheritance right now
        final String className = pathToName(classPath);
        return model.isPersistent(className);
        //return (model.isPersistent(className)
        //        && !model.hasPersistentSuperclass(className));
    
public booleanisPersistentField(java.lang.String classPath, java.lang.String fieldName)
Tests whether a field of a class is known to be persistent.

        final String className = pathToName(classPath);
        return model.isPersistent(className, fieldName);
    
public booleanisPrimaryKeyField(java.lang.String classPath, java.lang.String fieldName)
Tests whether a field of a class is known to be Primary Key.

        final String className = pathToName(classPath);
        return model.isKey(className, fieldName);
    
public booleanisSecondClassObjectType(java.lang.String classPath)
Tests whether a type is known for Second Class Objects.

        final String className = pathToName(classPath);
        return model.isSecondClassObject(className);
    
public booleanisTransactionalField(java.lang.String classPath, java.lang.String fieldName)
Tests whether a field of a class is known to be transactional.

        //throw new UnsupportedOperationException ("not implemented yet");
        return false;
    
public booleanisTransientClass(java.lang.String classPath)
Tests whether a class is known to be transient.

        //^olsen: delegate to Model once supported
        if (classPath.startsWith("java/"))//NOI18N
            return true;
        if (classPath.startsWith("javax/"))//NOI18N
            return true;
        if (classPath.startsWith("com/sun/jdo/"))//NOI18N
            return true;
        return false;
    
protected static java.lang.StringnameToPath(java.lang.String className)

        if (className != null) {
            return className.replace('.", '/");
        } else {
            return null;
        }
    
protected static java.lang.StringpathToName(java.lang.String classPath)

        if (classPath != null) {
            return classPath.replace('/", '.");
        } else {
            return null;
        }