Author: pete.muir(a)jboss.org
Date: 2009-03-16 10:56:06 -0400 (Mon, 16 Mar 2009)
New Revision: 2044
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/ClassReceiver.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/ParseXmlHelper.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlConstants.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParserEnvironment.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/XmlParserImplTest.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/beans/
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/beans/Order.java
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xsd/
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/ejb/interceptor/
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedClass.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
ri/trunk/impl/src/test/resources/org/jboss/webbeans/test/unit/xml/user-defined-beans.xml
Log:
Add victor's changes to trunk, add XmlParserEnvironment, start work on support for
loading methods, construtors and fields
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-16
14:50:01 UTC (rev 2043)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -17,9 +17,7 @@
package org.jboss.webbeans.bean;
-import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import javax.annotation.PostConstruct;
@@ -63,8 +61,7 @@
{
// Logger
private static LogProvider log = Logging.getLogProvider(SimpleBean.class);
- // Empty list representing no-args
- private static List<Class<?>> NO_ARGUMENTS = Collections.emptyList();
+
// The constructor
private ConstructorInjectionPoint<T> constructor;
// The post-construct method
@@ -398,10 +395,10 @@
return;
}
- if (getAnnotatedItem().getConstructor(NO_ARGUMENTS) != null)
+ if (getAnnotatedItem().getNoArgsConstructor() != null)
{
- this.constructor = ConstructorInjectionPoint.of(this,
getAnnotatedItem().getConstructor(NO_ARGUMENTS));
+ this.constructor = ConstructorInjectionPoint.of(this,
getAnnotatedItem().getNoArgsConstructor());
log.trace("Exactly one constructor (" + constructor + ") defined,
using it as the bean constructor for " + getType());
return;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-03-16
14:50:01 UTC (rev 2043)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -2,7 +2,9 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.event.Fires;
@@ -44,6 +46,9 @@
public class BeanDeployer
{
+ // Empty list representing no-args
+ private static List<Class<?>> NO_ARGUMENTS = Collections.emptyList();
+
private static final LogProvider log = Logging.getLogProvider(BeanDeployer.class);
private final Set<RIBean<?>> beans;
@@ -272,7 +277,7 @@
private static boolean hasSimpleWebBeanConstructor(AnnotatedClass<?> type)
{
- return type.getConstructor() != null ||
type.getAnnotatedConstructors(Initializer.class).size() > 0;
+ return type.getNoArgsConstructor() != null ||
type.getAnnotatedConstructors(Initializer.class).size() > 0;
}
private static <T> AnnotatedMethod<T> realizeProducerMethod(final
AnnotatedMethod<T> method, final AnnotatedClass<?> realizingClass)
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java 2009-03-16
14:50:01 UTC (rev 2043)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -43,4 +43,12 @@
*/
public Set<AnnotatedMethod<?>> getAnnotatedMembers(Class<? extends
Annotation> annotationType);
+ /**
+ * Get an annotation member by name
+ *
+ * @param memberName
+ * @return
+ */
+ public <A> AnnotatedMethod<A> getMember(String memberName,
AnnotatedClass<A> expectedType);
+
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java 2009-03-16
14:50:01 UTC (rev 2043)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -37,6 +37,16 @@
* @return A set of abstracted fields
*/
public Set<AnnotatedField<?>> getFields();
+
+ /**
+ * Get a field by name
+ *
+ * @param <F> the expected type of the field
+ * @param fieldName the field name
+ * @param expectedType the expected type of the field
+ * @return the field
+ */
+ public <F> AnnotatedField<F> getDeclaredField(String fieldName,
AnnotatedClass<F> expectedType);
/**
* Gets all fields which are annotated with the given annotation type on this
@@ -84,15 +94,19 @@
public Set<AnnotatedConstructor<T>> getConstructors();
/**
- * Gets the constructor with arguments given
+ * Gets the no-args constructor
*
- * @param arguments The list of arguments to match
- * @return A set of abstracted constructors with the given arguments. Returns
- * an empty set if there are no matches
+ * @return The no-args constructor, or null if not defined
*/
- public AnnotatedConstructor<T> getConstructor(List<Class<?>>
arguments);
+ public AnnotatedConstructor<T> getNoArgsConstructor();
- public AnnotatedConstructor<T> getConstructor(Class<?>... arguments);
+ /**
+ * Get the constructor which matches the argument list provided
+ *
+ * @param parameterTypes the parameters of the constructor
+ * @return the matching constructor, or null if not defined
+ */
+ public AnnotatedConstructor<T>
getDeclaredConstructor(List<AnnotatedClass<?>> parameterTypes);
/**
* Gets all methods annotated with annotationType
@@ -117,9 +131,25 @@
*
* @param methodDescriptor
* @return
+ *
+ * TODO Replace with AnnotatedMethod variant
*/
+ @Deprecated
public AnnotatedMethod<?> getMethod(Method method);
+ /**
+ * Get a method by name
+ *
+ * @param <M> the expected return type
+ * @param methodName the name of the method
+ * @param expectedReturnType the expected return type
+ * @param parameterTypes the parameter types of the method
+ * @return the method, or null if it doesn't exist
+ */
+ public <M> AnnotatedMethod<M> getDeclaredMethod(String methodName,
AnnotatedClass<M> expectedReturnType, AnnotatedClass<?>... parameterTypes);
+
+ // TODO Replace with AnnotatedMethod variant
+ @Deprecated
public AnnotatedMethod<?> getDeclaredMethod(Method method);
/**
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedClass.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedClass.java 2009-03-16
14:50:01 UTC (rev 2043)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedClass.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -41,15 +41,10 @@
return delegate().getAnnotatedMethods(annotationType);
}
- public AnnotatedConstructor<T> getConstructor(List<Class<?>>
arguments)
+ public AnnotatedConstructor<T> getNoArgsConstructor()
{
- return delegate().getConstructor(arguments);
+ return delegate().getNoArgsConstructor();
}
-
- public AnnotatedConstructor<T> getConstructor(Class<?>... arguments)
- {
- return delegate().getConstructor(arguments);
- }
public Set<AnnotatedConstructor<T>> getConstructors()
{
@@ -81,6 +76,7 @@
return delegate().getMetaAnnotatedFields(metaAnnotationType);
}
+ @Deprecated
public AnnotatedMethod<?> getMethod(Method method)
{
return delegate().getMethod(method);
@@ -111,9 +107,25 @@
return delegate().isAbstract();
}
+ @Deprecated
public AnnotatedMethod<?> getDeclaredMethod(Method method)
{
return delegate().getDeclaredMethod(method);
}
+ public <F> AnnotatedField<F> getDeclaredField(String fieldName,
AnnotatedClass<F> expectedType)
+ {
+ return delegate().getDeclaredField(fieldName, expectedType);
+ }
+
+ public <M> AnnotatedMethod<M> getDeclaredMethod(String methodName,
AnnotatedClass<M> expectedReturnType, AnnotatedClass<?>... parameterTypes)
+ {
+ return delegate().getDeclaredMethod(methodName, expectedReturnType,
parameterTypes);
+ }
+
+ public AnnotatedConstructor<T>
getDeclaredConstructor(List<AnnotatedClass<?>> parameterTypes)
+ {
+ return delegate().getDeclaredConstructor(parameterTypes);
+ }
+
}
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java 2009-03-16
14:50:01 UTC (rev 2043)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedAnnotationImpl.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -26,6 +26,7 @@
import java.util.Set;
import org.jboss.webbeans.introspector.AnnotatedAnnotation;
+import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.AnnotationStore;
import org.jboss.webbeans.util.Strings;
@@ -92,6 +93,8 @@
private final Class<T> clazz;
// The set of abstracted members
private final Set<AnnotatedMethod<?>> members;
+
+ private final Map<String, AnnotatedMethod<?>> namedMembers;
// Cached string representation
private String toString;
@@ -114,6 +117,7 @@
this.clazz = annotationType;
members = new HashSet<AnnotatedMethod<?>>();
annotatedMembers = new AnnotatedMemberMap();
+ this.namedMembers = new HashMap<String, AnnotatedMethod<?>>();
for (Method member : clazz.getDeclaredMethods())
{
AnnotatedMethod<?> annotatedMethod = AnnotatedMethodImpl.of(member,
this);
@@ -122,6 +126,7 @@
{
annotatedMembers.put(annotation.annotationType(), annotatedMethod);
}
+ namedMembers.put(annotatedMethod.getName(), annotatedMethod);
}
}
@@ -155,6 +160,11 @@
return Collections.unmodifiableSet(annotatedMembers.get(annotationType));
}
+ public <A> AnnotatedMethod<A> getMember(String memberName,
AnnotatedClass<A> expectedType)
+ {
+ return (AnnotatedMethod<A>) namedMembers.get(memberName);
+ }
+
/**
* Gets a string representation of the annotation
*
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java 2009-03-16
14:50:01 UTC (rev 2043)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -52,6 +52,8 @@
public class AnnotatedClassImpl<T> extends AbstractAnnotatedType<T>
implements AnnotatedClass<T>
{
+ private static List<Class<?>> NO_ARGUMENTS = Collections.emptyList();
+
/**
* A (annotation type -> set of field abstractions with annotation/meta
* annotation) map
@@ -409,6 +411,11 @@
return Collections.unmodifiableSet(declaredFields);
}
+ public <F> AnnotatedField<F> getDeclaredField(String fieldName,
AnnotatedClass<F> expectedType)
+ {
+ throw new UnsupportedOperationException();
+ }
+
public Set<AnnotatedField<?>> getDeclaredAnnotatedFields(Class<?
extends Annotation> annotationType)
{
return Collections.unmodifiableSet(declaredAnnotatedFields.get(annotationType));
@@ -426,6 +433,11 @@
return Collections.unmodifiableSet(constructors);
}
+ public AnnotatedConstructor<T>
getDeclaredConstructor(List<AnnotatedClass<?>> parameterTypes)
+ {
+ throw new UnsupportedOperationException();
+ }
+
/**
* Gets abstracted fields with requested meta-annotation type present
*
@@ -507,26 +519,11 @@
return Collections.unmodifiableSet(annotatedConstructors.get(annotationType));
}
- /**
- * Gets a constructor with given arguments
- *
- * @param arguments
- * The arguments to match
- * @return A constructor which takes given arguments. Null is returned if
- * there are no matches.
- *
- * @see org.jboss.webbeans.introspector.AnnotatedClass#getConstructor(List)
- */
- public AnnotatedConstructor<T> getConstructor(List<Class<?>>
arguments)
+ public AnnotatedConstructor<T> getNoArgsConstructor()
{
- return constructorsByArgumentMap.get(arguments);
+ return constructorsByArgumentMap.get(NO_ARGUMENTS);
}
- public AnnotatedConstructor<T> getConstructor(Class<?>... arguments)
- {
- return getConstructor(Arrays.asList(arguments));
- }
-
public Set<AnnotatedMethod<?>>
getMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
{
return
Collections.unmodifiableSet(methodsByAnnotatedParameters.get(annotationType));
@@ -563,6 +560,11 @@
return null;
}
+ public <M> AnnotatedMethod<M> getDeclaredMethod(String methodName,
AnnotatedClass<M> expectedReturnType, AnnotatedClass<?>... parameterTypes)
+ {
+ throw new UnsupportedOperationException();
+ }
+
/**
* Gets a string representation of the class
*
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/ClassReceiver.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/ClassReceiver.java
(rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/ClassReceiver.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -0,0 +1,12 @@
+package org.jboss.webbeans.util.xml;
+
+import java.lang.reflect.AnnotatedElement;
+
+import org.dom4j.Element;
+
+public interface ClassReceiver
+{
+ boolean accept(Element element);
+
+ AnnotatedElement reciveClass(Element element);
+}
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/ClassReceiver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/ParseXmlHelper.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/ParseXmlHelper.java
(rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/ParseXmlHelper.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -0,0 +1,209 @@
+package org.jboss.webbeans.util.xml;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.inject.DefinitionException;
+
+import org.dom4j.Element;
+
+public class ParseXmlHelper
+{
+ private static List<ClassReceiver> receivers;
+
+ static
+ {
+ receivers = initializeReceivers();
+ }
+
+ public static Set<AnnotatedElement> getBeanClasses(List<Element> beans)
+ {
+ Set<AnnotatedElement> result = new HashSet<AnnotatedElement>();
+
+ for (Element bean : beans)
+ result.add(reciveBeanClass(bean));
+
+ return result;
+ }
+
+ private static AnnotatedElement reciveBeanClass(Element element)
+ {
+ for (ClassReceiver receiver : receivers)
+ {
+ if (receiver.accept(element))
+ {
+ return receiver.reciveClass(element);
+ }
+ }
+
+ throw new DefinitionException("definition of a bean " + element.getName()
+ " is incorrect");
+ }
+
+ private static List<ClassReceiver> initializeReceivers()
+ {
+ List<ClassReceiver> receivers = new ArrayList<ClassReceiver>();
+
+ ClassReceiver jmsResourceClassReceiver = new ClassReceiver()
+ {
+ public boolean accept(Element element)
+ {
+ return isJMSResource(element);
+ }
+
+ public AnnotatedElement reciveClass(Element element)
+ {
+ return reciveJMSResourceClass(element);
+ }
+
+ };
+ ClassReceiver resourceClassReceiver = new ClassReceiver()
+ {
+ public boolean accept(Element element)
+ {
+ return isResource(element);
+ }
+
+ public AnnotatedElement reciveClass(Element element)
+ {
+ return reciveResourceClass(element);
+ }
+
+ };
+ ClassReceiver sessionBeanClassReceiver = new ClassReceiver()
+ {
+ public boolean accept(Element element)
+ {
+ return isSessionBean(element);
+ }
+
+ public AnnotatedElement reciveClass(Element element)
+ {
+ return reciveSessionBeanClass(element);
+ }
+
+ };
+ ClassReceiver simpleBeanClassReceiver = new ClassReceiver()
+ {
+ public boolean accept(Element element)
+ {
+ return isSimpleBean(element);
+ }
+
+ public AnnotatedElement reciveClass(Element element)
+ {
+ return reciveSimpleBeanClass(element);
+ }
+
+ };
+
+ receivers.add(jmsResourceClassReceiver);
+ receivers.add(resourceClassReceiver);
+ receivers.add(sessionBeanClassReceiver);
+ receivers.add(simpleBeanClassReceiver);
+
+ return receivers;
+ }
+
+ private static boolean isResource(Element element)
+ {
+ Iterator<?> elIterator = element.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element child = (Element) elIterator.next();
+ if
(child.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE) &&
+ (child.getName().equalsIgnoreCase(XmlConstants.RESOURCE) ||
+ child.getName().equalsIgnoreCase(XmlConstants.PERSISTENCE_CONTEXT)
||
+ child.getName().equalsIgnoreCase(XmlConstants.PERSISTENCE_UNIT) ||
+ child.getName().equalsIgnoreCase(XmlConstants.EJB) ||
+ child.getName().equalsIgnoreCase(XmlConstants.WEB_SERVICE_REF)))
+ return true;
+ }
+ return false;
+ }
+
+ private static AnnotatedElement reciveResourceClass(Element element)
+ {
+ // TODO:
+ return null;
+ }
+
+ private static boolean isJMSResource(Element element)
+ {
+ if
(element.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE)
&&
+ (element.getName().equalsIgnoreCase(XmlConstants.TOPIC) ||
+ element.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
+ return true;
+ return false;
+ }
+
+ private static AnnotatedElement reciveJMSResourceClass(Element element)
+ {
+ // TODO:
+ return null;
+ }
+
+ private static boolean isSimpleBean(Element element)
+ {
+ Class<?> beanClass = loadClass(element);
+
+ if (!Modifier.isAbstract(beanClass.getModifiers()) &&
+ beanClass.getTypeParameters().length == 0)
+ return true;
+
+ return false;
+ }
+
+ private static AnnotatedElement reciveSimpleBeanClass(Element element)
+ {
+ Class<?> beanClass = loadClass(element);
+
+ if (beanClass.isMemberClass())
+ throw new DefinitionException("class " + beanClass + " is a
non-static inner class");
+
+ // if (beanClass.getTypeParameters().length > 0)
+ // throw new DefinitionException("class " + beanClass +
+ // " is a parameterized type");
+
+ // TODO:
+ // boolean isDecorator = false;
+ // if (Modifier.isAbstract(beanClass.getModifiers()) && !isDecorator)
+ // throw new DefinitionException("class " + beanClass +
+ // " is an abstract and not Decorator");
+
+ return beanClass;
+ }
+
+ private static boolean isSessionBean(Element element)
+ {
+ // TODO:
+ return false;
+ }
+
+ private static AnnotatedElement reciveSessionBeanClass(Element element)
+ {
+ // TODO:
+ return null;
+ }
+
+ private static Class<?> loadClass(Element element)
+ {
+ String beanUri = element.getNamespace().getURI();
+ String packageName = beanUri.replaceFirst(XmlConstants.URN_PREFIX, "");
+ String classPath = packageName + "." + element.getName();
+
+ try
+ {
+ return Class.forName(classPath);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new DefinitionException("class " + classPath + " not
found");
+ }
+
+ }
+}
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/ParseXmlHelper.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlConstants.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlConstants.java
(rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlConstants.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -0,0 +1,34 @@
+package org.jboss.webbeans.util.xml;
+
+public class XmlConstants
+{
+ public static final String JAVA_EE_NAMESPACE = "urn:java:ee";
+
+ public static final String DEPLOY = "Deploy";
+
+ public static final String INTERCEPTORS = "Interceptors";
+
+ public static final String DECORATORS = "Decorators";
+
+ public static final String BINDING_TYPE = "BindingType";
+
+ public static final String INTERCEPTOR_BINDING_TYPE =
"InterceptorBindingType";
+
+ public static final String STEREOTYPE = "Stereotype";
+
+ public static final String RESOURCE = "Resource";
+
+ public static final String PERSISTENCE_CONTEXT = "PersistenceContext";
+
+ public static final String PERSISTENCE_UNIT = "PersistenceUnit";
+
+ public static final String EJB = "EJB";
+
+ public static final String WEB_SERVICE_REF = "WebServiceRef";
+
+ public static final String TOPIC = "Topic";
+
+ public static final String QUEUE = "Queue";
+
+ public static final String URN_PREFIX = "urn:java:";
+}
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlConstants.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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
(rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -0,0 +1,93 @@
+package org.jboss.webbeans.util.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.AnnotatedElement;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+public class XmlParserImpl // implements XmlParser
+{
+
+ private static Logger log = Logger.getLogger(XmlParserImpl.class);
+
+ public Set<AnnotatedElement> parse(Set<URL> xmls)
+ {
+ Set<AnnotatedElement> result = new HashSet<AnnotatedElement>();
+
+ for (URL url : xmls)
+ {
+ try
+ {
+ InputStream xmlStream;
+
+ xmlStream = url.openStream();
+ SAXReader reader = new SAXReader();
+ Document document = reader.read(xmlStream);
+ List<Element> beanElements = findBeans(document);
+ result.addAll(ParseXmlHelper.getBeanClasses(beanElements));
+ }
+ catch (IOException e)
+ {
+ log.debug("Can not open stream for " + url, e);
+ }
+ catch (DocumentException e)
+ {
+ log.debug("Error during the processing of a DOM4J document for " +
url, e);
+ }
+ }
+ return result;
+ }
+
+ private List<Element> findBeans(Document document)
+ {
+ List<Element> beans = new ArrayList<Element>();
+
+ Element root = document.getRootElement();
+
+ Iterator<?> elIterator = root.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element element = (Element) elIterator.next();
+ if (checkElementName(element) && checkElementChildrenNames(element))
+ beans.add(element);
+ }
+
+ return beans;
+ }
+
+ private boolean checkElementName(Element element)
+ {
+ if
(element.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE)
&&
+ (element.getName().equalsIgnoreCase(XmlConstants.DEPLOY) ||
+ element.getName().equalsIgnoreCase(XmlConstants.INTERCEPTORS) ||
+ element.getName().equalsIgnoreCase(XmlConstants.DECORATORS)))
+ return false;
+ return true;
+ }
+
+ private boolean checkElementChildrenNames(Element element)
+ {
+ Iterator<?> elIterator = element.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element child = (Element) elIterator.next();
+ if
(child.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE) &&
+ (child.getName().equalsIgnoreCase(XmlConstants.BINDING_TYPE) ||
+
child.getName().equalsIgnoreCase(XmlConstants.INTERCEPTOR_BINDING_TYPE) ||
+ child.getName().equalsIgnoreCase(XmlConstants.STEREOTYPE)))
+ return false;
+ }
+ return true;
+ }
+}
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/xml/XmlParserImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParserEnvironment.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParserEnvironment.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParserEnvironment.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -0,0 +1,63 @@
+package org.jboss.webbeans.xml;
+
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+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 Set<URL> webBeansXml;
+ private final List<AnnotatedAnnotation<?>> enabledDeploymentTypes;
+ private final ResourceLoader resourceLoader;
+
+ public XmlParserEnvironment(ResourceLoader resourceLoader, Set<URL>
webBeansXml)
+ {
+ this.classes = new ArrayList<AnnotatedClass<?>>();
+ this.annotations = new ArrayList<AnnotatedAnnotation<?>>();
+ this.enabledDeploymentTypes = new ArrayList<AnnotatedAnnotation<?>>();
+ this.webBeansXml = webBeansXml;
+ this.resourceLoader = resourceLoader;
+ }
+
+ public Set<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;
+ }
+
+}
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParserEnvironment.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/XmlParserImplTest.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/XmlParserImplTest.java
(rev 0)
+++
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/XmlParserImplTest.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -0,0 +1,55 @@
+package org.jboss.webbeans.test.unit.xml;
+
+import java.lang.reflect.AnnotatedElement;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+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.testng.annotations.Test;
+
+
+public class XmlParserImplTest extends AbstractWebBeansTest
+{
+ @Test
+ public void testParse()
+ {
+ Set<URL> xmls = new HashSet<URL>();
+ Iterable<URL> urls = getResources("user-defined-beans.xml");
+
+ for (URL url : urls)
+ xmls.add(url);
+
+ XmlParserImpl parser = new XmlParserImpl();
+ Set<AnnotatedElement> aSet = parser.parse(xmls);
+
+ for(AnnotatedElement aElement : aSet){
+ assert aElement.equals(Order.class);
+ }
+ assert aSet.size() == 1;
+ }
+}
+
+/*
+<Beans xmlns="urn:java:ee"
xmlns:myapp="urn:java:com.mydomain.myapp"
+xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml">
+<Deploy>
+ <Standard />
+ <Production />
+ <test:AnotherDeploymentType />
+</Deploy>
+<myapp:Order>
+ <ConversationScoped />
+ <myapp:PaymentProcessor>
+ <myapp:Asynchronous />
+ </myapp:PaymentProcessor>
+ <myapp:User />
+</myapp:Order>
+<myapp:Login>
+ <ConversationScoped />
+ <BindingType />
+</myapp:Login>
+</Beans>
+*/
Property changes on:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/XmlParserImplTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/beans/Order.java
===================================================================
--- ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/beans/Order.java
(rev 0)
+++
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/beans/Order.java 2009-03-16
14:56:06 UTC (rev 2044)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.xml.beans;
+
+public class Order
+{
+
+}
Property changes on:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/xml/beans/Order.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
ri/trunk/impl/src/test/resources/org/jboss/webbeans/test/unit/xml/user-defined-beans.xml
===================================================================
---
ri/trunk/impl/src/test/resources/org/jboss/webbeans/test/unit/xml/user-defined-beans.xml 2009-03-16
14:50:01 UTC (rev 2043)
+++
ri/trunk/impl/src/test/resources/org/jboss/webbeans/test/unit/xml/user-defined-beans.xml 2009-03-16
14:56:06 UTC (rev 2044)
@@ -1,8 +1,19 @@
-<Beans xmlns="urn:java:ee"
- xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml">
- <Deploy>
- <Standard />
- <Production />
- <test:AnotherDeploymentType />
- </Deploy>
-</Beans>
+<Beans xmlns="urn:java:ee"
xmlns:myapp="urn:java:org.jboss.webbeans.test.unit.xml.beans"
+ xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml">
+ <Deploy>
+ <Standard />
+ <Production />
+ <test:AnotherDeploymentType />
+ </Deploy>
+ <myapp:Order>
+ <ConversationScoped />
+ <myapp:PaymentProcessor>
+ <myapp:Asynchronous />
+ </myapp:PaymentProcessor>
+ <myapp:User />
+ </myapp:Order>
+ <myapp:Login>
+ <ConversationScoped />
+ <BindingType />
+ </myapp:Login>
+</Beans>
\ No newline at end of file