Author: vitold
Date: 2009-04-21 05:33:17 -0400 (Tue, 21 Apr 2009)
New Revision: 2611
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/AbstractBeanChildrenChecker.java
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/deploy/user-defined-beans.xml
Log:
some methods refactoring
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-04-21
09:09:34 UTC (rev 2610)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-04-21
09:33:17 UTC (rev 2611)
@@ -34,8 +34,18 @@
public static <T> AnnotatedClass<? extends T> loadElementClass(Element
element, Class<T> expectedType, XmlEnvironment environment, Map<String,
Set<String>> packagesMap)
{
+ List<AnnotatedClass<? extends T>> classesList =
tryLoadElementClass(element, expectedType, environment, packagesMap);
+ String className = element.getName();
+
+ if (classesList.size() == 0)
+ throw new DefinitionException("Could not find '" + className +
"'");
+
+ return classesList.get(0);
+ }
+
+ public static <T> List<AnnotatedClass<? extends T>>
tryLoadElementClass(Element element, Class<T> expectedType, XmlEnvironment
environment, Map<String, Set<String>> packagesMap)
+ {
List<AnnotatedClass<? extends T>> classesList = new
ArrayList<AnnotatedClass<? extends T>>();
- String className = element.getName();
String prefix = element.getNamespacePrefix();
for (Map.Entry<String, Set<String>> packagesEntry :
packagesMap.entrySet())
@@ -57,14 +67,11 @@
}
}
}
-
- if (classesList.size() == 0)
- throw new DefinitionException("Could not find '" + className +
"'", new DefinitionException(className + " not a Java type"));
-
- if (classesList.size() == 1)
- return classesList.get(0);
-
- throw new DefinitionException("There are multiple packages containing a Java
type with the same name '" + className + "'");
+
+ if(classesList.size() > 1)
+ throw new DefinitionException("There are multiple packages containing a
Java type with the same name '" + element.getName() + "'");
+
+ return classesList;
}
public static <T extends Annotation> Class<? extends T>
loadAnnotationClass(Element element, Class<T> expectedType, XmlEnvironment
environment, Map<String, Set<String>> packagesMap)
@@ -258,7 +265,6 @@
{
Set<String> packages = packagesMap.get(prefix);
packages.addAll(packagesSet);
- packagesMap.put(prefix, packages);
}
else
{
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/AbstractBeanChildrenChecker.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/AbstractBeanChildrenChecker.java 2009-04-21
09:09:34 UTC (rev 2610)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/AbstractBeanChildrenChecker.java 2009-04-21
09:33:17 UTC (rev 2611)
@@ -93,11 +93,26 @@
private void checkBeanChild(Element beanChildElement, AnnotatedClass<?>
beanClass)
{
- try
- {
- if(beanChildElement.getName().equalsIgnoreCase(XmlConstants.ARRAY))
+ if(beanChildElement.getName().equalsIgnoreCase(XmlConstants.ARRAY))
+ return;
+
+ List<AnnotatedClass<?>> beanChildClassList =
ParseXmlHelper.tryLoadElementClass(beanChildElement, Object.class, environment,
packagesMap);
+
+ if(beanChildClassList.size() == 0)
+ {
+ Element beanElement = beanChildElement.getParent();
+ Namespace beanNamespace = beanElement.getNamespace();
+ Namespace beanChildNamespace = beanChildElement.getNamespace();
+ if(beanChildNamespace.equals(beanNamespace))
+ {
+ //bean child element declaring a method or field of the bean.
+ checkFieldOrMethodChild(beanChildElement, beanClass);
return;
- AnnotatedClass<?> beanChildClass =
ParseXmlHelper.loadElementClass(beanChildElement, Object.class, environment,
packagesMap);
+ }
+ }
+ else
+ {
+ AnnotatedClass<?> beanChildClass = beanChildClassList.get(0);
Class<?> beanChildType = beanChildClass.getRawType();
boolean isJavaClass = !beanChildType.isEnum() &&
!beanChildType.isPrimitive() && !beanChildType.isInterface();
boolean isInterface = beanChildType.isInterface() &&
!beanChildType.isAnnotation();
@@ -113,27 +128,10 @@
constructorParameters.add(beanChildClass);
return;
}
- throw new DefinitionException(new DefinitionException(beanChildElement.getName()
+ " can't be interpreted as a Java class or interface or Java Annotation
type"));
}
- catch(DefinitionException e)
- {
- if(!(e.getCause() instanceof DefinitionException))
- {
- throw new DefinitionException(e);
- }
-
- Element beanElement = beanChildElement.getParent();
- Namespace beanNamespace = beanElement.getNamespace();
- Namespace beanChildNamespace = beanChildElement.getNamespace();
- if(beanChildNamespace.equals(beanNamespace))
- {
- //bean child element declaring a method or field of the bean.
- checkFieldOrMethodChild(beanChildElement, beanClass);
- return;
- }
- throw new DefinitionException("Can't determine type of element
<" + beanChildElement.getName() + "> in bean '" +
- beanElement.getName() + "'");
- }
+
+ throw new DefinitionException("Can't determine type of element <"
+ beanChildElement.getName() + "> in bean '" +
+ beanChildElement.getParent().getName() + "'");
}
private void checkAnnotationChild(Element beanChildElement, AnnotatedClass<?>
beanChildClass, AnnotatedClass<?> beanClass)
Modified:
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/deploy/user-defined-beans.xml
===================================================================
---
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/deploy/user-defined-beans.xml 2009-04-21
09:09:34 UTC (rev 2610)
+++
ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/deploy/user-defined-beans.xml 2009-04-21
09:33:17 UTC (rev 2611)
@@ -1,4 +1,4 @@
-<Beans xmlns="urn:java:ee"
xmlns:myapp="urn:java:org.jboss.webbeans.test.unit.xml.beans"
+<Beans xmlns="urn:java:ee"
xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml.deploy">
<Deploy>
<Standard />