You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by jk...@apache.org on 2007/01/19 23:34:26 UTC
svn commit: r497979 - in /incubator/woden/trunk/java:
src/org/apache/woden/internal/DOMWSDLReader.java
src/org/apache/woden/wsdl20/xml/TypesElement.java
test/org/apache/woden/tests/TestErrorHandler.java
test/org/apache/woden/tests/W3CTestSuiteTest.java
Author: jkaputin
Date: Fri Jan 19 14:34:25 2007
New Revision: 497979
URL: http://svn.apache.org/viewvc?view=rev&rev=497979
Log:
WODEN-101 Implemented namespace-only schema import
(i.e. not schemaLocation attribute).
Modified:
incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java
incubator/woden/trunk/java/src/org/apache/woden/wsdl20/xml/TypesElement.java
incubator/woden/trunk/java/test/org/apache/woden/tests/TestErrorHandler.java
incubator/woden/trunk/java/test/org/apache/woden/tests/W3CTestSuiteTest.java
Modified: incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java?view=diff&rev=497979&r1=497978&r2=497979
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/internal/DOMWSDLReader.java Fri Jan 19 14:34:25 2007
@@ -43,6 +43,8 @@
import org.apache.woden.schema.Schema;
import org.apache.woden.wsdl20.extensions.ExtensionRegistry;
import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.apache.woden.wsdl20.xml.ImportElement;
+import org.apache.woden.wsdl20.xml.IncludeElement;
import org.apache.woden.wsdl20.xml.TypesElement;
import org.apache.woden.wsdl20.xml.WSDLElement;
import org.apache.woden.xml.XMLAttr;
@@ -303,8 +305,8 @@
}
/*
- * Parse the <xs:import> element and retrieve the imported
- * schema document if schemaLocation specified. Failure to retrieve
+ * Parse the <xs:import> element and resolve the import to an
+ * XML Schema definition. Failure to retrieve
* the schema will only matter if any WSDL components contain elements or
* constraints that refer to the schema, and typically this will be
* determined later by WSDL validation. So just report any such errors
@@ -314,6 +316,8 @@
* - namespace attribute is REQUIRED
* - imported schema MUST have a targetNamespace
* - namespace and targetNamespace MUST be the same
+ *
+ * TODO implement a framework for caching schemas by namespace and resolving xs:import
*/
protected Schema parseSchemaImport(XMLElement importEl,
DescriptionElement desc)
@@ -321,14 +325,14 @@
{
ImportedSchemaImpl schema = new ImportedSchemaImpl();
- String ns = importEl.getAttributeValue(Constants.ATTR_NAMESPACE);
- if(ns != null) {
- schema.setNamespace(getURI(ns));
+ String importNS = importEl.getAttributeValue(Constants.ATTR_NAMESPACE);
+ if(importNS != null) {
+ schema.setNamespace(getURI(importNS));
}
- String sloc = importEl.getAttributeValue(SchemaConstants.ATTR_SCHEMA_LOCATION);
- if(sloc != null) {
- schema.setSchemaLocation(getURI(sloc));
+ String schemaLoc = importEl.getAttributeValue(SchemaConstants.ATTR_SCHEMA_LOCATION);
+ if(schemaLoc != null) {
+ schema.setSchemaLocation(getURI(schemaLoc));
}
if(schema.getNamespace() == null)
@@ -338,114 +342,65 @@
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
-
- Document importedSchemaDoc = null;
- Element schemaEl = null;
- URI contextURI = null;
- String schemaLoc = null;
- URL url = null;
+ XmlSchema schemaDef = null;
- try
+ if(schema.getSchemaLocation() != null)
{
- /*
- * 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;
+ schemaDef = retrieveSchema(desc.getDocumentBaseURI(), schemaLoc);
}
- 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 = getDocument(new InputSource(schemaURL), schemaURL);
-
- } 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;
+ if(schemaDef == null) {
+ //Either there was no schemaLocation or it did not resolve to a schema,
+ //so try to retrieve a schema at the namespace.
+ schemaDef = retrieveSchema(null, importNS);
+ }
+
+ if(schemaDef == null) {
+ //Check if any WSDL imports contain a schema with this namespace.
+ //TODO there may be multiple schemas that this namespace import could resolve to. This is a temporary solution pending WODEN- post M7.
+ ImportElement[] imports = desc.getImportElements();
+ for(int i=0; i<imports.length; i++) {
+ ImportElement importElem = (ImportElement) imports[i];
+ DescriptionElement nestedDesc = importElem.getDescriptionElement();
+ if(nestedDesc != null) {
+ TypesElement typesElem = nestedDesc.getTypesElement();
+ if(typesElem != null) {
+ Schema[] schemas = typesElem.getSchemas(schema.getNamespace());
+ for(int j=0; j<schemas.length; j++) {
+ Schema s = (Schema)schemas[i];
+ XmlSchema x = s.getSchemaDefinition();
+ if(x != null) {
+ schemaDef = x;
+ break;
+ }
+ }
+ }
+ }
}
-
- schemaEl = importedSchemaDoc.getDocumentElement();
-
- try {
- String baseLoc = contextURI != null ? contextURI.toString() : null;
- XmlSchemaCollection xsc = new XmlSchemaCollection();
-
- // Plug in the selected woden URI Resolver
- xsc.setSchemaResolver(new SchemaResolverAdapter(getURIResolver()));
-
- schemaDef = xsc.read(schemaEl, baseLoc);
- 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) {
+ //Check if any WSDL includes contain a schema with this namespace.
+ //TODO there may be multiple schemas that this namespace import could resolve to. This is a temporary solution pending WODEN- post M7.
+ IncludeElement[] includes = desc.getIncludeElements();
+ for(int i=0; i<includes.length; i++) {
+ IncludeElement includeElem = (IncludeElement) includes[i];
+ DescriptionElement nestedDesc = includeElem.getDescriptionElement();
+ if(nestedDesc != null) {
+ TypesElement typesElem = nestedDesc.getTypesElement();
+ if(typesElem != null) {
+ Schema[] schemas = typesElem.getSchemas(schema.getNamespace());
+ for(int j=0; j<schemas.length; j++) {
+ Schema s = (Schema)schemas[i];
+ XmlSchema x = s.getSchemaDefinition();
+ if(x != null) {
+ schemaDef = x;
+ break;
+ }
+ }
+ }
+ }
}
-
}
if(schemaDef != null) {
@@ -596,31 +551,101 @@
}
}
- /**
- * TODO - removed this method if not needed (might be needed for checking
- * the order of elements within a WSDL document).
- *
- * Check the actual element encountered against the expected qname
- *
- * @param el actual element encountered
- * @param qname expected element's qname
- * @throws WSDLException
- */
- /*
- private void checkElementName(XMLElement el, QName qname)
- throws WSDLException
- {
- if (!QNameUtils.matches(qname, el))
+ private XmlSchema retrieveSchema(URI contextURI, String schemaSpec) throws WSDLException {
+
+ Document importedSchemaDoc = null;
+ Element schemaEl = 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.
+ */
+ URL contextURL = (contextURI != null) ? contextURI.toURL() : null;
+ url = StringUtils.getURL(contextURL, schemaSpec);
+
+ } catch (MalformedURLException e) {
+
+ String baseLoc = contextURI != null ? contextURI.toString() : null;
getErrorReporter().reportError(
- new ErrorLocatorImpl(), //TODO line&col nos.
- "WSDL501",
- new Object[] {qname, el.getQName()},
- ErrorReporter.SEVERITY_FATAL_ERROR);
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL502",
+ new Object[] {baseLoc, schemaLoc},
+ ErrorReporter.SEVERITY_ERROR);
+ //can't continue schema retrieval with a bad URL.
+ return null;
}
- }
- */
+ 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.
+ String resolvedLoc = null;
+ try {
+ URI resolvedURI = resolveURI(getURI(schemaURL));
+ resolvedLoc = resolvedURI.toString();
+ importedSchemaDoc = getDocument(new InputSource(resolvedLoc), resolvedLoc);
+
+ } 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 resolving the URL
+ return null;
+ }
+
+ schemaEl = importedSchemaDoc.getDocumentElement();
+
+ try {
+ //String baseLoc = contextURI != null ? contextURI.toString() : null;
+ String baseLoc = resolvedLoc;
+ XmlSchemaCollection xsc = new XmlSchemaCollection();
+
+ // Plug in the selected woden URI Resolver
+ xsc.setSchemaResolver(new SchemaResolverAdapter(getURIResolver()));
+
+ schemaDef = xsc.read(schemaEl, baseLoc);
+ fImportedSchemas.put(schemaURL, schemaDef);
+ }
+ catch (XmlSchemaException e)
+ {
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL522",
+ new Object[] {schemaURL},
+ ErrorReporter.SEVERITY_WARNING,
+ e);
+ }
+ }
+
+ return schemaDef;
+ }
+
private Document getDocument(InputSource inputSource, String desc)
throws WSDLException, IOException
{
Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/xml/TypesElement.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/xml/TypesElement.java?view=diff&rev=497979&r1=497978&r2=497979
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/xml/TypesElement.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/xml/TypesElement.java Fri Jan 19 14:34:25 2007
@@ -76,7 +76,7 @@
* Return the schemas inlined or imported directly within this <types> element
* whose target namespace matches the specified namespace.
* <p>
- * If the namespace argument is null an empty array is returned.
+ * A null namespace argument will return schemas that have no target namespace.
*
* @return an array of Schema objects with the specified target namespace.
*/
Modified: incubator/woden/trunk/java/test/org/apache/woden/tests/TestErrorHandler.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/tests/TestErrorHandler.java?view=diff&rev=497979&r1=497978&r2=497979
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/tests/TestErrorHandler.java (original)
+++ incubator/woden/trunk/java/test/org/apache/woden/tests/TestErrorHandler.java Fri Jan 19 14:34:25 2007
@@ -48,7 +48,19 @@
}
/**
- * Determine whether a message has been reported.
+ * Determine whether an error or fatal error message has been reported.
+ *
+ * @return True if an error or fatal error message has been reported, false otherwise.
+ */
+ public boolean errorMessageHasBeenReported()
+ {
+ if(numErrors + numFatalErrors == 0)
+ return false;
+ return true;
+ }
+
+ /**
+ * Determine whether any message has been reported (warning, error or fatal error).
*
* @return True if a message has been reported, false otherwise.
*/
Modified: incubator/woden/trunk/java/test/org/apache/woden/tests/W3CTestSuiteTest.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/tests/W3CTestSuiteTest.java?view=diff&rev=497979&r1=497978&r2=497979
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/tests/W3CTestSuiteTest.java (original)
+++ incubator/woden/trunk/java/test/org/apache/woden/tests/W3CTestSuiteTest.java Fri Jan 19 14:34:25 2007
@@ -474,7 +474,7 @@
{
DescriptionElement desc = reader.readWSDL(wfr.getFilePath("http://dev.w3.org/cvsweb/~checkout~/2002/ws/desc/test-suite/documents/good/ImportedWSDL-1G/updateDetails.wsdl"), handler);
assertNotNull("DescriptionElement is null.", desc);
- assertFalse("The good ImportedWSDL-1G test returned errors. " + handler.getSummaryOfMessageKeys(), handler.messageHasBeenReported());
+ assertFalse("The good ImportedWSDL-1G test returned errors. " + handler.getSummaryOfMessageKeys(), handler.errorMessageHasBeenReported());
}
catch(Exception e)
{
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org