Author: vitold
Date: 2009-04-06 04:54:23 -0400 (Mon, 06 Apr 2009)
New Revision: 2311
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:
make 9.4
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-06
01:12:27 UTC (rev 2310)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java 2009-04-06
08:54:23 UTC (rev 2311)
@@ -86,14 +86,14 @@
}
catch (ClassCastException e)
{
- throw new DefinitionException("<Deploy> child <" +
element.getName() + "> must be a Java annotation type");
+ throw new DefinitionException("<" + element.getName() +
"> must be a Java annotation type");
}
}
}
}
if (classesList.size() == 0)
- throw new DefinitionException("Could not find '" + className +
"' for bean <");
+ throw new DefinitionException("Could not find '" + className +
"'");
if (classesList.size() == 1)
return classesList.get(0);
@@ -225,4 +225,11 @@
packagesMap.put(prefix, packagesSet);
}
}
+
+ public static void checkForUniqueElements(List<Class<? extends
Annotation>> list){
+ Set<Class<? extends Annotation>> set = new HashSet<Class<?
extends Annotation>>(list);
+ if(list.size() != set.size())
+ throw new DefinitionException("A certain annotation type is declared more
than once as a binding type, " +
+ "interceptor binding type or stereotype using XML");
+ }
}
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-04-06 01:12:27
UTC (rev 2310)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java 2009-04-06 08:54:23
UTC (rev 2311)
@@ -19,6 +19,7 @@
import javax.inject.DefinitionException;
import javax.inject.DeploymentException;
import javax.inject.DeploymentType;
+import javax.interceptor.InterceptorBindingType;
import org.dom4j.Document;
import org.dom4j.DocumentException;
@@ -60,12 +61,51 @@
Document document = createDocument(url);
if (document != null)
{
+ parseForAnnotationTypes(document);
parseForBeans(document);
parseForDeploy(document);
}
}
}
+
+ private void parseForAnnotationTypes(Document document)
+ {
+ Element root = document.getRootElement();
+
+ List<Class<? extends Annotation>> bindingTypes = new
ArrayList<Class<? extends Annotation>>();
+ List<Class<? extends Annotation>> interceptorBindingTypes = new
ArrayList<Class<? extends Annotation>>();
+ List<Class<? extends Annotation>> stereotypes = new
ArrayList<Class<? extends Annotation>>();
+
+ Iterator<?> elIterator = root.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element element = (Element) elIterator.next();
+ boolean isBindingType = ParseXmlHelper.findElementsInEeNamespace(element,
XmlConstants.BINDING_TYPE).size() > 0;
+ boolean isInterceptorBindingType =
ParseXmlHelper.findElementsInEeNamespace(element,
XmlConstants.INTERCEPTOR_BINDING_TYPE).size() > 0;
+ boolean isStereotype = ParseXmlHelper.findElementsInEeNamespace(element,
XmlConstants.STEREOTYPE).size() > 0;
+ if(isBindingType || isInterceptorBindingType || isStereotype)
+ {
+ Class<? extends Annotation> annotationType =
ParseXmlHelper.loadAnnotationClass(element, Annotation.class, environment, packagesMap);
+ if(isBindingType)
+ bindingTypes.add(annotationType);
+ if(isInterceptorBindingType)
+ {
+ interceptorBindingTypes.add(annotationType);
+ checkForInterceptorBindingTypeChildren(element);
+ }
+ if(isStereotype)
+ {
+ stereotypes.add(annotationType);
+ checkForStereotypeChildren(element);
+ }
+ }
+ }
+ ParseXmlHelper.checkForUniqueElements(bindingTypes);
+ ParseXmlHelper.checkForUniqueElements(interceptorBindingTypes);
+ ParseXmlHelper.checkForUniqueElements(stereotypes);
+ }
+
private void parseForBeans(Document document)
{
List<AnnotatedClass<?>> beanClasses = new
ArrayList<AnnotatedClass<?>>();
@@ -83,8 +123,7 @@
}
private void parseForDeploy(Document document)
- {
-
+ {
Element root = document.getRootElement();
Iterator<?> elIterator = root.elementIterator();
@@ -126,6 +165,38 @@
throw new DeploymentException(message, e);
}
}
+
+ private void checkForInterceptorBindingTypeChildren(Element element)
+ {
+ Iterator<?> elIterator = element.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element child = (Element)elIterator.next();
+ Class<? extends Annotation> clazz =
ParseXmlHelper.loadAnnotationClass(child, Annotation.class, environment, packagesMap);
+ if(!clazz.isAnnotationPresent(InterceptorBindingType.class))
+ throw new DefinitionException("Direct child <" + child.getName()
+ "> of interceptor binding type <" + element.getName() +
+ "> declaration must be interceptor binding type");
+
+ }
+ }
+
+ private void checkForStereotypeChildren(Element stereotypeElement)
+ {
+ Iterator<?> elIterator = stereotypeElement.elementIterator();
+ while (elIterator.hasNext())
+ {
+ Element stereotypeChild = (Element)elIterator.next();
+ Class<? extends Annotation> stereotypeClass =
ParseXmlHelper.loadAnnotationClass(stereotypeChild, Annotation.class, environment,
packagesMap);
+ if(stereotypeClass.isAnnotationPresent(ScopeType.class) ||
+ stereotypeClass.isAnnotationPresent(DeploymentType.class) ||
+ stereotypeClass.isAnnotationPresent(InterceptorBindingType.class) ||
+ stereotypeClass.isAnnotationPresent(Named.class))
+ return;
+ throw new DefinitionException("Direct child <" +
stereotypeChild.getName() + "> of stereotype <" +
stereotypeElement.getName() +
+ "> declaration must be scope type, or deployment type, or
interceptor binding type, or javax.annotation.Named");
+
+ }
+ }
private List<Element> findBeans(Document document)
{
Show replies by date