[jboss-cvs] JBossAS SVN: r76479 - projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 30 11:50:47 EDT 2008
Author: alesj
Date: 2008-07-30 11:50:46 -0400 (Wed, 30 Jul 2008)
New Revision: 76479
Added:
projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/CommitElement.java
Modified:
projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java
Log:
Only add annotations if full lookup was successful.
Copied: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/CommitElement.java (from rev 76469, projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/CommitElement.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/CommitElement.java 2008-07-30 15:50:46 UTC (rev 76479)
@@ -0,0 +1,91 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.deployers.plugins.annotations;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+
+import org.jboss.metadata.spi.signature.Signature;
+
+/**
+ * Gathering annotation information.
+ *
+ * Only push all this info into AnnotationEnvironment if
+ * complete lookup was successful.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+class CommitElement
+{
+ private Annotation annotation;
+ private ElementType type;
+ private String className;
+ private Signature signature;
+
+ CommitElement(Annotation annotation, ElementType type, String className, Signature signature)
+ {
+ this.annotation = annotation;
+ this.type = type;
+ this.className = className;
+ this.signature = signature;
+ }
+
+ /**
+ * Get the annotation.
+ *
+ * @return the annotation
+ */
+ public Annotation getAnnotation()
+ {
+ return annotation;
+ }
+
+ /**
+ * Get element type.
+ *
+ * @return the element type
+ */
+ public ElementType getType()
+ {
+ return type;
+ }
+
+ /**
+ * Get class name.
+ *
+ * @return the class name
+ */
+ public String getClassName()
+ {
+ return className;
+ }
+
+ /**
+ * Get signature.
+ *
+ * @return the signature
+ */
+ public Signature getSignature()
+ {
+ return signature;
+ }
+}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java 2008-07-30 15:26:52 UTC (rev 76478)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java 2008-07-30 15:50:46 UTC (rev 76479)
@@ -21,18 +21,20 @@
*/
package org.jboss.deployers.plugins.annotations;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
-import java.io.InputStream;
-import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
import javassist.ClassPool;
import javassist.CtBehavior;
import javassist.CtClass;
+import javassist.CtConstructor;
import javassist.CtMember;
+import javassist.CtMethod;
import javassist.NotFoundException;
-import javassist.CtConstructor;
-import javassist.CtMethod;
import org.jboss.classloading.spi.visitor.ClassFilter;
import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.classloading.spi.visitor.ResourceFilter;
@@ -40,9 +42,9 @@
import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
import org.jboss.logging.Logger;
import org.jboss.metadata.spi.signature.Signature;
-import org.jboss.metadata.spi.signature.javassist.JavassistSignatureFactory;
import org.jboss.metadata.spi.signature.javassist.JavassistConstructorParametersSignature;
import org.jboss.metadata.spi.signature.javassist.JavassistMethodParametersSignature;
+import org.jboss.metadata.spi.signature.javassist.JavassistSignatureFactory;
/**
* Generic annotation scanner deployer.
@@ -95,7 +97,12 @@
CtClass ctClass = pool.makeClass(stream);
try
{
- handleCtClass(ctClass);
+ List<CommitElement> commit = new ArrayList<CommitElement>();
+ handleCtClass(ctClass, commit);
+ for (CommitElement ce : commit)
+ {
+ env.putAnnotation(ce.getAnnotation(), ce.getType(), ce.getClassName(), ce.getSignature());
+ }
}
finally
{
@@ -142,10 +149,11 @@
* Handle CtClass for annotations.
*
* @param ctClass the ct class instance
+ * @param commit the commit list
* @throws ClassNotFoundException for any annotations lookup problems
* @throws NotFoundException for any annotations lookup problems
*/
- protected void handleCtClass(CtClass ctClass) throws ClassNotFoundException, NotFoundException
+ protected void handleCtClass(CtClass ctClass, List<CommitElement> commit) throws ClassNotFoundException, NotFoundException
{
if (ctClass == null || objectCtClass.equals(ctClass))
return;
@@ -158,11 +166,12 @@
String className = ctClass.getName();
Object[] annotations = forceAnnotations ? ctClass.getAnnotations() : ctClass.getAvailableAnnotations();
- handleAnnotations(ElementType.TYPE, (Signature)null, annotations, className);
- handleCtMembers(ElementType.CONSTRUCTOR, ctClass.getDeclaredConstructors(), className);
- handleCtMembers(ElementType.METHOD, ctClass.getDeclaredMethods(), className);
- handleCtMembers(ElementType.FIELD, ctClass.getDeclaredFields(), className);
+ handleAnnotations(ElementType.TYPE, (Signature)null, annotations, className, commit);
+ handleCtMembers(ElementType.CONSTRUCTOR, ctClass.getDeclaredConstructors(), className, commit);
+ handleCtMembers(ElementType.METHOD, ctClass.getDeclaredMethods(), className, commit);
+ handleCtMembers(ElementType.FIELD, ctClass.getDeclaredFields(), className, commit);
+
if (checkInterfaces)
{
// interfaces
@@ -170,12 +179,12 @@
if (interfaces != null && interfaces.length > 0)
{
for (CtClass intf : interfaces)
- handleCtClass(intf);
+ handleCtClass(intf, commit);
}
}
// super class
- handleCtClass(ctClass.getSuperclass());
+ handleCtClass(ctClass.getSuperclass(), commit);
}
/**
@@ -184,23 +193,24 @@
* @param type where we found the annotations
* @param members the ct member instances
* @param className the className
+ * @param commit the commit list
* @throws ClassNotFoundException for any annotations lookup problems
*/
- protected void handleCtMembers(ElementType type, CtMember[] members, String className) throws ClassNotFoundException
+ protected void handleCtMembers(ElementType type, CtMember[] members, String className, List<CommitElement> commit) throws ClassNotFoundException
{
if (members != null && members.length > 0)
{
for (CtMember member : members)
{
Object[] annotations = forceAnnotations ? member.getAnnotations() : member.getAvailableAnnotations();
- handleAnnotations(type, member, annotations, className);
+ handleAnnotations(type, member, annotations, className, commit);
if (member instanceof CtBehavior)
{
CtBehavior behavior = (CtBehavior)member;
Object[][] paramAnnotations = forceAnnotations ? behavior.getParameterAnnotations() : behavior.getAvailableParameterAnnotations();
for (int index = 0; index < paramAnnotations.length; index++)
{
- handleAnnotations(ElementType.PARAMETER, getBehaviorSignature(behavior, index), paramAnnotations[index], className);
+ handleAnnotations(ElementType.PARAMETER, getBehaviorSignature(behavior, index), paramAnnotations[index], className, commit);
}
}
}
@@ -215,7 +225,7 @@
* @return parameters signature
* @throws ClassNotFoundException for any error
*/
- protected Signature getBehaviorSignature(CtBehavior behavior, int index) throws ClassNotFoundException
+ protected static Signature getBehaviorSignature(CtBehavior behavior, int index) throws ClassNotFoundException
{
try
{
@@ -239,13 +249,14 @@
* @param member the ct member
* @param annotations the actual annotations
* @param className the className
+ * @param commit the commit list
*/
- protected void handleAnnotations(ElementType type, CtMember member, Object[] annotations, String className)
+ protected static void handleAnnotations(ElementType type, CtMember member, Object[] annotations, String className, List<CommitElement> commit)
{
Signature signature = null;
if (member != null)
signature = JavassistSignatureFactory.getSignature(member);
- handleAnnotations(type, signature, annotations, className);
+ handleAnnotations(type, signature, annotations, className, commit);
}
/**
@@ -255,15 +266,16 @@
* @param signature the signature
* @param annotations the actual annotations
* @param className the className
+ * @param commit the commit list
*/
- protected void handleAnnotations(ElementType type, Signature signature, Object[] annotations, String className)
+ protected static void handleAnnotations(ElementType type, Signature signature, Object[] annotations, String className, List<CommitElement> commit)
{
if (annotations != null && annotations.length > 0)
{
for (Object annObject : annotations)
{
Annotation annotation = Annotation.class.cast(annObject);
- env.putAnnotation(annotation, type, className, signature);
+ commit.add(new CommitElement(annotation, type, className, signature));
}
}
}
More information about the jboss-cvs-commits
mailing list