Package org.exolab.castor.mapping

Examples of org.exolab.castor.mapping.ClassDescriptor


     * @return JDOFieldDescriptor for the specified field, null if not found.
     */
    private FieldDescriptor getFieldDesc(final String fieldName,
                                            final ClassDescriptor clsDesc) {

        ClassDescriptor classDescriptor = clsDesc;
        FieldDescriptor fieldDescriptor;
        while (classDescriptor != null) {
            fieldDescriptor = new ClassDescriptorJDONature(classDescriptor).getField(fieldName);
            if (fieldDescriptor != null) {
                return fieldDescriptor;
            }
            classDescriptor = classDescriptor.getExtends();
        }
        return null;
    }
View Full Code Here


                                          final ClassDescriptor clsDesc,
                                          final QueryExpression expr,
                                          final Vector path, final int tableIndex) {
       
        FieldDescriptor field = null;
        ClassDescriptor cd = clsDesc;
        FieldDescriptor tempField = null;
        ClassDescriptor tempCd = clsDesc;
        Object[] retVal;

        while (tempCd != null) {
            tempField = new ClassDescriptorJDONature(tempCd).getField(fieldName);
            if (tempField != null) {
                field = tempField;
                cd = tempCd;
            }
            tempCd = tempCd.getExtends();
        }
    
        if (field == null) { return null; }

        // prepare the return value
View Full Code Here

                    projectionName.append(curName);
                    projectionInfo.addElement(curName);
                }

                //use the ClassDescriptor to check that the rest of the path is valid.
                ClassDescriptor curClassDesc = _clsDesc;
                FieldDescriptor curField = null;
                int count = 0;
                String curToken;
                while (iter.hasNext()) {
                    // there may be nested attribute name
View Full Code Here

        }

        _queryExpr.addTable(new ClassDescriptorJDONature(_clsDesc).getTableName());

        // add table names and joins for all base classes
        ClassDescriptor oldDesc = _clsDesc;
        ClassDescriptor tempDesc = _clsDesc.getExtends();
        while (tempDesc != null) {
            String tableName = new ClassDescriptorJDONature(tempDesc).getTableName();
            _queryExpr.addTable(tableName);
           
            FieldDescriptor leftField = oldDesc.getIdentity();
            FieldDescriptor rightField = tempDesc.getIdentity();
           
            _queryExpr.addInnerJoin(
                    new ClassDescriptorJDONature(oldDesc).getTableName(),
                    new FieldDescriptorJDONature(leftField).getSQLName(),
                    new ClassDescriptorJDONature(tempDesc).getTableName(),
                    new FieldDescriptorJDONature(rightField).getSQLName());

            oldDesc = tempDesc;
            tempDesc = tempDesc.getExtends();
        }
        _queryExpr.addSelect(getSQLExpr(selectPart));
    }
View Full Code Here

        if (path == null) {
            throw new IllegalStateException("path = null !");
        }

        // the class for the join is even this class or one of the base classes
        ClassDescriptor sourceClass = _clsDesc;

        for (int i = 1; i < path.size() - 1; i++) {
            FieldDescriptor fieldDesc = null;

            // Find the sourceclass and the fielsddescriptor in the class hierachie
            Object[] fieldAndClass = getFieldAndClassDesc(
                    (String) path.elementAt(i), sourceClass, _queryExpr, path, i - 1);
            if (fieldAndClass == null) {
                throw new IllegalStateException("Field not found:" + path.elementAt(i));
            }
            fieldDesc = (FieldDescriptor) fieldAndClass[0];
            sourceClass = (ClassDescriptor) fieldAndClass[1];

            ClassDescriptor clsDesc = fieldDesc.getClassDescriptor();
            FieldDescriptorJDONature fieldJDONature = new FieldDescriptorJDONature(fieldDesc);
            if (clsDesc != null) {
                //we must add this table as a join
                ClassDescriptorJDONature sourceClassJDONature =
                    new ClassDescriptorJDONature(sourceClass);
                if (fieldJDONature.getManyKey() == null) {
                    //a many -> one relationship
                    FieldDescriptor foreignKey = clsDesc.getIdentity();
                    String sourceTableAlias = sourceClassJDONature.getTableName();
                    if (i > 1) {
                        sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
                    }

                    ClassDescriptorJDONature clsDescNature;
                    clsDescNature = new ClassDescriptorJDONature(clsDesc);
                    _queryExpr.addInnerJoin(
                            sourceClassJDONature.getTableName(),
                            new FieldDescriptorJDONature(fieldDesc).getSQLName(),
                            sourceTableAlias,
                            clsDescNature.getTableName(),
                            new FieldDescriptorJDONature(foreignKey).getSQLName(),
                            buildTableAlias(clsDescNature.getTableName(), path, i));
                } else if (fieldJDONature.getManyTable() == null) {
                    //a one -> many relationship
                    FieldDescriptor identity = sourceClass.getIdentity();
                    String sourceTableAlias = sourceClassJDONature.getTableName();
                    if (i > 1) {
                        sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
                    }

                    ClassDescriptorJDONature clsDescNature;
                    clsDescNature = new ClassDescriptorJDONature(clsDesc);
                    _queryExpr.addInnerJoin(
                            sourceClassJDONature.getTableName(),
                            new FieldDescriptorJDONature(identity).getSQLName(),
                            sourceTableAlias,
                            clsDescNature.getTableName(),
                            fieldJDONature.getManyKey(),
                            buildTableAlias(clsDescNature.getTableName(), path, i));
                } else {
                    //a many -> many relationship
                    FieldDescriptor identity = sourceClass.getIdentity();
                    FieldDescriptor foreignKey = clsDesc.getIdentity();
                    String manyTableAlias = fieldJDONature.getManyTable();
                    String sourceTableAlias = sourceClassJDONature.getTableName();
                    if (i > 1) {
                        manyTableAlias = buildTableAlias(manyTableAlias, path, i - 1);
                        sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
View Full Code Here

            if (field == null) {
                throw new IllegalStateException(
                        "fieldInfo for " + exprTree.toStringEx() + " not found");
            }
           
            ClassDescriptor clsDesc = field.getContainingClassDescriptor();
            if (clsDesc == null) {
                throw new IllegalStateException(
                        "ContainingClass of " + field.toString() + " is null !");
            }
           
            String clsTableAlias;
            ClassDescriptorJDONature classDescriptorJDONature =
                new ClassDescriptorJDONature(clsDesc);
                if (tokenType == TokenType.DOT && path != null && path.size() > 2) {
              clsTableAlias = buildTableAlias(
                      classDescriptorJDONature.getTableName(), path, path.size() - 2);
              ClassDescriptor srcDesc = _clsDesc;
              for (int i = 1; i < path.size(); i++) {
                Object[] fieldAndClass = getFieldAndClassDesc(
                                                              (String) path.elementAt(i),
                                                              srcDesc, _queryExpr, path, i - 1);
                if (fieldAndClass == null) {
                  throw new IllegalStateException("Field not found: "
                                                  + path.elementAt(i) + " class "
                                                  + srcDesc.getJavaClass());
                }
                FieldDescriptor fieldDesc = (FieldDescriptor) fieldAndClass[0];
                srcDesc = fieldDesc.getClassDescriptor();
              }
            } else {
View Full Code Here

       
        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() ) );
                }
            }
        }
       

        enumeration = _clsDescs.elements();
        while ( enumeration.hasMoreElements() ) {
            ClassDescriptor clsDesc;

            clsDesc = (ClassDescriptor) enumeration.nextElement();
            if ( clsDesc != NoDescriptor  )
                resolveRelations( clsDesc );
        }
View Full Code Here

    {
        FieldDescriptor[] fields;

        fields = clsDesc.getFields();
        for ( int i = 0 ; i < fields.length ; ++i ) {
            ClassDescriptor   relDesc;

            relDesc = getDescriptor( fields[ i ].getFieldType() );
            if ( relDesc == NoDescriptor ) {
                // XXX Error message should come here
            } else if ( relDesc != null && fields[ i ] instanceof FieldDescriptorImpl ) {
View Full Code Here

            throws MappingException {

        FieldDescriptor[] fields;
        FieldDescriptor[] identities;
        Class             javaClass;
        ClassDescriptor   extend;
        ClassDescriptor   depend;
        ClassDescriptor   clsDesc;

        // See if we have a compiled descriptor.
        clsDesc = loadClassDescriptor( clsMap.getName() );
        if ( clsDesc != null )
            return clsDesc;
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;
           
            relDesc = getDescriptor( fields[ i ].getFieldType() );
            if ( relDesc == NoDescriptor ) {
                // XXX Error message should come here
            }
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.