jochen 2005/04/25 12:59:30
Modified: src/xs/org/apache/ws/jaxme/xs/junit Tag: v0_4
ParserTest.java
. Tag: v0_4 status.xml
src/xs/org/apache/ws/jaxme/xs/impl Tag: v0_4
XSLogicalParser.java
Log:
Fixed that recursive xs:include caused an endless loop. (Daniel Barclay,
daniel at fgm.com)
Revision Changes Path
No revision
No revision
1.20.2.1 +78 -16
ws-jaxme/src/xs/org/apache/ws/jaxme/xs/junit/ParserTest.java
Index: ParserTest.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/xs/org/apache/ws/jaxme/xs/junit/ParserTest.java,v
retrieving revision 1.20
retrieving revision 1.20.2.1
diff -u -r1.20 -r1.20.2.1
--- ParserTest.java 4 Dec 2004 23:22:33 -0000 1.20
+++ ParserTest.java 25 Apr 2005 19:59:30 -0000 1.20.2.1
@@ -18,6 +18,9 @@
import java.io.IOException;
import java.io.StringReader;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import javax.xml.parsers.ParserConfigurationException;
@@ -45,6 +48,7 @@
import org.apache.ws.jaxme.xs.XSWildcard;
import org.apache.ws.jaxme.xs.jaxb.JAXBGlobalBindings;
import org.apache.ws.jaxme.xs.jaxb.JAXBSchema;
+import org.apache.ws.jaxme.xs.jaxb.JAXBXsObjectFactory;
import org.apache.ws.jaxme.xs.jaxb.impl.JAXBParser;
import org.apache.ws.jaxme.xs.types.XSBoolean;
import org.apache.ws.jaxme.xs.types.XSDate;
@@ -58,8 +62,8 @@
import org.apache.ws.jaxme.xs.types.XSPositiveInteger;
import org.apache.ws.jaxme.xs.types.XSString;
import org.apache.ws.jaxme.xs.xml.XsNamespaceList;
+import org.apache.ws.jaxme.xs.xml.XsObjectFactory;
import org.apache.ws.jaxme.xs.xml.XsQName;
-import org.apache.ws.jaxme.xs.xml.impl.XsObjectFactoryImpl;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
@@ -1070,7 +1074,7 @@
InputSource isource = new InputSource(new
StringReader(schemaSource));
isource.setSystemId("testSimpleKey.xsd");
- XSSchema schema = pParser.parse(isource);
+ pParser.parse(isource);
}
/** <p>Tests whether xs:documentation may have arbitrary childs.</p>
@@ -1241,21 +1245,16 @@
" </xs:element>\n" +
"</xs:schema>\n";
- pParser.getContext().setXsObjectFactory(new XsObjectFactoryImpl(){
- public XMLReader newXMLReader(boolean pValidating) throws
ParserConfigurationException, SAXException {
- XMLReader result = super.newXMLReader(pValidating);
- result.setEntityResolver(new EntityResolver(){
- public InputSource resolveEntity(String publicId, String
systemId) throws SAXException, IOException {
- if ("abc.xsd".equals(systemId)) {
- return new InputSource(new
StringReader(importedSchema));
- } else {
- throw new SAXException("Invalid systemId: " +
systemId);
- }
- }
- });
- return result;
+ EntityResolver resolver = new EntityResolver(){
+ public InputSource resolveEntity(String publicId, String
systemId) throws SAXException, IOException {
+ if ("abc.xsd".equals(systemId)) {
+ return new InputSource(new StringReader(importedSchema));
+ } else {
+ throw new SAXException("Invalid systemId: " + systemId);
+ }
}
- });
+ };
+
pParser.getContext().setXsObjectFactory(getXsObjectFactoryProxy(pParser.getContext().getXsObjectFactory(),
resolver));
InputSource isource = new InputSource(new
StringReader(schemaSource));
isource.setSystemId("testImportSchemaWithoutNamespace.xsd");
XSSchema schema = pParser.parse(isource);
@@ -1299,6 +1298,7 @@
*/
public void testImportSchemaWithoutNamespace() throws Exception {
testImportSchemaWithoutNamespace(newXSParser());
+ testImportSchemaWithoutNamespace(newJAXBParser());
}
private void testElementReferenceGlobal(XSParser pParser) throws
Exception {
@@ -1359,4 +1359,66 @@
testElementReferenceGlobal(newXSParser());
testElementReferenceGlobal(newJAXBParser());
}
+
+ private XsObjectFactory getXsObjectFactoryProxy(final XsObjectFactory
pFactory,
+
final EntityResolver pResolver) {
+ InvocationHandler h = new InvocationHandler() {
+ public Object invoke(Object pProxy, Method pMethod,
Object[] pArgs)
+ throws Throwable {
+ if
(Object.class.equals(pMethod.getDeclaringClass())) {
+ return pMethod.invoke(pProxy, pArgs);
+ }
+ Object result = pMethod.invoke(pFactory, pArgs);
+ if ("newXMLReader".equals(pMethod.getName())
&& result instanceof XMLReader) {
+ XMLReader xr = (XMLReader) result;
+ xr.setEntityResolver(pResolver);
+ }
+ return result;
+ }
+ };
+ Class[] classes;
+ if (pFactory instanceof JAXBXsObjectFactory) {
+ classes = new Class[]{JAXBXsObjectFactory.class};
+ } else {
+ classes = new Class[]{XsObjectFactory.class};
+ }
+ return (XsObjectFactory)
Proxy.newProxyInstance(getClass().getClassLoader(), classes, h);
+ }
+
+ private void testRecursiveXsInclude(XSParser pParser) throws Exception {
+ final String a = "<xs:schema
xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n"
+ + " <xs:include schemaLocation='b.xsd'/>\n"
+ + "</xs:schema>\n";
+ final String b = "<xs:schema
xmlns:xs='http://www.w3.org/2001/XMLSchema'>\n"
+ + " <xs:include schemaLocation='a.xsd'/>\n"
+ + "</xs:schema>\n";
+ final EntityResolver resolver = new EntityResolver(){
+ public InputSource resolveEntity(String pPublicId,
String pSystemId) throws SAXException, IOException {
+ final String xml;
+ if ("a.xsd".equals(pSystemId)) {
+ xml = a;
+ } else if ("b.xsd".equals(pSystemId)) {
+ xml = b;
+ } else {
+ return null;
+ }
+ InputSource isource = new InputSource(new
StringReader(xml));
+ isource.setSystemId(pSystemId);
+ return isource;
+ }
+ };
+
pParser.getContext().setXsObjectFactory(getXsObjectFactoryProxy(pParser.getContext().getXsObjectFactory(),
resolver));
+ InputSource isource = new InputSource(new StringReader(a));
+ isource.setSystemId("a.xsd");
+ XSSchema schema = pParser.parse(isource);
+ assertEquals(0, schema.getElements().length);
+ assertEquals(0, schema.getTypes().length);
+ }
+
+ /** Tests, whether schemas can include each other recursively.
+ */
+ public void testRecursiveXsInclude() throws Exception {
+ testRecursiveXsInclude(newXSParser());
+ testRecursiveXsInclude(newJAXBParser());
+ }
}
No revision
No revision
1.45.2.4 +4 -0 ws-jaxme/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/ws-jaxme/status.xml,v
retrieving revision 1.45.2.3
retrieving revision 1.45.2.4
diff -u -r1.45.2.3 -r1.45.2.4
--- status.xml 21 Apr 2005 08:03:13 -0000 1.45.2.3
+++ status.xml 25 Apr 2005 19:59:30 -0000 1.45.2.4
@@ -31,6 +31,10 @@
<changes>
<release version="0.4" date="Not yet published">
+ <action dev="JW" type="fix" context="xs">
+ Fixed that recursive xs:include caused an endless loop.
+ (Daniel Barclay, daniel at fgm.com)
+ </action>
<action dev="NM" type="fix" context="js">
Fixed primitive array generation in IndentationEngineImpl
that raised a ClassCastException.
No revision
No revision
1.20.2.1 +18 -7
ws-jaxme/src/xs/org/apache/ws/jaxme/xs/impl/XSLogicalParser.java
Index: XSLogicalParser.java
===================================================================
RCS file:
/home/cvs/ws-jaxme/src/xs/org/apache/ws/jaxme/xs/impl/XSLogicalParser.java,v
retrieving revision 1.20
retrieving revision 1.20.2.1
diff -u -r1.20 -r1.20.2.1
--- XSLogicalParser.java 27 Aug 2004 01:02:42 -0000 1.20
+++ XSLogicalParser.java 25 Apr 2005 19:59:30 -0000 1.20.2.1
@@ -141,6 +141,7 @@
private XsESchema[] syntaxSchemaArray;
private XSSchema schema;
private Set importedSchemas;
+ private Set includedSchemas;
private List addedImports = new ArrayList();
protected XSContext getData() {
@@ -390,6 +391,15 @@
throw new LocSAXException("Invalid include: Missing 'schemaLocation'
attribute.",
pInclude.getLocator());
}
+ if (includedSchemas == null) {
+ includedSchemas = new HashSet();
+ } else {
+ if (includedSchemas.contains(schemaLocation)) {
+ // Already imported, do not import again
+ return;
+ }
+ }
+ includedSchemas.add(schemaLocation);
Locator locator = pInclude.getLocator();
XsESchema includedSchema = parseSyntax(locator,
schemaLocation.toString());
XsAnyURI incNamespace = includedSchema.getTargetNamespace();
@@ -470,13 +480,14 @@
}
checkValidImportSchema(pImportingSchema, pNamespace, pLocator);
- if (importedSchemas != null &&
importedSchemas.contains(pSchemaLocation)) {
- // Already imported, do not import again
- return;
- }
- if (importedSchemas == null) {
- importedSchemas = new HashSet();
- }
+ if (importedSchemas == null) {
+ importedSchemas = new HashSet();
+ } else {
+ if (importedSchemas.contains(pSchemaLocation)) {
+ // Already imported, do not import again
+ return;
+ }
+ }
importedSchemas.add(pSchemaLocation);
XsESchema importedSchema = parseSyntax(pLocator, pSchemaLocation);
importSchema(pImportingSchema, pNamespace, importedSchema, pLocator);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]