Author: ajith
Date: Mon Oct 22 19:58:27 2007
New Revision: 587375
URL: http://svn.apache.org/viewvc?rev=587375&view=rev
Log:
1.Added the functionality to pick types and elements from imported schemas
(WSCOMMONS-225)
2. Modified the existing import test to test this functionality
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ImportTest.java
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/importAux.xsd
Modified:
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java?rev=587375&r1=587374&r2=587375&view=diff
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
(original)
+++
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
Mon Oct 22 19:58:27 2007
@@ -133,11 +133,39 @@
}
public XmlSchemaElement getElementByName(QName name) {
- return (XmlSchemaElement)elements.getItem(name);
+ XmlSchemaElement element = (XmlSchemaElement) elements.getItem(name);
+ if (element == null){
+ //search the imports
+ for(Iterator includedItems =
includes.getIterator();includedItems.hasNext();){
+ XmlSchemaImport schemaImport =
(XmlSchemaImport)includedItems.next();
+ XmlSchema schema = schemaImport.getSchema();
+ if (schema.getElementByName(name)!=null){
+ return schema.getElementByName(name);
+ }
+ }
+ }else{
+ return element;
+ }
+
+ return null;
}
public XmlSchemaType getTypeByName(QName name) {
- return (XmlSchemaType)schemaTypes.getItem(name);
+ XmlSchemaType type = (XmlSchemaType) schemaTypes.getItem(name);
+ if (type == null){
+ //search the imports
+ for(Iterator includedItems =
includes.getIterator();includedItems.hasNext();){
+ XmlSchemaImport schemaImport =
(XmlSchemaImport)includedItems.next();
+ XmlSchema schema = schemaImport.getSchema();
+ if (schema.getTypeByName(name)!=null){
+ return schema.getTypeByName(name);
+ }
+ }
+ }else{
+ return type;
+ }
+
+ return null;
}
public XmlSchemaDerivationMethod getFinalDefault() {
Modified:
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ImportTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ImportTest.java?rev=587375&r1=587374&r2=587375&view=diff
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ImportTest.java
(original)
+++
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ImportTest.java
Mon Oct 22 19:58:27 2007
@@ -25,6 +25,7 @@
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.namespace.QName;
import java.io.File;
public class ImportTest extends TestCase {
@@ -64,5 +65,25 @@
XmlSchema schema = schemaCol.read(doc,file.toURL().toString(),null);
assertNotNull(schema);
+ }
+
+ /**
+ * see whether we can reach the types of the imported schemas.
+ * @throws Exception
+ */
+ public void testSchemaImport3() throws Exception{
+ File file = new File(Resources.asURI("importBase.xsd"));
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(file.toURL().toString());
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,file.toURL().toString(),null);
+ assertNotNull(schema);
+
+ assertNotNull(schema.getTypeByName(new
QName("http://soapinterop.org/xsd2","SOAPStruct")));
+ assertNotNull(schema.getElementByName(new
QName("http://soapinterop.org/xsd2","SOAPWrapper")));
}
}
Modified:
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/importAux.xsd
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/importAux.xsd?rev=587375&r1=587374&r2=587375&view=diff
==============================================================================
---
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/importAux.xsd
(original)
+++
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/importAux.xsd
Mon Oct 22 19:58:27 2007
@@ -30,4 +30,5 @@
<element name="varString" type="xsd:string"/>
</all>
</complexType>
+ <element name="SOAPWrapper" type="xsd:string"/>
</schema>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]