Package org.exolab.castor.xml.schema

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


        //-- base
        String base = atts.getValue(SchemaNames.BASE_ATTR);
        if ((base != null) && (base.length() > 0)) {

            XMLType baseType= _schema.getType(base);
            if (baseType == null) {
                _complexType.setBase(base); //the base type has not been read
                if (_complexType.isSimpleContent()) {
                    _complexType.setContentType(new SimpleContent(_schema, base));
                }
            }
        else {
         //--we cannot extend a simpleType in <complexContent>
         if ( (baseType.isSimpleType()) &&
            (_complexType.isComplexContent()) ) {
          String err = "In a 'complexContent', the base attribute "+
                    "must be a complexType but "+ base+" is a simpleType.\n";
                    error(err);
         }
         _complexType.setBase(base);
                 _complexType.setBaseType(baseType);
                if (_complexType.isSimpleContent()) {
                    //--set the content type
                    if (baseType.isSimpleType()) {
                        SimpleType simpleType = (SimpleType)baseType;
                      _complexType.setContentType(new SimpleContent(simpleType));
                    }
                    else {
                        ComplexType temp = (ComplexType)baseType;
View Full Code Here


            Annotation ann = (Annotation)unmarshaller.getObject();
            _element.addAnnotation(ann);
        }
        else if (SchemaNames.COMPLEX_TYPE.equals(name)) {

            XMLType xmlType
                = ((ComplexTypeUnmarshaller)unmarshaller).getComplexType();

            _element.setType(xmlType);

        }
        else if (SchemaNames.SIMPLE_TYPE.equals(name)) {
            XMLType xmlType
                = ((SimpleTypeUnmarshaller)unmarshaller).getSimpleType();
            _element.setType(xmlType);
        }
        else if (SchemaNames.KEY.equals(name) ||
                 SchemaNames.KEYREF.equals(name) ||
View Full Code Here

        //-- base
        String base = atts.getValue(SchemaNames.BASE_ATTR);
        if ((base != null) && (base.length() > 0)) {

            XMLType baseType= _schema.getType(base);
            if (baseType == null)
                _typeDefinition.setBaseTypeName(base);
            else if (baseType.getStructureType() == Structure.COMPLEX_TYPE) {
                String err = "The base type of a simpleType cannot "+
                    "be a complexType.";
                throw new IllegalStateException(err);
            }
            else _typeDefinition.setBaseType( (SimpleType) baseType);
View Full Code Here

                       +"ComplexType: "+structureName+" is not defined in XML Schema:" + _importedSchema.getSchemaLocation();
            error(err);
        }
       
        //2-- the base type must be itself
        XMLType baseType = complexType.getBaseType();
        //--just check the names since a top level complexType can only be defined once.
        if (baseType == null || !baseType.getName().equals(structureName)) {
          String err = "When redefining a complexType, the complexType must use itself as the base type definition.\n"
            +"ComplexType: "+structureName+" uses:" + baseType+ " as its base type.";
          error(err);
        }
       
        complexType.setRedefined();
        _redefineSchema.addComplexType(complexType);
            getResolver().addResolvable(complexType.getReferenceId(), complexType);
      }
      //-- <simpleType>
      else if (name.equals(SchemaNames.SIMPLE_TYPE)) {
        if (_redefineSchema.getSchemaLocation() == "") {
          String err = "In a <redefine>, only annotations can be defined when no -schemaLocation- is specified.";
          error(err);
        }
       
        SimpleType simpleType = null;
        simpleType = ((SimpleTypeUnmarshaller)_unmarshaller).getSimpleType();
            //-- Checks that the simpleType exists in the imported schema
        String structureName = simpleType.getName();
        if (structureName == null) {
          String err = "When redefining a simpleType, the simpleType must have a name.\n";
          error(err);
        }
       
        //1-- the simpleType must exist in the imported schema
        SimpleType original = _importedSchema.getSimpleType(structureName,_schema.getTargetNamespace() );
        if (original == null) {
          String err = "When redefining a simpleType, the simpleType must be present in the imported XML schema.\n"
            +"SimpleType: "+structureName+" is not defined in XML Schema:" + _importedSchema.getSchemaLocation();
          error(err);
        }
       
        //2-- the base type must be itself
        XMLType baseType = simpleType.getBaseType();
        //--just check the names since a top level complexType can only be defined once.
        if (!baseType.getName().equals(structureName)) {
          String err = "When redefining a simpleType, the simpleType must use itself as the base type definition.\n"
            +"SimpleType: "+structureName+" uses:" + baseType.getName() + " as its base type.";
          error(err);
       
       
        simpleType.setRedefined();
        _redefineSchema.addSimpleType(simpleType);
View Full Code Here

        //-- base
        String base = atts.getValue(SchemaNames.BASE_ATTR);
        if ((base != null) && (base.length() > 0)) {

            XMLType baseType= _schema.getType(base);
            if (baseType == null)
                _complexType.setBase(base);
            // the base must not be a simpleType
      else if (baseType.isSimpleType()) {
                String err ="complexType: "+(_complexType.getName()) != null?
                                            _complexType.getName():"\n";
                err += "A complex type cannot be a restriction"+
                    " of a simpleType.";
                throw new IllegalStateException(err);
            }
            else if (!baseType.isAnyType()) {
           // We are now sure the base is a complexType
          // but is it already a restriction? (see PR 5.11->restriction->1.1)
         
          //-- KV 2004-03-15
          //-- Need to valididate this constraint...I couldn't
View Full Code Here

        //-- base
        String base = atts.getValue(SchemaNames.BASE_ATTR);
       
        if ((base != null) && (base.length() > 0)) {

            XMLType baseType= _schema.getType(base);
            if (baseType == null) {
                _complexType.setBase(base);
                _complexType.setContentType(new SimpleContent(_schema, base));
            }
            else if (baseType.isSimpleType()) {
                String err ="complexType: ";
                String name = _complexType.getName();
                if (name != null) {
                    err += name;
                } else {
                    err += "#anonymous-complexType#";
                }
               
                err += "A complex type cannot be a restriction"+
                    " of a simpleType:";
                err += baseType.getName();
                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 {
View Full Code Here

            _complexType.setDerivationMethod(derivedBy);
            if ((derivedBy == null) ||
                (derivedBy.length() == 0) ||
                (derivedBy.equals(KEYWORD_EXTENSION)))
            {
                XMLType baseType= schema.getType(base);
                if (baseType == null)
                    _complexType.setBase(base); //the base type has not been read
                else
                    _complexType.setBaseType(baseType);
            }
View Full Code Here


        //-- handle simpleContent/complexContent if we have a baseType.
        String ELEM_CONTENT    = null;
        String ELEM_DERIVATION = null;
        XMLType baseType = complexType.getBaseType();
        if (baseType != null) {
            if (complexType.isSimpleContent())
                ELEM_CONTENT = schemaPrefix + SchemaNames.SIMPLE_CONTENT;
            else
                ELEM_CONTENT = schemaPrefix + SchemaNames.COMPLEX_CONTENT;

            _atts.clear();
            if (complexType.isComplexContent()) {
                if (complexType.getContentType() == ContentType.mixed) {
                    _atts.addAttribute(SchemaNames.MIXED, CDATA,
                        VALUE_TRUE);
                }

            }
            _handler.startElement(ELEM_CONTENT, _atts);

            ELEM_DERIVATION = schemaPrefix +
                complexType.getDerivationMethod();

            String baseTypeName = baseType.getName();

            //-- add "xsd" prefix if necessary
            if (complexType.isSimpleContent()) {
                //the base type can be a complexType in extension
                if (baseType.isSimpleType()) {
                    SimpleType simpleType = (SimpleType)baseType;
                    if (baseTypeName.indexOf(':') < 0) {
                        if (simpleType.isBuiltInType()) {
                            baseTypeName = schemaPrefix + baseTypeName;
                        }
                        else {
                            String targetNamespace = simpleType.getSchema().getTargetNamespace();
                            String prefix = getNSPrefix(complexType.getSchema(), targetNamespace);
                            if ((prefix != null) && (prefix.length() > 0)) {
                                baseTypeName = prefix + ":" + baseTypeName;
                            }
                        }
                    }
                }
            }
            else if (complexType.isComplexContent()) {
                //--complexType: add 'xsd' only for anyType
                if (baseType.isAnyType()) {
                    if (baseTypeName.indexOf(':') <0 ) {
                       baseTypeName = schemaPrefix + baseTypeName;
                    }

                }
            } //--end of 'xsd' appending
            //add the targetNamespace prefix if necessary
            if (baseType.isComplexType()) {
                String targetNamespace = baseType.getSchema().getTargetNamespace();
                //-- targetNamespace is null
                if (targetNamespace == null) {
                  if (complexType.isRedefined()) {
                    targetNamespace =  complexType.getSchema().getTargetNamespace();
                  }
View Full Code Here

        }

        //-- type attribute
        boolean hasAnonymousType = false;
        if (!element.isReference()) {
            XMLType type = element.getType();

            //-- no type?
            if (type == null) {
                //-- do nothing
            }
            //-- anonymous (in-lined) type
            else if (type.getName() == null) {
                hasAnonymousType = true;
            }
            //-- built-in simpleType
            else if (type.isSimpleType() && ((SimpleType)type).isBuiltInType()){
                _atts.addAttribute(ATTR_TYPE, CDATA,
                    schemaPrefix+type.getName());
            }
            else if (type.getStructureType() == Structure.ANYTYPE) {
                _atts.addAttribute(ATTR_TYPE, CDATA,
                    schemaPrefix+type.getName());
            }
            //-- type imported from another schema
            else if (isImportedType(type, element)) {
                String namespace = type.getSchema().getTargetNamespace();
                String prefix = getNSPrefix(element.getSchema(), namespace);
                if (prefix == null) {
                    //-- declare a temporary prefix
                    prefix = schemaPrefix + '2';
                    _atts.addAttribute("xmlns:" + prefix, CDATA, namespace);
                }
                _atts.addAttribute(ATTR_TYPE, CDATA,
                    prefix + ':' +type.getName());
            //-- otherwise...user defined type.
            }
            else {
                String typeName = type.getName();
                //add the targetNamespace prefix if necessary
                String targetNamespace = element.getSchema().getTargetNamespace();
                if ( targetNamespace!=null ) {
                    String nsPrefix = getNSPrefix(element.getSchema(), targetNamespace);
                    if ((nsPrefix != null) && (nsPrefix.length() != 0))
                        typeName = nsPrefix +':'+ typeName;
                    targetNamespace = null;
                    nsPrefix = null;
                }

                _atts.addAttribute(ATTR_TYPE, CDATA, typeName);
            }
        }

        // add various attributes if we are looking at a local element definition; iow,
        // for an element reference, this values should be specified on the
        // referenced (global) element definition only.
        if (!element.isReference()) {
           
            //-- @abstract
            if (element.isAbstract()) {
                _atts.addAttribute(SchemaNames.ABSTRACT, CDATA, VALUE_TRUE);
            }
           
            //-- @block
            if (element.getBlock() != null) {
                _atts.addAttribute(SchemaNames.BLOCK_ATTR, CDATA,
                        element.getBlock().toString());
            }
           
            //-- @default
            String defaultValue = element.getDefaultValue();
            if (defaultValue != null) {
                _atts.addAttribute(SchemaNames.DEFAULT_ATTR, CDATA,
                        defaultValue);
            }
           
            //-- @fixed
            String fixedValue = element.getFixedValue();
            if (fixedValue != null) {
                _atts.addAttribute(SchemaNames.FIXED_ATTR, CDATA,
                        fixedValue);
            }
           
            //-- @final
            FinalList finalValue = element.getFinal();
            if (finalValue != null) {
                _atts.addAttribute(SchemaNames.FINAL_ATTR, CDATA,
                        finalValue.toString());
            }
           
            //-- @substitutionGroup
            String substitutionGroup = element.getSubstitutionGroup();
            if (substitutionGroup != null) {
                _atts.addAttribute(SchemaNames.SUBSTITUTION_GROUP_ATTR, CDATA,
                        substitutionGroup);
            }
        }

        //-- @form
        Form form = element.getForm();
        if (form != null) {
            _atts.addAttribute(SchemaNames.FORM, CDATA, form.toString());
        }

        //-- @id
        String id = element.getId();
        if (id != null) {
            _atts.addAttribute(SchemaNames.ID_ATTR, CDATA,
                id);
        }

        //-- @nillable
        if (element.isNillable()) {
            _atts.addAttribute(SchemaNames.NILLABLE_ATTR, CDATA,
                VALUE_TRUE);
        }


        _handler.startElement(ELEMENT_NAME, _atts);

        //-- process annotations
        processAnnotated(element, schemaPrefix);

        //-- process anonymous type if necessary
        if (hasAnonymousType) {
            XMLType type = element.getType();
            if (type.isComplexType())
                processComplexType((ComplexType) type, schemaPrefix);
            else if (type.isSimpleType())
                   processSimpleType((SimpleType)type, schemaPrefix);
        }

        //-- process any identity-constraints
        Enumeration enumeration = element.getIdentityConstraints();
View Full Code Here

    public boolean createGroupItem() {
        int maxOccurs = 0;
        boolean result = false;
        switch (_annotated.getStructureType()) {
            case Structure.ELEMENT:
                XMLType type = ((ElementDecl) _annotated).getType();
                if (type.isComplexType()) {
                    maxOccurs = ((ComplexType) type).getMaxOccurs();
                    if (((maxOccurs > 1) || (maxOccurs < 0)) && (type.getName() == null)) {
                        result = true;
                    }
                }
                break;
            case Structure.COMPLEX_TYPE:
View Full Code Here

TOP

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

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.