Package org.exolab.castor.mapping

Examples of org.exolab.castor.mapping.ClassDescriptor


                        throw new MappingException(
                                "Identity type must contains sql information: " + _name);
                    }
                }

                ClassDescriptor relDesc = null;
                try {
                    JDOClassDescriptorResolver jdoCDR;
                    jdoCDR = (JDOClassDescriptorResolver) classDescrResolver;
                    relDesc = jdoCDR.resolve(fmFields[i].getType());
                } catch (ResolverException e) {
                    throw new MappingException("Problem resolving class descriptor for class "
                            + fmFields.getClass(), e);
                }
                               
                if (relDesc.hasNature(ClassDescriptorJDONature.class.getName())) {
                    FieldDescriptor[] relatedIds = ((ClassDescriptorImpl) relDesc).getIdentities();
                    relatedIdSQL = new String[relatedIds.length];
                    relatedIdType = new int[relatedIds.length];
                    relatedIdConvertTo = new TypeConvertor[relatedIds.length];
                    relatedIdConvertFrom = new TypeConvertor[relatedIds.length];
                    for (int j = 0; j < relatedIdSQL.length; j++) {
                        if (relatedIds[j].hasNature(FieldDescriptorJDONature.class.getName())) {
                            FieldDescriptorJDONature nature;
                            nature = new FieldDescriptorJDONature(relatedIds[j]);
                            String[] tempId = nature.getSQLName();
                            relatedIdSQL[j] = (tempId == null) ? null : tempId[0];
                            int[] tempType =  nature.getSQLType();
                            relatedIdType[j] = (tempType == null) ? 0 : tempType[0];
                            FieldHandlerImpl fh = (FieldHandlerImpl) relatedIds[j].getHandler();
                            relatedIdConvertTo[j] = fh.getConvertTo();
                            relatedIdConvertFrom[j] = fh.getConvertFrom();
                        } else {
                            throw new MappingException(
                                    "Field type is not persistence-capable: "
                                    + relatedIds[j].getFieldName());
                        }
                    }
                }

                // if many-key exist, idSQL is overridden
                String[] manyKey = fmFields[i].getSql().getManyKey();
                if ((manyKey != null) && (manyKey.length != 0)) {
                    if (manyKey.length != idSQL.length) {
                        throw new MappingException(
                                "The number of many-keys doesn't match referred object: "
                                + clsDesc.getJavaClass().getName());
                    }
                    idSQL = manyKey;
                }

                // if name="" exist, relatedIdSQL is overridden
                String[] manyName = fmFields[i].getSql().getName();
                if ((manyName != null) && (manyName.length != 0)) {
                    if (manyName.length != relatedIdSQL.length) {
                        throw new MappingException(
                                "The number of many-keys doesn't match referred object: "
                                + relDesc.getJavaClass().getName());
                    }
                    relatedIdSQL = manyName;
                }
               
                _fhs[fieldMolderNumber] = new FieldMolder(ds, this, fmFields[i], manyTable, idSQL,
View Full Code Here


        // get the id of the target object
        String id = null;
        try {
            ClassDescriptorResolver classDescriptorResolver = context.getClassDescriptorResolver();
            ClassDescriptor classDescriptor = classDescriptorResolver.resolve(object.getClass());
            FieldDescriptor fieldDescriptor = classDescriptor.getIdentity();
            FieldHandler fieldHandler = fieldDescriptor.getHandler();
            id = (String) fieldHandler.getValue(object);
        } catch (Exception e) {
            String err = "The object associated with IDREF \"" + object
            + "\" of type " + object.getClass() + " has no ID!";
View Full Code Here

            if (containerObject == null) {
                containerObject = handler.newInstance(parent);
                handler.setValue(parent, containerObject);
            }

            ClassDescriptor containerClassDesc =
                ((XMLFieldDescriptorImpl) descriptor).getClassDescriptor();
            descriptor = ((XMLClassDescriptor) containerClassDesc).getFieldDescriptor(
                    attName, attNamespace, NodeType.Attribute);
            parent = containerObject;
        }
View Full Code Here

                        final FieldDescriptor fieldDesc,
                        final String classTable, final boolean ext)
    throws MappingException {
        _fieldDescriptor = fieldDesc;
       
        ClassDescriptor related = fieldDesc.getClassDescriptor();
        if (related != null) {
            if (!(related.hasNature(ClassDescriptorJDONature.class.getName()))) {
                throw new MappingException("Related class is not JDOClassDescriptor");
            }

            FieldDescriptor[] relids = ((ClassDescriptorImpl) related).getIdentities();
            String[] relnames = new String[relids.length];
View Full Code Here

                _results = null;
            }
        }
       
        private Object followPath(final Object parent) {
            ClassDescriptor curClassDesc = _classDescriptor;
            Object curObject = parent;
            for (int i = 1; i < _pathInfo.size(); i++) {
                String curFieldName = (String) _pathInfo.elementAt(i);
                try {
                    ClassDescriptorJDONature nature;
View Full Code Here

         * A class may extend a dependent class.
         * A class may extend a depended class.
         * No loop or circle should exist
         */
        // then, we put depended class ids in the back
        ClassDescriptor base = clsDesc;

        // walk until the base class which this class extends
        base = clsDesc;
        Stack stack = new Stack();
        stack.push(base);
        while (base.getExtends() != null) {
            // if (base.getDepends() != null) {
            //     throw new MappingException(
            //             "Class should not both depends on and extended other classes");
            // }
            base = base.getExtends();
            stack.push(base);
            // do we need to add loop detection?
        }

        // now base is either the base of extended class, or
        // clsDesc
        // we always put the original id info in front
        // [oleg] except for SQL name, it may differ.
        FieldDescriptor[] baseIdDescriptors = ((ClassDescriptorImpl) base).getIdentities();
        FieldDescriptor[] idDescriptors = ((ClassDescriptorImpl) clsDesc).getIdentities();

        for (int i = 0; i < baseIdDescriptors.length; i++) {
            if (baseIdDescriptors[i].hasNature(FieldDescriptorJDONature.class.getName())) {
                String name = baseIdDescriptors[i].getFieldName();
                String[] sqlName =
                    new FieldDescriptorJDONature(baseIdDescriptors[i]).getSQLName();
                int[] sqlType =  new FieldDescriptorJDONature(baseIdDescriptors[i]).getSQLType();
                FieldHandlerImpl fh = (FieldHandlerImpl) baseIdDescriptors[i].getHandler();

                // The extending class may have other SQL names for identity fields
                for (int j = 0; j < idDescriptors.length; j++) {
                    if (name.equals(idDescriptors[j].getFieldName())
                            && (idDescriptors[j].hasNature(JDO_FIELD_NATURE))) {
                        sqlName = new FieldDescriptorJDONature(idDescriptors[j]).getSQLName();
                        break;
                    }
                }
                idsInfo.add(new SQLColumnInfo(sqlName[0], sqlType[0], fh.getConvertTo(),
                        fh.getConvertFrom()));
            } else {
                throw new MappingException("Except JDOFieldDescriptor");
            }
        }

        // then do the fields
        while (!stack.empty()) {
            base = (ClassDescriptor) stack.pop();
            FieldDescriptor[] fieldDescriptors = base.getFields();
            for (int i = 0; i < fieldDescriptors.length; i++) {
                // fieldDescriptors[i] is persistent in db if it is not transient
                // and it is a JDOFieldDescriptor or has a ClassDescriptor
                if (!fieldDescriptors[i].isTransient()) {
                    if ((fieldDescriptors[i].hasNature(FieldDescriptorJDONature.class.getName()))
View Full Code Here

    public static Object[] calculateNumberOfFields(final Collection extendingClassDescriptors,
            final int numberOfIdentityColumns, final int numberOfFields,
            final int numberOfExtendLevels, final ResultSet rs) throws SQLException {
       
        ClassDescriptor potentialLeafDescriptor = null;
        int suggestedNumberOfFields = numberOfFields;
        Collection potentialActualClassDescriptor = new LinkedList();
        int numberOfIdentitiesToAnalyze = 0;
        addExtendingClassDescriptors(potentialActualClassDescriptor, extendingClassDescriptors);
       
        ClassDescriptor potentialClassDescriptor = null;
        ClassDescriptor potentialClassDescriptorPrevious = null;
        int initialColumnIndex =
            numberOfFields + numberOfIdentityColumns * numberOfExtendLevels + 1;
        int columnIndex = initialColumnIndex;
        int numberOfExtendingClassDescriptors = 0;
        for (Iterator iter = potentialActualClassDescriptor.iterator(); iter.hasNext(); ) {
View Full Code Here

        return new Object[] {potentialLeafDescriptor, new Integer (suggestedNumberOfFields) };
    }

    public static int numberOfExtendingClassDescriptors(final ClassDescriptor classDescriptor) {
        int numberOfExtendLevels = 1;
        ClassDescriptor currentClassDescriptor = classDescriptor;
        while (currentClassDescriptor.getExtends() != null) {
            currentClassDescriptor = currentClassDescriptor.getExtends();
            numberOfExtendLevels++;
        }
        return numberOfExtendLevels;
    }
View Full Code Here

    }

    public static void addExtendingClassDescriptors(
            final Collection classDescriptorsToAdd, final Collection extendingClassDescriptors) {

        ClassDescriptor classDescriptor = null;
        for (Iterator iter = extendingClassDescriptors.iterator(); iter.hasNext(); ) {
            classDescriptor = (ClassDescriptor) iter.next();
            classDescriptorsToAdd.add (classDescriptor);
            ClassDescriptorJDONature nature = new ClassDescriptorJDONature(classDescriptor);
            addExtendingClassDescriptors(classDescriptorsToAdd, nature.getExtended());
View Full Code Here

            return;
        }

        //-- handle inheritence
        XMLClassDescriptor xmlClassDesc = null;
        ClassDescriptor extendsDesc = classDesc.getExtends();
        if (extendsDesc != null) {
            if (extendsDesc instanceof XMLClassDescriptor) {
                xmlClassDesc = (XMLClassDescriptor) extendsDesc;
            } else {
                xmlClassDesc = new XMLClassDescriptorAdapter(extendsDesc, null, primitiveNodeType);
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.