Author: vitold
Date: 2009-03-23 11:09:12 -0400 (Mon, 23 Mar 2009)
New Revision: 2147
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/AnnotatedItemReceiver.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
Log:
changes with getting bean class
Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/AnnotatedItemReceiver.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/AnnotatedItemReceiver.java 2009-03-23
14:25:23 UTC (rev 2146)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/AnnotatedItemReceiver.java 2009-03-23
15:09:12 UTC (rev 2147)
@@ -1,12 +0,0 @@
-package org.jboss.webbeans.xml;
-
-
-import org.dom4j.Element;
-import org.jboss.webbeans.introspector.AnnotatedItem;
-
-public interface AnnotatedItemReceiver
-{
- boolean accept(Element element);
-
- AnnotatedItem<?, ?> receiveAnnotatedItem(Element element);
-}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-23
14:25:23 UTC (rev 2146)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-03-23
15:09:12 UTC (rev 2147)
@@ -1,7 +1,6 @@
package org.jboss.webbeans.xml;
import java.io.IOException;
-import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
@@ -12,261 +11,23 @@
import java.util.Set;
import javax.inject.DefinitionException;
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.Topic;
import org.dom4j.Attribute;
import org.dom4j.Element;
import org.dom4j.Namespace;
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.introspector.AnnotatedItem;
-import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.resources.spi.ResourceLoadingException;
public class ParseXmlHelper
-{
- private static List<AnnotatedItemReceiver> receivers;
-
- static
- {
- receivers = initializeReceivers();
- }
-
- public static Set<AnnotatedItem<?, ?>> getBeanItems(List<Element>
beans)
- {
- Set<AnnotatedItem<?, ?>> result = new HashSet<AnnotatedItem<?,
?>>();
-
- for (Element bean : beans)
- result.add(receiveBeanItem(bean));
-
- return result;
- }
-
- private static AnnotatedItem<?, ?> receiveBeanItem(Element element)
- {
- for (AnnotatedItemReceiver receiver : receivers)
- {
- if (receiver.accept(element))
- {
- return receiver.receiveAnnotatedItem(element);
- }
- }
-
- throw new DefinitionException("definition of a bean " + element.getName()
+ " is incorrect");
- }
-
- private static List<AnnotatedItemReceiver> initializeReceivers()
- {
- List<AnnotatedItemReceiver> receivers = new
ArrayList<AnnotatedItemReceiver>();
-
- AnnotatedItemReceiver jmsResourceReceiver = new AnnotatedItemReceiver()
- {
- public boolean accept(Element element)
- {
- return isJMSResource(element);
- }
-
- public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
- {
- return receiveJMSResourceItem(element);
- }
-
- };
- AnnotatedItemReceiver resourceReceiver = new AnnotatedItemReceiver()
- {
- public boolean accept(Element element)
- {
- return isResource(element);
- }
-
- public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
- {
- return receiveResourceItem(element);
- }
-
- };
- AnnotatedItemReceiver sessionBeanReceiver = new AnnotatedItemReceiver()
- {
- public boolean accept(Element element)
- {
- return isSessionBean(element);
- }
-
- public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
- {
- return receiveSessionBeanItem(element);
- }
-
- };
- AnnotatedItemReceiver simpleBeanReceiver = new AnnotatedItemReceiver()
- {
- public boolean accept(Element element)
- {
- return isSimpleBean(element);
- }
-
- public AnnotatedItem<?, ?> receiveAnnotatedItem(Element element)
- {
- return receiveSimpleBeanItem(element);
- }
-
- };
-
- //order of elements is important
- receivers.add(jmsResourceReceiver);
- receivers.add(resourceReceiver);
- receivers.add(sessionBeanReceiver);
- receivers.add(simpleBeanReceiver);
-
- return receivers;
- }
-
- private static boolean isJMSResource(Element element)
- {
- if (isJavaEeNamespace(element) &&
- (element.getName().equalsIgnoreCase(XmlConstants.TOPIC) ||
- element.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
- return true;
- return false;
- }
-
- private static AnnotatedItem<?, ?> receiveJMSResourceItem(Element element)
- {
- final Element jmsElement = element;
-
- if(jmsElement.getName().equalsIgnoreCase(XmlConstants.QUEUE))
- {
- Queue queue = new Queue()
- {
- public String getQueueName() throws JMSException
- {
- return getJmsResourceName(jmsElement);
- }
- };
-
- return AnnotatedClassImpl.of(queue.getClass());
- }
-
- Topic topic = new Topic()
- {
- public String getTopicName() throws JMSException
- {
- return getJmsResourceName(jmsElement);
- }
- };
-
- return AnnotatedClassImpl.of(topic.getClass());
- }
-
- private static boolean isResource(Element element)
- {
- Iterator<?> elIterator = element.elementIterator();
- while (elIterator.hasNext())
- {
- Element child = (Element) elIterator.next();
- if (isJavaEeNamespace(child) &&
- (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 AnnotatedItem<?, ?> receiveResourceItem(Element element)
- {
- // TODO:
- return null;
- }
-
- private static boolean isSessionBean(Element element)
- {
- ManagerImpl manager = CurrentManager.rootManager();
- if (manager.getEjbDescriptorCache().containsKey(element.getName()) ||
- element.attribute(XmlConstants.EJB_NAME) != null)
- return true;
- return false;
- }
-
- private static AnnotatedItem<?, ?> receiveSessionBeanItem(Element element)
- {
- // TODO:
- return null;
- }
-
- private static boolean isSimpleBean(Element element)
- {
- //TODO
- String urn = element.getNamespace().getURI();
- Class<?> beanClass = null;//loadElementClass(urn, element.getName());
-
- if (!Modifier.isAbstract(beanClass.getModifiers()) &&
- beanClass.getTypeParameters().length == 0)
- return true;
-
- return false;
- }
-
- private static AnnotatedItem<?, ?> receiveSimpleBeanItem(Element element)
- {
- //TODO
- String urn = element.getNamespace().getURI();
- Class<?> beanClass = null;//loadElementClass(urn, element.getName());
-
- if (!Modifier.isStatic(beanClass.getModifiers()) &&
- 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 AnnotatedClassImpl.of(beanClass);
- }
-
- private static String getJmsResourceName(Element element)
- {
- Iterator<?> elIterator = element.elementIterator();
- while (elIterator.hasNext())
- {
- Element child = (Element) elIterator.next();
- if (isJavaEeNamespace(child) &&
- child.getName().equalsIgnoreCase(XmlConstants.RESOURCE))
- {
- Iterator<?> chIterator = child.elementIterator();
- while(chIterator.hasNext())
- {
- Element chChild = (Element) chIterator.next();
- if (isJavaEeNamespace(chChild) &&
- (chChild.getName().equalsIgnoreCase(XmlConstants.NAME) ||
-
chChild.getName().equalsIgnoreCase(XmlConstants.MAPPED_NAME)))
- {
- return chChild.getName();
- }
- }
- }
- }
- throw new DefinitionException("Incorrect JMSResource declaration for " +
element.getName());
- }
-
+{
public static boolean isJavaEeNamespace(Element element)
{
return
element.getNamespace().getURI().equalsIgnoreCase(XmlConstants.JAVA_EE_NAMESPACE);
}
- public static <T> Class<? extends T> loadElementClass(Element element,
Class<T> expectedType, XmlEnvironment environment, Map<String,
Set<String>> packagesMap)
+ public static <T> AnnotatedClass<? extends T> loadElementClass(Element
element, Class<T> expectedType, XmlEnvironment environment, Map<String,
Set<String>> packagesMap)
{
- List<Class<? extends T>> classesList = new ArrayList<Class<?
extends T>>();
+ List<AnnotatedClass<? extends T>> classesList = new
ArrayList<AnnotatedClass<? extends T>>();
String className = element.getName();
String prefix = element.getNamespacePrefix();
@@ -280,7 +41,7 @@
String classPath = packageName + "." + element.getName();
try
{
- Class<? extends T> classType = environment.loadClass(classPath,
expectedType).getRawType();
+ AnnotatedClass<? extends T> classType =
environment.loadClass(classPath, expectedType);
classesList.add(classType);
}
catch(ResourceLoadingException e){}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-23 14:25:23
UTC (rev 2146)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-23 15:09:12
UTC (rev 2147)
@@ -21,6 +21,7 @@
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.io.SAXReader;
+import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
@@ -54,9 +55,16 @@
private void parseForBeans(Document document)
{
- List<Element> beanElements = findBeans(document);
- // TODO Only pass in classes here
- //environment.getClasses().addAll(ParseXmlHelper.getBeanItems(beanElements));
+ List<AnnotatedClass<?>> beanClasses = new
ArrayList<AnnotatedClass<?>>();
+
+ List<Element> beanElements = findBeans(document);
+ for (Element beanElement : beanElements)
+ {
+ AnnotatedClass<?> beanClass = ParseXmlHelper.loadElementClass(beanElement,
Object.class, environment, packagesMap);
+ beanClasses.add(beanClass);
+ }
+
+ environment.getClasses().addAll(beanClasses);
}
private void parseForDeploy(Document document)
@@ -173,12 +181,12 @@
List<Element> children = element.elements();
for (Element child : children)
{
- Class<? extends Annotation> deploymentClass =
ParseXmlHelper.loadElementClass(child, Annotation.class, environment, packagesMap);
+ AnnotatedClass<? extends Annotation> deploymentClass =
ParseXmlHelper.loadElementClass(child, Annotation.class, environment, packagesMap);
// if(deploymentClass.getAnnotation(DeploymentType.class) == null)
// throw new DefinitionException("<Deploy> child <" +
element.getName() + "> must be a deployment type");
- deploymentClasses.add(deploymentClass);
+ deploymentClasses.add(deploymentClass.getRawType());
}
haveAnyDeployElement = true;
return deploymentClasses;