Package xdoclet.modules.ojb.model

Examples of xdoclet.modules.ojb.model.ClassDescriptorDef


     * @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 = fieldDef.getOwner().getName();
        ClassDescriptorDef     classDef;
        ReferenceDescriptorDef refDef;

        // 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();
                    if (ownerClassName.equals(refDef.getProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF)))
                    {
                        // the field is a primary key of the class referenced by this reference descriptor
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))
        {
            // specified element class must be a subtype of the element type
            try
            {
                InheritanceHelper helper = new InheritanceHelper();

                if (!helper.isSameOrSubTypeOf(elementClassDef, arrayElementClassName, true))
                {
                    throw new ConstraintException("The element class "+elementClassName+" of the collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" is not the same or a subtype of the array base type "+arrayElementClassName);
                }
            }
            catch (ClassNotFoundException ex)
            {
                throw new ConstraintException("Could not find the class "+ex.getMessage()+" on the classpath while checking the collection "+collDef.getName()+" in class "+collDef.getOwner().getName());
            }
        }
        // we're adjusting the property to use the classloader-compatible form
        collDef.setProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF, elementClassDef.getName());
    }
View Full Code Here

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

        ClassDescriptorDef ownerClass       = (ClassDescriptorDef)collDef.getOwner();
        String             elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF).replace('$', '.');
        ClassDescriptorDef elementClass     = ((ModelDef)ownerClass.getOwner()).getClass(elementClassName);
        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

     * @throws ConstraintException If there is a conflict between the primary keys
     */
    private void ensureReferencedPKs(ModelDef modelDef, ReferenceDescriptorDef refDef) throws ConstraintException
    {
        String             targetClassName = refDef.getProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF);
        ClassDescriptorDef targetClassDef  = modelDef.getClass(targetClassName);

        ensurePKsFromHierarchy(targetClassDef);
    }
View Full Code Here

     * @throws ConstraintException If there is a problem with the fitting collection (if any) or the primary keys
     */
    private void ensureReferencedPKs(ModelDef modelDef, CollectionDescriptorDef collDef) throws ConstraintException
    {
        String             elementClassName   = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
        ClassDescriptorDef elementClassDef    = modelDef.getClass(elementClassName);
        String             indirTable         = collDef.getProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE);
        String             localKey           = collDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY);
        String             remoteKey          = collDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);
        boolean            hasRemoteKey       = remoteKey != null;
        ArrayList          fittingCollections = new ArrayList();

        // we're checking for the fitting remote collection(s) and also
        // use their foreignkey as remote-foreignkey in the original collection definition
        for (Iterator it = elementClassDef.getAllExtentClasses(); it.hasNext();)
        {
            ClassDescriptorDef subTypeDef = (ClassDescriptorDef)it.next();

            // find the collection in the element class that has the same indirection table
            for (Iterator collIt = subTypeDef.getCollections(); collIt.hasNext();)
            {
                CollectionDescriptorDef curCollDef = (CollectionDescriptorDef)collIt.next();

                if (indirTable.equals(curCollDef.getProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE)) &&
                    (collDef != curCollDef) &&
View Full Code Here

     * @throws ConstraintException If there is a problem with the foreign keys
     */
    private void ensureReferencedFKs(ModelDef modelDef, CollectionDescriptorDef collDef) throws ConstraintException
    {
        String             elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
        ClassDescriptorDef elementClassDef  = modelDef.getClass(elementClassName);
        String             fkFieldNames     = collDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY);
        ArrayList          missingFields    = new ArrayList();
        SequencedHashMap   fkFields         = new SequencedHashMap();

        // first we gather all field names
        for (CommaListIterator it = new CommaListIterator(fkFieldNames); it.hasNext();)
        {
            String             fieldName = (String)it.next();
            FieldDescriptorDef fieldDef  = elementClassDef.getField(fieldName);

            if (fieldDef == null)
            {
                missingFields.add(fieldName);
            }
            fkFields.put(fieldName, fieldDef);
        }

        // next we traverse all sub types and gather fields as we go
        for (Iterator it = elementClassDef.getAllExtentClasses(); it.hasNext() && !missingFields.isEmpty();)
        {
            ClassDescriptorDef subTypeDef = (ClassDescriptorDef)it.next();

            for (int idx = 0; idx < missingFields.size();)
            {
                FieldDescriptorDef fieldDef = subTypeDef.getField((String)missingFields.get(idx));

                if (fieldDef != null)
                {
                    fkFields.put(fieldDef.getName(), fieldDef);
                    missingFields.remove(idx);
View Full Code Here

    {
        SequencedHashMap pks = new SequencedHashMap();

        for (Iterator it = classDef.getAllExtentClasses(); it.hasNext();)
        {
            ClassDescriptorDef subTypeDef = (ClassDescriptorDef)it.next();

            ArrayList subPKs = subTypeDef.getPrimaryKeys();

            // check against already present PKs
            for (Iterator pkIt = subPKs.iterator(); pkIt.hasNext();)
            {
                FieldDescriptorDef fieldDef   = (FieldDescriptorDef)pkIt.next();
View Full Code Here

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

        ClassDescriptorDef      classDef;
        CollectionDescriptorDef collDef;

        for (Iterator it = modelDef.getClasses(); it.hasNext();)
        {
            classDef = (ClassDescriptorDef)it.next();
            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

        // we know that the class is present because the collection constraints have been checked already
        // TODO: we must check whether there is a collection at the other side; if the type does not map to a
        // table then we have to check its subtypes
        String                  elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
        ClassDescriptorDef      elementClass     = modelDef.getClass(elementClassName);
        CollectionDescriptorDef remoteCollDef    = collDef.getRemoteCollection();

        if (remoteCollDef == null)
        {
            // error if there is none and we don't have remote-foreignkey specified
            if (!collDef.hasProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY))
            {
                throw new ConstraintException("The collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" must specify remote-foreignkeys as the class on the other side of the m:n association has no corresponding collection");
            }
        }
        else
        {   
            String remoteKeys2 = remoteCollDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY);

            if (collDef.hasProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY))
            {
                // check that the specified remote-foreignkey equals the remote foreignkey setting
                String remoteKeys1 = collDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);

                if (!CommaListIterator.sameLists(remoteKeys1, remoteKeys2))
                {
                    throw new ConstraintException("The remote-foreignkey property specified for collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" doesn't match the foreignkey property of the corresponding collection "+remoteCollDef.getName()+" in class "+elementClass.getName());
                }
            }
            else
            {
                // ensure the remote-foreignkey setting
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.