Package org.exolab.castor.builder

Examples of org.exolab.castor.builder.FactoryState


        } else {
            classes = new JClass[1];
        }

        //3-- Create factoryState and chain it to sgState to prevent endless loop
        FactoryState state =
            new FactoryState(className, sgState, packageName, component);
        state.setCreateGroupItem(createGroupItem);
        if (sgState.getCurrentFactoryState() != null) {
            state.setParent(sgState.getCurrentFactoryState());
        }
        sgState.setCurrentFactoryState(state);

        //--Prevent endless loop
        if (state.processed(component.getAnnotated())) {
            return new JClass[0];
        }

        //-- Mark the enclosed annotated structure as processed in the
        //-- current FactoryState for preventing endless loop.
        state.markAsProcessed(component.getAnnotated());

        //////////////////////////////////////////////////////
        //NOTE: check that the component is not referring to
        //an imported schema to prevent class creation
        //////////////////////////////////////////////////////

        //4-- intialization of the JClass
        ClassInfo classInfo = state.getClassInfo();
        JClass    jClass    = state.getJClass();
        initialize(jClass);

        if (classInfo.hasNature(XMLInfoNature.class.getName())) {
            final XMLInfoNature xmlNature = new XMLInfoNature(classInfo);
           
            //-- name information
            xmlNature.setNodeName(component.getXMLName());
           
            //-- namespace information
            xmlNature.setNamespaceURI(component.getTargetNamespace());
           
            //5--processing the type
            XMLType type = component.getXMLType();
            boolean createForSingleGroup = false;
            boolean creatingForAnElement =
                (component.getAnnotated().getStructureType() == Structure.ELEMENT);
           
            //-- created from element definition information
            xmlNature.setElementDefinition(creatingForAnElement);
           
            // deal with substitution groups
            if (creatingForAnElement) {
                ElementDecl elementDeclaration = (ElementDecl) component.getAnnotated();
                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());
                    }
                    xmlNature.setSubstitutionGroups(substitutionGroupMembers);
                }
            }

            if (type != null) {
                if (type.isComplexType()) {
                    processComplexType(component, sgState, state);
                } else if (type.isSimpleType()) {
                    SimpleType simpleType = (SimpleType) type;
                    //-- handle our special case for enumerated types
                    if (simpleType.hasFacet(Facet.ENUMERATION)) {
                        processSimpleTypeEnumeration(component, sgState, classInfo, simpleType);
                    } else {
                        //////////////////////////////////////////////////////////
                        //NOTE: generate sources if the flag for generating sources
                        //from imported schemas is on
                        //////////////////////////////////////////////////////////
                        return new JClass[0];
                    }
                } else if (type.isAnyType()) {
                    //-- Do not create classes for AnyType
                    xmlNature.setSchemaType(new XSClass(SGTypes.OBJECT));
                    return new JClass[0];
                }
            } else {
                //--no type we must be facing an XML schema group
                //--MODEL GROUP OR GROUP
                createForSingleGroup = processSchemaGroup(component, state, classInfo);
            }

            //6--createGroupItem
            if (createGroupItem) {
                //-- create Bound Properties code
                if (component.hasBoundProperties()) {
                    createPropertyChangeMethods(jClass);
                }

                sgState.bindReference(jClass, classInfo);

                classes[1] = jClass;

                //-- create main group class
                String fname = component.getJavaClassName() + ITEM_NAME;
                fname = getJavaNaming().toJavaMemberName(fname, false);

                FieldInfo fInfo = null;
                if (createForSingleGroup) {
                    //By default a nested group Item can occur only once
                    fInfo = getInfoFactory().createFieldInfo(new XSClass(jClass), fname);
                } else {
                    fInfo = getInfoFactory().createCollection(
                            new XSClass(jClass), "_items", fname, getJavaNaming(), getConfig().useJava50());
                }
                fInfo.setContainer(true);
                String newClassName = className.substring(0, className.length() - 4);
                state = new FactoryState(newClassName, sgState, packageName, component);
                classInfo = state.getClassInfo();
                jClass    = state.getJClass();
                initialize(jClass);
                if (type != null && type.isComplexType()) {
                    ComplexType complexType = (ComplexType) type;
                    if (complexType.isTopLevel() ^ creatingForAnElement) {
                        //process attributes and content type since it has not be performed before
View Full Code Here


        //-- class name information
        String typeName = simpleType.getName();
        if (typeName == null) {
            Structure struct = simpleType.getParent();
            FactoryState fstate = null;
            switch (struct.getStructureType()) {
                case Structure.ATTRIBUTE:
                    typeName = ((AttributeDecl) struct).getName();
                    fstate = sgState.getCurrentFactoryState();
                    break;
                case Structure.ELEMENT:
                    typeName = ((ElementDecl) struct).getName();
                    break;
                default:
                    // Nothing to do
                    break;
            }
            //-- In case of naming collision we append current class name
            if (fstate != null) {
                typeName = getJavaNaming().toJavaClassName(typeName);
                Structure attrDeclParent = ((AttributeDecl) struct).getParent();
                if (attrDeclParent != null
                        && attrDeclParent.getStructureType() == Structure.ATTRIBUTE_GROUP) {
                    typeName = getJavaNaming().toJavaClassName(
                            ((AttributeGroupDecl) attrDeclParent).getName() + typeName);
                } else {
                    typeName = fstate.getJClass().getLocalName() + typeName;
                }
            }
            //-- otherwise (???) just append "Type"
            typeName += "Type";
        }

        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;
        }

        className = resolveClassName(className, packageName);

        FactoryState state = new FactoryState(className, sgState, packageName, comp,
                (enumeration && getConfig().useJava5Enums()));

        state.setParent(sgState.getCurrentFactoryState());

        ClassInfo classInfo = state.getClassInfo();
        JClass    jClass    = state.getJClass();

        initialize(jClass);

        //-- XML information
        Schema  schema = simpleType.getSchema();
        XMLInfoNature xmlNature = new XMLInfoNature(classInfo);
        xmlNature.setNamespaceURI(schema.getTargetNamespace());
        xmlNature.setNodeName(typeName);

        extractAnnotations(simpleType, jClass);

        XSClass xsClass = new XSClass(jClass, typeName);

        xmlNature.setSchemaType(xsClass);

        //-- handle enumerated types
        if (enumeration) {
            xsClass.setAsEnumerated(true);
            processEnumeration(binding, simpleType, state);
        }

        //-- create Bound Properties code
        if (state.hasBoundProperties() && !enumeration) {
            createPropertyChangeMethods(jClass);
        }
       
        if (classInfo.hasNature(JDOClassInfoNature.class.getName())) {
            JDOClassInfoNature jdoNature = new JDOClassInfoNature(classInfo);
View Full Code Here

TOP

Related Classes of org.exolab.castor.builder.FactoryState

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.