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

JDOMetaDataPropertyImpl

public class JDOMetaDataPropertyImpl extends com.sun.jdo.api.persistence.enhancer.util.Support implements ExtendedJDOMetaData
Provides the JDO meta information based on properties.

Fields Summary
private static final HashSet
transientTypePrefixes
private static final HashSet
secondClassObjectTypes
private static final HashSet
mutableSecondClassObjectTypes
private final JDOMetaDataProperties
properties
Constructors Summary
public JDOMetaDataPropertyImpl(Properties properties, PrintWriter out)
Creates an instance.

lars:
out id not used anymore



         

    
    
        transientTypePrefixes.add("java/");//NOI18N
        transientTypePrefixes.add("javax/");//NOI18N
        transientTypePrefixes.add("com/sun/jdo/");//NOI18N

        mutableSecondClassObjectTypes.add("java/util/Date");//NOI18N
        mutableSecondClassObjectTypes.add("com/sun/jdo/spi/persistence/support/sqlstore/sco/Date");//NOI18N
        mutableSecondClassObjectTypes.add("java/sql/Date");//NOI18N
        mutableSecondClassObjectTypes.add("com/sun/jdo/spi/persistence/support/sqlstore/sco/SqlTime");//NOI18N
        mutableSecondClassObjectTypes.add("java/sql/Time");//NOI18N
        mutableSecondClassObjectTypes.add("com/sun/jdo/spi/persistence/support/sqlstore/sco/SqlDate");//NOI18N
        mutableSecondClassObjectTypes.add("java/sql/Timestamp");//NOI18N
        mutableSecondClassObjectTypes.add("com/sun/jdo/spi/persistence/support/sqlstore/sco/SqlTimestamp");//NOI18N
        mutableSecondClassObjectTypes.add("java/util/Collection");//NOI18N
        mutableSecondClassObjectTypes.add("java/util/Set");//NOI18N
        mutableSecondClassObjectTypes.add("java/util/List");//NOI18N
        mutableSecondClassObjectTypes.add("java/util/HashSet");//NOI18N
        mutableSecondClassObjectTypes.add("java/util/Vector");//NOI18N
        mutableSecondClassObjectTypes.add("java/util/ArrayList");//NOI18N

        secondClassObjectTypes.add("java/lang/Boolean");//NOI18N
        secondClassObjectTypes.add("java/lang/Byte");//NOI18N
        secondClassObjectTypes.add("java/lang/Short");//NOI18N
        secondClassObjectTypes.add("java/lang/Integer");//NOI18N
        secondClassObjectTypes.add("java/lang/Long");//NOI18N
        secondClassObjectTypes.add("java/lang/Float");//NOI18N
        secondClassObjectTypes.add("java/lang/Double");//NOI18N
        secondClassObjectTypes.add("java/lang/Number");//NOI18N
        secondClassObjectTypes.add("java/lang/Character");//NOI18N
        secondClassObjectTypes.add("java/lang/String");//NOI18N
        secondClassObjectTypes.add("java/math/BigInteger");//NOI18N
        secondClassObjectTypes.add("java/math/BigDecimal");//NOI18N
        secondClassObjectTypes.addAll(mutableSecondClassObjectTypes);

    
        // check arguments
        if (properties == null) {
            final String msg
                = "Initializing meta data: properties == null";//NOI18N
            throw new JDOMetaDataFatalError(msg);
        }
        /*
        if (out == null) {
            final String msg
                = "Initializing meta data: output stream == null";//NOI18N
            throw new JDOMetaDataFatalError(msg);
        }
        */

        this.properties = new JDOMetaDataProperties (properties);
        readProperties ();
        //this.out = out;
    
public JDOMetaDataPropertyImpl(Properties properties)
Creates an instance.

lars:
out id not used anymore

        this (properties, null);
    
Methods Summary
public final intgetClassModifiers(java.lang.String classname)
Gets the access modifier of a class.


        JDOClass clazz = getJDOClass (classname);
        return (clazz != null  ?  clazz.getModifiers ()  :  0);

    
public intgetFieldFlags(java.lang.String classPath, java.lang.String fieldName)

        if (!isManagedField(classPath, fieldName)) {
            affirm(!isTransactionalField(classPath, fieldName));
            affirm(!isPersistentField(classPath, fieldName));
            affirm(!isKeyField(classPath, fieldName));
            affirm(!isDefaultFetchGroupField(classPath, fieldName));
            return 0;
        }
        //affirm(isManagedField(classPath, fieldName));

        if (isTransactionalField(classPath, fieldName)) {
            affirm(!isPersistentField(classPath, fieldName));
            affirm(!isKeyField(classPath, fieldName));
            // ignore any dfg membership of transactional fields
            //affirm(!isDefaultFetchGroupField(classPath, fieldName));
            return CHECK_WRITE;
        }
        //affirm(!isTransactionalField(classPath, fieldName));
        affirm(isPersistentField(classPath, fieldName));

        if (isKeyField(classPath, fieldName)) {
            // ignore any dfg membership of key fields
            //affirm(!isDefaultFetchGroupField(classPath, fieldName));
            return MEDIATE_WRITE;
        }
        //affirm(!isKeyField(classPath, fieldName));

        if (isDefaultFetchGroupField(classPath, fieldName)) {
            return CHECK_READ | CHECK_WRITE;
        }
        //affirm(!isDefaultFetchGroupField(classPath, fieldName));

        return MEDIATE_READ | MEDIATE_WRITE;
    
public int[]getFieldFlags(java.lang.String classPath, java.lang.String[] fieldNames)

        final int n = (fieldNames != null ? fieldNames.length : 0);
        final int[] flags = new int[n];
        for (int i = 0; i < n; i++) {
            flags[i] = getFieldFlags(classPath, fieldNames[i]);
        }
        return flags;
    
public final intgetFieldModifiers(java.lang.String classname, java.lang.String fieldname)
Gets the access modifier of a field.


        JDOField field = getJDOField (classname, fieldname);
        return (field != null  ?  field.getModifiers ()  :  0);

    
public intgetFieldNo(java.lang.String classPath, java.lang.String fieldName)
Returns the unique field index of a declared, persistent field of a class.

        JDOClass clazz = getJDOClass (classPath);
        return (clazz != null  ?  clazz.getIndexOfField (fieldName)  :  -1);
    
public int[]getFieldNo(java.lang.String classPath, java.lang.String[] fieldNames)

        final int n = (fieldNames != null ? fieldNames.length : 0);
        final int[] flags = new int[n];
        for (int i = 0; i < n; i++) {
            flags[i] = getFieldNo(classPath, fieldNames[i]);
        }
        return flags;
    
public final java.lang.StringgetFieldType(java.lang.String classname, java.lang.String fieldname)


        JDOField field = getJDOField (classname, fieldname);
        return (field != null  ?  field.getType ()  :  null);

    
public final java.lang.String[]getFieldType(java.lang.String classname, java.lang.String[] fieldnames)

        final int n = (fieldnames != null ? fieldnames.length : 0);
        final String[] types = new String[n];
        for (int i = 0; i < n; i++) {
            types[i] = getFieldType(classname, fieldnames[i]);
        }
        return types;
    
private final com.sun.jdo.api.persistence.enhancer.meta.JDOMetaDataProperties.JDOClassgetJDOClass(java.lang.String classname)


        return this.properties.getJDOClass (classname);

    
private final com.sun.jdo.api.persistence.enhancer.meta.JDOMetaDataProperties.JDOFieldgetJDOField(java.lang.String classname, java.lang.String fieldname)


        JDOClass clazz = getJDOClass (classname);
        return (clazz != null  ?  clazz.getField (fieldname)  :  null);

    
public java.lang.StringgetKeyClass(java.lang.String classPath)

        final JDOClass clazz = getJDOClass(classPath);
        return (clazz != null ? clazz.getOidClassName() : null);
    
public java.lang.String[]getKeyFields(java.lang.String classPath)

        final List keys = new ArrayList();
        final String[] fieldNames = getManagedFields(classPath);
        final int n = fieldNames.length;
        for (int i = 0; i < n; i++) {
            if (isKeyField(classPath, fieldNames[i])) {
                keys.add(fieldNames[i]);
            }
        }
        return (String[])keys.toArray(new String[keys.size()]);
    
public final java.lang.String[]getKnownClasses()
No interface method.


        return this.properties.getKnownClassNames ();

    
public final java.lang.String[]getKnownFields(java.lang.String classname)
Gets all known fields of a class.


        JDOClass clazz = getJDOClass (classname);
        return (clazz != null  ?  clazz.getFields ()  :  new String [] {});

    
public java.lang.String[]getManagedFields(java.lang.String classname)
Returns an array of field names of all declared, persistent fields of a class.


        JDOClass clazz = getJDOClass (classname);
        return (clazz != null  ?  clazz.getManagedFieldNames ()  :  new String [] {});

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

        //^olsen: exchange dummy implementation
        return (isPersistenceCapableClass(classPath) ? classPath : null);
    
public java.lang.StringgetPersistenceCapableSuperClass(java.lang.String classPath)

        for (String clazz = getSuperClass(classPath);
             clazz != null;
             clazz = getSuperClass(clazz))  {
            if (isPersistenceCapableClass(clazz)) {
                return clazz;
            }
        }
        return null;
    
public final java.lang.StringgetSuperClass(java.lang.String classname)
Returns the superclass of a class.


        JDOClass clazz = getJDOClass (classname);
        return (clazz != null  ?  clazz.getSuperClassName ()  :  null);

    
public java.lang.StringgetSuperKeyClass(java.lang.String classPath)

        for (String superClass = getPersistenceCapableSuperClass(classPath);
             superClass != null;
             superClass = getPersistenceCapableSuperClass(superClass)) {
            final String superKeyClass = getKeyClass(superClass);
            if (superKeyClass != null) {
                return superKeyClass;
            }
        }
        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.

        JDOField field = getJDOField (classPath, fieldName);
        return (field != null  ?  field.isInDefaultFetchGroup ()  :  false);
    
public booleanisKeyField(java.lang.String classPath, java.lang.String fieldName)

        final JDOField field = getJDOField(classPath, fieldName);
        return (field != null ? field.isPk() : false);
    
public booleanisKnownNonManagedField(java.lang.String classPath, java.lang.String fieldName, java.lang.String fieldSig)

        final JDOClass clazz = getJDOClass(classPath);
        if (clazz == null) {
            return true;
        }
        final JDOField field = clazz.getField(fieldName);
        return (field != null ? field.isKnownTransient() : false);
    
public booleanisManagedField(java.lang.String classPath, java.lang.String fieldName)

        return (isPersistentField(classPath, fieldName)
                || isTransactionalField(classPath, fieldName));
    
public booleanisMutableSecondClassObjectType(java.lang.String classPath)
Tests whether a type is known for Mutable Second Class Objects.

        return mutableSecondClassObjectTypes.contains(classPath);
    
public booleanisPersistenceCapableClass(java.lang.String classPath)
Tests whether a class is known to be persistence-capable.

        //check the transient prefixes
        for (Iterator i = transientTypePrefixes.iterator(); i.hasNext();) {
            final String typePrefix = (String)i.next();
            if (classPath.startsWith(typePrefix))
                return false;
        }
        JDOClass clazz = getJDOClass (classPath);
        return (clazz != null  ?  clazz.isPersistent ()  :  false);
    
public booleanisPersistenceCapableRootClass(java.lang.String classPath)
Tests whether a class is known as a persistence-capable root class.

        //@lars
        if  ( ! isPersistenceCapableClass (classPath))
        {
            return false;
        }
        String superclass = getSuperClass (classPath);
        return (superclass != null  ?  ! isPersistenceCapableClass (superclass)  :  true);

        //^olsen: exchange dummy implementation
//        return isPersistenceCapableClass(classPath);
    
public booleanisPersistentField(java.lang.String classPath, java.lang.String fieldName)
Tests whether a field of a class is known to be persistent.

        JDOField field = getJDOField (classPath, fieldName);
        return (field != null  ?  field.isPersistent ()  :  false);
    
public booleanisPrimaryKeyField(java.lang.String classPath, java.lang.String fieldName)
Tests whether a field of a class is known to be Primary Key.

        JDOField field = getJDOField (classPath, fieldName);
        return (field != null  ?  field.isPk ()  :  false);
    
public booleanisSecondClassObjectType(java.lang.String classPath)
Tests whether a type is known for Second Class Objects.

        return secondClassObjectTypes.contains(classPath);
    
public booleanisTransactionalField(java.lang.String classPath, java.lang.String fieldName)
Tests whether a field of a class is known to be transactional.

        JDOField field = getJDOField (classPath, fieldName);
        return (field != null  ?  field.isTransactional ()  :  false);
    
public booleanisTransientClass(java.lang.String classPath)

        return ! isPersistenceCapableClass (classPath);
    
private final voidreadProperties()


        //read all classes
        String [] classnames = this.properties.getKnownClassNames ();
        for  (int i = classnames.length - 1; i >= 0; i--)
        {
            JDOClass clazz = getJDOClass (classnames [i]);  //should be always != null

            //if the class is persistence it cannot be a second class object type
            if  (clazz.isPersistent ()  &&  secondClassObjectTypes.contains (clazz.getName ()))
            {
                throw new JDOMetaDataUserException ("ERROR: Parsing meta data properties: " +
                                                    "The persistent-capable class '" + clazz.getName () +
                                                    "' is second class object type.");
            }
        }