geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment LoaderUtil.java LocalEntityResolver.java
Date Mon, 29 Sep 2003 19:34:10 GMT
ammulder    2003/09/29 12:34:10

  Modified:    modules/core maven.xml project.xml
               modules/core/src/java/org/apache/geronimo/xml/deployment
                        LoaderUtil.java LocalEntityResolver.java
  Log:
   - If a schema can't be resolved by its file path, try to load it from
     the classpath
   - Put the J2EE & Geronimo schemas on the classpath during testing, and
     put them into a JAR for runtime
  
  Revision  Changes    Path
  1.18      +7 -1      incubator-geronimo/modules/core/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/maven.xml,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- maven.xml	1 Sep 2003 20:38:48 -0000	1.17
  +++ maven.xml	29 Sep 2003 19:34:10 -0000	1.18
  @@ -41,6 +41,12 @@
                includes="org/apache/geronimo/rmi/RMIClassLoaderSpiImpl.class"/>
     </postGoal>
     
  +  <postGoal name="jar:jar">
  +    <ant:jar destfile="${basedir}/target/geronimo-schemas.jar"
  +             basedir="${basedir}/src/schema"
  +             includes="*.xsd"/>
  +  </postGoal>
  +  
     <!-- Set up the test files -->
     <postGoal name="test:test-resources">
       
  
  
  
  1.24      +17 -2     incubator-geronimo/modules/core/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/project.xml,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- project.xml	8 Sep 2003 04:55:00 -0000	1.23
  +++ project.xml	29 Sep 2003 19:34:10 -0000	1.24
  @@ -298,6 +298,21 @@
                   </includes>
               </resource>
           </resources>
  +        <unitTest>
  +            <includes>
  +                <include>**/*Test.java</include>
  +            </includes>
  +            <excludes>
  +                <exclude>**/Abstract*.java</exclude>
  +            </excludes>
  +            <resources>
  +                <resource>
  +                    <directory>${basedir}/src/schema</directory>
  +                    <includes>
  +                        <include>*.xsd</include>
  +                    </includes>
  +                </resource>
  +            </resources>
  +        </unitTest>
       </build>
  -
   </project>
  
  
  
  1.7       +2 -2      incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/LoaderUtil.java
  
  Index: LoaderUtil.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/LoaderUtil.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LoaderUtil.java	29 Sep 2003 14:00:56 -0000	1.6
  +++ LoaderUtil.java	29 Sep 2003 19:34:10 -0000	1.7
  @@ -189,7 +189,7 @@
           factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
           try {
               DocumentBuilder builder = factory.newDocumentBuilder();
  -            builder.setEntityResolver(new LocalEntityResolver(new File("modules/core/src/schema")));
// @todo get this from resource
  +            builder.setEntityResolver(new LocalEntityResolver());
               return builder.parse(new InputSource(new BufferedReader(reader)));
           } catch (ParserConfigurationException e) {
               throw new AssertionError("Unable to obtain suitable DocumentBuilder");
  
  
  
  1.4       +32 -9     incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/LocalEntityResolver.java
  
  Index: LocalEntityResolver.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/LocalEntityResolver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocalEntityResolver.java	29 Sep 2003 14:14:42 -0000	1.3
  +++ LocalEntityResolver.java	29 Sep 2003 19:34:10 -0000	1.4
  @@ -59,6 +59,7 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.IOException;
  +import java.io.InputStream;
   
   import org.xml.sax.EntityResolver;
   import org.xml.sax.InputSource;
  @@ -79,24 +80,46 @@
           this.root = root;
       }
   
  +    public LocalEntityResolver() {
  +        root = null;
  +    }
  +
       public InputSource resolveEntity(String publicId, String systemId) throws SAXException,
IOException {
           //todo: resolve the core XML Schema schemas locally so no network connection is
required
  -        if (log.isDebugEnabled()) {
  -            log.debug("Resolving entity S="+systemId+" P="+publicId);
  -        }
           if (publicId != null || systemId == null) {
  +            if (log.isDebugEnabled()) {
  +                log.debug("Not attempting to locally resolve entity S="+systemId+" P="+publicId);
  +            }
               return null;
           }
  +        String message = null;
  +        if(log.isDebugEnabled()) {
  +            message = "Resolving entity S="+systemId+" P="+publicId+": ";
  +        }
           int index = systemId.lastIndexOf("/");
           String fileName = systemId.substring(index+1);
  -        File file = new File(root, fileName);
  -        if (log.isDebugEnabled()) {
  -            log.debug("File "+file.getAbsolutePath()+" exists: "+file.exists());
  +        if(root != null) {
  +            File file = new File(root, fileName);
  +            if (file.exists()) {
  +                if (log.isDebugEnabled()) {
  +                    log.debug(message+"found file relative to "+root);
  +                }
  +                InputSource is = new InputSource(new BufferedInputStream(new FileInputStream(file)));
  +                is.setSystemId(systemId);
  +                return is;
  +            }
           }
  -        if (file.exists()) {
  -            InputSource is = new InputSource(new BufferedInputStream(new FileInputStream(file)));
  +        InputStream in = getClass().getClassLoader().getResourceAsStream(fileName);
  +        if(in != null) {
  +            if (log.isDebugEnabled()) {
  +                log.debug(message+"found file on classpath");
  +            }
  +            InputSource is = new InputSource(new BufferedInputStream(in));
               is.setSystemId(systemId);
               return is;
  +        }
  +        if (log.isDebugEnabled()) {
  +            log.debug(message+"not found");
           }
           return null;
       }
  
  
  

Mime
View raw message