Author: vitold
Date: 2009-03-25 12:05:11 -0400 (Wed, 25 Mar 2009)
New Revision: 2203
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanType.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanTypeObtainer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/JmsResourceTypeObtainer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/ResourceTypeObtainer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SessionBeanTypeObtainer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SimpleBeanTypeObtainer.java
Removed:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanChildrenChecker.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/JmsResourceChildrenChecker.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/ResourceChildrenChecker.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SessionBeanChildrenChecker.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SimpleBeanChildrenChecker.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
Log:
some changes with beans declaration validating
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-25 15:00:44
UTC (rev 2202)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-03-25 16:05:11
UTC (rev 2203)
@@ -28,11 +28,12 @@
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
-import org.jboss.webbeans.xml.check.BeanChildrenChecker;
-import org.jboss.webbeans.xml.check.JmsResourceChildrenChecker;
-import org.jboss.webbeans.xml.check.ResourceChildrenChecker;
-import org.jboss.webbeans.xml.check.SessionBeanChildrenChecker;
-import org.jboss.webbeans.xml.check.SimpleBeanChildrenChecker;
+import org.jboss.webbeans.xml.check.BeanType;
+import org.jboss.webbeans.xml.check.BeanTypeObtainer;
+import org.jboss.webbeans.xml.check.JmsResourceTypeObtainer;
+import org.jboss.webbeans.xml.check.ResourceTypeObtainer;
+import org.jboss.webbeans.xml.check.SessionBeanTypeObtainer;
+import org.jboss.webbeans.xml.check.SimpleBeanTypeObtainer;
public class XmlParser
{
@@ -40,7 +41,7 @@
private final XmlEnvironment environment;
- private List<BeanChildrenChecker> childrenCheckers = new
ArrayList<BeanChildrenChecker>();
+ private List<BeanTypeObtainer> beanTypeObtainers = new
ArrayList<BeanTypeObtainer>();
private boolean haveAnyDeployElement = false;
@@ -49,10 +50,10 @@
public XmlParser(XmlEnvironment environment)
{
this.environment = environment;
- this.childrenCheckers.add(new JmsResourceChildrenChecker());
- this.childrenCheckers.add(new ResourceChildrenChecker());
- this.childrenCheckers.add(new SessionBeanChildrenChecker());
- this.childrenCheckers.add(new SimpleBeanChildrenChecker());
+ this.beanTypeObtainers.add(new JmsResourceTypeObtainer());
+ this.beanTypeObtainers.add(new ResourceTypeObtainer());
+ this.beanTypeObtainers.add(new SessionBeanTypeObtainer());
+ this.beanTypeObtainers.add(new SimpleBeanTypeObtainer());
}
public void parse()
@@ -76,8 +77,8 @@
for (Element beanElement : beanElements)
{
AnnotatedClass<?> beanClass = ParseXmlHelper.loadElementClass(beanElement,
Object.class, environment, packagesMap);
+ checkBeanElement(beanElement, beanClass);
checkProduces(beanElement, beanClass);
- checkBeanChildren(beanElement, beanClass);
beanClasses.add(beanClass);
}
@@ -204,18 +205,19 @@
return deploymentClasses;
}
- private void checkBeanChildren(Element beanElement, AnnotatedClass<?>
beanClass)
- {
- for (BeanChildrenChecker childrenChecker : childrenCheckers)
+ private void checkBeanElement(Element beanElement, AnnotatedClass<?> beanClass)
+ {//TODO: not finished
+ BeanType beanType = BeanType.SIMPLE_BEAN;
+ for(BeanTypeObtainer beanTypeObtainer : beanTypeObtainers)
{
- if (childrenChecker.accept(beanElement, beanClass))
+ if(beanTypeObtainer.accept(beanElement, beanClass))
{
- childrenChecker.checkChildren(beanElement);
- return;
+ beanType = beanTypeObtainer.obtainType(beanElement, beanClass);
+ break;
}
}
-
- throw new DefinitionException("Definition of a bean " +
beanElement.getName() + " is incorrect");
+
+
}
private void checkProduces(Element beanElement, AnnotatedClass<?> beanClass)
Deleted:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanChildrenChecker.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanChildrenChecker.java 2009-03-25
15:00:44 UTC (rev 2202)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanChildrenChecker.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -1,11 +0,0 @@
-package org.jboss.webbeans.xml.check;
-
-import org.dom4j.Element;
-import org.jboss.webbeans.introspector.AnnotatedClass;
-
-public interface BeanChildrenChecker
-{
- boolean accept(Element element, AnnotatedClass<?> beanClass);
-
- void checkChildren(Element element);
-}
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanType.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanType.java
(rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanType.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.xml.check;
+
+public enum BeanType
+{
+ JMS_RESOURCE, RESOURCE, SESSION_BEAN, SIMPLE_BEAN
+}
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanTypeObtainer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanTypeObtainer.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/BeanTypeObtainer.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.xml.check;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+
+public interface BeanTypeObtainer
+{
+ boolean accept(Element beanElement, AnnotatedClass<?> beanClass);
+
+ BeanType obtainType(Element beanElement, AnnotatedClass<?> beanClass);
+}
Deleted:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/JmsResourceChildrenChecker.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/JmsResourceChildrenChecker.java 2009-03-25
15:00:44 UTC (rev 2202)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/JmsResourceChildrenChecker.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -1,25 +0,0 @@
-package org.jboss.webbeans.xml.check;
-
-import org.dom4j.Element;
-import org.jboss.webbeans.introspector.AnnotatedClass;
-import org.jboss.webbeans.xml.ParseXmlHelper;
-import org.jboss.webbeans.xml.XmlConstants;
-
-public class JmsResourceChildrenChecker implements BeanChildrenChecker
-{
- public boolean accept(Element element, AnnotatedClass<?> beanClass)
- {
- if (ParseXmlHelper.isJavaEeNamespace(element) &&
- (element.getName().equalsIgnoreCase(XmlConstants.TOPIC) ||
- element.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
- return true;
- return false;
- }
-
- public void checkChildren(Element element)
- {
- // TODO Auto-generated method stub
-
- }
-
-}
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/JmsResourceTypeObtainer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/JmsResourceTypeObtainer.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/JmsResourceTypeObtainer.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -0,0 +1,23 @@
+package org.jboss.webbeans.xml.check;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.xml.ParseXmlHelper;
+import org.jboss.webbeans.xml.XmlConstants;
+
+public class JmsResourceTypeObtainer implements BeanTypeObtainer
+{
+ public boolean accept(Element beanElement, AnnotatedClass<?> beanClass)
+ {
+ if (ParseXmlHelper.isJavaEeNamespace(beanElement) &&
+ (beanElement.getName().equalsIgnoreCase(XmlConstants.TOPIC) ||
+ beanElement.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
+ return true;
+ return false;
+ }
+
+ public BeanType obtainType(Element beanElement, AnnotatedClass<?> beanClass)
+ {
+ return BeanType.JMS_RESOURCE;
+ }
+}
Deleted:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/ResourceChildrenChecker.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/ResourceChildrenChecker.java 2009-03-25
15:00:44 UTC (rev 2202)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/ResourceChildrenChecker.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -1,41 +0,0 @@
-package org.jboss.webbeans.xml.check;
-
-import java.util.Iterator;
-
-import org.dom4j.Element;
-import org.jboss.webbeans.introspector.AnnotatedClass;
-import org.jboss.webbeans.xml.ParseXmlHelper;
-import org.jboss.webbeans.xml.XmlConstants;
-
-public class ResourceChildrenChecker implements BeanChildrenChecker
-{
-
- public boolean accept(Element element, AnnotatedClass<?> beanClass)
- {
- if (ParseXmlHelper.isJavaEeNamespace(element) &&
- (element.getName().equalsIgnoreCase(XmlConstants.TOPIC) ||
- element.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
- return false;
-
- Iterator<?> elIterator = element.elementIterator();
- while (elIterator.hasNext())
- {
- Element child = (Element) elIterator.next();
- if (ParseXmlHelper.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;
- }
-
- public void checkChildren(Element element)
- {
- // TODO Auto-generated method stub
-
- }
-
-}
Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/ResourceTypeObtainer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/ResourceTypeObtainer.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/ResourceTypeObtainer.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -0,0 +1,39 @@
+package org.jboss.webbeans.xml.check;
+
+import java.util.Iterator;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.xml.ParseXmlHelper;
+import org.jboss.webbeans.xml.XmlConstants;
+
+public class ResourceTypeObtainer implements BeanTypeObtainer
+{
+
+ public boolean accept(Element beanElement, AnnotatedClass<?> beanClass)
+ {
+ if (ParseXmlHelper.isJavaEeNamespace(beanElement) &&
+ (beanElement.getName().equalsIgnoreCase(XmlConstants.TOPIC) ||
+ beanElement.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
+ return false;
+
+ Iterator<?> elIterator = beanElement.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element child = (Element) elIterator.next();
+ if (ParseXmlHelper.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;
+ }
+
+ public BeanType obtainType(Element beanElement, AnnotatedClass<?> beanClass)
+ {
+ return BeanType.RESOURCE;
+ }
+}
Deleted:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SessionBeanChildrenChecker.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SessionBeanChildrenChecker.java 2009-03-25
15:00:44 UTC (rev 2202)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SessionBeanChildrenChecker.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -1,27 +0,0 @@
-package org.jboss.webbeans.xml.check;
-
-import org.dom4j.Element;
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.introspector.AnnotatedClass;
-import org.jboss.webbeans.xml.XmlConstants;
-
-public class SessionBeanChildrenChecker implements BeanChildrenChecker
-{
-
- public boolean accept(Element element, AnnotatedClass<?> beanClass)
- {
- ManagerImpl manager = CurrentManager.rootManager();
- if (manager.getEjbDescriptorCache().containsKey(element.getName()) ||
- element.attribute(XmlConstants.EJB_NAME) != null)
- return true;
- return false;
- }
-
- public void checkChildren(Element element)
- {
- // TODO Auto-generated method stub
-
- }
-
-}
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SessionBeanTypeObtainer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SessionBeanTypeObtainer.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SessionBeanTypeObtainer.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -0,0 +1,25 @@
+package org.jboss.webbeans.xml.check;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.xml.XmlConstants;
+
+public class SessionBeanTypeObtainer implements BeanTypeObtainer
+{
+
+ public boolean accept(Element beanElement, AnnotatedClass<?> beanClass)
+ {
+ ManagerImpl manager = CurrentManager.rootManager();
+ if (manager.getEjbDescriptorCache().containsKey(beanElement.getName()) ||
+ beanElement.attribute(XmlConstants.EJB_NAME) != null)
+ return true;
+ return false;
+ }
+
+ public BeanType obtainType(Element beanElement, AnnotatedClass<?> beanClass)
+ {
+ return BeanType.SESSION_BEAN;
+ }
+}
Deleted:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SimpleBeanChildrenChecker.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SimpleBeanChildrenChecker.java 2009-03-25
15:00:44 UTC (rev 2202)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SimpleBeanChildrenChecker.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -1,29 +0,0 @@
-package org.jboss.webbeans.xml.check;
-
-import org.dom4j.Element;
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.introspector.AnnotatedClass;
-import org.jboss.webbeans.xml.XmlConstants;
-
-public class SimpleBeanChildrenChecker implements BeanChildrenChecker
-{
-
- public boolean accept(Element element, AnnotatedClass<?> beanClass)
- {
- ManagerImpl manager = CurrentManager.rootManager();
- boolean isSessionBean =
manager.getEjbDescriptorCache().containsKey(element.getName()) ||
- element.attribute(XmlConstants.EJB_NAME) !=
null;
-
- if (!beanClass.isAbstract() && !isSessionBean &&
!beanClass.isParameterizedType())
- return true;
-
- return false;
- }
-
- public void checkChildren(Element element)
- {
- // TODO Auto-generated method stub
-
- }
-}
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SimpleBeanTypeObtainer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SimpleBeanTypeObtainer.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/check/SimpleBeanTypeObtainer.java 2009-03-25
16:05:11 UTC (rev 2203)
@@ -0,0 +1,47 @@
+package org.jboss.webbeans.xml.check;
+
+import javax.decorator.Decorator;
+import javax.inject.DefinitionException;
+import javax.interceptor.Interceptor;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.xml.ParseXmlHelper;
+import org.jboss.webbeans.xml.XmlConstants;
+
+public class SimpleBeanTypeObtainer implements BeanTypeObtainer
+{
+
+ public boolean accept(Element beanElement, AnnotatedClass<?> beanClass)
+ {
+ ManagerImpl manager = CurrentManager.rootManager();
+ boolean isSessionBean =
manager.getEjbDescriptorCache().containsKey(beanElement.getName()) ||
+ beanElement.attribute(XmlConstants.EJB_NAME) !=
null;
+
+ if (!beanClass.isAbstract() && !isSessionBean &&
!beanClass.isParameterizedType())
+ return true;
+
+ return false;
+ }
+
+ public BeanType obtainType(Element beanElement, AnnotatedClass<?> beanClass)
+ {
+ if(beanClass.isNonStaticMemberClass())
+ throw new DefinitionException("Bean class '" + beanClass.getName()
+ "' of a simple bean <" + beanElement.getName() +
+ "> is a non static member class");
+
+ if(beanClass.getRawType().isAnnotationPresent(Interceptor.class) &&
+ ParseXmlHelper.findElementsInEeNamespace(beanElement,
XmlConstants.INTERCEPTOR).size() != 1)
+ throw new DefinitionException("a simple bean defined in XML as <" +
beanElement.getName() + "> has a bean class '" +
+ beanClass.getName() + "' annotated @Interceptor and is not
declared as an interceptor in XML");
+
+ if(beanClass.getRawType().isAnnotationPresent(Decorator.class) &&
+ ParseXmlHelper.findElementsInEeNamespace(beanElement,
XmlConstants.DECORATOR).size() != 1)
+ throw new DefinitionException("a simple bean defined in XML as <" +
beanElement.getName() + "> has a bean class '" +
+ beanClass.getName() + "' annotated @Decorator and is not declared
as an interceptor in XML");
+
+ return BeanType.SIMPLE_BEAN;
+ }
+}