Package org.apache.woden.internal.schema

Examples of org.apache.woden.internal.schema.ImportedSchemaImpl


     */
    protected Schema parseSchemaImport(XMLElement importEl,
                                     DescriptionElement desc)
                                     throws WSDLException {

        ImportedSchemaImpl schema = new ImportedSchemaImpl();
        schema.setXMLElement(importEl);

        String ns = importEl.getAttributeValue(Constants.ATTR_NAMESPACE);

        if(ns != null) {
            schema.setNamespace(getURI(ns));
        }

        String sloc = importEl.getAttributeValue(SchemaConstants.ATTR_SCHEMA_LOCATION);
        if(sloc != null) {
            schema.setSchemaLocation(getURI(sloc));
        }

        if(schema.getNamespace() == null){
            //The namespace attribute is REQUIRED on xs:import, so don't continue.
            schema.setReferenceable(false);
            return schema;
        }

        if(schema.getSchemaLocation() == null){
            //This is a namespace-only import, no schema document to be retrieved so don't continue.

            /* TODO investigate whether/how to try to resolve the imported namespace to known schema
             * components from that namespace (e.g. via a URI catalog resolver). Currently, any attempt
             * to resolve a QName against schema components from this namespace will search ALL
             * schemas imported from this namespace (see methods in TypesImpl).
             */

            return schema;
        }

        //Now try to retrieve the schema import using schemaLocation

        OMElement importedSchemaDoc = null;
        URI contextURI = null;
        String schemaLoc = null;
        URL url = null;

        try{
          /*
           * For simple resolvers, we resolve the parent (Description) URI
           * to be used as the context. This allows for relative locationURIs
           * to be resolved implicitly - they are considered to be located
           * relative to the resolved parent. Therefore, relative URIs such as these
           * need not be listed in the catalog file.
           */
         
          /* TODO
           * OASIS-style catalogs have a convenience notation to define root URIs
           * thus grouping related URLs together. In this case the context URI here
           * should be left alone, but the resultant locationURL resolved instead.
           *
           * Implement a boolean system property like org.apache.woden.resolver.useRelativeURLs
           * (set by the resolver ctor). SimpleURIResolver (et al) should set this to true,
           * OASISCatalogResolver should set to false.
           */
          // contextURI = desc.getDocumentBaseURI();
          contextURI = resolveURI(desc.getDocumentBaseURI());
            URL contextURL = (contextURI != null) ? contextURI.toURL() : null;
            schemaLoc = schema.getSchemaLocation().toString();
            url = StringUtils.getURL(contextURL, schemaLoc);

        }
        catch (MalformedURLException e) {

            String baseLoc = contextURI != null ? contextURI.toString() : null;
            getErrorReporter().reportError(
                    new ErrorLocatorImpl()//TODO line&col nos.
                    "WSDL502",
                    new Object[] {baseLoc, schemaLoc},
                    ErrorReporter.SEVERITY_ERROR);

            //can't continue schema retrieval with a bad URL.
            schema.setReferenceable(false);
            return schema;
        }

        String schemaURL = url.toString();

        //If the schema has already been imported, reuse it.
        XmlSchema schemaDef = (XmlSchema)fImportedSchemas.get(schemaURL);

        if(schemaDef == null){
            //not previously imported, so retrieve it now.
            try {
                importedSchemaDoc = OMUtils.getElement(schemaURL);
            } catch (URISyntaxException e){
                String msg = getErrorReporter().getFormattedMessage(
                        "WSDL502", new Object[] {null, schemaURL});
                throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
            } catch (XMLStreamException e){
                String msg = getErrorReporter().getFormattedMessage(
                        "WSDL500", new Object[] {"XML", schemaURL});
                throw new WSDLException(WSDLException.PARSER_ERROR, msg, e);
            } catch (IOException e4) {
               
                //schema retrieval failed (e.g. 'not found')
                getErrorReporter().reportError(
                        new ErrorLocatorImpl()//TODO line&col nos.
                        "WSDL504",
                        new Object[] {schemaURL},
                        ErrorReporter.SEVERITY_WARNING,
                        e4);
               
                //cannot continue without an imported schema
                schema.setReferenceable(false);
                return schema;
            }

            /*
            * First get the schema element and serialize that into a byte array.
            * This is used in getting an InputSource which is later used as an argument
            * to the XMLSchemaCollection object.
            */
            String schemaElStr = null;
            try {
                schemaElStr = importedSchemaDoc.toStringWithConsume();
            }
            catch (XMLStreamException e) {
                e.printStackTrace();
            }
            byte[] schemaElbytes = schemaElStr.getBytes();
            InputSource schemaSource = new InputSource(new ByteArrayInputStream(schemaElbytes));
            schemaSource.setSystemId(schemaURL);

            try {
                XmlSchemaCollection xsc = new XmlSchemaCollection();
               
                // Plug in the selected woden URI Resolver
                xsc.setSchemaResolver(new OMSchemaResolverAdapter(getURIResolver(), importEl));
               
                schemaDef = xsc.read(schemaSource, null);
                fImportedSchemas.put(schemaURL, schemaDef);
            }
            catch (XmlSchemaException e){
                getErrorReporter().reportError(
                        new ErrorLocatorImpl()//TODO line&col nos.
                        "WSDL522",
                        new Object[] {schemaURL},
                        ErrorReporter.SEVERITY_WARNING,
                        e);
            }
        }
        if(schemaDef != null) {
            schema.setSchemaDefinition(schemaDef);
        }
        else {
            schema.setReferenceable(false);
        }
        return schema;
    }
View Full Code Here


    // Test that no error is reported for an imported schema that has
  // a null schema. This error should be caught elseware.
  handler.reset();
  try
  {
    ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
    importedSchema.setNamespace(new URI("http://www.sample.org"));
 
    if(!val.testAssertionSchema1070(importedSchema, reporter))
    {
    fail("The testAssertionSchema1070 method returned false for a null schema.");
    }
  }
  catch(URISyntaxException e)
  {
    fail("There was a problem setting the namespace of the imported schema: " + e);
  }
  catch(WSDLException e)
  {
    fail("There was a problem running the test assertion method " + e);
    }
 
  // Test that no error is reported for an imported schema that has
  // the same target namespace as the imported element.
  handler.reset();
  try
  {
    ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
 
    importedSchema.setNamespace(new URI("http://www.sample.org"));
 
 
    XmlSchema schema = new XmlSchema("http://www.sample.org", null);
    importedSchema.setSchemaDefinition(schema);
    if(!val.testAssertionSchema1070(importedSchema, reporter))
    {
    fail("The testAssertionSchema1070 method returned false for a schema with the same target namespace as the import element.");
    }
  }
  catch(URISyntaxException e)
  {
    fail("There was a problem setting the namespace of the imported schema: " + e);
  }
  catch(WSDLException e)
  {
    fail("There was a problem running the test assertion method " + e);
    }
 
  // Test that an error is reported for an imported schema that has
  // a different defined target namespace than the import element.
  handler.reset();
  try
  {
    ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
 
    importedSchema.setNamespace(new URI("http://www.sample.org"));
 
 
    XmlSchema schema = new XmlSchema("http://differentnamespace.sample.org", null);
    importedSchema.setSchemaDefinition(schema);
    if(val.testAssertionSchema1070(importedSchema, reporter))
    {
    fail("There was no error reported for a schema with a different target namespace than the import element.");
    }
    else if(handler.errors.size() > 1)
    {
    fail("More than one error was reported for a schema with a different target namespace than the import element.");
    }
    else if(!handler.errors.containsKey("Schema-1070"))
    {
    fail("The error Schema-1070 was not reported for a schema with a different target namespace than the import element.");
    }
  }
  catch(URISyntaxException e)
  {
    fail("There was a problem setting the namespace of the imported schema: " + e);
  }
  catch(WSDLException e)
  {
    fail("There was a problem running the test assertion method " + e);
    }
 
    // Test that an error is reported for an imported schema that has
  // no defined target namespace.
  handler.reset();
  try
  {
    ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
 
    importedSchema.setNamespace(new URI("http://www.sample.org"));
 
 
    XmlSchema schema = new XmlSchema(null, null);
    importedSchema.setSchemaDefinition(schema);
    if(val.testAssertionSchema1070(importedSchema, reporter))
    {
    fail("There was no error reported for a schema with a null target namespace.");
    }
    else if(handler.errors.size() > 1)
    {
    fail("More than one error was reported for a schema with a null target namespace.");
    }
    else if(!handler.errors.containsKey("Schema-1070"))
    {
    fail("The error Schema-1070 was not reported for a schema with a null target namespace.");
    }
  }
  catch(URISyntaxException e)
  {
    fail("There was a problem setting the namespace of the imported schema: " + e);
  }
  catch(WSDLException e)
  {
    fail("There was a problem running the test assertion method " + e);
    }
 
    // Test that an error is reported for an imported schema that has
  // an empty defined target namespace.
  handler.reset();
  try
  {
    ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
 
    importedSchema.setNamespace(new URI("http://www.sample.org"));
 
 
    XmlSchema schema = new XmlSchema("", null);
    importedSchema.setSchemaDefinition(schema);
    if(val.testAssertionSchema1070(importedSchema, reporter))
    {
    fail("There was no error reported for a schema with an empty target namespace.");
    }
    else if(handler.errors.size() > 1)
View Full Code Here

    // Test that no error is reported for an imported schema that has
  // a null schema. This error should be caught elseware.
  handler.reset();
  try
  {
    ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
    importedSchema.setNamespace(new URI("http://www.sample.org"));
 
    if(!val.testAssertionSchema1069(importedSchema, reporter))
    {
    fail("The testAssertionSchema0017 method returned false for a null schema.");
    }
  }
  catch(URISyntaxException e)
  {
    fail("There was a problem setting the namespace of the imported schema: " + e);
  }
  catch(WSDLException e)
  {
    fail("There was a problem running the test assertion method " + e);
    }
 
  // Test that no error is reported for an imported schema that has
  // defined a target namespace.
  handler.reset();
  try
  {
    ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
    importedSchema.setNamespace(new URI("http://www.sample.org"));
 
    XmlSchema schema = new XmlSchema("http://www.sample.org", null);
    importedSchema.setSchemaDefinition(schema);
    if(!val.testAssertionSchema1069(importedSchema, reporter))
    {
    fail("The testAssertionSchema1069 method returned false for a schema with a target namespace.");
    }
  }
  catch(URISyntaxException e)
  {
    fail("There was a problem setting the namespace of the imported schema: " + e);
  }
  catch(WSDLException e)
  {
    fail("There was a problem running the test assertion method " + e);
    }
 
    // Test that an error is reported for an imported schema that has
  // no defined target namespace.
  handler.reset();
  try
  {
    ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
 
    importedSchema.setNamespace(new URI("http://www.sample.org"));
 
 
    XmlSchema schema = new XmlSchema(null, null);
    importedSchema.setSchemaDefinition(schema);
    if(val.testAssertionSchema1069(importedSchema, reporter))
    {
    fail("There was no error reported for a schema with a null target namespace.");
    }
    else if(handler.errors.size() > 1)
    {
    fail("More than one error was reported for a schema with a null target namespace.");
    }
    else if(!handler.errors.containsKey("Schema-1069"))
    {
    fail("The error Schema-1069 was not reported for a schema with a null target namespace.");
    }
  }
  catch(URISyntaxException e)
  {
    fail("There was a problem setting the namespace of the imported schema: " + e);
  }
  catch(WSDLException e)
  {
    fail("There was a problem running the test assertion method " + e);
    }
 
    // Test that an error is reported for an imported schema that has
  // an empty defined target namespace.
  handler.reset();
  try
  {
    ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
 
    importedSchema.setNamespace(new URI("http://www.sample.org"));
 
 
    XmlSchema schema = new XmlSchema("", null);
    importedSchema.setSchemaDefinition(schema);
    if(val.testAssertionSchema1069(importedSchema, reporter))
    {
    fail("There was no error reported for a schema with an empty target namespace.");
    }
    else if(handler.errors.size() > 1)
View Full Code Here

TOP

Related Classes of org.apache.woden.internal.schema.ImportedSchemaImpl

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.