Package org.exolab.castor.builder.binding

Examples of org.exolab.castor.builder.binding.XMLBindingComponent


                        JClass typeJClass = _xpathToJClass.get(xPathType);
                        if (typeJClass != null) {
                            jClass.changeLocalName(typeJClass.getLocalName());
                        } else {
                            // manually deriving class name for referenced type
                            XMLBindingComponent temp = component;
                            temp.setView(referredType);
                            jClass.changeLocalName(temp.getJavaClassName());
                            component.setView(annotated);
                        }
//                        String typeXPath = XPathHelper
//                                .getSchemaLocation(referredElement);
//                        JClass referredJClass = (JClass) _xpathToJClass
View Full Code Here


            generateConstantDefinitions = false;
        }

        Enumeration<Facet> enumeration = simpleType.getFacets(Facet.ENUMERATION);

        XMLBindingComponent component = new XMLBindingComponent(getConfig(), getGroupNaming());
        if (binding != null) {
            component.setBinding(binding);
            component.setView(simpleType);
        }
       
        //-- select naming for types and instances
        boolean useValuesAsName = true;
        useValuesAsName = selectNamingScheme(component, enumeration, useValuesAsName);

        enumeration = simpleType.getFacets(Facet.ENUMERATION);

        JClass jClass = state.getJClass();
        String className = jClass.getLocalName();

        if (component.getJavaClassName() != null) {
            className = component.getJavaClassName();
        }
       
        // the java 5 way -> create an enum
        if (state.getJClass() instanceof JEnum) {
            createJava5Enum(simpleType, state, component,
                    useValuesAsName, enumeration);
            return;
        }

        JField  field  = null;
        JField  fHash  = new JField(
                SGTypes.createHashtable(getConfig().useJava50()), "_memberTable");
        fHash.setInitString("init()");
        fHash.getModifiers().setStatic(true);

        JSourceCode jsc = null;

        //-- modify constructor
        JConstructor constructor = jClass.getConstructor(0);
        constructor.getModifiers().makePrivate();
        constructor.addParameter(new JParameter(JType.INT, "type"));
        constructor.addParameter(new JParameter(SGTypes.STRING, "value"));
        jsc = constructor.getSourceCode();
        jsc.add("this.type = type;");
        jsc.add("this.stringValue = value;");

        createValueOfMethod(jClass, className);
        createEnumerateMethod(jClass, className);
        createToStringMethod(jClass, className);
        createInitMethod(jClass);
        createReadResolveMethod(jClass);

        //-- Loop through "enumeration" facets
        int count = 0;

        while (enumeration.hasMoreElements()) {
            Facet facet = (Facet) enumeration.nextElement();

            String value = facet.getValue();

            String typeName = null;
            String objName  = null;

            if (useValuesAsName) {
                objName = translateEnumValueToIdentifier(component.getEnumBinding(), facet);
            } else {
                objName = "VALUE_" + count;
            }

            //-- create typeName
View Full Code Here

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

        ComplexType complexType = (ComplexType) type;
        if (complexType.isTopLevel() && creatingForAnElement) {
             //--move the view and keep the structure
             Annotated saved = component.getAnnotated();
             String previousPackage = component.getJavaPackage();
             XMLBindingComponent baseComponent = new XMLBindingComponent(
                     getConfig(), getGroupNaming());
             baseComponent.setBinding(component.getBinding());
             baseComponent.setView(complexType);
             //-- call createSourceCode to pre-process the complexType
             createSourceCode(baseComponent, sgState);
             String baseClassName = null;
             String basePackage = baseComponent.getJavaPackage();
             //--if the base class is not in the same package
             //--of the current class then we have to qualify the base
             //--class
             if (basePackage != null && !basePackage.equals(previousPackage)) {
                 baseClassName = baseComponent.getQualifiedName();
                 if (baseClassName.indexOf('.') == -1) {
                     //--be sure it is a valid className
                     baseClassName = getJavaNaming().toJavaClassName(baseClassName);
                 }
             } else {
                 baseClassName = baseComponent.getJavaClassName();
             }
             jClass.setSuperClass(baseClassName);
             basePackage = null;
             baseClassName = null;
             component.setView(saved);
View Full Code Here

        String className   = getJavaNaming().toJavaClassName(typeName);

        //--XMLBindingComponent is only used to retrieve the java package
        //-- we need to optimize it by enabling the binding of simpleTypes.
        XMLBindingComponent comp =
            new XMLBindingComponent(getConfig(), getGroupNaming());
        if (binding != null) {
            comp.setBinding(binding);
        }
       
        // set component view for anonymous simple types to parent
        if (simpleType.getName() == null) {
            Annotated annotated = (Annotated) simpleType.getParent();
            comp.setView(annotated);
        } else {
            comp.setView(simpleType);
        }

        String packageName = comp.getJavaPackage();
        if ((packageName == null) || (packageName.length() == 0)) {
            packageName = sgState.getPackageName();
        }

        // reset component view for anonymous simple types
        if (simpleType.getName() == null) {
            comp.setView(simpleType);
        }
       
        if (simpleType.hasFacet(Facet.ENUMERATION)) {
            enumeration = true;
            // Fix packageName
            // TODO  this is a hack I know, we should change this
            if ((packageName != null) && (packageName.length() > 0)) {
                packageName = packageName + "." + SourceGeneratorConstants.TYPES_PACKAGE;
            } else {
                packageName = SourceGeneratorConstants.TYPES_PACKAGE;
            }
        }

        String boundClassName = comp.getJavaClassName();
        if ((boundClassName != null) && (boundClassName.length() > 0)) {
            className = boundClassName;
            typeName = boundClassName;
        }
View Full Code Here

        if (complexType == null) {
            return;
        }

        Enumeration<AttributeDecl> enumeration = complexType.getAttributeDecls();
        XMLBindingComponent component = new XMLBindingComponent(getConfig(), getGroupNaming());
        if (_binding != null) {
            component.setBinding(_binding);
        }

        while (enumeration.hasMoreElements()) {
            AttributeDecl attr = enumeration.nextElement();

            component.setView(attr);

            //-- if we have a new SimpleType...generate ClassInfo
            SimpleType sType = attr.getSimpleType();

            // look for simpleType def in base type(s)
            XMLType baseXMLType = complexType.getBaseType();
            while (sType == null) {
                // If no simple type found: Get the same attribute of the base type.
                // If base type is not complex, forget it; break out of loop now.
                if (baseXMLType == null || !(baseXMLType instanceof ComplexType)) {
                    break;
                }

                // There's a base complexType; get the attribute with the same name
                // as this attribute (=attr) from it
                final ComplexType baseComplexType = (ComplexType) baseXMLType;
                AttributeDecl baseAttribute = baseComplexType.getAttributeDecl(attr.getName());

                if (baseAttribute != null) {
                    // See if this one has a simple-type...
                    sType = baseAttribute.getSimpleType();
                    if (sType != null) {
                        attr.setSimpleType(sType);
                        break;
                    }
                }

                // ... if not, go another step higher in the class hierarchy
                baseXMLType = baseXMLType.getBaseType();
            }

            // Look for referenced type (if any) for setting type, and use
            // it, if found.
            if (sType == null && attr.getReference() != null) {
                SimpleType referencedSimpleType = attr.getReference().getSimpleType();
                attr.setSimpleType(referencedSimpleType);
                sType = referencedSimpleType;
            }

            if (sType != null && !(SimpleTypesFactory.isBuiltInType(sType.getTypeCode()))) {
                if (sType.getSchema() == component.getSchema() && state.resolve(sType) == null) {
                    if (sType.hasFacet(Facet.ENUMERATION)) {
                        createSourceCode(component.getBinding(), sType, state.getSGStateInfo());
                    }
                }
            }

            FieldInfo fieldInfo = _memberFactory.createFieldInfo(
View Full Code Here

    /**
     * @param complexType the ComplexType to process
     * @param state the FactoryState.
     */
    private void processComplexType(final ComplexType complexType, final FactoryState state) {
        XMLBindingComponent component = new XMLBindingComponent(getConfig(), getGroupNaming());
        if (_binding != null) {
            component.setBinding(_binding);
        }
        component.setView(complexType);

        String typeName = component.getXMLName();

        ClassInfo classInfo = state.getClassInfo();
        XMLInfoNature xmlNature = new XMLInfoNature(classInfo);
        xmlNature.setSchemaType(new XSClass(state.getJClass(), typeName));

        /// I don't believe this should be here: kv 20030423
        ///classInfo.setNamespaceURI(component.getTargetNamespace());

        //- Handle derived types
        XMLType base = complexType.getBaseType();

        //-- if the base is a complexType, we need to process it
        if (base != null) {
            if (base.isComplexType()) {
                String baseClassName = null;

                component.setView(base);
                //-- Is this base type from the schema we are currently generating source for?
                //////////////////////////////////////////////////////////
                //NOTE: generate sources if the flag for generating sources
                //from imported schemas in on
                //////////////////////////////////////////////////////////
                if (base.getSchema() == complexType.getSchema()) {
                    ClassInfo cInfo = state.resolve(base);
                    //--no classInfo yet so no source code available
                    //--for the base type: we need to generate it
                    if (cInfo == null) {
                        JClass[] classes = createSourceCode(component, state.getSGStateInfo());
                        cInfo = state.resolve(base);
                        baseClassName = classes[0].getName();
                    } else {
                        baseClassName = cInfo.getJClass().getName();
                    }
                    //set the base class
                    classInfo.setBaseClass(cInfo);
                } else {
                    //-- Create qualified class name for a base type class
                    //-- from another package
                    baseClassName = component.getQualifiedName();
                 }
                //-- Set super class
                //-- and reset the view on the current ComplexType
                component.setView(complexType);
                // only set a super class name if the current complexType is not a
                // restriction of a simpleContent (--> no object hierarchy, only content hierarchy)
                /*
                 Note: There are times when a simpleContent restriction needs to
                 extend the hierarchy, such as a restriction of a restriction, so
                 I'm commenting out the following line for now. see bug 1875
                 for more details. If this causes any regressions we'll need to
                 find a more appropriate solution.
                 if (! ( complexType.isRestricted() && ((ComplexType)base).isSimpleContent() ) )
                */
                state.getJClass().setSuperClass(baseClassName);
            } //--complexType

            //--if the content type is a simpleType create a field info for it.
            if (complexType.getContentType().getType() == ContentType.SIMPLE) {
                SimpleContent simpleContent = (SimpleContent) complexType.getContentType();
                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);
            }
View Full Code Here

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

        _groupNaming = new GroupNaming(getJavaNaming());

        _jclassPrinterFactoryRegistry = new JClassPrinterFactoryRegistry(this);
        _singleClassGenerator = new SingleClassGenerator(_dialog, this, _nameConflictStrategy,
                _jclassPrinterType);
        _bindingComponent = new XMLBindingComponent(this, _groupNaming);
        setBinding(binding);
       
        _conflictResolver.setSourceGenerator(this);
        _xmlInfoRegistry = new JClassRegistry(_conflictResolver, getJavaNaming());
    } //-- SourceGenerator
View Full Code Here

                ComplexType complexType = (ComplexType)type;
                if (complexType.isTopLevel() && creatingForAnElement) {
                     //--move the view and keep the structure
                     Annotated saved = component.getAnnotated();
                     String previousPackage = component.getJavaPackage();
                     XMLBindingComponent baseComponent = new XMLBindingComponent(_config);
                     baseComponent.setBinding(component.getBinding());
                     baseComponent.setView(complexType);
                     String baseClassName = null;
                     String basePackage = baseComponent.getJavaPackage();
                     //--if the base class is not in the same package
                     //--of the current class then we have to qualify the base
                     //--class
                     if (basePackage != null && !basePackage.equals(previousPackage)) {
                         baseClassName = baseComponent.getQualifiedName();
                         if (baseClassName.indexOf('.') == -1) {
                             //--be sure it is a valid className
                             baseClassName = JavaNaming.toJavaClassName(baseClassName);
                         }
                     } else {
                         baseClassName = baseComponent.getJavaClassName();
                     }
                     jClass.setSuperClass(baseClassName);
                     basePackage = null;
                     baseClassName = null;
                     component.setView(saved);
View Full Code Here

TOP

Related Classes of org.exolab.castor.builder.binding.XMLBindingComponent

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.