Package org.exolab.castor.mapping.loader

Examples of org.exolab.castor.mapping.loader.ClassDescriptorImpl


                    classInfo.getDescribedClass().getName());
        }

        JPAClassNature nature = new JPAClassNature(classInfo);

        ClassDescriptorImpl descriptor = new ClassDescriptorImpl();
        descriptor.addNature(ClassDescriptorJDONature.class.getName());
        ClassDescriptorJDONature jdoNature = new ClassDescriptorJDONature(
                descriptor);

        /*
         * set classDescriptor infos
         */

        /*
         * working
         */
        descriptor.setJavaClass(classInfo.getDescribedClass());
        descriptor.setExtends(null);
        Class<?> extendedClass = classInfo.getExtendedClass();

        if (extendedClass != null && extendedClass != Object.class) {
            ClassDescriptor extendedClassDescriptor = command
                    .resolve(extendedClass);
            if (extendedClassDescriptor == null) {
                throw new MappingException("mapping.extendsMissing", classInfo
                        .getDescribedClass(), extendedClass);
            }
            descriptor.setExtends(extendedClassDescriptor);
            if (extendedClassDescriptor
                    .hasNature(ClassDescriptorJDONature.class.getName())) {
                new ClassDescriptorJDONature(extendedClassDescriptor)
                        .addExtended(descriptor);
            }
        }

        /*
         * interm setters of not working features
         */
        descriptor.setDepends(null);
        descriptor.setMapping(null);

        /*
         * set ClassDescriptorJDONature infos
         */

        /*
         * working
         */
        /*
         * interm setters of not working features
         */
        jdoNature.setTableName(null);
        jdoNature.setAccessMode(null);
        jdoNature.setKeyGeneratorDescriptor(null);

        /*
         * generate and set FieldDescriptors for fields
         */
        FieldDescriptor[] fields = new FieldDescriptor[classInfo
                .getFieldCount()];
        int i = 0;
        for (FieldInfo fieldInfo : classInfo.getFieldInfos()) {
            fields[i] = convert(descriptor, fieldInfo);
            i++;
        }

        descriptor.setFields(fields);

        /*
         * generate and set FieldDescriptors for identities
         */
        FieldDescriptor[] keys = new FieldDescriptor[classInfo
                .getKeyFieldCount()];
        i = 0;
        for (FieldInfo fieldInfo : classInfo.getKeyFieldInfos()) {
            keys[i] = convert(descriptor, fieldInfo);
            i++;
        }

        descriptor.setIdentities(keys);

        return descriptor;
    }
View Full Code Here


        _requestedEngine = engine;
        _requestedFactory = factory;
        _types = types;
        _values = new Object[ _types.length ];
        _sql = sql;
        ClassDescriptorImpl cdi = (ClassDescriptorImpl) _engine.getDescriptor();
        _identSqlType = new int[cdi.getIdentities().length];
        for (int i = 0; i < _identSqlType.length; i++) {
            FieldDescriptor fldDesc = cdi.getIdentities()[i];
            _identSqlType[i] new FieldDescriptorJDONature(fldDesc).getSQLType()[0];
        }
       
        _isCallSql = isCallSql;
    }
View Full Code Here

            LOG.info(Messages.format("mapping.ignoringMapping", classMapping.getName()));
            return null;
        }

        // Create the class descriptor, and register the JDO nature with it.
        ClassDescriptorImpl clsDesc = new ClassDescriptorImpl();
        clsDesc.addNature(ClassDescriptorJDONature.class.getName());
        ClassDescriptorJDONature jdoNature = new ClassDescriptorJDONature(clsDesc);
       
        // Set reference to class mapping on class descriptor.
        clsDesc.setMapping(classMapping);
       
        // Obtain the Java class.
        Class javaClass = resolveType(classMapping.getName());
        if (!Types.isConstructable(javaClass, true)) {
            throw new MappingException(
                    "mapping.classNotConstructable", javaClass.getName());
        }
        clsDesc.setJavaClass(javaClass);
       
        // If this class extends another class, we need to obtain the extended
        // class and make sure this class indeed extends it.
        ClassDescriptor extDesc = getExtended(classMapping, javaClass);
        if (extDesc != null) {
            if (!(extDesc.hasNature(ClassDescriptorJDONature.class.getName()))) {
                throw new IllegalArgumentException(
                        "Extended class does not have a JDO descriptor");
            }
           
            new ClassDescriptorJDONature(extDesc).addExtended(clsDesc);
        }
        clsDesc.setExtends(extDesc);
       
        // If this class depends on another class, obtain the depended class.
        clsDesc.setDepends(getDepended(classMapping, javaClass));
       
        // Create all field descriptors.
        FieldDescriptorImpl[] allFields = createFieldDescriptors(classMapping, javaClass);

        // Make sure there are no two fields with the same name.
        checkFieldNameDuplicates(allFields, javaClass);

        // Set class descriptor containing the field
        for (int i = 0; i < allFields.length; i++) {
            allFields[i].setContainingClassDescriptor(clsDesc);
        }
       
        // Identify identity and normal fields. Note that order must be preserved.
        List fieldList = new ArrayList(allFields.length);
        List idList = new ArrayList();
        if (extDesc == null) {
            // Sort fields into 2 lists based on identity definition of field.
            for (int i = 0; i < allFields.length; i++) {
                if (!allFields[i].isIdentity()) {
                    fieldList.add(allFields[i]);
                } else {
                    idList.add(allFields[i]);
                }
            }
           
            if (idList.size() == 0) {
                // Found no identities based on identity definition of field.
                // Try to find identities based on identity definition on class.
                String[] idNames = classMapping.getIdentity();
                if ((idNames == null) || (idNames.length == 0)) {
                    // There are also no identity definitions on class.
                    throw new MappingException("mapping.noIdentity", javaClass.getName());
                }

                FieldDescriptor identity;
                for (int i = 0; i < idNames.length; i++) {
                    identity = findIdentityByName(fieldList, idNames[i], javaClass);
                    if (identity != null) {
                        idList.add(identity);
                    } else {
                        throw new MappingException("mapping.identityMissing",
                                idNames[i], javaClass.getName());
                    }
                }
            }
        } else {
            // Add all fields of extending class to field list.
            for (int i = 0; i < allFields.length; i++) { fieldList.add(allFields[i]); }
           
            // Add all identities of extended class to identity list.
            FieldDescriptor[] extIds = ((ClassDescriptorImpl) extDesc).getIdentities();
            for (int i = 0; i < extIds.length; i++) { idList.add(extIds[i]); }
           
            // Search redefined identities in extending class.
            FieldDescriptor identity;
            for (int i = 0; i < idList.size(); i++) {
                String idName = ((FieldDescriptor) idList.get(i)).getFieldName();
                identity = findIdentityByName(fieldList, idName, javaClass);
                if (identity != null) { idList.set(i, identity); }
            }
        }
       
        // Set identities on class descriptor.
        FieldDescriptor[] ids = new FieldDescriptor[idList.size()];
        clsDesc.setIdentities(((FieldDescriptor[]) idList.toArray(ids)));

        // Set fields on class descriptor.
        FieldDescriptor[] fields = new FieldDescriptor[fieldList.size()];
        clsDesc.setFields((FieldDescriptor[]) fieldList.toArray(fields));
       
        jdoNature.setTableName(classMapping.getMapTo().getTable());
       
        extractAndSetAccessMode(jdoNature, classMapping);
        extractAndAddCacheParams(jdoNature, classMapping, javaClass);
View Full Code Here

            numberOfExtendingClassDescriptors += 1;
            if (LOG.isDebugEnabled()) {
                LOG.debug ("Potential extending class descriptor: "
                        + potentialClassDescriptor.getJavaClass().getName());
            }
            ClassDescriptorImpl cdi = (ClassDescriptorImpl) potentialClassDescriptor;
            FieldDescriptor[] identityDescriptors = cdi.getIdentities();
            boolean isNull = true;
           
            for (int i = 0; i < identityDescriptors.length; i++) {
                Object temp;
                final FieldDescriptorJDONature jdoFieldNature =
View Full Code Here

        //-- This is really a bug in ClassDescriptorImpl, but
        //-- since it's shared code between JDO + XML I don't
        //-- want to change it there until both the XML and JDO
        //-- folks can both approve the change.
        if (classDesc instanceof ClassDescriptorImpl) {
            ClassDescriptorImpl cdImpl = (ClassDescriptorImpl)classDesc;
            FieldDescriptor[] identities = cdImpl.getIdentities();
            if ((identities != null) && (identities.length > 1)) {
                int size = fields.length + identities.length;
                FieldDescriptor[] newFields = new FieldDescriptor[size];
                System.arraycopy(fields, 0, newFields, 0, fields.length);
                System.arraycopy(identities, 0, newFields, fields.length, identities.length);
View Full Code Here

        assertEquals(Object.class, classInfo.getExtendedClass());

        assertEquals(3, classInfo.getFieldCount());
        assertEquals(0, classInfo.getKeyFieldCount());

        ClassDescriptorImpl classDescriptor =
            InfoToDescriptorConverter.convert(classInfo, _cmd);

        FieldDescriptor[] fdFields = classDescriptor.getFields();
        FieldDescriptor[] fdIdentities = classDescriptor.getIdentities();

        assertNotNull(fdFields);
        assertEquals(3, fdFields.length);
        assertNotNull(fdIdentities);
        assertEquals(0, fdIdentities.length);
View Full Code Here

        assertEquals(TestI2DCJPATest.class, classInfo.getExtendedClass());

        assertEquals(1, classInfo.getFieldCount());
        assertEquals(0, classInfo.getKeyFieldCount());

        ClassDescriptorImpl classDescriptor =
            InfoToDescriptorConverter.convert(classInfo, _cmd);

        FieldDescriptor[] fdFields = classDescriptor.getFields();
        FieldDescriptor[] fdIdentities = classDescriptor.getIdentities();

        assertNotNull(fdFields);
        assertEquals(1, fdFields.length);
        assertNotNull(fdIdentities);
        assertEquals(0, fdIdentities.length);
View Full Code Here

        //-- This is really a bug in ClassDescriptorImpl, but
        //-- since it's shared code between JDO + XML I don't
        //-- want to change it there until both the XML and JDO
        //-- folks can both approve the change.
        if (classDesc instanceof ClassDescriptorImpl) {
            ClassDescriptorImpl cdImpl = (ClassDescriptorImpl)classDesc;
            FieldDescriptor[] identities = cdImpl.getIdentities();
            if ((identities != null) && (identities.length > 1)) {
                int size = fields.length + identities.length;
                FieldDescriptor[] newFields = new FieldDescriptor[size];
                int idx = 0;
                for ( ; idx < fields.length; idx++) {
View Full Code Here

TOP

Related Classes of org.exolab.castor.mapping.loader.ClassDescriptorImpl

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.