Package org.exolab.castor.mapping

Examples of org.exolab.castor.mapping.FieldDescriptor


        KeyGenerator keyGen = null;
        if (engine.getDescriptor().getExtends() == null) {
            KeyGeneratorDescriptor keyGenDesc =
                new ClassDescriptorJDONature(engine.getDescriptor()).getKeyGeneratorDescriptor();
            if (keyGenDesc != null) {
                FieldDescriptor fldDesc = engine.getDescriptor().getIdentity();
                int[] tempType = new FieldDescriptorJDONature(fldDesc).getSQLType();
                keyGen = keyGenDesc.getKeyGeneratorRegistry().getKeyGenerator(
                        factory, keyGenDesc, (tempType == null) ? 0 : tempType[0]);

                // Does the key generator support the sql type specified in the mapping?
View Full Code Here


                if ((idNames == null) || (idNames.length == 0)) {
                    // There are also no identity definitions on class.
                    throw new MappingException("mapping.noIdentity", javaClass.getName());
                }

                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 all identities of extended class to identity list.
            FieldDescriptor[] extIds = ((ClassDescriptorImpl) extDesc).getIdentities();
            for (int i = 0; i < extIds.length; i++) { idList.add(extIds[i]); }
           
            // 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); }
            }
View Full Code Here

   
    protected FieldDescriptor findIdentityByName(
            final List fldList, final String idName, final Class javaClass)
    throws MappingException {
        for (int i = 0; i < fldList.size(); i++) {
            FieldDescriptor field = (FieldDescriptor) fldList.get(i);
            if (idName.equals(field.getFieldName())) {
                if (!(field.hasNature(FieldDescriptorJDONature.class.getName()))) {
                    throw new IllegalStateException(
                            "Identity field must be of type JDOFieldDescriptor");
                }
               
                String[] sqlName = new FieldDescriptorJDONature(field).getSQLName();
                if (sqlName == null) {
                    throw new MappingException("mapping.noSqlName",
                            field.getFieldName(), javaClass.getName());
                }

                fldList.remove(i);
                return field;
            }
View Full Code Here

     *            The ClassDescriptor in focus.
     */
    protected void resolveRelations(final ClassDescriptor clsDesc) {
        FieldDescriptor[] fields = clsDesc.getFields();
        for (int i = 0; i < fields.length; ++i) {
            FieldDescriptor field = fields[i];
            ClassDescriptor desc = getDescriptor(field.getFieldType().getName());
            // Resolve ClassDescriptor from the file system as well.
            if (desc == null && !field.getFieldType().isPrimitive()) {
                ClassResolutionByFile resolutionCommand = new ClassResolutionByFile();
                resolutionCommand.addNature(ClassLoaderNature.class.getName());
                ClassLoaderNature clNature = new ClassLoaderNature(
                        resolutionCommand);
                clNature.setClassLoader(getClassLoader());
                desc = resolutionCommand.resolve(field.getFieldType());
                ((FieldDescriptorImpl) field).setClassDescriptor(desc);
            }
            if ((desc != null) && (field instanceof FieldDescriptorImpl)) {
                ((FieldDescriptorImpl) field).setClassDescriptor(desc);
            }
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!";
            throw new ValidationException(err);
View Full Code Here

                if (!(relids[i].hasNature(FieldDescriptorJDONature.class.getName()))) {
                    throw new MappingException("Related class identities field does "
                            + "not contains sql information!");
                }

                FieldDescriptor relId = relids[i];
                FieldHandlerImpl fh = (FieldHandlerImpl) relId.getHandler();
                _columns[i] = new SQLColumnInfo(names[i],
                        new FieldDescriptorJDONature(relId).getSQLType()[0],
                        fh.getConvertTo(), fh.getConvertFrom());
            }
        } else {
View Full Code Here

     * @return The associated {@link FieldDescriptor}.
     */
    public FieldDescriptor getField(final String name) {
        FieldDescriptor[] fields = ((ClassDescriptor) getHolder()).getFields();
        for (int i = 0; i < fields.length; ++i) {
            FieldDescriptor field = fields[i];
            if ((field.hasNature(FieldDescriptorJDONature.class.getName()))
                    && (field.getFieldName().equals(name))) {
                return field;
            }
        }
       
        FieldDescriptor[] identities = ((ClassDescriptorImpl) getHolder()).getIdentities();
        for (int i = 0; i < identities.length; ++i) {
            FieldDescriptor field = identities[i];
            if ((field.hasNature(FieldDescriptorJDONature.class.getName()))
                    && (field.getFieldName().equals(name))) {
                return field;
            }
        }

        return null;
View Full Code Here

            for (int i = 1; i < _pathInfo.size(); i++) {
                String curFieldName = (String) _pathInfo.elementAt(i);
                try {
                    ClassDescriptorJDONature nature;
                    nature = new ClassDescriptorJDONature(curClassDesc);
                    FieldDescriptor curFieldDesc = nature.getField(curFieldName);
                    FieldHandler handler = curFieldDesc.getHandler();
                    curObject = handler.getValue(curObject);
                    curClassDesc = curFieldDesc.getClassDescriptor();
                } catch (Exception ex) {
                    throw new NoSuchElementException(
                            "An exception was thrown trying to access get methods to follow "
                            + "the path expression. " + ex.toString());
                }
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];
                System.arraycopy(fields, 0, newFields, 0, fields.length);
                System.arraycopy(identities, 0, newFields, fields.length, identities.length);
                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();
                String xmlFieldName = _internalContext.getXMLNaming().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,
View Full Code Here

     * XMLClassDescriptor.
     *
     * @param classDesc the XMLClassDescriptor to process
     */
    private void process(XMLClassDescriptor classDesc) {
        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

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.