Package xdoclet.modules.ojb.model

Examples of xdoclet.modules.ojb.model.ClassDescriptorDef


                           getClass(),
                           "checkCollectionForeignkeys",
                           "For the collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+", a remote foreignkey was specified though it is a 1:n, not a m:n collection");
        }
       
        ClassDescriptorDef ownerClass       = (ClassDescriptorDef)collDef.getOwner();
        ArrayList          primFields       = ownerClass.getPrimaryKeys();
        String             elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
        ArrayList          queue            = new ArrayList();
        ClassDescriptorDef elementClass;
        ArrayList          keyFields;
        FieldDescriptorDef keyField;
        FieldDescriptorDef primField;
        String             primType;
        String             keyType;
       
        // we know that the class is present because the collection constraints have been checked already
        queue.add(modelDef.getClass(elementClassName));
        while (!queue.isEmpty())
        {
            elementClass = (ClassDescriptorDef)queue.get(0);
            queue.remove(0);

            for (Iterator it = elementClass.getExtentClasses(); it.hasNext();)
            {
                queue.add(it.next());
            }
            if (!elementClass.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_REPOSITORY_INFO, true))
            {
                continue;
            }
            try
            {
                keyFields = elementClass.getFields(foreignkey);
            }
            catch (NoSuchFieldException ex)
            {
                throw new ConstraintException("The collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" specifies a foreignkey "+ex.getMessage()+" that is not a persistent field in the element class (or its subclass) "+elementClass.getName());
            }
            if (primFields.size() != keyFields.size())
            {
                throw new ConstraintException("The number of foreignkeys ("+keyFields.size()+") of the collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" doesn't match the number of primarykeys ("+primFields.size()+") of its owner class "+ownerClass.getName());
            }
            for (int idx = 0; idx < keyFields.size(); idx++)
            {
                keyField  = (FieldDescriptorDef)keyFields.get(idx);
                if (keyField.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    throw new ConstraintException("The collection "+collDef.getName()+" in class "+ownerClass.getName()+" uses the field "+keyField.getName()+" as foreignkey although this field is ignored in the element class (or its subclass) "+elementClass.getName());
                }
            }
            // the jdbc types of the primary keys must match the jdbc types of the foreignkeys (in the correct order)
            for (int idx = 0; idx < primFields.size(); idx++)
            {
                keyField  = (FieldDescriptorDef)keyFields.get(idx);
                if (keyField.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    throw new ConstraintException("The collection "+collDef.getName()+" in class "+ownerClass.getName()+" uses the field "+keyField.getName()+" as foreignkey although this field is ignored in the element class (or its subclass) "+elementClass.getName());
                }
                primField = (FieldDescriptorDef)primFields.get(idx);
                primType  = primField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE);
                keyType   = keyField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE);
                if (!primType.equals(keyType))
                {
                    throw new ConstraintException("The jdbc-type of foreignkey "+keyField.getName()+" in the element class (or its subclass) "+elementClass.getName()+" used by the collection "+collDef.getName()+" in class "+ownerClass.getName()+" doesn't match the jdbc-type of the corresponding primarykey "+primField.getName());
                }
            }
        }
    }
View Full Code Here


        if (CHECKLEVEL_NONE.equals(checkLevel))
        {
            return;
        }

        ClassDescriptorDef     classDef;
        ReferenceDescriptorDef refDef;

        for (Iterator it = modelDef.getClasses(); it.hasNext();)
        {
            classDef = (ClassDescriptorDef)it.next();
            for (Iterator refIt = classDef.getReferences(); refIt.hasNext();)
            {
                refDef = (ReferenceDescriptorDef)refIt.next();
                if (!refDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    checkReferenceForeignkeys(modelDef, refDef);
View Full Code Here

        {
            throw new ConstraintException("The reference "+refDef.getName()+" in class "+refDef.getOwner().getName()+" has no foreignkeys");
        }

        // we know that the class is present because the reference constraints have been checked already
        ClassDescriptorDef ownerClass = (ClassDescriptorDef)refDef.getOwner();
        ArrayList          keyFields;
        FieldDescriptorDef keyField;
       
        try
        {
            keyFields = ownerClass.getFields(foreignkey);
        }
        catch (NoSuchFieldException ex)
        {
            throw new ConstraintException("The reference "+refDef.getName()+" in class "+refDef.getOwner().getName()+" specifies a foreignkey "+ex.getMessage()+" that is not a persistent field in its owner class "+ownerClass.getName());
        }
        for (int idx = 0; idx < keyFields.size(); idx++)
        {
            keyField = (FieldDescriptorDef)keyFields.get(idx);
            if (keyField.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
            {
                throw new ConstraintException("The reference "+refDef.getName()+" in class "+ownerClass.getName()+" uses the field "+keyField.getName()+" as foreignkey although this field is ignored in this class");
            }
        }
           
        // for the referenced class and any subtype that is instantiable (i.e. not an interface or abstract class)
        // there must be the same number of primary keys and the jdbc types of the primary keys must
        // match the jdbc types of the foreignkeys (in the correct order)
        String             targetClassName = refDef.getProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF);
        ArrayList          queue           = new ArrayList();
        ClassDescriptorDef referencedClass;
        ArrayList          primFields;
        FieldDescriptorDef primField;
        String             primType;
        String             keyType;
       
        queue.add(modelDef.getClass(targetClassName));

        while (!queue.isEmpty())
        {
            referencedClass = (ClassDescriptorDef)queue.get(0);
            queue.remove(0);

            for (Iterator it = referencedClass.getExtentClasses(); it.hasNext();)
            {
                queue.add(it.next());
            }
            if (!referencedClass.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_REPOSITORY_INFO, true))
            {
                continue;
            }
            primFields = referencedClass.getPrimaryKeys();
            if (primFields.size() != keyFields.size())
            {
                throw new ConstraintException("The number of foreignkeys ("+keyFields.size()+") of the reference "+refDef.getName()+" in class "+refDef.getOwner().getName()+" doesn't match the number of primarykeys ("+primFields.size()+") of the referenced class (or its subclass) "+referencedClass.getName());
            }
            for (int idx = 0; idx < primFields.size(); idx++)
            {
                keyField  = (FieldDescriptorDef)keyFields.get(idx);
                primField = (FieldDescriptorDef)primFields.get(idx);
                primType  = primField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE);
                keyType   = keyField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE);
                if (!primType.equals(keyType))
                {
                    throw new ConstraintException("The jdbc-type of foreignkey "+keyField.getName()+" of the reference "+refDef.getName()+" in class "+refDef.getOwner().getName()+" doesn't match the jdbc-type of the corresponding primarykey "+primField.getName()+" of the referenced class (or its subclass) "+referencedClass.getName());
                }
            }
        }
    }
View Full Code Here

        if (CHECKLEVEL_NONE.equals(checkLevel))
        {
            return;
        }

        ClassDescriptorDef classDef;
        FieldDescriptorDef fieldDef;

        // we check for every inherited field
        for (Iterator classIt = modelDef.getClasses(); classIt.hasNext();)
        {
            classDef = (ClassDescriptorDef)classIt.next();
            for (Iterator fieldIt = classDef.getFields(); fieldIt.hasNext();)
            {
                fieldDef = (FieldDescriptorDef)fieldIt.next();
                if (fieldDef.isInherited())
                {
                    checkKeyModifications(modelDef, fieldDef);
View Full Code Here

     * @return The collection that uses the field or <code>null</code> if the field is not
     *         used in this way
     */
    private CollectionDescriptorDef usedByCollection(ModelDef modelDef, FieldDescriptorDef fieldDef, boolean elementClassSuffices)
    {
        ClassDescriptorDef      ownerClass     = (ClassDescriptorDef)fieldDef.getOwner();
        String                  ownerClassName = ownerClass.getQualifiedName();
        String                  name           = fieldDef.getName();
        ClassDescriptorDef      classDef;
        CollectionDescriptorDef collDef;
        String                  elementClassName;

        for (Iterator classIt = modelDef.getClasses(); classIt.hasNext();)
        {
            classDef = (ClassDescriptorDef)classIt.next();
            for (Iterator collIt = classDef.getCollections(); collIt.hasNext();)
            {
                collDef          = (CollectionDescriptorDef)collIt.next();
                elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF).replace('$', '.');
                // if the owner class of the field is the element class of a normal collection
                // and the field is a foreignkey of this collection
View Full Code Here

     * @return The reference that uses the field or <code>null</code> if the field is not used in this way
     */
    private ReferenceDescriptorDef usedByReference(ModelDef modelDef, FieldDescriptorDef fieldDef)
    {
        String                 ownerClassName = ((ClassDescriptorDef)fieldDef.getOwner()).getQualifiedName();
        ClassDescriptorDef     classDef;
        ReferenceDescriptorDef refDef;
        String                 targetClassName;

        // only relevant for primarykey fields
        if (PropertyHelper.toBoolean(fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_PRIMARYKEY), false))
        {
            for (Iterator classIt = modelDef.getClasses(); classIt.hasNext();)
            {
                classDef = (ClassDescriptorDef)classIt.next();
                for (Iterator refIt = classDef.getReferences(); refIt.hasNext();)
                {
                    refDef          = (ReferenceDescriptorDef)refIt.next();
                    targetClassName = refDef.getProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF).replace('$', '.');
                    if (ownerClassName.equals(targetClassName))
                    {
View Full Code Here

                throw new ConstraintException("Reference "+refDef.getName()+" in class "+refDef.getOwner().getName()+" does not reference any class");
            }
        }

        // now checking the type
        ClassDescriptorDef ownerClassDef   = (ClassDescriptorDef)refDef.getOwner();
        ModelDef           model           = (ModelDef)ownerClassDef.getOwner();
        String             targetClassName = refDef.getProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF);
        ClassDescriptorDef targetClassDef  = model.getClass(targetClassName);

        if (targetClassDef == null)
        {
            throw new ConstraintException("The class "+targetClassName+" referenced by "+refDef.getName()+" in class "+ownerClassDef.getName()+" is unknown or not persistent");
        }
        if (!targetClassDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_OJB_PERSISTENT, false))
        {
            throw new ConstraintException("The class "+targetClassName+" referenced by "+refDef.getName()+" in class "+ownerClassDef.getName()+" is not persistent");
        }
       
        if (CHECKLEVEL_STRICT.equals(checkLevel))
        {
            try
            {
                InheritanceHelper helper = new InheritanceHelper();

                if (refDef.isAnonymous())
                {
                    // anonymous reference: class must be a baseclass of the owner class
                    if (!helper.isSameOrSubTypeOf(ownerClassDef, targetClassDef.getName(), true))
                    {
                        throw new ConstraintException("The class "+targetClassName+" referenced by the anonymous reference "+refDef.getName()+" in class "+ownerClassDef.getName()+" is not a basetype of the class");
                    }
                }
                else
                {   
                    // specified element class must be a subtype of the variable type (if it exists, i.e. not for anonymous references)
                    String  varType      = refDef.getProperty(PropertyHelper.OJB_PROPERTY_VARIABLE_TYPE);
                    boolean performCheck = true;
   
                    // but we first check whether there is a useable type for the the variable type
                    if (model.getClass(varType) == null)
                    {
                        try
                        {
                            InheritanceHelper.getClass(varType);
                        }
                        catch (ClassNotFoundException ex)
                        {
                            // no, so defer the check but issue a warning
                            performCheck = false;
                            LogHelper.warn(true,
                                           getClass(),
                                           "ensureClassRef",
                                           "Cannot check whether the type "+targetClassDef.getQualifiedName()+" specified as class-ref at reference "+refDef.getName()+" in class "+ownerClassDef.getName()+" is assignable to the declared type "+varType+" of the reference because this variable type cannot be found in source or on the classpath");
                        }
                    }
                    if (performCheck && !helper.isSameOrSubTypeOf(targetClassDef, varType, true))
                    {
                        throw new ConstraintException("The class "+targetClassName+" referenced by "+refDef.getName()+" in class "+ownerClassDef.getName()+" is not the same or a subtype of the variable type "+varType);
                    }
                }
            }
            catch (ClassNotFoundException ex)
            {
                throw new ConstraintException("Could not find the class "+ex.getMessage()+" on the classpath while checking the reference "+refDef.getName()+" in class "+refDef.getOwner().getName());
            }
        }
        // we're adjusting the property to use the classloader-compatible form
        refDef.setProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF, targetClassDef.getName());
    }
View Full Code Here

        }

        // now checking the element type
        ModelDef           model            = (ModelDef)collDef.getOwner().getOwner();
        String             elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
        ClassDescriptorDef elementClassDef  = model.getClass(elementClassName);

        if (elementClassDef == null)
        {
            throw new ConstraintException("Collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" references an unknown class "+elementClassName);
        }
        if (!elementClassDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_OJB_PERSISTENT, false))
        {
            throw new ConstraintException("The element class "+elementClassName+" of the collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" is not persistent");
        }
        if (CHECKLEVEL_STRICT.equals(checkLevel) && (arrayElementClassName != null))
        {
View Full Code Here

        if ((orderbySpec == null) || (orderbySpec.length() == 0))
        {
            return;
        }

        ClassDescriptorDef ownerClass       = (ClassDescriptorDef)collDef.getOwner();
        ClassDescriptorDef elementClass     = ((ModelDef)ownerClass.getOwner()).getClass(collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF));
        FieldDescriptorDef fieldDef;
        String             token;
        String             fieldName;
        String             ordering;
        int                pos;

        for (CommaListIterator it = new CommaListIterator(orderbySpec); it.hasNext();)
        {
            token = it.getNext();
            pos   = token.indexOf('=');
            if (pos == -1)
            {
                fieldName = token;
                ordering  = null;
            }
            else
            {
                fieldName = token.substring(0, pos);
                ordering  = token.substring(pos + 1);
            }
            fieldDef = elementClass.getField(fieldName);
            if (fieldDef == null)
            {
                throw new ConstraintException("The field "+fieldName+" specified in the orderby attribute of the collection "+collDef.getName()+" in class "+ownerClass.getName()+" hasn't been found in the element class "+elementClass.getName());
            }
            if ((ordering != null) && (ordering.length() > 0) &&
                !"ASC".equals(ordering) && !"DESC".equals(ordering))
            {
                throw new ConstraintException("The ordering "+ordering+" specified in the orderby attribute of the collection "+collDef.getName()+" in class "+ownerClass.getName()+" is invalid");
View Full Code Here

     * @throws ConstraintException If there is an error with the keys of the subtypes or there
     *                             ain't any subtypes
     */
    private void ensureReferencedKeys(ModelDef modelDef, String checkLevel) throws ConstraintException
    {
        ClassDescriptorDef      classDef;
        CollectionDescriptorDef collDef;
        ReferenceDescriptorDef  refDef;

        for (Iterator it = modelDef.getClasses(); it.hasNext();)
        {
            classDef = (ClassDescriptorDef)it.next();
            for (Iterator refIt = classDef.getReferences(); refIt.hasNext();)
            {
                refDef = (ReferenceDescriptorDef)refIt.next();
                if (!refDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    ensureReferencedPKs(modelDef, refDef);
                }
            }
            for (Iterator collIt = classDef.getCollections(); collIt.hasNext();)
            {
                collDef = (CollectionDescriptorDef)collIt.next();
                if (!collDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    if (collDef.hasProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE))
View Full Code Here

TOP

Related Classes of xdoclet.modules.ojb.model.ClassDescriptorDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.