Package org.exolab.castor.xml.schema

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


          throw new DTDException(err);
       }
       ElementDecl schemaElement = new ElementDecl(schema, name);

       // start converting content of the element
       ComplexType complexType = schema.createComplexType();
       ContentType contentType = null;
       Group group = null; // auxiliary
       Iterator mixedChildrenIterator = null; // auxiliary
       String elementRef = null; // auxiliary
       ElementDecl elem = null// auxiliary

       if (dtdElement.isEmptyContent()) {

          // mixed="false"
          contentType = ContentType.elemOnly;
          //-- mixed="false"

       } else if (dtdElement.isAnyContent()) {

          // mixed="true"
          contentType = ContentType.mixed;
          //-- mixed="true"

          group = new Group();
          group.setOrder(Order.sequence);
          group.setMinOccurs(0);
          group.setMaxOccurs(-1);
          Wildcard any = new Wildcard(group);
          group.addWildcard(any);
          complexType.addGroup(group);

       } else if (dtdElement.isElemOnlyContent()) {

          // mixed="false"
          contentType = ContentType.elemOnly;
          //-- mixed="false"

          ContentParticle dtdContent = dtdElement.getContent();
          if (dtdContent == null) { // content is not specified
             String err = "DTD to Schema converter: element \"" + dtdElement.getName();
             err += "\" has no content.";
             throw new DTDException(err);
          }

          Particle content = null;
          try {
             content = convertContentParticle(dtdContent, schema);
          }
          catch (DTDException e) {
             String err = "DTD to Schema converter: content of DTD element \"" + dtdElement.getName();
             err += "\", represented by a Content Particle, is malformed.";
             throw new DTDException(err);
          }

          if (content instanceof ElementDecl) {
             group = new Group();
             group.setOrder(Order.sequence);
             group.addElementDecl((ElementDecl)content);
             complexType.addGroup(group);
          } else {
             complexType.addGroup((Group)content);
          }

       } else if (dtdElement.isMixedContent()) {

          // mixed="true"
          contentType = ContentType.mixed;
          //-- mixed="true"

          mixedChildrenIterator = dtdElement.getMixedContentChildren();
          if ((mixedChildrenIterator != null) && (mixedChildrenIterator.hasNext())) {
             group = new Group();
             group.setOrder(Order.choice);
             group.setMinOccurs(0);
             group.setMaxOccurs(-1);
             while (mixedChildrenIterator.hasNext()) {
                elementRef = (String)mixedChildrenIterator.next();
                elem = new ElementDecl(schema);
                elem.setReferenceName(elementRef);
                group.addElementDecl(elem);
             }
             complexType.addGroup(group);
          }

       } else { // the type of the element has not been specified
          String err = "DTD to Schema converter: content type of DTD element \"" + dtdElement.getName();
          err += "\" has not been specified.";
          throw new DTDException(err);
       }
       complexType.setContentType(contentType);
       // finish converting content of the element

       // start attributes convertion
       Enumeration dtdAttributes = dtdElement.getAttributes();
       Attribute dtdAttribute;
       AttributeDecl schemaAttribute;

       while (dtdAttributes.hasMoreElements()) {
          dtdAttribute = (Attribute)dtdAttributes.nextElement();
          schemaAttribute = convertAttribute(dtdAttribute, schema);
          complexType.addAttributeDecl(schemaAttribute);
       }
       // end attributes convertion

       schemaElement.setType(complexType);
       return schemaElement;
View Full Code Here


     * @throws SAXException
     * @throws FileNotFoundException
     */
    public void testUnmarshallSchema() throws FileNotFoundException, SAXException, IOException {
        Schema schema = unmarshalSchema("schema-entity.xsd");
        ComplexType bookType = schema.getComplexType("bookType");
        Enumeration annotations = bookType.getAnnotations();
        Annotation annotation = (Annotation) annotations.nextElement();
        Enumeration appInfos = annotation.getAppInfo();
        AppInfo appInfo = (AppInfo) appInfos.nextElement();
        List jdoContent = appInfo.getJdoContent();

        assertEquals(1, jdoContent.size());
        Table t = (Table) jdoContent.get(0);
        assertEquals("book", t.getName());
        assertEquals("isbn", t.getPrimaryKey().getKey(0));

        ElementDecl isbn = bookType.getElementDecl("isbn");
        annotations = isbn.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();

        assertEquals(1, jdoContent.size());
        Column c = (Column) jdoContent.get(0);
        assertEquals("isbn", c.getName());
        assertEquals("jdo:string", c.getType());

        ElementDecl title = bookType.getElementDecl("title");
        annotations = title.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();
View Full Code Here

     * @throws IOException
     * @throws SAXException
     */
    public void testUnmarshallNonJdoSchema() throws SAXException, IOException {
        Schema schema = unmarshalSchema("schema-entity-non-jdo.xsd");
        ComplexType bookType = schema.getComplexType("bookType");
        Enumeration annotations = bookType.getAnnotations();
        Annotation annotation = (Annotation) annotations.nextElement();
        Enumeration appInfos = annotation.getAppInfo();
        AppInfo appInfo = (AppInfo) appInfos.nextElement();
        List jdoContent = appInfo.getJdoContent();

        assertEquals(0, jdoContent.size());

        ElementDecl isbn = bookType.getElementDecl("isbn");
        annotations = isbn.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();

        assertEquals(0, jdoContent.size());

        ElementDecl title = bookType.getElementDecl("title");
        annotations = title.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();
View Full Code Here

     * @throws IOException
     * @throws SAXException
     */
    public void testUnmarshallMixedSchema() throws SAXException, IOException {
        Schema schema = unmarshalSchema("schema-entity-mixed.xsd");
        ComplexType bookType = schema.getComplexType("bookType");
        Enumeration annotations = bookType.getAnnotations();
        Annotation annotation = (Annotation) annotations.nextElement();
        Enumeration appInfos = annotation.getAppInfo();
        AppInfo appInfo = (AppInfo) appInfos.nextElement();
        List jdoContent = appInfo.getJdoContent();

        assertEquals(0, jdoContent.size());

        ElementDecl isbn = bookType.getElementDecl("isbn");
        annotations = isbn.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();

        assertEquals(0, jdoContent.size());

        ElementDecl title = bookType.getElementDecl("title");
        annotations = title.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();
View Full Code Here

     * @throws IOException
     * @throws SAXException
     */
    public void testUnmarshallOneToManySchema() throws SAXException, IOException {
        Schema schema = unmarshalSchema("schema-one-to-many.xsd");
        ComplexType bookType = schema.getComplexType("bookType");
        Enumeration annotations = bookType.getAnnotations();
        Annotation annotation = (Annotation) annotations.nextElement();
        Enumeration appInfos = annotation.getAppInfo();
        AppInfo appInfo = (AppInfo) appInfos.nextElement();
        List jdoContent = appInfo.getJdoContent();

        assertEquals(1, jdoContent.size());
        Table t = (Table) jdoContent.get(0);
        assertEquals("book", t.getName());
        assertEquals("isbn", t.getPrimaryKey().getKey(0));

        ElementDecl isbn = bookType.getElementDecl("isbn");
        annotations = isbn.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();

        assertEquals(1, jdoContent.size());
        Column c = (Column) jdoContent.get(0);
        assertEquals("isbn", c.getName());
        assertEquals("varchar", c.getType());

        ElementDecl title = bookType.getElementDecl("title");
        annotations = title.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();

        assertEquals(1, jdoContent.size());
        c = (Column) jdoContent.get(0);
        assertEquals("title", c.getName());
        assertEquals("varchar", c.getType());
       
        ElementDecl author = bookType.getElementDecl("author");
        annotations = author.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();
View Full Code Here

     * @throws IOException
     * @throws SAXException
     */
    public void testUnmarshallOneToOneSchema() throws SAXException, IOException {
        Schema schema = unmarshalSchema("schema-one-to-one.xsd");
        ComplexType bookType = schema.getComplexType("bookType");
        Enumeration annotations = bookType.getAnnotations();
        Annotation annotation = (Annotation) annotations.nextElement();
        Enumeration appInfos = annotation.getAppInfo();
        AppInfo appInfo = (AppInfo) appInfos.nextElement();
        List jdoContent = appInfo.getJdoContent();

        assertEquals(1, jdoContent.size());
        Table t = (Table) jdoContent.get(0);
        assertEquals("book", t.getName());
        assertEquals("isbn", t.getPrimaryKey().getKey(0));

        ElementDecl isbn = bookType.getElementDecl("isbn");
        annotations = isbn.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();

        assertEquals(1, jdoContent.size());
        Column c = (Column) jdoContent.get(0);
        assertEquals("isbn", c.getName());
        assertEquals("varchar", c.getType());

        ElementDecl title = bookType.getElementDecl("title");
        annotations = title.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();

        assertEquals(1, jdoContent.size());
        c = (Column) jdoContent.get(0);
        assertEquals("title", c.getName());
        assertEquals("varchar", c.getType());
       
        ElementDecl author = bookType.getElementDecl("author");
        annotations = author.getAnnotations();
        annotation = (Annotation) annotations.nextElement();
        appInfos = annotation.getAppInfo();
        appInfo = (AppInfo) appInfos.nextElement();
        jdoContent = appInfo.getJdoContent();
View Full Code Here

                    if (baseType.isSimpleType()) {
                        SimpleType simpleType = (SimpleType)baseType;
                      _complexType.setContentType(new SimpleContent(simpleType));
                    }
                    else {
                        ComplexType temp = (ComplexType)baseType;
                        SimpleContent simpleContent = (SimpleContent) temp.getContentType();
                        _complexType.setContentType(simpleContent.copy());
                    }
                }
                  
        }
View Full Code Here

                }
            }
            break;

        case Structure.COMPLEX_TYPE:
            ComplexType complexType = (ComplexType) structure;
            parent = (complexType).getParent();
            if (parent.getStructureType() != Structure.SCHEMA) {
                getSchemaLocation(parent, location, dealWithAnonTypes);
            }
            if (complexType.getName() != null) {
                location.append(ExtendedBinding.PATH_SEPARATOR);
                location.append(ExtendedBinding.COMPLEXTYPE_ID);
                location.append(((ComplexType) structure).getName());
            }
//            else if (dealWithAnonTypes){
View Full Code Here

      else if (name.equals(SchemaNames.COMPLEX_TYPE)) {
        if (_redefineSchema.getSchemaLocation() == "") {
          String err = "In a <redefine>, only annotations can be defined when no -schemaLocation- is specified.";
          error(err);
        }
        ComplexType complexType = null;
        complexType = ((ComplexTypeUnmarshaller)_unmarshaller).getComplexType();
        //-- Checks that the complexType exists in the imported schema
        String structureName = complexType.getName();
        if (structureName == null) {
          String err = "When redefining a complexType, the complexType must have a name.\n";
          error(err);
        }
       
        //1-- the complexType must exist in the imported schema
        ComplexType original = _importedSchema.getComplexType(structureName);
        if (original == null) {
            String err = "When redefining a complexType, the complexType must be present in the imported XML schema.\n"
                       +"ComplexType: "+structureName+" is not defined in XML Schema:" + _importedSchema.getSchemaLocation();
            error(err);
        }
View Full Code Here

                throw new IllegalStateException(err);
            }
      //we are now sure that the base is a ComplexType
            //but is the base of this complexType a simpleType? (see 4.3.3->simpleContent->content type)
            else {
                ComplexType temp = (ComplexType) baseType;
               
                if ( ! temp.isSimpleContent() ) {
                    // UPO - base type may have complex content if
                    // 1. content model is emptiable
                    // 2. it has mixed content
                    // See bug report http://jira.codehaus.org/browse/CASTOR-1238
                    if ( (temp.getContentType().getType() == ContentType.MIXED&&  temp.isEmptiable() ) {
                      // OK
                    }
                    else {
                      String err ="complexType: ";
                      String name = _complexType.getName();
                      if (name != null) {
                          err += name;
                      } else {
                          err += "#anonymous-complexType#";
                      }
                   
                      err += ": In a simpleContent when using restriction the base type"+
                          " must be a complexType with a simple content model or it must" +
                          " be a complex content model which is mixed and emptiable.";
                      throw new IllegalStateException(err);
                    }
                }
                else {
            //retrieve the base type of this complexType
                    //the base type is the complexType but we have to
                    //work with the simple type of the content type.
                    SimpleContent contentType = (SimpleContent)temp.getContentType();
                    _complexType.setBaseType(temp);
                    _complexType.setBase(temp.getName());
              _simpleTypeDef = new SimpleTypeDefinition(_schema, temp.getName(),_id);
              SimpleType simpleType = contentType.getSimpleType();
              if (simpleType != null) {
                        _simpleTypeDef.setBaseType(simpleType);
                    }
                    else {
View Full Code Here

TOP

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

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.