jochen      2005/04/25 12:59:19

  Modified:    .        status.xml
               src/xs/org/apache/ws/jaxme/xs/junit ParserTest.java
               src/xs/org/apache/ws/jaxme/xs/impl XSLogicalParser.java
  Log:
  Fixed that recursive xs:include caused an endless loop. (Daniel Barclay, 
daniel at fgm.com)
  
  Revision  Changes    Path
  1.50      +4 -0      ws-jaxme/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/status.xml,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- status.xml        24 Apr 2005 20:16:48 -0000      1.49
  +++ status.xml        25 Apr 2005 19:59:19 -0000      1.50
  @@ -36,6 +36,10 @@
          </action>
        </release>
       <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.
  
  
  
  1.22      +77 -15    
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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ParserTest.java   24 Apr 2005 20:16:48 -0000      1.21
  +++ ParserTest.java   25 Apr 2005 19:59:19 -0000      1.22
  @@ -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;
  @@ -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 {
  @@ -1455,4 +1455,66 @@
        testMailTemplateMixed(newXSParser());
           testMailTemplateMixed(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());
  +     }
   }
  
  
  
  1.21      +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.21
  diff -u -r1.20 -r1.21
  --- XSLogicalParser.java      27 Aug 2004 01:02:42 -0000      1.20
  +++ XSLogicalParser.java      25 Apr 2005 19:59:19 -0000      1.21
  @@ -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]

Reply via email to