[seam-commits] Seam SVN: r12787 - in modules/xml/trunk/impl/src: main/resources/META-INF/services and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon May 24 18:19:29 EDT 2010
Author: swd847
Date: 2010-05-24 18:19:28 -0400 (Mon, 24 May 2010)
New Revision: 12787
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ResourceLoaderXmlDocumentProvider.java
Removed:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java
Modified:
modules/xml/trunk/impl/src/main/resources/META-INF/services/org.jboss.seam.xml.XmlExtension
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/TestXmlProvider.java
Log:
changed seam-xml to use WELDX resource loaders for SEAMXML-3
Deleted: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java 2010-05-24 21:47:00 UTC (rev 12786)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java 2010-05-24 22:19:28 UTC (rev 12787)
@@ -1,174 +0,0 @@
-/*
- * Distributed under the LGPL License
- *
- */
-package org.jboss.seam.xml.bootstrap;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.ListIterator;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.xml.sax.InputSource;
-
-/**
- * Document Provider that loads XML documents from the classpath
- *
- * @author Stuart Douglas <stuart at baileyroberts.com.au>
- *
- */
-public class ClassPathXmlDocumentProvider implements XmlDocumentProvider
-{
-
- static final String[] DEFAULT_RESOURCES = { "seam-beans.xml", "META-INF/seam-beans.xml", "META-INF/beans.xml"};
-
- final String[] resources;
-
- InputStream stream;
-
- public ClassPathXmlDocumentProvider()
- {
- resources = DEFAULT_RESOURCES;
- }
-
- public ClassPathXmlDocumentProvider(String[] resources)
- {
- this.resources = resources;
- }
-
- List<URL> docs;
-
- ListIterator<URL> iterator;
-
- DocumentBuilderFactory factory;
- DocumentBuilder builder;
-
- public void open()
- {
- factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- factory.setIgnoringComments(true);
- factory.setIgnoringElementContentWhitespace(true);
- try
- {
- builder = factory.newDocumentBuilder();
- }
- catch (ParserConfigurationException e1)
- {
- throw new RuntimeException(e1);
- }
- docs = new ArrayList<URL>();
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl == null)
- {
- cl = getClass().getClassLoader();
- }
- for (String i : resources)
- {
- try
- {
- Enumeration<URL> e = cl.getResources(i);
- while (e.hasMoreElements())
- {
- docs.add(e.nextElement());
- }
- iterator = docs.listIterator();
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- }
- }
-
- public void close()
- {
- if (stream != null)
- {
- try
- {
- stream.close();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
-
- public XmlDocument getNextDocument()
- {
- if (stream != null)
- {
- try
- {
- stream.close();
- stream = null;
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- try
- {
- while(iterator.hasNext())
- {
- final URL url = iterator.next();
- //ignore empty files
- InputStream test = null;
- try
- {
- test = url.openStream();
- if(test.available() == 0)
- {
- continue;
- }
- }
- finally
- {
- if(test != null)
- {
- test.close();
- }
- }
-
- return new XmlDocument()
- {
-
- public InputSource getInputSource()
- {
- try
- {
- stream = url.openStream();
- return new InputSource(stream);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- public String getFileUrl()
- {
- return url.toString();
- }
- };
- }
- return null;
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
-}
Copied: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ResourceLoaderXmlDocumentProvider.java (from rev 12784, modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java)
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ResourceLoaderXmlDocumentProvider.java (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ResourceLoaderXmlDocumentProvider.java 2010-05-24 22:19:28 UTC (rev 12787)
@@ -0,0 +1,180 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.bootstrap;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.weld.extensions.resourceLoader.ResourceLoader;
+import org.jboss.weld.extensions.util.service.ServiceLoader;
+import org.xml.sax.InputSource;
+
+/**
+ * Document Provider that loads XML documents from the classpath
+ *
+ * @author Stuart Douglas <stuart at baileyroberts.com.au>
+ *
+ */
+public class ResourceLoaderXmlDocumentProvider implements XmlDocumentProvider
+{
+
+ private final List<ResourceLoader> resourceLoaders;
+
+ static final String[] DEFAULT_RESOURCES = { "seam-beans.xml", "META-INF/seam-beans.xml", "META-INF/beans.xml" };
+
+ final String[] resources;
+
+ InputStream stream;
+
+ public ResourceLoaderXmlDocumentProvider()
+ {
+ this(DEFAULT_RESOURCES);
+ }
+
+ public ResourceLoaderXmlDocumentProvider(String[] resources)
+ {
+ this.resources = resources;
+ resourceLoaders = new ArrayList<ResourceLoader>();
+ for (ResourceLoader resourceLoader : ServiceLoader.load(ResourceLoader.class))
+ {
+ resourceLoaders.add(resourceLoader);
+ }
+ }
+
+ List<URL> docs;
+
+ ListIterator<URL> iterator;
+
+ DocumentBuilderFactory factory;
+ DocumentBuilder builder;
+
+ public void open()
+ {
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setIgnoringComments(true);
+ factory.setIgnoringElementContentWhitespace(true);
+ try
+ {
+ builder = factory.newDocumentBuilder();
+ }
+ catch (ParserConfigurationException e1)
+ {
+ throw new RuntimeException(e1);
+ }
+ docs = new ArrayList<URL>();
+
+ for (String i : resources)
+ {
+ Set<URL> e = getResources(i);
+ docs.addAll(e);
+ iterator = docs.listIterator();
+ }
+ }
+
+ protected Set<URL> getResources(String resource)
+ {
+ Set<URL> ret = new HashSet<URL>();
+ for (ResourceLoader r : resourceLoaders)
+ {
+ ret.addAll(r.getResources(resource));
+ }
+ return ret;
+ }
+
+ public void close()
+ {
+ if (stream != null)
+ {
+ try
+ {
+ stream.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public XmlDocument getNextDocument()
+ {
+ if (stream != null)
+ {
+ try
+ {
+ stream.close();
+ stream = null;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ try
+ {
+ while (iterator.hasNext())
+ {
+ final URL url = iterator.next();
+ // ignore empty files
+ InputStream test = null;
+ try
+ {
+ test = url.openStream();
+ if (test.available() == 0)
+ {
+ continue;
+ }
+ }
+ finally
+ {
+ if (test != null)
+ {
+ test.close();
+ }
+ }
+
+ return new XmlDocument()
+ {
+
+ public InputSource getInputSource()
+ {
+ try
+ {
+ stream = url.openStream();
+ return new InputSource(stream);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public String getFileUrl()
+ {
+ return url.toString();
+ }
+ };
+ }
+ return null;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Modified: modules/xml/trunk/impl/src/main/resources/META-INF/services/org.jboss.seam.xml.XmlExtension
===================================================================
--- modules/xml/trunk/impl/src/main/resources/META-INF/services/org.jboss.seam.xml.XmlExtension 2010-05-24 21:47:00 UTC (rev 12786)
+++ modules/xml/trunk/impl/src/main/resources/META-INF/services/org.jboss.seam.xml.XmlExtension 2010-05-24 22:19:28 UTC (rev 12787)
@@ -1 +1 @@
-org.jboss.seam.xml.bootstrap.ClassPathXmlDocumentProvider
\ No newline at end of file
+org.jboss.seam.xml.bootstrap.ResourceLoaderXmlDocumentProvider
\ No newline at end of file
Modified: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/TestXmlProvider.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/TestXmlProvider.java 2010-05-24 21:47:00 UTC (rev 12786)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/TestXmlProvider.java 2010-05-24 22:19:28 UTC (rev 12787)
@@ -4,7 +4,7 @@
*/
package org.jboss.seam.xml.test;
-import org.jboss.seam.xml.bootstrap.ClassPathXmlDocumentProvider;
+import org.jboss.seam.xml.bootstrap.ResourceLoaderXmlDocumentProvider;
import org.jboss.seam.xml.bootstrap.XmlDocument;
import org.jboss.seam.xml.bootstrap.XmlDocumentProvider;
@@ -13,7 +13,7 @@
public static String fileName;
- ClassPathXmlDocumentProvider docProvider;
+ ResourceLoaderXmlDocumentProvider docProvider;
public void close()
{
@@ -29,7 +29,7 @@
{
String[] r = new String[1];
r[0] = fileName;
- docProvider = new ClassPathXmlDocumentProvider(r);
+ docProvider = new ResourceLoaderXmlDocumentProvider(r);
docProvider.open();
}
More information about the seam-commits
mailing list