Package org.exolab.castor.xml.schema

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


        } else if (isString(aType) && isString(bType)) {
            // TODO Finish this so we can implement Unions
        }

        //-- Just return string for now, as all simpleTypes can fit into a string
        Schema schema = aType.getSchema();
        return schema.getSimpleType("string", schema.getSchemaNamespace());
    }
View Full Code Here


            unmarshaller
                = new SimpleTypeRestrictionUnmarshaller(getSchemaContext(), _simpleTypeDef, atts);
        }
        else if (SchemaNames.LIST.equals(name)) {
            foundList = true;
            Schema schema = _simpleTypeDef.getSchema();
            unmarshaller = new SimpleTypeListUnmarshaller(getSchemaContext(), schema, atts);
        }
        else if (SchemaNames.UNION.equals(name)) {
            foundUnion = true;
            Schema schema = _simpleTypeDef.getSchema();
            unmarshaller = new UnionUnmarshaller(getSchemaContext(), schema, atts);
        }
        else illegalElement(name);

    } //-- startElement
View Full Code Here

        }

        //-- Schema object to hold import schema
    boolean addSchema = false;
    _redefineSchema = schema.getRedefineSchema(schemaLocation);
    Schema importedSchema = null;
   
    boolean alreadyLoaded = false;
   
        //-- The schema is not yet loaded
    if (_redefineSchema == null) {
            if (uri instanceof SchemaLocation) {
                importedSchema = ((SchemaLocation)uri).getSchema();
                //-- set the main schema in order to handle
                //-- redefinition at runtime
               
                // importedSchema.addMainSchema(schema);
               
                _redefineSchema = new RedefineSchema(schema, importedSchema);
          schema.addRedefineSchema(_redefineSchema);
          alreadyLoaded = true;
            }
            else {
          importedSchema = new Schema();
          addSchema = true;
      }
    }
    else {
      //-- check schema location, if different, allow merge
        String tmpLocation = _redefineSchema.getOriginalSchema().getSchemaLocation();
        alreadyLoaded = schemaLocation.equals(tmpLocation);
    }

        state.markAsProcessed(schemaLocation, importedSchema);

        if (alreadyLoaded) return;
       
        //-- Parser Schema
    Parser parser = null;
    try {
        parser = getSchemaContext().getParser();
    }
    catch(RuntimeException rte) {}
    if (parser == null) {
        throw new SchemaException("Error failed to create parser for import");
    }
    //-- Create Schema object and setup unmarshaller
    SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(getSchemaContext(), state);
    schemaUnmarshaller.setURIResolver(getURIResolver());
    schemaUnmarshaller.setSchema(importedSchema);
    Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
    parser.setDocumentHandler(handler);
    parser.setErrorHandler(handler);

    try {
        InputSource source = new InputSource(uri.getReader());
            source.setSystemId(uri.getAbsoluteURI());
            parser.parse(source);
    }
    catch(java.io.IOException ioe) {
        throw new SchemaException("Error reading import file '"+schemaLocation+"': "+ ioe);
    }
    catch(org.xml.sax.SAXException sx) {
        throw new SchemaException(sx);
    }
   
    //-- namespace checking
    String namespace = importedSchema.getTargetNamespace();
    if ( namespace != null ) {
      //-- Make sure targetNamespace is not the same as the
      //-- importing schema, see section 4.2.2 in the
      //-- XML Schema Recommendation
      if (!namespace.equals(schema.getTargetNamespace()) ) {
          String err = "The 'namespace' attribute in the <redefine> element must be the same of the targetNamespace of the global schema.\n"
                     +namespace+" is different from:"+schema.getTargetNamespace();
          error (err);
      }
    } else {
      importedSchema.setTargetNamespace(schema.getTargetNamespace());
    }
   
        //-- set the main schema in order to handle
    //-- redefinition at runtime
   
    // importedSchema.addMainSchema(schema);
   
    _importedSchema = importedSchema;
    _redefineSchema = new RedefineSchema(schema, _importedSchema);
    //-- Add schema to list of redefine schemas (if not already present)
    if (addSchema)
    {
            importedSchema.setSchemaLocation(schemaLocation);
            _schema.addRedefineSchema(_redefineSchema);
    }
  }
View Full Code Here

           
           //--check if this attributeGroup is not
           //-- included
           Enumeration includedSchemas = schema.getCachedIncludedSchemas();
           while (includedSchemas.hasMoreElements()) {
               Schema tempSchema = (Schema)includedSchemas.nextElement();
               if (temp instanceof AttributeGroupDecl) {
                   String name = ((AttributeGroupDecl)temp).getName()
                   found = (tempSchema.getAttributeGroup(name)!= null);
               }
           }
          
           if (!found)
                processAttributeGroup(temp,schemaPrefix);
        }

        //-- process all top level attribute declarations
        enumeration = schema.getAttributes();
        while (enumeration.hasMoreElements()) {
          AttributeDecl temp = (AttributeDecl) enumeration.nextElement();
          boolean found = false;
          //--check if this attributeGroup is not
          //-- included
          Enumeration includedSchemas = schema.getCachedIncludedSchemas();
          while (includedSchemas.hasMoreElements()) {
            Schema tempSchema = (Schema)includedSchemas.nextElement();
            found = (tempSchema.getAttribute(temp.getName())!= null);
          }
         
          if (!found)
                processAttribute(temp,schemaPrefix);
        }

        //-- process all top level element declarations
        enumeration = schema.getElementDecls();
        while (enumeration.hasMoreElements()) {
          ElementDecl temp = (ElementDecl) enumeration.nextElement();
          boolean found = false;
          //--check if this attributeGroup is not
          //-- included
          Enumeration includedSchemas = schema.getCachedIncludedSchemas();
          while (includedSchemas.hasMoreElements()) {
            Schema tempSchema = (Schema)includedSchemas.nextElement();
            found = (tempSchema.getElementDecl(temp.getName())!= null);
          }
         
          if (!found)
              processElement(temp,schemaPrefix);
        }

        //-- process all top level complex types
        enumeration = schema.getComplexTypes();
        while (enumeration.hasMoreElements()) {
            ComplexType temp = (ComplexType) enumeration.nextElement();
            boolean found = false;
            //--check if this attributeGroup is not
            //-- included
            Enumeration includedSchemas = schema.getCachedIncludedSchemas();
            while (includedSchemas.hasMoreElements()) {
              Schema tempSchema = (Schema)includedSchemas.nextElement();
              found = (tempSchema.getComplexType(temp.getName())!= null);
            }
            if (!temp.isRedefined() && !found)
                processComplexType(temp, schemaPrefix);
        }

        //-- process all top level groups
        enumeration = schema.getModelGroups();
        while (enumeration.hasMoreElements()) {
          ModelGroup temp = (ModelGroup)enumeration.nextElement();
          boolean found = false;
          //--check if this Group is not
          //-- included
          Enumeration includedSchemas = schema.getCachedIncludedSchemas();
          while (includedSchemas.hasMoreElements()) {
            Schema tempSchema = (Schema)includedSchemas.nextElement();
            found = (tempSchema.getModelGroup(temp.getName())!= null);
          }
         
          if (!temp.isRedefined() && !found)
              processGroup(temp, schemaPrefix);
        }

        //-- process all top level simple types
        enumeration = schema.getSimpleTypes();
        while (enumeration.hasMoreElements()) {
            SimpleType temp = (SimpleType) enumeration.nextElement();
            boolean found = false;
            //--check if this attributeGroup is not
            //-- included
            Enumeration includedSchemas = schema.getCachedIncludedSchemas();
            while (includedSchemas.hasMoreElements()) {
              Schema tempSchema = (Schema)includedSchemas.nextElement();
              found = (tempSchema.getSimpleType(temp.getName())!= null);
            }
            if (!temp.isRedefined() && !found)
                processSimpleType(temp, schemaPrefix);
        }
View Full Code Here

         * check whether its definition can be obtained from one of the
         * imported schemas.
         */
        String typeName = simpleType.getBaseTypeName();
        if(base == null && typeName != null) {
          Schema schema = simpleType.getSchema();
          base = getSimpleTypeFromSchema(schema, typeName);
        }

        boolean isRestriction = false;
        if (base != null) {
View Full Code Here

    private SimpleType getSimpleTypeFromSchema(Schema schema, String typeName) {
      SimpleType base = schema.getSimpleType(typeName);
      if(base == null) {
        Enumeration imports = schema.getImportedSchema();
        while (imports.hasMoreElements() && base == null) {
        Schema sch = (Schema) imports.nextElement();
        base = getSimpleTypeFromSchema(sch, typeName);
      }
      }
      return base;
    }
View Full Code Here

        }

        File schemaFile = new File(_test.getTestFile() + "/" + _schemaName);
        String schemaURL = schemaFile.toURL().toString();

        Schema schema = testReadingSchema(schemaURL);
        if (schema == null) {
            return;
        }
        testWritingSchema(schemaURL, schema);
View Full Code Here

            SchemaReader reader = new SchemaReader();
           
            reader.setSchemaContext(new SchemaContextImpl());
            reader.setInputSource(new InputSource(url));
           
            Schema returnValue  = reader.read();
            if (_failure != null && _failure.getContent() && _failure.getFailureStep() != null &&
                 _failure.getFailureStep().equals(FailureStepType.PARSE_SCHEMA)) {
                fail("Reading/Parsing the schema was expected to fail, but succeeded");
            }
            return returnValue;
View Full Code Here

     *
     * @return the schemaLocation of the parent schema of the wrapped structure.
     */
    public String getSchemaLocation() {
        String location = null;
        Schema schema = getSchema();
        if (schema != null) {
            location = schema.getSchemaLocation();
        }

        return location;
    }
View Full Code Here

     *
     * @return the targetNamespace of the parent schema of the wrapped structure.
     */
    public String getTargetNamespace() {
        String result = null;
        Schema schema = null;
        Form   form   = null;

        switch (_annotated.getStructureType()) {
            case Structure.ATTRIBUTE:
                AttributeDecl attribute = (AttributeDecl) _annotated;
                //-- resolve reference
                if (attribute.isReference()) {
                    attribute = attribute.getReference();
                }

                schema = attribute.getSchema();

                //-- top-level (use targetNamespace of schema)
                if (attribute.getParent() == schema) {
                    break;
                }

                //-- check form (qualified or unqualified)
                form = attribute.getForm();
                if (form == null) {
                    form = schema.getAttributeFormDefault();
                }

                if ((form == null) || form.isUnqualified()) {
                    //-- no targetNamespace by default
                    return null;
                }
                //-- use targetNamespace of schema
                break;
            case Structure.ELEMENT:
                //--resolve reference?
                ElementDecl element = (ElementDecl) _annotated;
                if (element.isReference()) {
                    element = element.getReference();
                }

                schema = element.getSchema();
                //-- top-level (use targetNamespace of schema)
                if (element.getParent() == schema) {
                    break;
                }

                //-- check form (qualified or unqualified)
                form = element.getForm();
                if (form == null) {
                    form = schema.getElementFormDefault();
                }

                //-- no targetNamespace by default
                if ((form == null) || form.isUnqualified()) {
                    return null;
                }
                //-- use targetNamespace of schema
                break;
            case Structure.COMPLEX_TYPE:
                ComplexType complexType = (ComplexType) _annotated;
                schema = complexType.getSchema();
                if (complexType.getParent() == schema) {
                    break;
                }
                return null;
            case Structure.SIMPLE_TYPE:
                SimpleType simpleType = (SimpleType) _annotated;
                schema = simpleType.getSchema();
                if (simpleType.getParent() == schema) {
                    break;
                }
                return null;
            default:
                break;
        }
        if (schema == null) {
            schema = getSchema();
        }

        if (schema != null) {
            result = schema.getTargetNamespace();
        }
        return result;
    } //-- getTargetNamespace
View Full Code Here

TOP

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

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.