You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2007/05/03 21:22:30 UTC

svn commit: r534966 - /webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java

Author: dims
Date: Thu May  3 12:22:29 2007
New Revision: 534966

URL: http://svn.apache.org/viewvc?view=rev&rev=534966
Log:
resolve imports better by setting the EntityResolver

Modified:
    webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java

Modified: webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java?view=diff&rev=534966&r1=534965&r2=534966
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java (original)
+++ webservices/axis2/trunk/java/modules/jaxbri/src/org/apache/axis2/jaxbri/CodeGenerationUtility.java Thu May  3 12:22:29 2007
@@ -35,16 +35,20 @@
 import org.w3c.dom.Element;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXParseException;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.SAXException;
 
 import javax.xml.namespace.QName;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.StringReader;
+import java.io.IOException;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
+import java.util.ArrayList;
 
 public class CodeGenerationUtility {
     private static final Log log = LogFactory.getLog(CodeGenerationUtility.class);
@@ -53,7 +57,7 @@
      * @param additionalSchemas
      * @throws RuntimeException
      */
-    public static TypeMapper processSchemas(List schemas,
+    public static TypeMapper processSchemas(final List schemas,
                                             Element[] additionalSchemas,
                                             CodeGenConfiguration cgconfig)
             throws RuntimeException {
@@ -67,12 +71,12 @@
                 return new DefaultTypeMapper();
             }
 
-            Vector xmlObjectsVector = new Vector();
+            final ArrayList xmlObjectsVector = new ArrayList();
 
             //create the type mapper
             JavaTypeMapper mapper = new JavaTypeMapper();
 
-            String baseURI = cgconfig.getBaseURI();
+            final String baseURI = cgconfig.getBaseURI();
 
             for (int i = 0; i < schemas.size(); i++) {
                 XmlSchema schema = (XmlSchema)schemas.get(i);
@@ -86,6 +90,20 @@
             outputDir.mkdir();
 
             Map nsMap = cgconfig.getUri2PackageNameMap();
+            EntityResolver resolver = new EntityResolver() {
+                public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+                    for (int i = 0; i < schemas.size(); i++) {
+                        XmlSchema schema = (XmlSchema) schemas.get(i);
+                        if(schema.getTargetNamespace().equals(publicId)){
+                            InputSource inputSource =
+                                    new InputSource(new StringReader(getSchemaAsString(schema)));
+                            inputSource.setSystemId(baseURI);
+                            return inputSource;
+                        }
+                    }
+                    return null;
+                }
+            };
 
             for (int i = 0; i < xmlObjectsVector.size(); i++) {
 
@@ -101,6 +119,8 @@
                 }
                 sc.setDefaultPackageName(pkg);
 
+                sc.setEntityResolver(resolver);
+
                 sc.setErrorListener(new ErrorListener(){
                     public void error(SAXParseException saxParseException) {
                         log.error(saxParseException.getMessage(), saxParseException);
@@ -118,7 +138,7 @@
                         log.info(saxParseException.getMessage(), saxParseException);
                     }
                 });
-                sc.parseSchema((InputSource)xmlObjectsVector.elementAt(i));
+                sc.parseSchema((InputSource)xmlObjectsVector.get(i));
 
                 // Bind the XML
                 S2JJAXBModel jaxbModel = sc.bind();



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org