Package org.exolab.castor.mapping

Examples of org.exolab.castor.mapping.FieldDescriptor


        _mappings.put( cls, classMap );
       
        fields = xmlClass.getFields();
        for ( int i = 0 ; i < fields.length ; ++i ) {
           
            FieldDescriptor fdesc = fields[ i ];
           
            String fieldName = fdesc.getFieldName();
           
            boolean isContainer = false;
            //-- check for collection wrapper
            if (introspected && fieldName.startsWith("##container")) {
                fdesc = fdesc.getClassDescriptor().getFields()[0];
                fieldName = fdesc.getFieldName();
                isContainer = true;
            }
           
           
            Class fieldType = fdesc.getFieldType();
           
           
            //-- check to make sure we can find the accessors...
            //-- if we used introspection we don't need to
            //-- enter this block...only when descriptors
            //-- were generated using the source code generator
            //-- or by hand.
            if ((!introspected) && fieldName.startsWith(UNDERSCORE)) {
               
                //-- check to see if we need to remove underscore
                if (!_mappingLoader.canFindAccessors(cls, fieldName, fieldType))
                    fieldName = fieldName.substring(1);
               
                //-- check to see if we need to remove "List" prefix
                //-- used by generated source code
                if (!_mappingLoader.canFindAccessors(cls, fieldName, fieldType))
                {
                    if (fieldName.endsWith("List")) {
                        int len = fieldName.length()-4;
                        String tmpName = fieldName.substring(0, len);
                        if (_mappingLoader.canFindAccessors(cls, tmpName, fieldType))
                            fieldName = tmpName;                           
                    }
                }
            }
           
            fieldMap = new FieldMapping();
            fieldMap.setName( fieldName );
           
           
            //-- unwrap arrays of objects
            boolean isArray = fieldType.isArray();
            while (fieldType.isArray())
                fieldType = fieldType.getComponentType();
               
           
            //-- To prevent outputing of optional fields...check
            //-- for value first before setting
            if (fdesc.isRequired())  fieldMap.setRequired( true );
            if (fdesc.isTransient()) fieldMap.setTransient( true );
            if ( fdesc.isMultivalued() ) {
               
                //-- special case for collections
                if (isContainer) {
                    //-- backwards than what you'd expect, but
                    //-- if the collection had a "container" wrapper
View Full Code Here



    protected FieldDescriptor createFieldDesc( Class javaClass, FieldMapping fieldMap )
            throws MappingException {

        FieldDescriptor  fieldDesc;
        String[]           sqlName;
        Class            sqlType;
        int[]            sType;

        // If not an SQL field, return a stock field descriptor.
        if ( fieldMap.getSql() == null )
            return super.createFieldDesc( javaClass, fieldMap );

        // Create a JDO field descriptor
        fieldDesc = super.createFieldDesc( javaClass, fieldMap );

        sqlName = fieldMap.getSql().getName();

        String[] sqlTypes = getSqlTypes(fieldMap);

        int len = sqlTypes.length;
        if ( len > 0 ) {
            sType = new int[len];
            for ( int i=0; i < len; i++ ) {
                sqlType = SQLTypes.typeFromName( sqlTypes[i] );
                if ( _factory != null )
                    sqlType = _factory.adjustSqlType( sqlType );
                sType[i] = SQLTypes.getSQLType( sqlType );
            }
        } else {
            sqlType = fieldDesc.getFieldType();
            if ( _factory != null )
                sqlType = _factory.adjustSqlType( sqlType );
            sType = new int[] {SQLTypes.getSQLType(sqlType)};
        }
View Full Code Here

                xmlClassDesc = new XMLClassDescriptorAdapter(extendsDesc, null, primitiveNodeType);
            }
        }
        setExtends(xmlClassDesc);
       
        FieldDescriptor   identity = classDesc.getIdentity();
        FieldDescriptor[] fields   = classDesc.getFields();
       
        //-- Note from Keith for anyone interested...
        //-- hack for multiple identities if ClassDescriptor is
        //-- an implementation of ClassDescriptorImpl...
        //-- 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++) {
                    newFields[idx] = fields[idx];
                }
                for (int i = 0; i < identities.length; i++) {
                    newFields[idx++] = identities[i];
                }
                fields = newFields;
            }
        }
        //-- End ClassDescriptorImpl fix
       
        for (int i = 0; i < fields.length; i++) {
            FieldDescriptor fieldDesc = fields[i];
            if (fieldDesc == null) continue;
            if ( fieldDesc instanceof XMLFieldDescriptorImpl ) {
                if (identity == fieldDesc) {
                    setIdentity((XMLFieldDescriptorImpl)fieldDesc);
                    identity = null; //-- clear identity
                }
                else {
                    addFieldDescriptor((XMLFieldDescriptorImpl)fieldDesc);
                }
            }
            else {
                String name = fieldDesc.getFieldName();
                XMLNaming naming = XMLNaming.getInstance();
                String xmlFieldName = naming.toXMLName(name);
                   
                if (identity == fieldDesc) {
                    setIdentity(new XMLFieldDescriptorImpl(fieldDesc,
                                                          xmlFieldName,
                                                         NodeType.Attribute,
                                                         primitiveNodeType));
                    identity = null; //-- clear identity
                }
                else {
                    NodeType nodeType = NodeType.Element;
                    if (isPrimitive(fieldDesc.getFieldType()))
                        nodeType = primitiveNodeType;
                       
                    addFieldDescriptor(new XMLFieldDescriptorImpl(fieldDesc,
                                                                xmlFieldName,
                                                                nodeType,
View Full Code Here

     * @param classDesc the XMLClassDescriptor to process
    **/
    private void process(XMLClassDescriptor classDesc)
        throws org.exolab.castor.mapping.MappingException
    {
        FieldDescriptor identity = classDesc.getIdentity();
        FieldDescriptor[] fields = classDesc.getFields();
        for (int i = 0; i < fields.length; i++) {
            if (identity == fields[i]) {
                setIdentity((XMLFieldDescriptor)fields[i]);
                identity = null; //-- clear identity
View Full Code Here

        _mappings.put( cls, classMap );
       
        fields = xmlClass.getFields();
        for ( int i = 0 ; i < fields.length ; ++i ) {
           
            FieldDescriptor fdesc = fields[ i ];
           
            String fieldName = fdesc.getFieldName();
           
            boolean isContainer = false;
            //-- check for collection wrapper
            if (introspected && fieldName.startsWith("##container")) {
                fdesc = fdesc.getClassDescriptor().getFields()[0];
                fieldName = fdesc.getFieldName();
                isContainer = true;
            }
           
           
            Class fieldType = fdesc.getFieldType();
           
           
            //-- check to make sure we can find the accessors...
            //-- if we used introspection we don't need to
            //-- enter this block...only when descriptors
            //-- were generated using the source code generator
            //-- or by hand.
            if ((!introspected) && fieldName.startsWith(UNDERSCORE)) {
               
                //-- check to see if we need to remove underscore
                if (!_mappingLoader.canFindAccessors(cls, fieldName, fieldType))
                    fieldName = fieldName.substring(1);
               
                //-- check to see if we need to remove "List" prefix
                //-- used by generated source code
                if (!_mappingLoader.canFindAccessors(cls, fieldName, fieldType))
                {
                    if (fieldName.endsWith("List")) {
                        int len = fieldName.length()-4;
                        String tmpName = fieldName.substring(0, len);
                        if (_mappingLoader.canFindAccessors(cls, tmpName, fieldType))
                            fieldName = tmpName;                           
                    }
                }
            }
           
            fieldMap = new FieldMapping();
            fieldMap.setName( fieldName );
           
           
            //-- unwrap arrays of objects
            boolean isArray = fieldType.isArray();
            while (fieldType.isArray())
                fieldType = fieldType.getComponentType();
               
           
            //-- To prevent outputing of optional fields...check
            //-- for value first before setting
            if (fdesc.isRequired())  fieldMap.setRequired( true );
            if (fdesc.isTransient()) fieldMap.setTransient( true );
            if ( fdesc.isMultivalued() ) {
               
                //-- special case for collections
                if (isContainer) {
                    //-- backwards than what you'd expect, but
                    //-- if the collection had a "container" wrapper
View Full Code Here


    protected FieldDescriptor createFieldDesc( Class javaClass, FieldMapping fieldMap )
        throws MappingException
    {
        FieldDescriptor        fieldDesc;
        String                 xmlName  = null;
        NodeType               nodeType = null;
        String                 match    = null;
        XMLFieldDescriptorImpl xmlDesc;
        boolean                isReference = false;
        boolean                isXMLTransient = false;

        // Create an XML field descriptor

        fieldDesc = super.createFieldDesc( javaClass, fieldMap );

        BindXml xml = fieldMap.getBindXml();

        boolean deriveNameByClass = false;

        if (xml != null) {
            //-- xml name
            xmlName = xml.getName();

            //-- node type
            if ( xml.getNode() != null )
                nodeType = NodeType.getNodeType( xml.getNode().toString() );

            //-- matches
            match = xml.getMatches();

            //-- reference
            isReference = xml.getReference();

            //-- XML transient
            isXMLTransient = xml.getTransient();

            //-- autonaming
            BindXmlAutoNamingType autoName = xml.getAutoNaming();
            if (autoName != null) {
                deriveNameByClass = (autoName == BindXmlAutoNamingType.DERIVEBYCLASS);
            }

        }
       
        //-- transient
        //-- XXXX -> if it's transient we probably shouldn't do all
        //-- XXXX -> the unecessary work
        isXMLTransient = isXMLTransient || fieldDesc.isTransient();
       
        //--

        //-- handle QName for xmlName
        String namespace = null;
        if ((xmlName != null) && (xmlName.length() > 0)){
            if (xmlName.charAt(0) == '{') {
                int idx = xmlName.indexOf('}');
                if (idx < 0) {
                    throw new MappingException("Invalid QName: " + xmlName);
                }
                namespace = xmlName.substring(1, idx);
                xmlName = xmlName.substring(idx+1);
            }
        }

        if (nodeType == null) {
            if (isPrimitive(javaClass))
                nodeType = _primitiveNodeType;
            else
                nodeType = NodeType.Element;
        }

        //-- Create XML name if necessary. Note if name is to be derived
        //-- by class..we just make sure we set the name to null...
        //-- the Marshaller does this during runtime. This allows
        //-- Collections to be handled properly.
        if ((!deriveNameByClass) && ((xmlName == null) && (match == null)))
        {
            xmlName = _naming.toXMLName( fieldDesc.getFieldName() );
            match = xmlName + ' ' + fieldDesc.getFieldName();
        }

        xmlDesc = new XMLFieldDescriptorImpl( fieldDesc, xmlName, nodeType, _primitiveNodeType );

        //-- transient?
View Full Code Here

TOP

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

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.