Author: pete.muir(a)jboss.org
Date: 2009-03-19 10:34:12 -0400 (Thu, 19 Mar 2009)
New Revision: 2110
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockXmlEnvironment.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironment.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironmentImpl.java
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParserEnvironment.java
Modified:
ri/trunk/impl/pom.xml
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java
Log:
Wire in the new XML parser Deploy stuff
Modified: ri/trunk/impl/pom.xml
===================================================================
--- ri/trunk/impl/pom.xml 2009-03-19 13:24:44 UTC (rev 2109)
+++ ri/trunk/impl/pom.xml 2009-03-19 14:34:12 UTC (rev 2110)
@@ -87,6 +87,7 @@
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
+ <optional>true</optional>
</dependency>
<dependency>
<groupId>javax.el</groupId>
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-03-19
13:24:44 UTC (rev 2109)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-03-19
14:34:12 UTC (rev 2110)
@@ -55,6 +55,9 @@
import org.jboss.webbeans.servlet.HttpSessionManager;
import org.jboss.webbeans.servlet.ServletApiAbstraction;
import org.jboss.webbeans.transaction.spi.TransactionServices;
+import org.jboss.webbeans.util.xml.XmlParserImpl;
+import org.jboss.webbeans.xml.XmlEnvironment;
+import org.jboss.webbeans.xml.XmlEnvironmentImpl;
/**
* Common bootstrapping functionality that is run at application startup and
@@ -153,10 +156,11 @@
// bean is an EJB!
manager.getEjbDescriptorCache().addAll(getServices().get(EjbServices.class).discoverEjbs());
}
- BeansXmlParser parser = new
BeansXmlParser(getServices().get(ResourceLoader.class),
getServices().get(WebBeanDiscovery.class).discoverWebBeansXml());
+ XmlEnvironment xmlEnvironmentImpl = new XmlEnvironmentImpl(getServices());
+ XmlParserImpl parser = new XmlParserImpl(xmlEnvironmentImpl);
parser.parse();
- List<Class<? extends Annotation>> enabledDeploymentTypes =
parser.getEnabledDeploymentTypes();
- if (enabledDeploymentTypes != null)
+ List<Class<? extends Annotation>> enabledDeploymentTypes =
xmlEnvironmentImpl.getEnabledDeploymentTypes();
+ if (enabledDeploymentTypes.size() > 0)
{
manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
}
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockXmlEnvironment.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockXmlEnvironment.java
(rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockXmlEnvironment.java 2009-03-19
14:34:12 UTC (rev 2110)
@@ -0,0 +1,36 @@
+package org.jboss.webbeans.mock;
+
+import java.net.URL;
+
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
+import org.jboss.webbeans.bootstrap.api.helpers.SimpleServiceRegistry;
+import org.jboss.webbeans.resources.DefaultResourceLoader;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+import org.jboss.webbeans.xml.XmlEnvironmentImpl;
+
+public class MockXmlEnvironment extends XmlEnvironmentImpl
+{
+
+ private static final ServiceRegistry services;
+
+ static
+ {
+ services = new SimpleServiceRegistry();
+ services.add(ResourceLoader.class, new DefaultResourceLoader());
+ }
+
+ private final Iterable<URL> beansXmlUrls;
+
+ public MockXmlEnvironment(Iterable<URL> beansXmlUrls)
+ {
+ super(services);
+ this.beansXmlUrls = beansXmlUrls;
+ }
+
+ @Override
+ public Iterable<URL> getBeansXmlUrls()
+ {
+ return beansXmlUrls;
+ }
+
+}
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/mock/MockXmlEnvironment.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java 2009-03-19
13:24:44 UTC (rev 2109)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java 2009-03-19
14:34:12 UTC (rev 2110)
@@ -13,66 +13,72 @@
import javax.inject.DefinitionException;
import javax.inject.DeploymentException;
import javax.inject.DeploymentType;
-import javax.inject.Production;
-import javax.inject.Standard;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Namespace;
-import org.dom4j.QName;
import org.dom4j.io.SAXReader;
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.xml.XmlEnvironment;
-public class XmlParserImpl // implements XmlParser
+public class XmlParserImpl
{
private static Log log = Logging.getLog(XmlParserImpl.class);
+
+ private final XmlEnvironment environment;
+
+ public XmlParserImpl(XmlEnvironment environment)
+ {
+ this.environment = environment;
+ }
+
+ public void parse()
+ {
+ // TODO extremely inefficient, no need to make dom4j parse each beans.xml multiple
times, do as one parse over each document
+ parseForBeans();
+ parseForDeploy();
+ }
- public Set<AnnotatedItem<?, ?>> parseForBeans(Set<URL> xmls)
+ private void parseForBeans()
{
- Set<AnnotatedItem<?, ?>> result = new HashSet<AnnotatedItem<?,
?>>();
- for (URL url : xmls)
+ for (URL url : environment.getBeansXmlUrls())
{
- Document document = createDocument(url);
- List<Element> beanElements = findBeans(document);
- result.addAll(ParseXmlHelper.getBeanItems(beanElements));
+ Document document = createDocument(url);
+ if (document != null)
+ {
+ List<Element> beanElements = findBeans(document);
+ // TODO Only pass in classes here
+
//environment.getClasses().addAll(ParseXmlHelper.getBeanItems(beanElements));
+ }
}
- return result;
+
}
- public void parseForDeploy(Set<URL> xmls)
+ private void parseForDeploy()
{
- List<Class<? extends Annotation>> deploymentClasses = new
ArrayList<Class<? extends Annotation>>();
int counter = 0;
- for (URL url : xmls)
+ for (URL url : environment.getBeansXmlUrls())
{
Document document = createDocument(url);
- Element root = document.getRootElement();
-
- Iterator<?> elIterator = root.elementIterator();
- while (elIterator.hasNext())
+ if (document != null)
{
- Element element = (Element) elIterator.next();
- if (ParseXmlHelper.isJavaEeNamespace(element) &&
- element.getName().equalsIgnoreCase(XmlConstants.DEPLOY))
- deploymentClasses.addAll(obtainDeploymentTypes(element, counter++));
- }
+ Element root = document.getRootElement();
+
+ Iterator<?> elIterator = root.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element element = (Element) elIterator.next();
+ if (ParseXmlHelper.isJavaEeNamespace(element) &&
+ element.getName().equalsIgnoreCase(XmlConstants.DEPLOY))
+
environment.getEnabledDeploymentTypes().addAll(obtainDeploymentTypes(element,
counter++));
+ }
+ }
}
- if(deploymentClasses.size() == 0)
- {
- deploymentClasses.add(Standard.class);
- deploymentClasses.add(Production.class);
- }
-
- ManagerImpl manager = CurrentManager.rootManager();
- manager.setEnabledDeploymentTypes(deploymentClasses);
}
@SuppressWarnings("unchecked")
@@ -92,6 +98,10 @@
InputStream xmlStream;
xmlStream = url.openStream();
+ if (xmlStream.available() == 0)
+ {
+ return null;
+ }
SAXReader reader = new SAXReader();
Document document = reader.read(xmlStream);
checkNamespaces(document);
@@ -169,10 +179,6 @@
String standardPrefix = "";
String standardUri = XmlConstants.JAVA_EE_NAMESPACE;
Namespace standardNamespace = new Namespace(standardPrefix, standardUri);
- QName qName = new QName(standardName, standardNamespace);
- Element standardElement = element.element(qName);
- if (standardElement == null)
- throw new DeploymentException("The @Standard deployment type must be
declared");
List<Class<? extends Annotation>> deploymentClasses = new
ArrayList<Class<? extends Annotation>>();
List<Element> children = element.elements();
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironment.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironment.java
(rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironment.java 2009-03-19
14:34:12 UTC (rev 2110)
@@ -0,0 +1,25 @@
+package org.jboss.webbeans.xml;
+
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.List;
+
+import org.jboss.webbeans.introspector.AnnotatedAnnotation;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+
+public interface XmlEnvironment
+{
+
+ public List<AnnotatedClass<?>> getClasses();
+
+ public List<AnnotatedAnnotation<?>> getAnnotations();
+
+ public Iterable<URL> getBeansXmlUrls();
+
+ public <T> AnnotatedClass<? extends T> loadClass(String className,
Class<T> expectedType);
+
+ public <T extends Annotation> AnnotatedAnnotation<? extends T>
loadAnnotation(String className, Class<T> expectedType);
+
+ public List<Class<? extends Annotation>> getEnabledDeploymentTypes();
+
+}
\ No newline at end of file
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironment.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironmentImpl.java (from
rev 2108, ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParserEnvironment.java)
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironmentImpl.java
(rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironmentImpl.java 2009-03-19
14:34:12 UTC (rev 2110)
@@ -0,0 +1,64 @@
+package org.jboss.webbeans.xml;
+
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
+import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.introspector.AnnotatedAnnotation;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.introspector.jlr.AnnotatedAnnotationImpl;
+import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
+
+public class XmlEnvironmentImpl implements XmlEnvironment
+{
+
+ private final List<AnnotatedClass<?>> classes;
+ private final List<AnnotatedAnnotation<?>> annotations;
+ private final ServiceRegistry serviceRegistry;
+ private final List<Class<? extends Annotation>> enabledDeploymentTypes;
+ private final Iterable<URL> beansXmlUrls;
+
+ public XmlEnvironmentImpl(ServiceRegistry serviceRegistry)
+ {
+ this.classes = new ArrayList<AnnotatedClass<?>>();
+ this.annotations = new ArrayList<AnnotatedAnnotation<?>>();
+ this.enabledDeploymentTypes = new ArrayList<Class<? extends
Annotation>>();
+ this.serviceRegistry = serviceRegistry;
+ this.beansXmlUrls =
serviceRegistry.get(WebBeanDiscovery.class).discoverWebBeansXml();
+ }
+
+ public List<AnnotatedClass<?>> getClasses()
+ {
+ return classes;
+ }
+
+ public List<AnnotatedAnnotation<?>> getAnnotations()
+ {
+ return annotations;
+ }
+
+ public Iterable<URL> getBeansXmlUrls()
+ {
+ return beansXmlUrls;
+ }
+
+ public <T> AnnotatedClass<? extends T> loadClass(String className,
Class<T> expectedType)
+ {
+ return
AnnotatedClassImpl.of(serviceRegistry.get(ResourceLoader.class).classForName(className).asSubclass(expectedType));
+ }
+
+ public <T extends Annotation> AnnotatedAnnotation<? extends T>
loadAnnotation(String className, Class<T> expectedType)
+ {
+ return
AnnotatedAnnotationImpl.of(serviceRegistry.get(ResourceLoader.class).classForName(className).asSubclass(expectedType));
+ }
+
+ public List<Class<? extends Annotation>> getEnabledDeploymentTypes()
+ {
+ return enabledDeploymentTypes;
+ }
+
+}
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironmentImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParserEnvironment.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParserEnvironment.java 2009-03-19
13:24:44 UTC (rev 2109)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParserEnvironment.java 2009-03-19
14:34:12 UTC (rev 2110)
@@ -1,62 +0,0 @@
-package org.jboss.webbeans.xml;
-
-import java.lang.annotation.Annotation;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.webbeans.introspector.AnnotatedAnnotation;
-import org.jboss.webbeans.introspector.AnnotatedClass;
-import org.jboss.webbeans.introspector.jlr.AnnotatedAnnotationImpl;
-import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
-import org.jboss.webbeans.resources.spi.ResourceLoader;
-
-public class XmlParserEnvironment
-{
-
- private final List<AnnotatedClass<?>> classes;
- private final List<AnnotatedAnnotation<?>> annotations;
- private final Iterable<URL> webBeansXml;
- private final List<AnnotatedAnnotation<?>> enabledDeploymentTypes;
- private final ResourceLoader resourceLoader;
-
- public XmlParserEnvironment(ResourceLoader resourceLoader, Iterable<URL>
webBeansXml)
- {
- this.classes = new ArrayList<AnnotatedClass<?>>();
- this.annotations = new ArrayList<AnnotatedAnnotation<?>>();
- this.enabledDeploymentTypes = new ArrayList<AnnotatedAnnotation<?>>();
- this.webBeansXml = webBeansXml;
- this.resourceLoader = resourceLoader;
- }
-
- public Iterable<URL> getWebBeansXml()
- {
- return webBeansXml;
- }
-
- public List<AnnotatedClass<?>> getClasses()
- {
- return classes;
- }
-
- public List<AnnotatedAnnotation<?>> getAnnotations()
- {
- return annotations;
- }
-
- public <T> AnnotatedClass<? extends T> loadClass(String className,
Class<T> expectedType)
- {
- return
AnnotatedClassImpl.of(resourceLoader.classForName(className).asSubclass(expectedType));
- }
-
- public <T extends Annotation> AnnotatedAnnotation<? extends T>
loadAnnotation(String className, Class<T> expectedType)
- {
- return
AnnotatedAnnotationImpl.of(resourceLoader.classForName(className).asSubclass(expectedType));
- }
-
- public List<AnnotatedAnnotation<?>> getEnabledDeploymentTypes()
- {
- return enabledDeploymentTypes;
- }
-
-}
Modified:
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java
===================================================================
---
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java 2009-03-19
13:24:44 UTC (rev 2109)
+++
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java 2009-03-19
14:34:12 UTC (rev 2110)
@@ -28,7 +28,7 @@
* @author Pete Muir
*
*/
-class SimpleServiceRegistry implements ServiceRegistry
+public class SimpleServiceRegistry implements ServiceRegistry
{
private final Map<Class<? extends Service>, Service> services;
Modified:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java 2009-03-19
13:24:44 UTC (rev 2109)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java 2009-03-19
14:34:12 UTC (rev 2110)
@@ -10,11 +10,11 @@
import org.jboss.testharness.impl.packaging.Resources;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedItem;
-import org.jboss.webbeans.resources.DefaultResourceLoader;
+import org.jboss.webbeans.mock.MockXmlEnvironment;
import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
import org.jboss.webbeans.test.unit.xml.beans.Order;
import org.jboss.webbeans.util.xml.XmlParserImpl;
-import org.jboss.webbeans.xml.XmlParserEnvironment;
+import org.jboss.webbeans.xml.XmlEnvironmentImpl;
import org.testng.annotations.Test;
@Artifact
@@ -27,7 +27,7 @@
@Test
public void testParse()
{
- XmlParserEnvironment parserEnv = new XmlParserEnvironment(new
DefaultResourceLoader(), getResources("beans.xml"));
+ XmlEnvironmentImpl parserEnv = new
MockXmlEnvironment(getResources("beans.xml"));
AnnotatedClass<?> aClass =
parserEnv.loadClass("org.jboss.webbeans.test.unit.xml.beans.Order",
Order.class);
Set<URL> xmls = new HashSet<URL>();
@@ -36,15 +36,15 @@
for (URL url : urls)
xmls.add(url);
- XmlParserImpl parser = new XmlParserImpl();
- Set<AnnotatedItem<?, ?>> aSet = parser.parseForBeans(xmls);
+ XmlParserImpl parser = new XmlParserImpl(parserEnv);
+ parser.parse();
- for (AnnotatedItem<?, ?> aElement : aSet)
+ for (AnnotatedItem<?, ?> aElement : parserEnv.getClasses())
{
assert aElement.equals(aClass);
}
- assert aSet.size() == 1;
+ assert parserEnv.getClasses().size() == 1;
}
}