Package org.exolab.castor.builder.info.nature

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


        for (int i = 0; i < cInfos.size(); ++i) {
            ClassInfo cInfo = (ClassInfo) cInfos.get(i);

            assertNotNull(cInfo);

            XMLInfoNature xmlNature = new XMLInfoNature(cInfo);
           
            if (xmlNature.getNodeName().equals("book")) {
                /*
                 * No JDO-specific information should be stored to this
                 * ClassInfo.
                 */
                assertFalse(cInfo.hasNature(JDOClassInfoNature.class.getName()));
//                JDOClassNature cNature = new JDOClassNature(cInfo);
//               
//                assertEquals(null, cNature.getTableName());
//               
//                List primaryKeys = cNature.getPrimaryKeys();
//               
//                assertNull(primaryKeys);
               
                assertEquals(0, cInfo.getFieldCount());
               
            } else if (xmlNature.getNodeName().equals("bookType")) {
                JDOClassInfoNature cNature = new JDOClassInfoNature(cInfo);
               
                assertEquals("book", cNature.getTableName());
               
                List primaryKeys = cNature.getPrimaryKeys();
View Full Code Here


            ClassInfo cInfo = (ClassInfo) cInfos.get(i);
           
            assertNotNull(cInfo);
           
            JDOClassInfoNature cNature = new JDOClassInfoNature(cInfo);
            XMLInfoNature xmlNature = new XMLInfoNature(cInfo);
           
            assertNotNull(cNature);
           
            if (xmlNature.getNodeName().equals("person")) {
                String tableName = cNature.getTableName();
                assertEquals("person", tableName);
               
                List primaryKeys = cNature.getPrimaryKeys();
               
                assertEquals(1, primaryKeys.size());
                assertEquals("ssn", (String) primaryKeys.get(0));
               
                assertEquals(4, cInfo.getFieldCount());
               
                FieldInfo[] fInfos = cInfo.getElementFields();
               
                assertNotNull(fInfos);
               
                for (int j = 0; j < fInfos.length; ++j) {
                    FieldInfo fInfo = fInfos[j];
                    assertNotNull(fInfo);
                    JDOFieldInfoNature fNature = new JDOFieldInfoNature(fInfo);
                    assertNotNull(fNature);
                   
                    String columnName = fNature.getColumnName();
                    String columnType = fNature.getColumnType();
                   
                    XMLInfoNature xmlFieldNature = new XMLInfoNature(fInfo);
                   
                    if (xmlFieldNature.getNodeName().equals("ssn")) {   
                        assertEquals("ssn", columnName);
                        assertEquals("bigint", columnType);
                    } else if (xmlFieldNature.getNodeName().equals("firstName")) {
                        assertEquals("firstName", columnName);
                        assertEquals("varchar", columnType);
                    } else if (xmlFieldNature.getNodeName().equals("lastName")) {
                        assertEquals("lastName", columnName);
                        assertEquals("varchar", columnType);
                    } else if (xmlFieldNature.getNodeName().equals("birthdate")) {
                        assertEquals("birthdate", columnName);
                        assertEquals("date", columnType);
                    } else {
                        fail("Unexpected FieldInfo Element encountered!");
                    }
View Full Code Here

     */
    public IdentityInfo(final String name,
            final FieldMemberAndAccessorFactory memberAndAccessorFactory) {
        super(new XSId(), name, memberAndAccessorFactory);
        if (hasNature(XMLInfoNature.class.getName())) {
            XMLInfoNature xmlNature = new XMLInfoNature(this);
            xmlNature.setNodeType(NodeType.ATTRIBUTE);
        }
    }
View Full Code Here

        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
                        Annotated saved = component.getAnnotated();
                        processAttributes(component.getBinding(), complexType, state);
                        component.setView(saved);
                        if (complexType.getContentType() == ContentType.mixed) {
                            FieldInfo fieldInfo = _memberFactory.createFieldInfoForContent(
                                    component, new XSString(), getConfig().useJava50());
                            handleField(fieldInfo, state, component);
                        } else if (complexType.getContentType().getType() == ContentType.SIMPLE) {
                            SimpleContent simpleContent = (SimpleContent) complexType.getContentType();
                            SimpleType temp = simpleContent.getSimpleType();
                            XSType xsType = _typeConversion.convertType(
                                    temp, packageName, getConfig().useJava50());
                            FieldInfo fieldInfo = _memberFactory.createFieldInfoForContent(
                                    component, xsType, getConfig().useJava50());
                            handleField(fieldInfo, state, component);
                            temp = null;
                        } else {
                            // handle multi-valued choice group
                            xmlNature.setSchemaType(new XSClass(jClass));
                        }
                    }
                }

                classInfo.addFieldInfo(fInfo);
                fInfo.getMemberAndAccessorFactory().createJavaField(fInfo, jClass);
                fInfo.getMemberAndAccessorFactory().createAccessMethods(
                        fInfo, jClass, getConfig().useJava50(), getConfig().getAnnotationBuilders());
                fInfo.getMemberAndAccessorFactory().generateInitializerCode(
                        fInfo, jClass.getConstructor(0).getSourceCode());

                //-- name information
                XMLInfoNature xmlInfoNature = new XMLInfoNature(classInfo);
                xmlInfoNature.setNodeName(component.getXMLName());

                //-- mark as a container
                xmlInfoNature.setContainer(true);
               
                // -- if we have a superclass, make sure that the actual type extends it, not the
                // xxxItem holder class.
                String actSuperClass = classes[1].getSuperClassQualifiedName();
                jClass.setSuperClass(actSuperClass);
View Full Code Here

        }
       

        // discard primitiv types and collections
        if (textFieldInfo != null) {
            XSType textFieldType = new XMLInfoNature(textFieldInfo).getSchemaType();
            if (textFieldType != null && textFieldType.getJType().isArray()) {
                generate = false;
            }
        }

        if (!generate) {
            return;
        }

        XMLInfoNature xmlNature = new XMLInfoNature(textFieldInfo);
       
        // create constructor
        JClass jClass = classInfo.getJClass();
        JParameter parameter = new JParameter(new JClass("java.lang.String"), "defaultValue");
        JConstructor constructor = jClass.createConstructor(new JParameter[] {parameter});
        JSourceCode sourceCode = new JSourceCode();

        if (inherited) {
            sourceCode.add("super(defaultValue);");
        } else {
            sourceCode.add("try {");
            String defaultValue =
                xmlNature.getSchemaType().createDefaultValueWithString("defaultValue");
            sourceCode.addIndented("setContent(" + defaultValue + ");");
            sourceCode.add(" } catch(Exception e) {");
            sourceCode.addIndented("throw new RuntimeException(\"Unable to cast default value for simple content!\");");
            sourceCode.add(" } ");
        }
View Full Code Here

            processContentModel(group, state);
            component.setView(group);

            //-- Check Group Type
            Order order = group.getOrder();
            GroupInfo groupInfo = new XMLInfoNature(classInfo).getGroupInfo();
            if (order == Order.choice) {
                groupInfo.setAsChoice();
            } else if (order == Order.sequence) {
                groupInfo.setAsSequence();
            } else {
View Full Code Here

            if (tmpInfo != null) {
                tmpClass = tmpInfo.getJClass();
            } else {
                tmpClass = createSourceCode(component.getBinding(), simpleType, sgState);
            }
            XMLInfoNature xmlNature = new XMLInfoNature(classInfo);
            xmlNature.setSchemaType(new XSClass(tmpClass));
        }
    }
View Full Code Here

            if (complexType.getParticleCount() == 1) {
                Particle particle = complexType.getParticle(0);
                if (particle.getStructureType() == Structure.GROUP) {
                    Group group = (Group) particle;
                    if (group.getOrder() == Order.choice) {
                        new XMLInfoNature(classInfo).getGroupInfo().setAsChoice();
                    }
                }
            }
            Annotated saved = component.getAnnotated();
            processComplexType(complexType, state);
View Full Code Here

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

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

TOP

Related Classes of org.exolab.castor.builder.info.nature.XMLInfoNature

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.