Package org.exolab.castor.builder.info

Examples of org.exolab.castor.builder.info.FieldInfo


                SimpleType temp = simpleContent.getSimpleType();
                SimpleType baseType = (SimpleType) temp.getBaseType();
                XSType xsType = _typeConversion.convertType(
                        temp, state.getPackageName(), getConfig().useJava50());

                FieldInfo fieldInfo = null;
                if ((baseType != null) && extendsSimpleType(state.getJClass(), baseType, state)) {
                    if (xsType.isEnumerated()) {
                        fieldInfo = _memberFactory.createFieldInfoForContent(
                                component, xsType, getConfig().useJava50());
                        fieldInfo.setBound(false);

                        handleField(fieldInfo, state, component);

                        //-- remove getter since we don't need to override the original getter
                        String mname = fieldInfo.getReadMethodName();
                        JClass jClass = state.getJClass();
                        JMethod method = jClass.getMethod(mname, 0);
                        jClass.removeMethod(method);

                        //-- update setter method
                        mname = fieldInfo.getWriteMethodName();
                        method = jClass.getMethod(mname, 0);
                        JSourceCode jsc = method.getSourceCode();
                        jsc.add("super.");
                        jsc.append(mname);
                        jsc.append("(this.");
                        jsc.append(fieldInfo.getName());
                        jsc.append(".toString());");
                    }
                    //-- else just use superclass setters/getters
                    //-- do nothing
                } else {
                    //
                    while (temp.getBaseType() != null && !temp.isBuiltInType()) {
                        temp = (SimpleType) temp.getBaseType();
                    }
                   
                    xsType = _typeConversion.convertType(
                            temp, state.getPackageName(), getConfig().useJava50());
                    fieldInfo = _memberFactory.createFieldInfoForContent(
                            component, xsType, getConfig().useJava50());
                    handleField(fieldInfo, state, component);
                }
            }
        } //--base not null

        //---------------------/
        //- handle attributes -/
        //- and mixed content -/
        //---------------------/

        if (!state.isCreateGroupItem()) {
            processAttributes(component.getBinding(), complexType, state);
            //--reset the view on the current ComplexType
            component.setView(complexType);
            if (complexType.getContentType() == ContentType.mixed) {
                FieldInfo fieldInfo = _memberFactory.createFieldInfoForContent(
                        component, new XSString(), getConfig().useJava50());
                handleField(fieldInfo, state, component);
            }
        }
        //--process the contentModelGroup
View Full Code Here


            state.getFieldInfoForChoice().getMemberAndAccessorFactory().createAccessMethods(
                    state.getFieldInfoForChoice(), state.getJClass(), getConfig().useJava50(),
                     getConfig().getAnnotationBuilders());
        }

        FieldInfo fieldInfo = null;
        XMLBindingComponent component = new XMLBindingComponent(getConfig(), getGroupNaming());
        if (_binding != null) {
            component.setBinding(_binding);
        }

        while (enumeration.hasMoreElements()) {
            Annotated annotated = enumeration.nextElement();
            component.setView(annotated);

            switch (annotated.getStructureType()) {
                case Structure.ELEMENT: //-- handle element declarations
                    fieldInfo = _memberFactory.createFieldInfo(
                            component, state, getConfig().useJava50());
                    //-- Fix for element declarations being used in
                    //-- a group with minOccurs = 0;
                    //-- (kvisco - 20021007)
                    if (contentModel.getMinOccurs() == 0) {
                        XMLInfoNature xmlNature = new XMLInfoNature(fieldInfo);
                        xmlNature.setRequired(false);
                    }

                    handleField(fieldInfo, state, component);
                    break;
                case Structure.GROUP: //-- handle groups
                    Group group = (Group) annotated;
                    //set the compositor
                    if ((contentModel instanceof ComplexType)
                            || (contentModel instanceof ModelGroup)) {
                        if (group.getOrder() == Order.choice) {
                            new XMLInfoNature(state.getClassInfo()).getGroupInfo().setAsChoice();
                        } else if (group.getOrder() == Order.all) {
                            new XMLInfoNature(state.getClassInfo()).getGroupInfo().setAsAll();
                        } else if (group.getOrder() == Order.sequence) {
                            new XMLInfoNature(state.getClassInfo()).getGroupInfo().setAsSequence();
                        }
                    }

                    //-- create class member,if necessary
                    if (!((contentModel instanceof ComplexType)
                            || (contentModel instanceof ModelGroup))) {
                        if (contentModel instanceof ModelGroup) {
                            ModelGroup mg = (ModelGroup) contentModel;
                            if (mg.isReference()) {
                                contentModel = mg.getReference();
                            }
                        }

                        if (contentModel.getParticleCount() > 0) {
                            fieldInfo = _memberFactory.createFieldInfo(
                                    component, state.getSGStateInfo(), getConfig().useJava50());
                            handleField(fieldInfo, state, component);
                        }
                    } else {
                       //--else we just flatten the group
                       processContentModel(group, state);
                    }
                    break;

                case Structure.MODELGROUP:
                     ModelGroup modelgroup = (ModelGroup) annotated;
                     //--a Model Group definition can only referenced
                     //--another group at this point.
                     //get the contentModel and proccess it
                    if (modelgroup.getName() != null) {
                        //create the field info for the element
                        //that is referring to a model group in order
                        //not to loose the Particle information
                        if (modelgroup.isReference()) {
                            modelgroup = modelgroup.getReference();
                        }

                        if (modelgroup.getParticleCount() > 0) {
                            fieldInfo = _memberFactory.createFieldInfo(
                                    component, state.getSGStateInfo(), getConfig().useJava50());
                            handleField(fieldInfo, state, component);
                        }
                        break;
                    }
                    //--else we just flatten the group
                    processContentModel(modelgroup.getContentModelGroup(), state);
                    break;

                case Structure.WILDCARD:
                    Wildcard wildcard = (Wildcard) annotated;
                    FieldInfo fieldForAny = _memberFactory.createFieldInfoForAny(
                            wildcard, getConfig().useJava50());
                    handleField(fieldForAny, state, component);
                    break;

                default:
View Full Code Here

                    if (baseNodeName != null
                            && !(baseNodeName.equals(XMLInfo.CHOICE_NODE_NAME_ERROR_INDICATION))) {
                        // check whether there is an equally named field in the base
                        // class, and don't forget to consider the namspaces as well to
                        // determine whether the fields are really equal.
                        FieldInfo inheritedFieldInfo = base.getElementField(baseNodeName);
                       
                        if (inheritedFieldInfo != null) {
                            if (xmlNature.getNamespaceURI()
                                    .equals(new XMLInfoNature(inheritedFieldInfo).getNamespaceURI())) {
                                present = true;
View Full Code Here

        XMLType xmlType = component.getXMLType();

        ClassInfo classInfo = resolver.resolve(component);

        XSType   xsType = null;
        FieldInfo fieldInfo = null;
        boolean enumeration = false;
        boolean simpleTypeCollection = false;

        if (xmlType != null) {
            if (xmlType.isSimpleType() ) {
                SimpleType simpleType = (SimpleType) xmlType;

                SimpleType baseType = null;
                String derivationMethod = simpleType.getDerivationMethod();
                if (derivationMethod != null) {
                    if (SchemaNames.RESTRICTION.equals(derivationMethod)) {
                        baseType = (SimpleType) simpleType.getBaseType();
                    }
                }

                //-- handle special case for enumerated types
                if (simpleType.hasFacet(Facet.ENUMERATION)) {
                    //-- LOok FoR CLasSiNfO iF ReSoLvR is NoT NuLL
                    enumeration = true;
                    if (resolver != null) {
                        classInfo = resolver.resolve(xmlType);
                    }
                    if (classInfo != null) {
                        XMLInfoNature xmlNature = new XMLInfoNature(classInfo);
                        xsType = xmlNature.getSchemaType();
                    }
                } else if ((simpleType instanceof ListType) || (baseType instanceof ListType)) {
                    if (baseType != null) {
                        if (!baseType.isBuiltInType()) {
                            simpleTypeCollection = true;
                        }
                    } else {
                        if (!simpleType.isBuiltInType()) {
                            simpleTypeCollection = true;
                        }
                    }
                   
                    // handle special case where the list type uses an item type
                    // that has enumeration facets defined.
                    ListType listType = (ListType) simpleType;
                    if (listType == null) {
                        listType = (ListType) baseType;
                    }
                    SimpleType itemType = listType.getItemType();
                    if (itemType.hasFacet(Facet.ENUMERATION)) {
                        ClassInfo itemClassInfo = resolver.resolve(itemType);
                        if (itemClassInfo != null) {
                            xsType = new XMLInfoNature(itemClassInfo).getSchemaType();
                        } else {
                            XMLBindingComponent temp = new XMLBindingComponent(
                                    getConfig(), getGroupNaming());
                            temp.setBinding(component.getBinding());
                            temp.setView(itemType);
                            String packageName = temp.getJavaPackage();
                            if (packageName != null && packageName.length() > 0) {
                                packageName = packageName + "." + SourceGeneratorConstants.TYPES_PACKAGE;
                            } else {
                                packageName = SourceGeneratorConstants.TYPES_PACKAGE;
                            }
                            JClass tempClass = new JClass(packageName+ "." + temp.getJavaClassName());
                            xsType = new XSClass(tempClass);
                            xsType.setAsEnumerated(true);
                        }
                    }
                   
                   
                }

                if (xsType == null) {
                    xsType = component.getJavaType();
                }
            } else if (xmlType.isAnyType()) {
                //-- Just treat as java.lang.Object.
                if (classInfo != null) {
                    XMLInfoNature xmlNature = new XMLInfoNature(classInfo);
                    xsType = xmlNature.getSchemaType();
                }
                if (xsType == null) {
                    xsType = new XSClass(SGTypes.OBJECT);
                }
            } else if (xmlType.isComplexType() && (xmlType.getName() != null)) {
                //--if we use the type method then no class is output for
                //--the element we are processing
                if (getConfig().mappingSchemaType2Java()) {
                    XMLBindingComponent temp = new XMLBindingComponent(
                            getConfig(), getGroupNaming());
                    temp.setBinding(component.getBinding());
                    temp.setView(xmlType);
                    ClassInfo typeInfo = resolver.resolve(xmlType);
                    if (typeInfo != null) {
                        // if we have not processed the <complexType> referenced
                        // by the ClassInfo yet, this will return null
                        // TODO find a way to resolve an unprocessed <complexType>
                        XMLInfoNature xmlNature = new XMLInfoNature(typeInfo);
                        xsType = xmlNature.getSchemaType();
                    } else {
                        String className = temp.getQualifiedName();
                        if (className != null) {
                            JClass jClass = new JClass(className);
                            if (((ComplexType) xmlType).isAbstract()) {
                                jClass.getModifiers().setAbstract(true);
                            }
                            xsType = new XSClass(jClass);
                            className = null;
                        }
                    }
                }
            } // complexType
        } else {
            if (xsType == null) {
                xsType = component.getJavaType();
            }

            if (xsType == null) {
                //-- patch for bug 1471 (No XMLType specified)
                //-- treat unspecified type as anyType
                switch (component.getAnnotated().getStructureType()) {
                case Structure.ATTRIBUTE:
                    AttributeDecl attribute = (AttributeDecl) component.getAnnotated();
                    if (!attribute.hasXMLType()) {
                        xsType = new XSClass(SGTypes.OBJECT);
                    }
                    break;               
                case Structure.ELEMENT:
                    ElementDecl element = (ElementDecl) component.getAnnotated();
                    if (!element.hasXMLType()) {
                        xsType = new XSClass(SGTypes.OBJECT);
                    }
                    break;
                default:
                    // probably a model-group
                    break;
                }
            }
        }

        // is the XSType found?
        if (xsType == null) {
            String className = component.getQualifiedName();
            JClass jClass = new JClass(className);
            if (component.isAbstract()) {
                jClass.getModifiers().setAbstract(true);
            }
            if (getConfig().isAutomaticConflictResolution()) {
                getSourceGenerator().getXMLInfoRegistry().bind(jClass,
                        component, "field");
            }
            xsType = new XSClass(jClass);
            if (xmlType != null && xmlType.isComplexType()) {
                ComplexType complexType = (ComplexType) xmlType;
                if (complexType.isAbstract() || getConfig().mappingSchemaElement2Java()) {
                    jClass.getModifiers().setAbstract(true);
                }
            }
            className = null;
        }

        // create the fieldInfo
        // check whether this should be a collection or not
        int maxOccurs = component.getUpperBound();
        int minOccurs = component.getLowerBound();
        if (simpleTypeCollection
                || ((maxOccurs < 0 || maxOccurs > 1) && !this.isChoice(component))) {
            String vName = memberName + "List";

            // if xmlName is null it means that
            // we are processing a container object (group)
            // so we need to adjust the name of the members of the collection
            CollectionInfo cInfo;
            cInfo = this.getInfoFactory().createCollection(xsType, vName, memberName,
                                                       component.getCollectionType(), getJavaNaming(), useJava50);

            XSListType xsList = cInfo.getXSList();
            if (!simpleTypeCollection) {
                xsList.setMaximumSize(maxOccurs);
                xsList.setMinimumSize(minOccurs);
            } else {
                if (xsList instanceof XSList) {
                    ((XSList) xsList).setDerivedFromXSList(true);
                }
            }
            fieldInfo = cInfo;
        } else  {
            switch (xsType.getType()) {
                case XSType.ID_TYPE:
                     fieldInfo = this.getInfoFactory().createIdentity(memberName);
                     break;
                case XSType.COLLECTION:
                case XSType.IDREFS_TYPE:
                case XSType.NMTOKENS_TYPE:
                    String collectionName = component.getCollectionType();
                    XSType contentType = ((XSListType) xsType).getContentType();
                    fieldInfo = this.getInfoFactory().createCollection(contentType,
                                                                   memberName, memberName,
                                                                   collectionName, getJavaNaming(), useJava50);
                    break;
                default:
                    fieldInfo = this.getInfoFactory().createFieldInfo(xsType, memberName);
                    break;
            }
        }

        // initialize the field
        XMLInfoNature xmlNature = new XMLInfoNature(fieldInfo);
        xmlNature.setNodeName(xmlName);
        xmlNature.setRequired(minOccurs > 0);
        switch (component.getAnnotated().getStructureType()) {
            case Structure.ELEMENT:
                xmlNature.setNodeType(NodeType.ELEMENT);
                 break;
            case Structure.ATTRIBUTE:
                xmlNature.setNodeType(NodeType.ATTRIBUTE);
                break;
            case Structure.MODELGROUP:
            case Structure.GROUP:
                xmlNature.setNodeName(XMLInfo.CHOICE_NODE_NAME_ERROR_INDICATION);
                fieldInfo.setContainer(true);
                break;
            default:
                break;
        }

        //-- handle namespace URI / prefix
        String nsURI = component.getTargetNamespace();
        if ((nsURI != null) && (nsURI.length() > 0)) {
            xmlNature.setNamespaceURI(nsURI);
            // TODO set the prefix used in the XML Schema
            //      in order to use it inside the Marshaling Framework
        }

        // handle default value (if any is set)
        handleDefaultValue(component, classInfo, xsType, fieldInfo, enumeration);

        //-- handle nillable values
        if (component.isNillable()) {
            fieldInfo.setNillable(true);
        }

        //-- add annotated comments
        String comment = createComment(component.getAnnotated());
        if (comment != null) {
             fieldInfo.setComment(comment);
        }

        //--specific field handler or validator?
        if (component.getXMLFieldHandler() != null) {
            fieldInfo.setXMLFieldHandler(component.getXMLFieldHandler());
        }

        if (component.getValidator() != null) {
            fieldInfo.setValidator(component.getValidator());
        }

        if (component.getVisiblity() != null) {
            String visibility = component.getVisiblity();
            fieldInfo.setVisibility(visibility);
        }
       
        // deal with substitution groups
        switch (component.getAnnotated().getStructureType()) {
        case Structure.ELEMENT:
            ElementDecl elementDeclaration = (ElementDecl) component.getAnnotated();
            if (elementDeclaration.isReference()) {
                elementDeclaration = elementDeclaration.getReference();
            }
            Enumeration<ElementDecl> possibleSubstitutes = elementDeclaration.getSubstitutionGroupMembers();
            if (possibleSubstitutes.hasMoreElements()) {
                List<String> substitutionGroupMembers = new ArrayList<String>();
                while (possibleSubstitutes.hasMoreElements()) {
                    ElementDecl substitute = possibleSubstitutes.nextElement();
                    substitutionGroupMembers.add(substitute.getName());
                }
                fieldInfo.setSubstitutionGroupMembers(substitutionGroupMembers);
            }
        default:
        }

        return fieldInfo;
View Full Code Here

     * @param type {@link XSType} of the field.
     * @param name Field name.
     * @return The {@link FieldInfo} instance just created.
     */
    public FieldInfo createFieldInfo(final XSType type, final String name) {
        FieldInfo fieldInfo = new FieldInfo(type, name, this.fieldMemberAndAccessorFactory);
        if (_bound) { fieldInfo.setBound(true); }
        return fieldInfo;
    }
View Full Code Here

       //=================
       // FieldDescriptors
       //=================

       for (int i = 0; i < classInfo.getElementFields().length; i++) {
           FieldInfo fInfo = classInfo.getElementFields()[i];
           if (checkFieldInfoNatures(fInfo)) {
              
               if (fInfo.hasNature(JDOOneToOneNature.class.getName())) {
                   jsc = createOneToOneFieldInfoPart(fInfo, jsc);
                  
               } else if (fInfo.hasNature(JDOOneToManyNature.class.getName())) {
                   jsc = createOneToManyFieldInfoPart(fInfo, jsc);
               } else {
                   jsc = createEntityFieldInfoPart(fInfo, jsc);
               }
           }
View Full Code Here

    * @return names of all FieldDescriptors as one String (separated by comma)
    */
   private String setFields(final FieldInfo[] fInfos) {
       String str = "";

       FieldInfo fInfo;
       ClassInfo cInfo;
       for (int i = 0; i < fInfos.length; i++) {
           fInfo = fInfos[i];
           cInfo = fInfo.getDeclaringClassInfo();
           JDOClassInfoNature cNature = new JDOClassInfoNature(cInfo);
           if (cNature.getPrimaryKeys() != null) {
               if (cNature.getPrimaryKeys().contains(new XMLInfoNature(fInfo).getNodeName())) {
                   continue;
               }
View Full Code Here

        ClassInfo holder = (ClassInfo) getHolder();
        // Now merge all fields.
        List<FieldInfo> mergedFields = new LinkedList<FieldInfo>();
        mergedFields.addAll(holder.getAttributeFieldsAsCollection());
        mergedFields.addAll(holder.getElementFieldsAsCollection());
        FieldInfo textField = holder.getTextField();
        if (textField != null) {
            mergedFields.add(textField);
        }
        // Walk through all fields and check for Nature.
        Iterator<FieldInfo> fieldIterator = mergedFields.iterator();
        List<JDOFieldInfoNature> naturedFields = new LinkedList<JDOFieldInfoNature>();
        while (fieldIterator.hasNext()) {
            FieldInfo field = fieldIterator.next();
            if (field.hasNature(JDOFieldInfoNature.class.getName())) {
                JDOFieldInfoNature nature = new JDOFieldInfoNature(field);
                naturedFields.add(nature);
            }
        }
        return naturedFields;
View Full Code Here

TOP

Related Classes of org.exolab.castor.builder.info.FieldInfo

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.