Examples of XMLInfoNature


Examples of org.exolab.castor.builder.info.nature.XMLInfoNature

        ContentModelGroup contentModel = model;
        Enumeration<Annotated> enumeration = contentModel.enumerate();

        //-- handle choice item
        if (new XMLInfoNature(state.getClassInfo()).isChoice()
                && state.getFieldInfoForChoice() == null) {
            state.setFieldInfoForChoice(_memberFactory.createFieldInfoForChoiceValue());
            state.getFieldInfoForChoice().getMemberAndAccessorFactory().createJavaField(
                    state.getFieldInfoForChoice(),
                    state.getJClass());
            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)
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.XMLInfoNature

    private void handleField(final FieldInfo fieldInfo, final FactoryState state, final XMLBindingComponent component) {
        if (fieldInfo == null) {
            return;
        }

        XMLInfoNature xmlNature = new XMLInfoNature(fieldInfo);
       
        if (CLASS_METHOD_SUFFIX.equals(fieldInfo.getMethodSuffix())) {
            SGStateInfo sInfo = state.getSGStateInfo();
            if (!sInfo.getSuppressNonFatalWarnings()) {
                String warn = "warning a field name conflicts with \""
                    + CLASS_KEYWORD + "\", please use a binding file to specify "
                    + "a different name for the " + xmlNature.getNodeTypeName()
                    + " '" + xmlNature.getNodeName() + "'.";
                sInfo.getDialog().notify(warn);
            }
        } else if (CLASS_KEYWORD.equals(xmlNature.getNodeName())) {
            SGStateInfo sInfo = state.getSGStateInfo();
            if (!sInfo.getSuppressNonFatalWarnings()) {
                String warn = "warning a field name conflicts with \""
                    + CLASS_KEYWORD + "\" and is being replaced by \"clazz\". "
                    + "You may use a binding file to specify a different "
                    + "name for the " + xmlNature.getNodeTypeName()
                    + " '" + xmlNature.getNodeName() + "'.";
                sInfo.getDialog().notify(warn);
            }
        }
       
        processAppInfo(component.getAnnotated(), fieldInfo);
       
        JSourceCode scInitializer = state.getJClass().getConstructor(0).getSourceCode();

        ClassInfo base = state.getClassInfo().getBaseClass();
        boolean present = false;
        if (base != null) {
            switch (new XMLInfoNature(fieldInfo).getNodeType()) {
                case ATTRIBUTE:
                    present = (base.getAttributeField(xmlNature.getNodeName()) != null);
                    break;
                case ELEMENT:
                    String baseNodeName = xmlNature.getNodeName();
                    // TODO[WG]: replace this error check with something more meaningful
                    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;
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
        }

        state.getClassInfo().addFieldInfo(fieldInfo);
        present = present && !xmlNature.isMultivalued();
        //create the relevant Java fields only if the field
        //info is not yet in the base classInfo or if it is not a collection
        if (!present) {
            if (state.getFieldInfoForChoice() != null) {
                if (fieldInfo != state.getFieldInfoForChoice()) {
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.XMLInfoNature

            } else {
                message.append(XPathHelper.getSchemaLocation(a1));
            }
        } else {
            if (newClassInfo.hasNature(XMLInfoNature.class.getName())) {
                XMLInfoNature xmlNature = new XMLInfoNature(newClassInfo);
                message.append(xmlNature.getNodeTypeName());
                message.append(" '");
                message.append(xmlNature.getNodeName());
            }
        }
        message.append("' and ");
        if (a2 != null) {
            message.append(SchemaNames.getStructureName(a2));
            message.append(" '");
            if (a2 instanceof ElementDecl) {
                ElementDecl element = (ElementDecl) a2;
                annotated2XPath = XPathHelper.getSchemaLocation(a2) + "[/complexType:"
                + element.getType().getName() + "]";
                message.append(annotated2XPath);
            } else {
                message.append(XPathHelper.getSchemaLocation(a2));
            }
        } else {
            if (oldClassInfo.hasNature(XMLInfoNature.class.getName())) {
                XMLInfoNature xmlNature = new XMLInfoNature(oldClassInfo);
                message.append(xmlNature.getNodeTypeName());
                message.append(" '");
                message.append(xmlNature.getNodeName());
            }
        }
        message.append("'. Please use a Binding file to solve this problem.");
        LOG.warn(message);
        return state;
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.XMLInfoNature

                error.append(SchemaNames.getStructureName(a1));
                error.append(" '");
                error.append(XPathHelper.getSchemaLocation(a1));
            } else {
                if (newClassInfo.hasNature(XMLInfoNature.class.getName())) {
                    XMLInfoNature xmlNature = new XMLInfoNature(newClassInfo);
                    error.append(xmlNature.getNodeTypeName());
                    error.append(" '");
                    error.append(xmlNature.getNodeName());
                }
            }
            error.append("' and ");
            if (a2 != null) {
                error.append(SchemaNames.getStructureName(a2));
                error.append(" '");
                error.append(XPathHelper.getSchemaLocation(a2));
            } else {
                if (oldClassInfo.hasNature(XMLInfoNature.class.getName())) {
                    XMLInfoNature xmlNature = new XMLInfoNature(oldClassInfo);
                    error.append(xmlNature.getNodeTypeName());
                    error.append(" '");
                    error.append(xmlNature.getNodeName());
                }
            }
            error.append("'. Please use a Binding file to solve this problem.");
            error.append("Continue anyway [not recommended] ");
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.XMLInfoNature

        } else {
            result = this.getInfoFactory().createFieldInfo(xsType, vName);
        }

        if (result.hasNature(XMLInfoNature.class.getName())) {
            XMLInfoNature xmlNature = new XMLInfoNature(result);
           
            if (any.getMinOccurs() > 0) {
                xmlNature.setRequired(true);
            } else {
                xmlNature.setRequired(false);
            }
           
            xmlNature.setNodeName(xmlName);
           
            //--LIMITATION:
            //-- 1- we currently support only the FIRST namespace
            //-- 2- ##other, ##any are not supported
            if (any.getNamespaces().hasMoreElements()) {
                String nsURI = (String) any.getNamespaces().nextElement();
                if (nsURI.length() > 0) {
                    if (nsURI.equals("##targetNamespace")) {
                        Schema schema = any.getSchema();
                        if (schema != null) {
                            xmlNature.setNamespaceURI(schema.getTargetNamespace());
                        }
                    } else if (!nsURI.startsWith("##")) {
                        xmlNature.setNamespaceURI(nsURI);
                    }
                }
            } //--first namespace
        }
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.XMLInfoNature

        fInfo.setComment("Internal choice value storage");
        fInfo.setTransient(true);
        fInfo.setMethods(FieldInfo.READ_METHOD);
       
        if (fInfo.hasNature(XMLInfoNature.class.getName())) {
            XMLInfoNature xmlNature = new XMLInfoNature(fInfo);
           
            xmlNature.setNodeType(NodeType.ELEMENT);
            xmlNature.setRequired(false);
            xmlNature.setNodeName("##any");
        }
       
        return fInfo;
    }
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.XMLInfoNature

        fInfo.setComment("internal content storage");
        if (xsType instanceof XSString) {
            fInfo.setDefaultValue("\"\"");
        }
        if (fInfo.hasNature(XMLInfoNature.class.getName())) {
            XMLInfoNature xmlNature = new XMLInfoNature(fInfo);
            xmlNature.setNodeType(NodeType.TEXT);
            xmlNature.setRequired(false);
            xmlNature.setNodeName("#text");
        }
        return fInfo;
    }
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.XMLInfoNature

                    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)
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.XMLInfoNature

     */
    public void createXMLFieldHandler(final FieldInfo member,
            final XSType xsType, final String localClassName,
            final JSourceCode jsc, final boolean forGeneralizedHandler) {

        XMLInfoNature xmlNature = new XMLInfoNature(member);
       
        boolean any = false;
        boolean isEnumerated = false;

        // -- a hack, I know, I will change later (kv)
        if (member.getName().equals("_anyObject")) {
            any = true;
        }

        if (xsType.getType() == XSType.CLASS) {
            isEnumerated = ((XSClass) xsType).isEnumerated();
        }

        jsc.add("handler = new org.exolab.castor.xml.XMLFieldHandler() {");
        jsc.indent();

        createGetValueMethod(member, xsType, localClassName, jsc);

        NodeType nodeType = xmlNature.getNodeType();
        boolean isAttribute = (nodeType == NodeType.ATTRIBUTE);
        boolean isContent = (nodeType == NodeType.TEXT);

        createSetValueMethod(member, xsType, localClassName, jsc, any, isAttribute, isContent);
        createResetMethod(member, localClassName, jsc);
View Full Code Here

Examples of org.exolab.castor.builder.info.nature.XMLInfoNature

     */
    private void createGetValueMethod(final FieldInfo member, final XSType xsType,
            final String localClassName, final JSourceCode jsc) {
        // -- getValue(Object) method
       
        XMLInfoNature xmlNature = new XMLInfoNature(member);
       
        if (_config.useJava50()) {
            jsc.add("@Override");
        }
        jsc.add("public java.lang.Object getValue( java.lang.Object object ) ");
        jsc.indent();
        jsc.add("throws IllegalStateException");
        jsc.unindent();
        jsc.add("{");
        jsc.indent();
        jsc.add(localClassName);
        jsc.append(" target = (");
        jsc.append(localClassName);
        jsc.append(") object;");
        // -- handle primitives
        if ((!xsType.isEnumerated()) && (xsType.getJType().isPrimitive())
                && (!xmlNature.isMultivalued())) {
            jsc.add("if (!target." + member.getHasMethodName() + "()) { return null; }");
        }
        // -- Return field value
        jsc.add("return ");
        String value = "target." + member.getReadMethodName() + "()";
        if (xmlNature.isMultivalued()) {
            jsc.append(value); // --Be careful : different for attributes
        } else {
            jsc.append(xsType.createToJavaObjectCode(value));
        }
        jsc.append(";");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.