Package org.exolab.castor.mapping.xml

Examples of org.exolab.castor.mapping.xml.MapTo


        // -- prevent default access from showing up in the mapping
        classMap.setAccess(null);

        // -- map-to
        MapTo mapTo = new MapTo();
        mapTo.setXml(xmlClass.getXMLName());
        mapTo.setNsUri(xmlClass.getNameSpaceURI());
        mapTo.setNsPrefix(xmlClass.getNameSpacePrefix());
        classMap.setMapTo(mapTo);

        // -- add mapping to hashtable before processing
        // -- fields so we can do recursive processing
        _mappings.put(cls, classMap);
View Full Code Here


       re-factored, too.
    */

    protected void initQuery(final ClassMapping clsMapping, final QueryExpression expr)
    throws DTXException {
        MapTo mapTo = clsMapping.getMapTo();

        if (mapTo == null) {
            throw new DTXException("no table mapping for: " + clsMapping.getName());
        }

        String table = mapTo.getTable();

            FieldMapping[] fields = clsMapping.getClassChoice().getFieldMapping();
        FieldMapping identity = null;

            String identityName = clsMapping.getIdentity(0);

        for (int j = 0; j < fields.length; j++) {
            if (fields[j].getName().equals(identityName)) {
            identity = fields[j];
            break;
            }
        }

        if (identity == null) {
            throw new DTXException("no identity field in class: " + clsMapping.getName());
        }

        Sql identitySQLElement = identity.getSql();

        if (identitySQLElement == null) {
            throw new DTXException("no identity SQL info in class: " + clsMapping.getName());
        }

        String identitySQL = identitySQLElement.getName()[0];

        _ids.add(table + "." + identitySQL);

        DTXClassDescriptor desc = new DTXClassDescriptor(clsMapping);

        _classes.put(table + "." + identitySQL, desc);

        // If this class extends another class, create a join with the parent table and
        // add the load fields of the parent class (but not the store fields)
        if (clsMapping.getExtends() != null) {

        /**
          * TODO : Needs to be resolved by Hand
          */

            MapTo extendsTo = new MapTo()//(ClassMapping) clsMapping.getExtends()).getMapTo();
            if (extendsTo == null) {
                throw new DTXException("no mapping info for extends table.");
            }
            String extendsTable = extendsTo.getTable();
            expr.addInnerJoin(table, identitySQL, extendsTable, identitySQL);
            /**
             * needs to be resolved by hand
             */
            initQuery(new ClassMapping(), expr);
            //(ClassMapping) clsMapping.getExtends(), expr);
        }

        for (int i = 0; i < fields.length; ++i) {
            FieldMapping field = fields[i];
            Sql fieldSql = field.getSql();
            ClassMapping relMapping = _eng.getClassMapping(field.getType());

            if (fieldSql == null) {
                if (relMapping != null) {

                    // We have a one-to-many relationship with a sub object.
                    // get those objects, too.

                    FieldMapping[] relFields = relMapping.getClassChoice().getFieldMapping();
                    MapTo relMapTo = relMapping.getMapTo();

                    if (relMapTo == null) {
                        throw new DTXException("dtx.NoRelatedMapTo");
                    }

                    String relTable = relMapTo.getTable();

                    String foreKey = null;

                    for (int k = 0; k < relFields.length; k++) {
                        Sql relSql = relFields[k].getSql();
View Full Code Here

            }
            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();
                    identity = findIdentityByName(fieldList, idname, javaClass);
                    if (identity != null) { idList.set(i, identity); }
                }
            }
           
            FieldDescriptor xmlId = null;
            if (idList.size() != 0) { xmlId = (FieldDescriptor) idList.get(0); }
           
            if (xmlId != null) { xmlClassDesc.setIdentity((XMLFieldDescriptorImpl) xmlId); }
            for (int i = 0; i < fieldList.size(); i++) {
                FieldDescriptor fieldDesc = (FieldDescriptor) fieldList.get(i);
                if (fieldDesc != null) {
                    xmlClassDesc.addFieldDescriptor((XMLFieldDescriptorImpl) fieldDesc);
                }
            }
           
            if (classMapping.getAutoComplete()) {

                XMLClassDescriptor referenceDesc = null;
               
                Class type = xmlClassDesc.getJavaClass();
               
                //-- check compiled descriptors
                if ((getInternalContext() == null)
                        || (getInternalContext().getXMLClassDescriptorResolver() == null)) {
                    String message = "Internal context or class descriptor resolver within are not valid";
                    LOG.warn(message);
                    throw new IllegalStateException(message);
                }
                try {
                    referenceDesc = (XMLClassDescriptor) getInternalContext().getXMLClassDescriptorResolver().resolve(type);
                } catch (ResolverException rx) {
                    throw new MappingException(rx);
                }

                if (referenceDesc == null) {
                    Introspector introspector = getInternalContext().getIntrospector();
                    try {
                        referenceDesc = introspector.generateClassDescriptor(type);
                        if (classMapping.getExtends() != null) {
                            //-- clear parent from introspected descriptor since
                            //-- a mapping was provided in the mapping file
                            ((XMLClassDescriptorImpl) referenceDesc).setExtends(null);
                        }
                    } catch (MarshalException mx) {
                        String error = "unable to introspect class '" +
                            type.getName() + "' for auto-complete: ";
                        throw new MappingException(error + mx.getMessage());
                    }
                }

                //-- check for identity
                String identity = "";
                if (classMapping.getIdentityCount() > 0) {
                    identity = classMapping.getIdentity(0);
                }

               
                FieldDescriptor[] xmlFields2 = xmlClassDesc.getFields();

                // Attributes
                XMLFieldDescriptor[] introFields = referenceDesc.getAttributeDescriptors();
                for (int i = 0; i < introFields.length; ++i) {
                    if (!isMatchFieldName(xmlFields2, introFields[i].getFieldName())) {
                        // If there is no field with this name, we can add it
                        if (introFields[i].getFieldName().equals(identity)) {
                            xmlClassDesc.setIdentity(introFields[i]);
                        }
                        else {
                            xmlClassDesc.addFieldDescriptor(introFields[i]);
                        }
                    }
                }

                // Elements
                introFields = referenceDesc.getElementDescriptors();
                for (int i = 0; i < introFields.length; ++i) {
                    if (!isMatchFieldName(xmlFields2, introFields[i].getFieldName())) {
                        // If there is no field with this name, we can add it
                        if (introFields[i].getFieldName().equals(identity)) {
                            xmlClassDesc.setIdentity(introFields[i]);
                        }
                        else {
                            xmlClassDesc.addFieldDescriptor(introFields[i]);
                        }
                    }
                }

                // Content
                XMLFieldDescriptor field = referenceDesc.getContentDescriptor();
                if (field != null) {
                    if (!isMatchFieldName(xmlFields2, field.getFieldName())) {
                        // If there is no field with this name, we can add
                        xmlClassDesc.addFieldDescriptor(field);
                    }
                }
            }

            // Copy ns-uri + ns-prefix + element-definition
            if (mapTo != null) {
                xmlClassDesc.setNameSpacePrefix(mapTo.getNsPrefix());
                xmlClassDesc.setNameSpaceURI(mapTo.getNsUri());
                xmlClassDesc.setElementDefinition(mapTo.getElementDefinition());
            }
        }
        finally {
            getInternalContext().getXMLClassDescriptorResolver().setUseIntrospection(true);
            getInternalContext().getXMLClassDescriptorResolver().setLoadPackageMappings(true);
View Full Code Here

    public AddressJDODescriptor() {
        super();
        addNature(ClassDescriptorJDONature.class.getName());
        ClassMapping mapping = new ClassMapping();
        ClassChoice choice = new ClassChoice();
        MapTo mapTo = new MapTo();

        LOG.debug("Constructor invoked");

        // Set DB table name
        new ClassDescriptorJDONature(this).setTableName("address");
        // Set corresponding Java class
        setJavaClass(Address.class);
        // Set access mode
        new ClassDescriptorJDONature(this).setAccessMode(AccessMode.Shared);
        // Set cache key
        new ClassDescriptorJDONature(this).addCacheParam("name", "org.castor.cpa.functional.onetoone.Address");

        // Configure class mapping
        mapping.setAccess(ClassMappingAccessType.SHARED);
        mapping.setAutoComplete(true);
        mapping.setName("org.castor.cpa.functional.onetoone.Address");
        // Set class choice
        mapping.setClassChoice(choice);
        // Set table mapping
        mapping.setMapTo(mapTo);
        // Set table
        mapTo.setTable("address");
        // Set mapping
        setMapping(mapping);

        FieldDescriptor idFieldDescr = initId(choice);
View Full Code Here

        ClassMapping classMapping = new ClassMapping();
        classMapping.setName(className);

        //-- Set namespace prefix
        MapTo mapTo = new MapTo();
        classMapping.setMapTo(mapTo);

        XMLInfoNature xmlNature = new XMLInfoNature(classInfo);

        String nsPrefix = xmlNature.getNamespacePrefix();
        if ((nsPrefix != null) && (nsPrefix.length() > 0)) {
            mapTo.setNsPrefix(nsPrefix);
        }

        //-- Set namespace URI
        String nsURI = xmlNature.getNamespaceURI();
        if ((nsURI != null) && (nsURI.length() > 0)) {
            mapTo.setNsUri(nsURI);
        }

        //-- set XML Name
        mapTo.setXml(xmlNature.getNodeName());

        //-- set Element Definition flag
        mapTo.setElementDefinition(xmlNature.isElementDefinition());

        //-- set grouping compositor
        if (xmlNature.isChoice()) {
            // TODO need a way to specify choice in Mapping file
        }
View Full Code Here

        } else {
            resolveCm = new ClassMapping();
            resolveCm.setName(fm.getSql().getManyTable());
            resolveCm.setKeyGenerator(keyGen);

            MapTo mapto = new MapTo();
            mapto.setTable(fm.getSql().getManyTable());
            resolveCm.setMapTo(mapto);
            _resolveTable.put(fm.getSql().getManyTable(), resolveCm);
        }

        FieldMapping resolveFm = new FieldMapping();
View Full Code Here

    public FatherJDODescriptor() {
        super();
        ClassMapping mapping = new ClassMapping();
        ClassChoice choice = new ClassChoice();
        MapTo mapTo = new MapTo();

        addNature(ClassDescriptorJDONature.class.getName());
        ClassDescriptorJDONature jdoNature = new ClassDescriptorJDONature(this);
        jdoNature.setTableName("Father");
        setJavaClass(Father.class);
        jdoNature.setAccessMode(AccessMode.valueOf("shared"));
        jdoNature.addCacheParam("name", "org.exolab.castor.builder.cdr.generated.simple.Father");

        mapping.setAccess(ClassMappingAccessType.valueOf("shared"));
        mapping.setAutoComplete(true);
        mapping.setName("org.exolab.castor.builder.cdr.generated.simple.Father");
        mapping.setClassChoice(choice);
        mapTo.setTable("Father");
        mapping.setMapTo(mapTo);
        setMapping(mapping);

        //ssnr field
        String ssnrFieldName = "ssnr";
View Full Code Here

            return clsDesc;

        // Use super class to create class descriptor. Field descriptors will be
        // generated only for supported fields, see createFieldDesc later on.
        clsDesc = super.createDescriptor( clsMap );
        MapTo mapTo = clsMap.getMapTo();
        if (( mapTo == null) || (mapTo.getXml() == null)) {
            String clsName = clsDesc.getJavaClass().getName();
            int idx = clsName.lastIndexOf('.');
            if (idx >= 0) {
                clsName = clsName.substring(idx+1);
            }
            xmlName = _naming.toXMLName( clsName );
        }
        else {
            xmlName = clsMap.getMapTo().getXml();

        }

        XMLClassDescriptorImpl xmlClassDesc
            = new XMLClassDescriptorAdapter( clsDesc, xmlName, _primitiveNodeType );

        if (clsMap.getAutoComplete()) {

            XMLClassDescriptor referenceDesc = null;
           
            Class type = xmlClassDesc.getJavaClass();
           
            //-- check compiled descriptors
            ClassDescriptorResolverImpl cdr
                = new ClassDescriptorResolverImpl();
            cdr.setIntrospection(false);
            referenceDesc = cdr.resolve(type);
            if (referenceDesc == null) {
                Introspector introspector = new Introspector();
                try {
                    referenceDesc = introspector.generateClassDescriptor(type);
                    if (clsMap.getExtends() != null) {
                        //-- clear parent from introspected descriptor since
                        //-- a mapping was provided in the mapping file
                        ((XMLClassDescriptorImpl)referenceDesc).setExtends(null);
                    }
                } catch (MarshalException mx) {
                    String error = "unable to introspect class '" +
                        type.getName() + "' for auto-complete: ";
                    throw new MappingException(error + mx.getMessage());
                }
            }

            //-- check for identity
            String identity = "";
            if (clsMap.getIdentityCount() > 0)
                identity = clsMap.getIdentity(0);

           
            FieldDescriptor[] fields = xmlClassDesc.getFields();

            // Attributes
            XMLFieldDescriptor[] introFields = referenceDesc.getAttributeDescriptors();
            for (int i = 0; i<introFields.length; ++i) {
                if (!isMatchFieldName(fields, introFields[i].getFieldName())) {
                    // If there is no field with this name, we can add it
                    if (introFields[i].getFieldName().equals(identity)) {
                        xmlClassDesc.setIdentity(introFields[i]);
                    }
                    else {
                        xmlClassDesc.addFieldDescriptor(introFields[i]);
                    }
                }
            }

            // Elements
            introFields = referenceDesc.getElementDescriptors();
            for (int i = 0; i<introFields.length; ++i) {
                if (!isMatchFieldName(fields, introFields[i].getFieldName())) {
                    // If there is no field with this name, we can add it
                    if (introFields[i].getFieldName().equals(identity)) {
                        xmlClassDesc.setIdentity(introFields[i]);
                    }
                    else {
                        xmlClassDesc.addFieldDescriptor(introFields[i]);
                    }
                }
            }

            // Content
            XMLFieldDescriptor field = referenceDesc.getContentDescriptor();
            if (field!= null)
                if (isMatchFieldName(fields, field.getFieldName()))
                    // If there is no field with this name, we can add
                    xmlClassDesc.addFieldDescriptor(field);


        } //-- End of auto-complete


        //-- copy ns-uri + ns-prefix
        if (mapTo != null) {
            xmlClassDesc.setNameSpacePrefix(mapTo.getNsPrefix());
            xmlClassDesc.setNameSpaceURI(mapTo.getNsUri());
        }
        return xmlClassDesc;
    } //-- createDescriptor
View Full Code Here

       
        //-- prevent default access from showing up in the mapping
        classMap.setAccess(null);
       
        //-- map-to
        MapTo mapTo = new MapTo();
        mapTo.setXml( xmlClass.getXMLName() );
        mapTo.setNsUri( xmlClass.getNameSpaceURI() );
        mapTo.setNsPrefix( xmlClass.getNameSpacePrefix() );
        classMap.setMapTo( mapTo );
       
        //-- add mapping to hashtable before processing
        //-- fields so we can do recursive processing
        _mappings.put( cls, classMap );
View Full Code Here

       
        //-- prevent default access from showing up in the mapping
        classMap.setAccess(null);
       
        //-- map-to
        MapTo mapTo = new MapTo();
        mapTo.setXml( xmlClass.getXMLName() );
        mapTo.setNsUri( xmlClass.getNameSpaceURI() );
        mapTo.setNsPrefix( xmlClass.getNameSpacePrefix() );
        classMap.setMapTo( mapTo );
       
        //-- add mapping to hashtable before processing
        //-- fields so we can do recursive processing
        _mappings.put( cls, classMap );
View Full Code Here

TOP

Related Classes of org.exolab.castor.mapping.xml.MapTo

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.