Package org.exolab.castor.builder.types

Examples of org.exolab.castor.builder.types.XSType


        //--currently anyAttribute is not supported
        if (any.isAttributeWildcard()) {
            return null;
        }

        XSType xsType    = new XSClass(SGTypes.OBJECT, "any");
        String vName     = "_anyObject";
        String xmlName   = null;
        FieldInfo result = null;

        if (any.getMaxOccurs() > 1 || any.getMaxOccurs() < 0) {
View Full Code Here


     *
     * @return the new FieldInfo
     */
    public FieldInfo createFieldInfoForChoiceValue() {
        String fieldName = "_choiceValue";
        XSType xsType = new XSClass(SGTypes.OBJECT, "any");
        FieldInfo fInfo = null;
        fInfo = this.getInfoFactory().createFieldInfo(xsType, fieldName);
        fInfo.setComment("Internal choice value storage");
        fInfo.setTransient(true);
        fInfo.setMethods(FieldInfo.READ_METHOD);
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:
View Full Code Here

     * @param fieldInfo the collectionInfo to translate
     * @param jClass the jClass to add the method to.
     */
    protected void createGetByIndexMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        XSType contentType = fieldInfo.getContentType();
        JMethod method = new JMethod(fieldInfo.getReadMethodName(), contentType.getJType(),
                "the value of the " + contentType.getJType().toString() + " at the given index");

        method.addException(SGTypes.INDEX_OUT_OF_BOUNDS_EXCEPTION,
                "if the index given is outside the bounds of the collection");
        method.addParameter(new JParameter(JType.INT, "index"));

        JSourceCode sourceCode = method.getSourceCode();
        this.addIndexCheck(fieldInfo, sourceCode, method.getName());

        String value = fieldInfo.getName() + ".get(index)";
        sourceCode.add("return ");
        if (contentType.getType() == XSType.CLASS) {
            sourceCode.append("(");
            sourceCode.append(method.getReturnType().toString());
            sourceCode.append(") ");
            sourceCode.append(value);
        } else {
            sourceCode.append(contentType.createFromJavaObjectCode(value));
        }
        sourceCode.append(";");

        jClass.addMethod(method);
    }
View Full Code Here

     * associated with this FieldInfo.
     *
     * @return true if the has and delete methods are needed.
     */
    public final boolean requiresHasAndDeleteMethods() {
        XSType xsType = new XMLInfoNature(this).getSchemaType();
        JType jType  = xsType.getJType();
        return ((!xsType.isEnumerated()) && jType.isPrimitive());
    } //-- requiresHasAndDeleteMethods
View Full Code Here

     *
     * @return an XSType
     */
    public XSType getJavaType() {
        //--no need for caching it is called only once
        XSType result = null;
        boolean useWrapper = useWrapper();
        XMLType type = getXMLType();

        if (type != null && type.isComplexType()) {
            if (_type == MEMBER && _member.getJavaType() != null) {
View Full Code Here

       jsc.add("FieldMapping " + name + "FM = new FieldMapping();");

       //-- set typeInfo
       String type = null;
       XSType schemaType;
      
       schemaType = xmlNature.getSchemaType();
       JType javaType = schemaType.getJType();
       type = javaType.toString();
       String wrapperType = null;
       if (javaType instanceof JPrimitiveType) {
           wrapperType = ((JPrimitiveType) javaType).getWrapperName();
       } else {
View Full Code Here

       jsc.add("FieldDescriptorImpl " + name + "FieldDescr;");
       jsc.add("FieldMapping " + name + "FM = new FieldMapping();");

       //-- set typeInfo
       String type = null;
       XSType schemaType;
      
       schemaType = xmlNature.getSchemaType();
       JType javaType = schemaType.getJType();
       type = javaType.toString();
      
       String wrapperType = null;
       if (javaType instanceof JPrimitiveType) {
        wrapperType = ((JPrimitiveType) javaType).getWrapperName();
View Full Code Here

     * @param fieldInfo the fieldInfo to translate
     * @param jClass the jclass the jField will be added to
     */
    public final void createJavaField(final FieldInfo fieldInfo,  final JClass jClass) {
        XMLInfoNature xmlNature = new XMLInfoNature(fieldInfo);
        XSType type = xmlNature.getSchemaType();
        JType jType = type.getJType();
        JField field = new JField(type.getJType(), fieldInfo.getName());

        if (xmlNature.getSchemaType().isDateTime()) {
            field.setDateTime(true);
        }

        if (fieldInfo.isStatic() || fieldInfo.isFinal()) {
            JModifiers modifiers = field.getModifiers();
            modifiers.setFinal(fieldInfo.isFinal());
            modifiers.setStatic(fieldInfo.isStatic());
        }

        if (!(fieldInfo.getVisibility().equals("private"))) {
            JModifiers modifiers = field.getModifiers();
            if (fieldInfo.getVisibility().equals("protected")) {
                modifiers.makeProtected();
            } else if (fieldInfo.getVisibility().equals("public")) {
                modifiers.makePublic();
            }
        }

        //-- set init String
        if (fieldInfo.getDefaultValue() != null) {
            field.setInitString(fieldInfo.getDefaultValue());
        }

        if (fieldInfo.getFixedValue() != null && !xmlNature.getSchemaType().isDateTime()) {
            field.setInitString(fieldInfo.getFixedValue());
        }

        //-- set Javadoc comment
        if (fieldInfo.getComment() != null) {
            field.setComment(fieldInfo.getComment());
        }

        jClass.addField(field);

        //-- special supporting fields

        //-- has_field
        if ((!type.isEnumerated()) && (jType.isPrimitive())) {
            field = new JField(JType.BOOLEAN, "_has" + fieldInfo.getName());
            field.setComment("keeps track of state for field: " + fieldInfo.getName());
            jClass.addField(field);
        }

View Full Code Here

        JMethod method    = null;
        JSourceCode jsc   = null;

        String mname = fieldInfo.getMethodSuffix();

        XSType xsType = new XMLInfoNature(fieldInfo).getSchemaType();
        JType jType  = xsType.getJType();

        //-- create get method
        method = new JMethod(fieldInfo.getReadMethodName(), jType,
                             "the value of field '" + mname + "'.");
//        if (useJava50) {
//            Java5HacksHelper.addOverrideAnnotations(method.getSignature());
//        }
       
        for (int i = 0; i < annotationBuilders.length; i++) {
            AnnotationBuilder annotationBuilder = annotationBuilders[i];
            annotationBuilder.addFieldGetterAnnotations(fieldInfo, method);
        }
       
        jClass.addMethod(method);
        createGetterComment(fieldInfo, method.getJDocComment());
        jsc = method.getSourceCode();
        jsc.add("return this.");
        jsc.append(fieldInfo.getName());
        jsc.append(";");

        if (xsType.getType() == XSType.BOOLEAN_TYPE) {

            // -- create is<Property>t method
            method = new JMethod(fieldInfo.getIsMethodName(), jType,
                    "the value of field '" + mname + "'.");
//            if (useJava50) {
View Full Code Here

TOP

Related Classes of org.exolab.castor.builder.types.XSType

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.