Package org.exolab.castor.xml.schema

Examples of org.exolab.castor.xml.schema.Group


        // create targeted schema
        _schema.addNamespace("pre", "my.namespace.org");
        ComplexType cType = _schema.createComplexType("myType");
        _schema.addComplexType(cType);

        Group group = new Group();
        group.setOrder(Order.choice);
        cType.addGroup(group);

        ElementDecl e = new ElementDecl(_schema);
        e.setName("myAttr");
        group.addElementDecl(e);

        ElementDecl e2 = new ElementDecl(_schema);
        e2.setName("myAttr2");
        group.addElementDecl(e2);

        ElementDecl e3 = new ElementDecl(_schema);
        e3.setName("myAttr3");
        group.addElementDecl(e3);

        // compare
        TestResult result = doTest("complextype_choiceattribute.xsd");
        assertEquals("choice group attributes test failed",
                TestResult.IDENTICAL, result);
View Full Code Here


        // create targeted schema
        // create base type
        ComplexType cBaseType = _schema.createComplexType("baseType");
        _schema.addComplexType(cBaseType);

        Group gBase = new Group();
        cBaseType.addGroup(gBase);

        ElementDecl ebase = new ElementDecl(_schema);
        ebase.setName("baseAttr");
        gBase.addElementDecl(ebase);

        // create dependency
        ComplexType cType = _schema.createComplexType("myType");
        _schema.addComplexType(cType);
        cType.setBaseType(cBaseType);
        cType.setDerivationMethod(SchemaNames.EXTENSION);

        Group group = new Group();
        cType.addGroup(group);

        ElementDecl e = new ElementDecl(_schema);
        e.setName("myAttr");
        group.addElementDecl(e);

        ElementDecl e2 = new ElementDecl(_schema);
        e2.setName("myAttr2");
        group.addElementDecl(e2);

        // compare
        TestResult result = doTest("complextype_attributeorder.xsd");
        assertEquals("create extension test failed", TestResult.IDENTICAL,
                result);
View Full Code Here

        // create dependency
        ComplexType cType = _schema.createComplexType("myType");
        _schema.addComplexType(cType);

        Group group = new Group();
        cType.addGroup(group);

        ElementDecl e = new ElementDecl(_schema);
        e.setName("myAttr");
        group.addElementDecl(e);

        ElementDecl element = new ElementDecl(_schema);
        element.setName("myElement");
        element.setTypeReference("myType");
        _schema.addElementDecl(element);
View Full Code Here

                ComplexType cType = new ComplexType(_schema);
                //-- SHOULD CHANGE THIS TO SIMPLE CONTENT WHEN
                //-- SCHEMA WRITER BUGS ARE FIXED
                cType.setContentType(ContentType.mixed);
                sInfo.element.setType(cType);
                Group group = new Group();
                group.setOrder(_defaultGroupOrder);
                //-- add attributes
                try {
                    cType.addGroup(group);
                    for (int i = 0; i < sInfo.attributes.size(); i++) {
                        AttributeDecl attDecl =
                            (AttributeDecl)sInfo.attributes.elementAt(i);
                        cType.addAttributeDecl(attDecl);
                    }
                }
                catch(SchemaException sx) {
                    throw new SAXException(sx);
                }
            }
        }
        else {
            ComplexType cType = (ComplexType)sInfo.element.getType();
           
            if ((cType == null) && (sInfo.attributes.size() > 0)) {
                cType = new ComplexType(_schema);
                sInfo.element.setType(cType);
                Group group = new Group();
                group.setOrder(_defaultGroupOrder);
                //-- add attributes
                try {
                    cType.addGroup(group);
                }
                catch(SchemaException sx) {
                    throw new SAXException(sx);
                }
            }
           
            if (cType != null) {
                for (int i = 0; i < sInfo.attributes.size(); i++) {
                    AttributeDecl attDecl =
                        (AttributeDecl)sInfo.attributes.elementAt(i);
                    cType.addAttributeDecl(attDecl);
                }
            }
        }
       
        //-- put element into parent element or as top-level in schema
        if (!_siStack.isEmpty()) {
            StateInfo parentInfo = (StateInfo)_siStack.peek();
            ComplexType type = (ComplexType) parentInfo.element.getType();
            Group group = null;
            if ((type == null) || (type.getParticleCount() == 0)) {
                if (type == null) {
                    parentInfo.complex = true;
                    type = new ComplexType(_schema);
                    parentInfo.element.setType(type);
                }
                group = new Group();
                group.setOrder(_defaultGroupOrder);
                try {
                    type.addGroup(group);
                    //-- add element
                    group.addElementDecl(sInfo.element);
                }
                catch(SchemaException sx) {
                    throw new SAXException(sx);
                }
            }
            else {
                group = (Group) type.getParticle(0);
                //-- check for another element declaration with
                //-- same name ...
                ElementDecl element = group.getElementDecl(name);
                boolean checkGroupType = false;
                if (element != null) {
                    //-- if complex...merge definition
                    if (sInfo.complex) {
                        try {
                            merge(element, sInfo.element);
                        }
                        catch(SchemaException sx) {
                            throw new SAXException(sx);
                        }
                    }
                    element.setMaxOccurs(Particle.UNBOUNDED);
                    checkGroupType = true;
                }
                else {
                    try {
                        group.addElementDecl(sInfo.element);
                    }
                    catch(SchemaException sx) {
                        throw new SAXException(sx);
                    }
                }
               
                //-- change group type if necessary
                if (checkGroupType && (group.getOrder() == Order.sequence)) {
                    //-- make sure element is last item in group,
                    //-- otherwise we need to switch to all
                    boolean found = false;
                    boolean changeType = false;
                    for (int i = 0; i < group.getParticleCount(); i++) {
                        if (found) {
                            changeType = true;
                            break;
                        }
                        if (element == group.getParticle(i)) found = true;
                    }
                    if (changeType) {
                        group.setOrder(Order.all);
                    }
                }
            }
        }
        else {
View Full Code Here

      if (e2Type.isSimpleType()) {
          e1.setType(e2Type);
      }
      else {
          ComplexType cType = new ComplexType(_schema);
          Group group = new Group();
          group.setOrder(_defaultGroupOrder);
          cType.addGroup(group);
          e1.setType(cType);
          e1Type = cType;
      }
        }
        else if (e2Type == null) {
            if (e1Type.isSimpleType()) {
                e2.setType(e1Type);
            }
            else {
                ComplexType cType = new ComplexType(_schema);
                Group group = new Group();
                group.setOrder(_defaultGroupOrder);
                cType.addGroup(group);
                e2.setType(cType);
                e2Type = cType;
            }
        }
       
        //-- both simple types
        if (e1Type.isSimpleType() && e2Type.isSimpleType()) {
            if (!e1Type.getName().equals(e2Type.getName())) {
                String typeName = _nsPrefix + ':' +
                    DatatypeHandler.whichType(e1Type.getName(),
                        e2Type.getName());
                e1.setType(null);
                e1.setTypeReference(typeName);
            }
            return;
        }
        //-- e1 is simple, e2 is complex
        else if (e1Type.isSimpleType()) {
            ComplexType cType = new ComplexType(_schema);
            e1.setType(cType);
            Group group = new Group();
            group.setOrder(_defaultGroupOrder);
            cType.addGroup(group);
            cType.setContentType(ContentType.mixed);
            e1Type = cType;
            //-- do not return here...we need to now treat as both
            //-- were complex
        }
        //-- e2 is simple, e1 is complex
        else if (e2Type.isSimpleType()) {
            ComplexType cType = new ComplexType(_schema);
            e2.setType(cType);
            Group group = new Group();
            group.setOrder(_defaultGroupOrder);
            cType.addGroup(group);
            cType.setContentType(ContentType.mixed);
            e2Type = cType;
            //-- do not return here...we need to now treat as both
            //-- were complex
        }
       
        //-- both complex types
        ComplexType cType1 = (ComplexType)e1Type;
        ComplexType cType2 = (ComplexType)e2Type;
       
        //-- loop through all element/attribute declarations
        //-- of e2 and add them to e1 if they do not already exist
        //-- and mark them as optional
       
        Group e1Group = (Group) cType1.getParticle(0);
        if (e1Group == null) {
            e1Group = new Group();
            e1Group.setOrder(_defaultGroupOrder);
            cType1.addGroup(e1Group);
           
        }
        Group e2Group = (Group) cType2.getParticle(0);
        if (e2Group == null) {
            e2Group = new Group();
            e2Group.setOrder(_defaultGroupOrder);
            cType2.addGroup(e2Group);
           
        }
       
        Enumeration enumeration = e2Group.enumerate();
        while (enumeration.hasMoreElements()) {
            Particle particle = (Particle)enumeration.nextElement();
            if (particle.getStructureType() == Structure.ELEMENT) {
                ElementDecl element = (ElementDecl)particle;
                ElementDecl main = e1Group.getElementDecl(element.getName());
                if (main == null) {
                    e1Group.addElementDecl(element);
                    element.setMinOccurs(0);
                }
                else {
                    merge(main, element);
                }
            }
        }
        //-- add all attributes from type2
        enumeration = cType2.getAttributeDecls();
       
        while (enumeration.hasMoreElements()) {
            //-- check for attribute with same name
            AttributeDecl attNew =  (AttributeDecl)enumeration.nextElement();
                   
            String attName = attNew.getName();
            AttributeDecl attPrev = cType1.getAttributeDecl(attName);
            if (attPrev == null) {
                attNew.setUse(AttributeDecl.USE_OPTIONAL);
                cType1.addAttributeDecl(attNew);
            }
            else {
                String type1 = attPrev.getSimpleType().getName();
                String type2 = attNew.getSimpleType().getName();
                if (!type1.equals(type2)) {
                    String typeName = _nsPrefix + ':' +
                        DatatypeHandler.whichType(type1, type2);
                    attPrev.setSimpleTypeReference(typeName);                        }
            }
        }
       
        //-- loop through all element/attribute declarations
        //-- of e1 and if they do not exist in e2, simply
        //-- mark them as optional
        enumeration = e1Group.enumerate();
        while (enumeration.hasMoreElements()) {
            Particle particle = (Particle)enumeration.nextElement();
            if (particle.getStructureType() == Structure.ELEMENT) {
                ElementDecl element = (ElementDecl)particle;
                if (e2Group.getElementDecl(element.getName()) == null) {
                    element.setMinOccurs(0);
                }
            }
        }
       
View Full Code Here

     *            The XMLBindingComponent to check.
     * @return <code>true</code> if and only if the given XMLBindingComponent
     *         represents a choice. Otherwise returns <code>false</code>
     */
    private boolean isChoice(final XMLBindingComponent component) {
        Group group = this.getGroup(component.getAnnotated());
        if (group == null || group.getOrder() == null) {
            return false;
        }
       
        return group.getOrder() == Order.choice;
    }
View Full Code Here

                (AttributeGroupReference) unmarshaller.getObject();
            _complexType.addAttributeGroupReference(attrGroupRef);
        }
    //-- group declarations (all, choice, group, sequence)
        else if (SchemaNames.isGroupName(name)) {
            Group group = ((GroupUnmarshaller)unmarshaller).getGroup();
            _complexType.addGroup(group);
        }
        unmarshaller = null;
    } //-- endElement
View Full Code Here

        }

        //-- group declarations (all, choice, sequence)
        else if ( (SchemaNames.isGroupName(name)) && (name != SchemaNames.GROUP) )
        {
            Group group = ((GroupUnmarshaller)unmarshaller).getGroup();
            _complexType.addGroup(group);
        }
        //-- annotation
        else if (SchemaNames.ANNOTATION.equals(name)) {
            Annotation ann = ((AnnotationUnmarshaller)unmarshaller).getAnnotation();
View Full Code Here

                    if ((maxOccurs > 1) || (maxOccurs < 0))
                        result = true;
                    break;
            case Structure.MODELGROUP:
            case Structure.GROUP:
                Group group = (Group)_annotated;
                maxOccurs = group.getMaxOccurs();
                if ((maxOccurs > 1) || (maxOccurs < 0))
                    result = true;

                break;
            case Structure.ATTRIBUTE:
View Full Code Here

            case Structure.COMPLEX_TYPE:
                return ((ComplexType)annotated).getMinOccurs();

            case Structure.MODELGROUP:
            case Structure.GROUP:
                Group group = (Group)annotated;
                //-- if the group is top-level, then
                //-- we always return 0
                Structure parent = group.getParent();
                if (parent != null) {
                    if (parent.getStructureType() == Structure.SCHEMA)
                        return 0;
                }               
                int minOccurs = group.getMinOccurs();               
                //-- if minOccurs == 1, then check to see
                //-- if all elements inside group are
                //-- optional, if so, we return 0, not 1.
                if (minOccurs == 1) {
                    Enumeration enumeration = group.enumerate();                   
                    while (enumeration.hasMoreElements()) {
                        if (getLowerBound((Annotated)enumeration.nextElement()) != 0)
                            return 1;
                    }
                    //-- if we make it here, all items in group have a
View Full Code Here

TOP

Related Classes of org.exolab.castor.xml.schema.Group

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.