Package org.exolab.castor.mapping.xml

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


     //- Constructors -/
    //----------------/

    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";
        FieldDescriptorImpl ssnrFieldDescr;
View Full Code Here


     * @see org.exolab.castor.xml.IDResolver#resolve(java.lang.String)
     */
    public Object resolve(final String idref) {
        if (_mapping == null) { return null; }
        for (int i = 0; i < _mapping.getClassMappingCount(); i++) {
            ClassMapping clsMap = _mapping.getClassMapping(i);
            if (idref.equals(clsMap.getName())) { return clsMap; }
        }
        return null;
    }
View Full Code Here

        // --------------------------------------------------------------------

        LOG.info( "Begin: Walking the mapping descriptor via objects" );

        MappingRoot mappingRoot = _mapping.getRoot();
        ClassMapping classMap;
        FieldMapping fieldMap;
        FieldMapping[] fieldMaps;

        int mappingCount = mappingRoot.getClassMappingCount();

        // loop over the classes
        for ( int i = 0; i < mappingCount; ++i )
        {
            classMap = mappingRoot.getClassMapping( i );
            LOG.debug( "Class name: " + classMap.getName() );

            fieldMaps = classMap.getClassChoice().getFieldMapping();

            LOG.debug( "fieldMaps.length: " + fieldMaps.length );

            // loop over the fields in each class
            for ( int j = 0; j < fieldMaps.length; ++j )
View Full Code Here

        enumeration = mapping.enumerateClassMapping();
       
        Vector retryList = null;
        while ( enumeration.hasMoreElements() ) {

            ClassMapping clsMap = (ClassMapping) enumeration.nextElement();
            ClassDescriptor clsDesc = null;
           
            try {
                clsDesc = createDescriptor( clsMap );
            }
            catch(MappingException mx) {
                //-- save for later for possible out-of-order
                //-- mapping files...
                if (retryList == null) {
                    retryList = new Vector();
                }
                retryList.addElement(clsMap);
                continue;
            }
           
           
            if ( clsDesc != NoDescriptor )
                addDescriptor( clsDesc );
            // If the return value is NoDescriptor then the derived
            // class was not successful in constructing a descriptor.
            if ( clsDesc == NoDescriptor && _logWriter != null ) {
                _logWriter.println( Messages.format( "mapping.ignoringMapping", clsMap.getName() ) );
            }
        }
       
        //-- handle possible retries, for now we only loop once
        //-- on the retries, but we should change this to keep
        //-- looping until we have no more success rate.
        if (retryList != null) {
            Vector tmpRetryList = retryList;
            retryList = null;
            enumeration = tmpRetryList.elements();
            while ( enumeration.hasMoreElements() ) {
                ClassMapping clsMap = (ClassMapping) enumeration.nextElement();
                ClassDescriptor clsDesc = createDescriptor( clsMap );
                if ( clsDesc != NoDescriptor )
                    addDescriptor( clsDesc );
                // If the return value is NoDescriptor then the derived
                // class was not successful in constructing a descriptor.
                if ( clsDesc == NoDescriptor && _logWriter != null ) {
                    _logWriter.println( Messages.format( "mapping.ignoringMapping", clsMap.getName() ) );
                }
            }
        }
       
View Full Code Here

        // Obtain the identity field from one of the above fields.
        // The identity field is removed from the list of fields.
        identities = null;
        boolean idfield = false;
        String[] ids;
        ClassMapping origin = clsMap;
        Vector fieldList = new Vector();

        while (origin.getExtends() != null) {
            origin = (ClassMapping) origin.getExtends();
        }
        ids = origin.getIdentity();
        if (( ids != null ) && ( ids.length > 0)) {

            // Check that an XML mapping file do not declare more identity
            // attributes for a given class than there are field elements
            // defined for that class.
View Full Code Here

         * @return the Object whose id matches the given IDREF.
        **/
        public Object resolve(String idref) {
            if (_mapping == null) return null;
            for (int i = 0; i < _mapping.getClassMappingCount(); i++) {
                ClassMapping clsMap = _mapping.getClassMapping(i);
                if (idref.equals(clsMap.getName()))
                    return clsMap;
            }
            return null;
        } //-- resolve
View Full Code Here

            ClassDescriptor clsDesc, Persistence persist )
            throws ClassNotFoundException, MappingException {

        _debug = Boolean.getBoolean("org.exolab.castor.debug");

        ClassMapping clsMap = ((ClassDescriptorImpl) clsDesc).getMapping();

        _engine = lock;

        _persistence = persist;

        _name = clsMap.getName();

        _accessMode = AccessMode.getAccessMode( clsMap.getAccess().toString() );

        _timeStampable = TimeStampable.class.isAssignableFrom( clsDesc.getJavaClass() );

        ds.register( _name, this );

        ClassMapping dep = (ClassMapping) clsMap.getDepends();
        ClassMapping ext = (ClassMapping) clsMap.getExtends();

        //if ( dep != null && ext != null )
        //    throw new MappingException("A JDO cannot both extends and depends on other objects");

        if ( dep != null ) {
            ds.pairDepends( this, dep.getName() );
        }

        if ( ext != null ) {
            ds.pairExtends( this, ext.getName() );
        }

        if ( clsDesc instanceof JDOClassDescriptor ) {
            if ( ((JDOClassDescriptor) clsDesc).getCacheType() != null ) {
                _cachetype = ((JDOClassDescriptor) clsDesc).getCacheType();
View Full Code Here

     * If the class is an extended class, the id
     * fields of the extended class will be returned.
     */
    private FieldMapping[] getIdFields( ClassMapping clsMap )
            throws MappingException {
        ClassMapping base;
        FieldMapping[] fmDepended;
        FieldMapping[] fmResult;
        FieldMapping[] fmBase;
        FieldMapping[] fmIds;
        String[] identities;

        // start with the extended class
        base = clsMap;
        while ( base.getExtends() != null ) {
            base = (ClassMapping) base.getExtends();
        }
        fmDepended = null;

        identities = base.getIdentity();

        if ( identities == null || identities.length == 0 )
            throw new MappingException("Identity is null!");


        fmIds = new FieldMapping[identities.length];
        fmBase = base.getFieldMapping();
        for ( int i = 0; i < fmBase.length; i++ ) {
            for ( int k=0; k<identities.length; k++ ) {
                if ( fmBase[i].getName().equals( identities[k] ) ) {
                    fmIds[k] = fmBase[i];
                    break;
View Full Code Here

        FieldMapping[] extendFields;
        FieldMapping[] thisFields;
        FieldMapping[] fields = null;
        String[] identities;
        boolean idfield;
        ClassMapping extend = (ClassMapping) clsMap.getExtends();
        ClassMapping origin;
        ArrayList fieldList;

        if ( extend != null ) {
            origin = extend;
            while (origin.getExtends() != null) {
                origin = (ClassMapping) origin.getExtends();
            }
            identities = origin.getIdentity();
            extendFields = getFullFields( extend );
            thisFields = clsMap.getFieldMapping();

            fieldList = new ArrayList(extendFields.length + thisFields.length);
            for (int i = 0; i < extendFields.length; i++) {
View Full Code Here

        throws MappingException
    {
        if (cls == null)
            throw new MappingException("Cannot introspect a null class.");
           
        ClassMapping clsMap;
        Method[]     methods;

        if ( _mappings.get( cls ) != null )
            return;
           
        if ( cls.isArray() ) {
           
            Class cType = cls.getComponentType();
            if ( _mappings.get(cType) != null) return;
            if (Types.isSimpleType(cType)) return;               
            //-- handle component type
            addClass( cType );
        }
           
        if ( _forceIntrospection && (!Types.isConstructable( cls )))
            throw new MappingException( "mapping.classNotConstructable", cls.getName() );

        XMLClassDescriptor xmlClass;
        FieldDescriptor[]  fields;
        ClassMapping       classMap;
        FieldMapping       fieldMap;

        boolean introspected = false;
        try {
            if (_forceIntrospection) {
                xmlClass = _introspector.generateClassDescriptor( cls );
                introspected = true;
            }
            else {
                xmlClass = _resolver.resolve( cls );
                introspected = _introspector.introspected(xmlClass);
            }
        }
        catch ( MarshalException except ) {
            throw new MappingException( except );
        }
        classMap = new ClassMapping();
        classMap.setName( cls.getName() );
        classMap.setDescription( "Default mapping for class " + cls.getName() );
       
        //-- 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 );
       
        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
                    //-- then we specify container="false" in the
                    //-- mapping file.
                    fieldMap.setContainer(false);
                }
               
                //-- try to guess collection type
                if (isArray) {
                    fieldMap.setCollection(CollectionType.ARRAY);
                }
                else {
                    //-- if the fieldType is the collection, then set appropriate
                    //-- collection type
                    String colName = CollectionHandlers.getCollectionName(fieldType);
                    if (colName != null) {
                        fieldMap.setCollection(CollectionType.valueOf(colName));
                        fieldType = Object.class;
                    }
                    //-- help maintain compatibility with generated
                    //-- descriptors
                    else if (_mappingLoader.returnsArray(cls, fieldName, fieldType)) {
                        fieldMap.setCollection( CollectionType.ARRAY );
                    }
                    else {
                        fieldMap.setCollection( CollectionType.ENUMERATE );
                    }
                }
            }
           
            //-- fieldType
            fieldMap.setType( fieldType.getName() );
           
               
            //-- handle XML Specific information
            fieldMap.setBindXml( new BindXml() );
            fieldMap.getBindXml().setName( ( (XMLFieldDescriptor) fdesc ).getXMLName() );
            fieldMap.getBindXml().setNode( BindXmlNodeType.valueOf( ((XMLFieldDescriptor) fields[ i ]).getNodeType().toString() ) );
            classMap.addFieldMapping( fieldMap );
           
            if (deep) {
                if ( _mappings.get(fieldType) != null) continue;
                if (Types.isSimpleType(fieldType)) continue;               
                //-- recursive add needed classes
View Full Code Here

TOP

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

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.