Package org.exolab.castor.mapping

Examples of org.exolab.castor.mapping.ClassDescriptor


                        && ((classMapping.getClassChoice() == null)
                                || (classMapping.getClassChoice().getFieldMappingCount() == 0))
                                && (classMapping.getIdentityCount() == 0)) {
                    // If we make it here we simply try to load a compiled mapping
                    try {
                        ClassDescriptor clsDesc =
                            getInternalContext()
                            .getXMLClassDescriptorResolver().resolve(classMapping.getName());
                        if (clsDesc != null) { return clsDesc; }
                    } catch (ResolverException e) {
                        if (LOG.isDebugEnabled()) {
                            String message =
                                new StringBuffer().append("Ignoring exception: ").append(e)
                                .append(" at resolving: ").append(classMapping.getName()).toString();
                            LOG.debug(message);
                        }
                    }
                }
            }
           
            // Obtain the Java class.
            Class javaClass = resolveType(classMapping.getName());
            if (classMapping.getVerifyConstructable()) {
                if (!Types.isConstructable(javaClass, true)) {
                    throw new MappingException(
                            "mapping.classNotConstructable", javaClass.getName());
                }
            }
            xmlClassDesc.setJavaClass(javaClass);

            // Obtain XML name.
            String xmlName;
            MapTo mapTo = classMapping.getMapTo();
            if ((mapTo != null) && (mapTo.getXml() != null)) {
                xmlName = mapTo.getXml();
            } else {
                String clsName = getInternalContext().getJavaNaming().getClassName(javaClass);
                xmlName = getInternalContext().getXMLNaming().toXMLName(clsName);
            }
            xmlClassDesc.setXMLName(xmlName);

            // 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);
            xmlClassDesc.setExtends((XMLClassDescriptor) extDesc);
           
            // Create all field descriptors.
            FieldDescriptorImpl[] allFields = createFieldDescriptors(classMapping, javaClass);

            // Make sure there are no two fields with the same name.
            checkFieldNameDuplicates(allFields, javaClass);
           
            // 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();
                   
                    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 identity of extended class to identity list.
                if (extDesc.getIdentity() != null) { idList.add(extDesc.getIdentity()); }
               
                // Search redefined identities in extending class.
                FieldDescriptor identity;
                for (int i = 0; i < idList.size(); i++) {
                    String idname = ((FieldDescriptor) idList.get(i)).getFieldName();
View Full Code Here


        FieldDescriptor[] fields;

        fields = clsDesc.getFields();
        for (int i = 0 ; i < fields.length ; ++i ) {
            if (fields[i].getClassDescriptor() != null) continue;
            ClassDescriptor   relDesc;
           
            Class fieldType = fields[i].getFieldType();
            if (fieldType != null) {
                relDesc = getDescriptor(fieldType.getName());
                if (relDesc != null &&
View Full Code Here

        if (xml != null) {

            //-- has class descriptor for type specified
            if (xml.getClassMapping() != null) {
                ClassDescriptor cd = createClassDescriptor(xml.getClassMapping());
                xmlDesc.setClassDescriptor(cd);
            }

            //-- has location path?
            if (xml.getLocation() != null) {
View Full Code Here

        JDOMappingLoader mappingLoader = (JDOMappingLoader) mappingUnmarshaller
                .getMappingLoader(mapping, BindingType.JDO);

        assertEquals(2, mapping.getRoot().getClassMappingCount());

        ClassDescriptor entityDescriptor = mappingLoader
                .getDescriptor("org.exolab.castor.jdo.engine.Entity");

        assertNotNull(entityDescriptor);

        FieldDescriptor id = entityDescriptor.getIdentity();
        assertEquals("id", id.getFieldName());
        FieldDescriptor[] fields = entityDescriptor.getFields();
        assertEquals("item", fields[0].getFieldName());

        ClassDescriptor itemDescriptor = mappingLoader
                .getDescriptor("org.exolab.castor.jdo.engine.Item");

        assertNotNull(itemDescriptor);

        id = itemDescriptor.getIdentity();
        assertEquals("id", id.getFieldName());
    }
View Full Code Here

        JDOMappingLoader mappingLoader = (JDOMappingLoader) mappingUnmarshaller
                .getMappingLoader(mapping, BindingType.JDO);

        assertEquals(1, mapping.getRoot().getClassMappingCount());

        ClassDescriptor entityDescriptor = mappingLoader
                .getDescriptor("org.exolab.castor.jdo.engine.Employee");

        assertNotNull(entityDescriptor);

        FieldDescriptor id = entityDescriptor.getIdentity();
        assertEquals("id", id.getFieldName());
        FieldDescriptor[] fields = entityDescriptor.getFields();
        assertEquals("address", fields[0].getFieldName());
    }
View Full Code Here

        JDOMappingLoader mappingLoader = (JDOMappingLoader) mappingUnmarshaller
                .getMappingLoader(mapping, BindingType.JDO);

        assertEquals(1, mapping.getRoot().getClassMappingCount());

        ClassDescriptor entityDescriptor = mappingLoader
                .getDescriptor("org.exolab.castor.jdo.engine.Address");

        assertNotNull(entityDescriptor);

        FieldDescriptor id = entityDescriptor.getIdentity();
        assertEquals("id", id.getFieldName());
    }
View Full Code Here

        ClassLoaderNature clNature = new ClassLoaderNature(_resolver);
        clNature.setClassLoader(getClass().getClassLoader());
    }

    public void testSuccessfulResolve() throws Exception {
        ClassDescriptor classDesc = _resolver.resolve(ClassToBeResolved.class);

        assertEquals(ClassToBeResolvedJDODescriptor.class.getName(), classDesc
                .getClass().getName());
    }
View Full Code Here

        assertEquals(ClassToBeResolvedJDODescriptor.class.getName(), classDesc
                .getClass().getName());
    }

    public void testUnsuccessfulResolve() throws Exception {
        ClassDescriptor classDesc = _resolver
                .resolve(ClassNotToBeResolved.class);

        assertNull(classDesc);
    }
View Full Code Here

    throws MappingException, ClassNotFoundException {
   
        Vector result = new Vector();
        ClassMolder mold;
        Persistence persist;
        ClassDescriptor desc;

        // TODO[WG]: remove down-cast
        JDOClassDescriptorResolver jdoCDR;
        jdoCDR = (JDOClassDescriptorResolver) cdResolver;
        DatingService ds = new DatingService(jdoCDR.getClassLoader());

        Iterator iter = ((JDOClassDescriptorResolver) cdResolver).descriptorIterator();
        while (iter.hasNext()) {
            Object next = iter.next();
            ClassDescriptor nextCd = (ClassDescriptor) next;
            Class toResolve = nextCd.getJavaClass();
            try {
                desc = cdResolver.resolve(toResolve);
            } catch (ResolverException e) {
                throw new MappingException ("Cannot resolve type for " + toResolve.getName(), e);
            }
View Full Code Here

        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);
            }
        }
View Full Code Here

TOP

Related Classes of org.exolab.castor.mapping.ClassDescriptor

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.