[jboss-cvs] JBossAS SVN: r102644 - in projects/scanning/trunk: plugins/src/main/java/org/jboss/scanning/hibernate and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 19 18:30:10 EDT 2010
Author: alesj
Date: 2010-03-19 18:30:09 -0400 (Fri, 19 Mar 2010)
New Revision: 102644
Added:
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java
Modified:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/SingleAnnotationVisitor.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java
Log:
Hierarchy refactoring.
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java 2010-03-19 22:22:59 UTC (rev 102643)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/GenericAnnotationVisitor.java 2010-03-19 22:30:09 UTC (rev 102644)
@@ -29,13 +29,13 @@
import org.jboss.classloading.spi.visitor.ResourceFilter;
import org.jboss.metadata.spi.signature.Signature;
import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.scanning.plugins.visitor.ClassHierarchyResourceVisitor;
import org.jboss.scanning.plugins.visitor.ReflectProvider;
-import org.jboss.scanning.plugins.visitor.ReflectResourceVisitor;
/**
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public class GenericAnnotationVisitor extends ReflectResourceVisitor
+public class GenericAnnotationVisitor extends ClassHierarchyResourceVisitor
{
/** The mutable repository */
private MutableAnnotationRepository repository;
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/SingleAnnotationVisitor.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/SingleAnnotationVisitor.java 2010-03-19 22:22:59 UTC (rev 102643)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/SingleAnnotationVisitor.java 2010-03-19 22:30:09 UTC (rev 102644)
@@ -68,10 +68,4 @@
System.out.println("scanner = " + scanner); // TODO
}
}
-
- @Override
- protected boolean isRelevant(ClassInfo classInfo)
- {
- return false; // we actually don't endup here
- }
}
\ No newline at end of file
Copied: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java (from rev 102643, projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java)
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ClassHierarchyResourceVisitor.java 2010-03-19 22:30:09 UTC (rev 102644)
@@ -0,0 +1,221 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.scanning.plugins.visitor;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+
+import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
+import org.jboss.metadata.spi.signature.MethodParametersSignature;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.reflect.spi.*;
+
+/**
+ * Class hierarchy resource visitor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class ClassHierarchyResourceVisitor extends ReflectResourceVisitor
+{
+ private boolean checkInterfaces;
+ private boolean checkSuper;
+
+ protected ClassHierarchyResourceVisitor(ReflectProvider provider)
+ {
+ super(provider);
+ }
+
+ /**
+ * Is this class info relevant for scanning.
+ *
+ * @param classInfo the class info
+ * @return true if relevant, false otherwise
+ */
+ protected abstract boolean isRelevant(ClassInfo classInfo);
+
+ /**
+ * Handle class adapter for annotations.
+ *
+ * @param classInfo the class info instance
+ * @throws Exception for any annotations lookup problems
+ */
+ protected void handleClass(ClassInfo classInfo) throws Exception
+ {
+ if (classInfo == null || isRelevant(classInfo) == false)
+ return;
+
+ String className = classInfo.getName();
+ if (log.isTraceEnabled())
+ log.trace("Scanning class " + className + " for annotations");
+
+ Annotation[] annotations = classInfo.getUnderlyingAnnotations();
+ handleAnnotations(ElementType.TYPE, (Signature)null, annotations, className);
+
+ handleMembers(ElementType.CONSTRUCTOR, classInfo.getDeclaredConstructors(), className);
+ handleMembers(ElementType.METHOD, classInfo.getDeclaredMethods(), className);
+ handleMembers(ElementType.FIELD, classInfo.getDeclaredFields(), className);
+
+ if (checkInterfaces || checkSuper)
+ {
+ if (checkInterfaces)
+ {
+ // interfaces
+ ClassInfo[] interfaces = classInfo.getInterfaces();
+ if (interfaces != null && interfaces.length > 0)
+ {
+ for (ClassInfo intf : interfaces)
+ handleClass(intf);
+ }
+ }
+
+ if (checkSuper)
+ {
+ // super class
+ handleClass(classInfo.getSuperclass());
+ }
+ }
+ }
+
+ /**
+ * Handle members for annotations.
+ *
+ * @param type where we found the annotations
+ * @param members the member instances
+ * @param className the className
+ * @throws Exception for any annotations lookup problems
+ */
+ protected void handleMembers(ElementType type, AnnotatedInfo[] members, String className) throws Exception
+ {
+ if (members != null && members.length > 0)
+ {
+ for (AnnotatedInfo ainfo : members)
+ {
+ if (ainfo instanceof MemberInfo == false)
+ throw new IllegalArgumentException("Can only handle member info: " + ainfo);
+
+ Annotation[] annotations = ainfo.getUnderlyingAnnotations();
+ MemberInfo member = MemberInfo.class.cast(ainfo);
+ handleAnnotations(type, member, annotations, className);
+ if (isParametrized(ainfo))
+ {
+ Annotation[][] paramAnnotations = getParameterAnnotations(member);
+ for (int index = 0; index < paramAnnotations.length; index++)
+ {
+ Signature signature = getParameterSignature(member, index);
+ handleAnnotations(ElementType.PARAMETER, signature, paramAnnotations[index], className);
+ }
+ }
+ }
+ }
+ }
+
+ protected boolean isParametrized(AnnotatedInfo member)
+ {
+ return member instanceof MethodInfo || member instanceof ConstructorInfo;
+ }
+
+ protected Annotation[][] getParameterAnnotations(MemberInfo info)
+ {
+ ParameterInfo[] pinfos;
+ if (info instanceof ConstructorInfo)
+ {
+ ConstructorInfo ci = ConstructorInfo.class.cast(info);
+ pinfos = ci.getParameters();
+ }
+ else if (info instanceof MethodInfo)
+ {
+ MethodInfo mi = MethodInfo.class.cast(info);
+ pinfos = mi.getParameters();
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot handle info: " + info);
+ }
+
+ Annotation[][] values = new Annotation[pinfos.length][];
+ for (int i = 0; i < pinfos.length; i++)
+ {
+ ParameterInfo pi = pinfos[i];
+ values[i] = pi.getUnderlyingAnnotations();
+ }
+ return values;
+ }
+
+ protected Signature getParameterSignature(MemberInfo info, int index)
+ {
+ if (info instanceof ConstructorInfo)
+ {
+ ConstructorInfo ci = ConstructorInfo.class.cast(info);
+ return new ConstructorParametersSignature(ci, index);
+ }
+ else if (info instanceof MethodInfo)
+ {
+ MethodInfo mi = MethodInfo.class.cast(info);
+ return new MethodParametersSignature(mi, index);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot handle info: " + info);
+ }
+ }
+
+ /**
+ * Handle annotations.
+ *
+ * @param type where we found the annotations
+ * @param member the member
+ * @param annotations the actual annotations
+ * @param className the className
+ * @throws Exception for any annotations lookup problems
+ */
+ protected void handleAnnotations(ElementType type, MemberInfo member, Annotation[] annotations, String className) throws Exception
+ {
+ Signature signature = null;
+ if (member != null)
+ signature = Signature.getSignature(member);
+
+ handleAnnotations(type, signature, annotations, className);
+ }
+
+ /**
+ * Handle annotations.
+ *
+ * @param type where we found the annotations
+ * @param signature the signature
+ * @param annotations the actual annotations
+ * @param className the className
+ */
+ protected void handleAnnotations(ElementType type, Signature signature, Annotation[] annotations, String className)
+ {
+ }
+
+ public void setCheckInterfaces(boolean checkInterfaces)
+ {
+ this.checkInterfaces = checkInterfaces;
+ }
+
+ public void setCheckSuper(boolean checkSuper)
+ {
+ this.checkSuper = checkSuper;
+ }
+}
\ No newline at end of file
Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java 2010-03-19 22:22:59 UTC (rev 102643)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/visitor/ReflectResourceVisitor.java 2010-03-19 22:30:09 UTC (rev 102644)
@@ -22,16 +22,11 @@
package org.jboss.scanning.plugins.visitor;
-import java.lang.annotation.Annotation;
-import java.lang.annotation.ElementType;
-
import org.jboss.classloading.spi.visitor.ResourceContext;
import org.jboss.classloading.spi.visitor.ResourceVisitor;
import org.jboss.logging.Logger;
-import org.jboss.metadata.spi.signature.ConstructorParametersSignature;
-import org.jboss.metadata.spi.signature.MethodParametersSignature;
-import org.jboss.metadata.spi.signature.Signature;
-import org.jboss.reflect.spi.*;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.TypeInfo;
/**
* Reflect based resource visitor.
@@ -43,11 +38,8 @@
protected final Logger log = Logger.getLogger(getClass());
private ReflectProvider provider;
+ protected boolean failOnError;
- private boolean failOnError;
- private boolean checkInterfaces;
- private boolean checkSuper;
-
protected ReflectResourceVisitor(ReflectProvider provider)
{
if (provider == null)
@@ -114,26 +106,6 @@
}
/**
- * Log throwable.
- *
- * @param resource the resource we're visiting
- * @param t the throwable
- */
- protected void logThrowable(ResourceContext resource, Throwable t)
- {
- if (log.isTraceEnabled())
- log.trace("Exception reading resource: " + resource.getResourceName(), t);
- }
-
- /**
- * Is this class info relevant for scanning.
- *
- * @param classInfo the class info
- * @return true if relevant, false otherwise
- */
- protected abstract boolean isRelevant(ClassInfo classInfo);
-
- /**
* Handle class adapter for annotations.
*
* @param classInfo the class info instance
@@ -141,166 +113,22 @@
*/
protected void handleClass(ClassInfo classInfo) throws Exception
{
- if (classInfo == null || isRelevant(classInfo) == false)
- return;
-
- String className = classInfo.getName();
- if (log.isTraceEnabled())
- log.trace("Scanning class " + className + " for annotations");
-
- Annotation[] annotations = classInfo.getUnderlyingAnnotations();
- handleAnnotations(ElementType.TYPE, (Signature)null, annotations, className);
-
- handleMembers(ElementType.CONSTRUCTOR, classInfo.getDeclaredConstructors(), className);
- handleMembers(ElementType.METHOD, classInfo.getDeclaredMethods(), className);
- handleMembers(ElementType.FIELD, classInfo.getDeclaredFields(), className);
-
- if (checkInterfaces || checkSuper)
- {
- if (checkInterfaces)
- {
- // interfaces
- ClassInfo[] interfaces = classInfo.getInterfaces();
- if (interfaces != null && interfaces.length > 0)
- {
- for (ClassInfo intf : interfaces)
- handleClass(intf);
- }
- }
-
- if (checkSuper)
- {
- // super class
- handleClass(classInfo.getSuperclass());
- }
- }
}
/**
- * Handle members for annotations.
+ * Log throwable.
*
- * @param type where we found the annotations
- * @param members the member instances
- * @param className the className
- * @throws Exception for any annotations lookup problems
+ * @param resource the resource we're visiting
+ * @param t the throwable
*/
- protected void handleMembers(ElementType type, AnnotatedInfo[] members, String className) throws Exception
+ protected void logThrowable(ResourceContext resource, Throwable t)
{
- if (members != null && members.length > 0)
- {
- for (AnnotatedInfo ainfo : members)
- {
- if (ainfo instanceof MemberInfo == false)
- throw new IllegalArgumentException("Can only handle member info: " + ainfo);
-
- Annotation[] annotations = ainfo.getUnderlyingAnnotations();
- MemberInfo member = MemberInfo.class.cast(ainfo);
- handleAnnotations(type, member, annotations, className);
- if (isParametrized(ainfo))
- {
- Annotation[][] paramAnnotations = getParameterAnnotations(member);
- for (int index = 0; index < paramAnnotations.length; index++)
- {
- Signature signature = getParameterSignature(member, index);
- handleAnnotations(ElementType.PARAMETER, signature, paramAnnotations[index], className);
- }
- }
- }
- }
+ if (log.isTraceEnabled())
+ log.trace("Exception reading resource: " + resource.getResourceName(), t);
}
- protected boolean isParametrized(AnnotatedInfo member)
- {
- return member instanceof MethodInfo || member instanceof ConstructorInfo;
- }
-
- protected Annotation[][] getParameterAnnotations(MemberInfo info)
- {
- ParameterInfo[] pinfos;
- if (info instanceof ConstructorInfo)
- {
- ConstructorInfo ci = ConstructorInfo.class.cast(info);
- pinfos = ci.getParameters();
- }
- else if (info instanceof MethodInfo)
- {
- MethodInfo mi = MethodInfo.class.cast(info);
- pinfos = mi.getParameters();
- }
- else
- {
- throw new IllegalArgumentException("Cannot handle info: " + info);
- }
-
- Annotation[][] values = new Annotation[pinfos.length][];
- for (int i = 0; i < pinfos.length; i++)
- {
- ParameterInfo pi = pinfos[i];
- values[i] = pi.getUnderlyingAnnotations();
- }
- return values;
- }
-
- protected Signature getParameterSignature(MemberInfo info, int index)
- {
- if (info instanceof ConstructorInfo)
- {
- ConstructorInfo ci = ConstructorInfo.class.cast(info);
- return new ConstructorParametersSignature(ci, index);
- }
- else if (info instanceof MethodInfo)
- {
- MethodInfo mi = MethodInfo.class.cast(info);
- return new MethodParametersSignature(mi, index);
- }
- else
- {
- throw new IllegalArgumentException("Cannot handle info: " + info);
- }
- }
-
- /**
- * Handle annotations.
- *
- * @param type where we found the annotations
- * @param member the member
- * @param annotations the actual annotations
- * @param className the className
- * @throws Exception for any annotations lookup problems
- */
- protected void handleAnnotations(ElementType type, MemberInfo member, Annotation[] annotations, String className) throws Exception
- {
- Signature signature = null;
- if (member != null)
- signature = Signature.getSignature(member);
-
- handleAnnotations(type, signature, annotations, className);
- }
-
- /**
- * Handle annotations.
- *
- * @param type where we found the annotations
- * @param signature the signature
- * @param annotations the actual annotations
- * @param className the className
- */
- protected void handleAnnotations(ElementType type, Signature signature, Annotation[] annotations, String className)
- {
- }
-
public void setFailOnError(boolean failOnError)
{
this.failOnError = failOnError;
}
-
- public void setCheckInterfaces(boolean checkInterfaces)
- {
- this.checkInterfaces = checkInterfaces;
- }
-
- public void setCheckSuper(boolean checkSuper)
- {
- this.checkSuper = checkSuper;
- }
}
More information about the jboss-cvs-commits
mailing list