[jboss-cvs] JBossAS SVN: r92284 - in projects/annotations/trunk/core/src/main/java/org/jboss/annotations: impl and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 12 17:05:20 EDT 2009
Author: jesper.pedersen
Date: 2009-08-12 17:05:20 -0400 (Wed, 12 Aug 2009)
New Revision: 92284
Modified:
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationScanner.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractAnnotationScanner.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractJavassistAnnotationScanner.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/BinaryLoader.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/XMLLoader.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java
Log:
[JBANN-10] Create the JBoss Annotations XSD (Part 3)
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationScanner.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationScanner.java 2009-08-12 20:50:18 UTC (rev 92283)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/AnnotationScanner.java 2009-08-12 21:05:20 UTC (rev 92284)
@@ -32,14 +32,14 @@
{
/**
* Scan
- * @param urls The URLs with .class or .jar files
+ * @param urls The URLs with the .jar files
* @return The annotation repository
*/
public AnnotationRepository scan(URL[] urls);
/**
* Scan using additional classloader to resolve annotation class definitions
- * @param urls The URLs with .class .files
+ * @param urls The URLs with the .jar files
* @param cls Additional class loaders
* @return The annotation repository
*/
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractAnnotationScanner.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractAnnotationScanner.java 2009-08-12 20:50:18 UTC (rev 92283)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractAnnotationScanner.java 2009-08-12 21:05:20 UTC (rev 92284)
@@ -24,13 +24,20 @@
import org.jboss.annotations.AnnotationRepository;
import org.jboss.annotations.AnnotationScanner;
+import org.jboss.annotations.impl.BinaryLoader;
+import org.jboss.annotations.impl.Scan;
+import org.jboss.annotations.impl.XMLLoader;
import org.jboss.annotations.util.ClassScanner;
import org.jboss.annotations.util.JarScanner;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -43,6 +50,12 @@
private static Logger log;
private static boolean trace;
+ /** Name of the binary metadata */
+ public static final String JBOSS_ANNOTATION_BINARY = "jboss-annotation.ser";
+
+ /** Name of the XML metadata */
+ public static final String JBOSS_ANNOTATION_XML = "jboss-annotation.xml";
+
/**
* Constructor
* @param logger The logger name
@@ -113,6 +126,71 @@
}
/**
+ * Check a JAR file for metadata
+ * @param jarFile The JAR file
+ * @return The scan definition; <code>null</code> if no metadata is found
+ */
+ protected Scan getScan(JarFile jarFile)
+ {
+ Scan result = null;
+
+ InputStream binaryIS = null;
+ InputStream xmlIS = null;
+
+ try
+ {
+ JarEntry binary = jarFile.getJarEntry("META-INF/" + JBOSS_ANNOTATION_BINARY);
+ if (binary != null)
+ {
+ binaryIS = jarFile.getInputStream(binary);
+ result = BinaryLoader.loadJBossAnnotation(binaryIS);
+ }
+
+ if (result == null)
+ {
+ JarEntry xml = jarFile.getJarEntry("META-INF/" + JBOSS_ANNOTATION_XML);
+ if (xml != null)
+ {
+ xmlIS = jarFile.getInputStream(xml);
+ result = XMLLoader.loadJBossAnnotation(xmlIS);
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ log.finest(t.getMessage());
+ }
+ finally
+ {
+ if (binaryIS != null)
+ {
+ try
+ {
+ binaryIS.close();
+ }
+ catch (IOException ioe)
+ {
+ // Ignore
+ }
+ }
+
+ if (xmlIS != null)
+ {
+ try
+ {
+ xmlIS.close();
+ }
+ catch (IOException ioe)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
* Scan
* @param urls The URLs with class files
* @return The map of annotations
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractJavassistAnnotationScanner.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractJavassistAnnotationScanner.java 2009-08-12 20:50:18 UTC (rev 92283)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractJavassistAnnotationScanner.java 2009-08-12 21:05:20 UTC (rev 92284)
@@ -24,6 +24,7 @@
import org.jboss.annotations.Annotation;
import org.jboss.annotations.AnnotationType;
+import org.jboss.annotations.impl.ScanClass;
import java.util.Collection;
import java.util.HashSet;
@@ -38,7 +39,7 @@
import javassist.NotFoundException;
/**
- * An abstract annotation scanner - base class
+ * An abstract annotation scanner - base class for Javassist based implementations
* @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
*/
public abstract class AbstractJavassistAnnotationScanner extends AbstractAnnotationScanner
@@ -61,10 +62,12 @@
/**
* Process class
* @param ctClass The class
+ * @param scanClass The scan class structure; <code>null</code> if no information about the class
* @param result The resulting map
* @exception NotFoundException Thrown if the class types cant be resolved
*/
- protected void processClass(CtClass ctClass, Map<String, Collection<Annotation>> result) throws NotFoundException
+ protected void processClass(CtClass ctClass, ScanClass scanClass, Map<String, Collection<Annotation>> result)
+ throws NotFoundException
{
if (trace)
log.finest("Class=" + ctClass.getName());
@@ -94,30 +97,33 @@
if (trace)
log.finest("Constructor=" + constructor.getName());
- Object[] constructorAnnotations = constructor.getAvailableAnnotations();
- if (constructorAnnotations != null)
+ String[] parameterTypes = null;
+ CtClass[] parameters = constructor.getParameterTypes();
+ if (parameters != null && parameters.length > 0)
{
- String[] parameterTypes = null;
- CtClass[] parameters = constructor.getParameterTypes();
- if (parameters != null && parameters.length > 0)
+ parameterTypes = new String[parameters.length];
+ for (int i = 0; i < parameters.length; i++)
{
- parameterTypes = new String[parameters.length];
- for (int i = 0; i < parameters.length; i++)
+ parameterTypes[i] = parameters[i].getName();
+
+ if (trace)
+ log.finest("Parameter=" + parameters[i].getName());
+ }
+ }
+
+ if (scanClass == null || scanClass.hasConstructor(parameterTypes))
+ {
+ Object[] constructorAnnotations = constructor.getAvailableAnnotations();
+ if (constructorAnnotations != null)
+ {
+ for (Object annotation : constructorAnnotations)
{
- parameterTypes[i] = parameters[i].getName();
-
- if (trace)
- log.finest("Parameter=" + parameters[i].getName());
+ processAnnotation(annotation,
+ AnnotationType.CONSTRUCTOR,
+ ctClass.getName(), null, parameterTypes,
+ result);
}
}
-
- for (Object annotation : constructorAnnotations)
- {
- processAnnotation(annotation,
- AnnotationType.CONSTRUCTOR,
- ctClass.getName(), null, parameterTypes,
- result);
- }
}
}
}
@@ -132,29 +138,32 @@
if (trace)
log.finest("Method=" + method.getName());
- Object[] methodAnnotations = method.getAvailableAnnotations();
- if (methodAnnotations != null)
+ String[] parameterTypes = null;
+ CtClass[] parameters = method.getParameterTypes();
+ if (parameters != null && parameters.length > 0)
{
- String[] parameterTypes = null;
- CtClass[] parameters = method.getParameterTypes();
- if (parameters != null && parameters.length > 0)
+ parameterTypes = new String[parameters.length];
+ for (int i = 0; i < parameters.length; i++)
{
- parameterTypes = new String[parameters.length];
- for (int i = 0; i < parameters.length; i++)
- {
- parameterTypes[i] = parameters[i].getName();
+ parameterTypes[i] = parameters[i].getName();
- if (trace)
- log.finest("Parameter=" + parameters[i].getName());
- }
+ if (trace)
+ log.finest("Parameter=" + parameters[i].getName());
}
-
- for (Object annotation : methodAnnotations)
+ }
+
+ if (scanClass == null || scanClass.hasMethod(method.getName(), parameterTypes))
+ {
+ Object[] methodAnnotations = method.getAvailableAnnotations();
+ if (methodAnnotations != null)
{
- processAnnotation(annotation,
- AnnotationType.METHOD,
- ctClass.getName(), method.getName(), parameterTypes,
- result);
+ for (Object annotation : methodAnnotations)
+ {
+ processAnnotation(annotation,
+ AnnotationType.METHOD,
+ ctClass.getName(), method.getName(), parameterTypes,
+ result);
+ }
}
}
}
@@ -171,15 +180,18 @@
if (trace)
log.finest("Field=" + field.getName());
- Object[] fieldAnnotations = field.getAvailableAnnotations();
- if (fieldAnnotations != null)
+ if (scanClass == null || scanClass.hasField(field.getName()))
{
- for (Object annotation : fieldAnnotations)
+ Object[] fieldAnnotations = field.getAvailableAnnotations();
+ if (fieldAnnotations != null)
{
- processAnnotation(annotation,
- AnnotationType.FIELD,
- ctClass.getName(), field.getName(), null,
- result);
+ for (Object annotation : fieldAnnotations)
+ {
+ processAnnotation(annotation,
+ AnnotationType.FIELD,
+ ctClass.getName(), field.getName(), null,
+ result);
+ }
}
}
}
@@ -192,52 +204,55 @@
{
for (CtClass interfaceClass : interfaces)
{
- // Interface level annotations
- Object[] interfaceAnnotations = interfaceClass.getAvailableAnnotations();
+ if (!interfaceClass.getName().startsWith("java."))
+ {
+ // Interface level annotations
+ Object[] interfaceAnnotations = interfaceClass.getAvailableAnnotations();
- if (interfaceAnnotations != null)
- {
- for (Object annotation : interfaceAnnotations)
+ if (interfaceAnnotations != null)
{
- processAnnotation(annotation,
- AnnotationType.CLASS,
- ctClass.getName(), null, null,
- result);
+ for (Object annotation : interfaceAnnotations)
+ {
+ processAnnotation(annotation,
+ AnnotationType.CLASS,
+ ctClass.getName(), null, null,
+ result);
+ }
}
- }
- // Interface method level annotations
- CtMethod[] interfaceMethods = interfaceClass.getDeclaredMethods();
- if (interfaceMethods != null)
- {
- for (CtMethod method : interfaceMethods)
+ // Interface method level annotations
+ CtMethod[] interfaceMethods = interfaceClass.getDeclaredMethods();
+ if (interfaceMethods != null)
{
- if (trace)
- log.finest("Interface Method=" + method.getName());
+ for (CtMethod method : interfaceMethods)
+ {
+ if (trace)
+ log.finest("Interface Method=" + method.getName());
- Object[] methodAnnotations = method.getAvailableAnnotations();
- if (methodAnnotations != null)
- {
- String[] parameterTypes = null;
- CtClass[] parameters = method.getParameterTypes();
- if (parameters != null && parameters.length > 0)
+ Object[] methodAnnotations = method.getAvailableAnnotations();
+ if (methodAnnotations != null)
{
- parameterTypes = new String[parameters.length];
- for (int i = 0; i < parameters.length; i++)
+ String[] parameterTypes = null;
+ CtClass[] parameters = method.getParameterTypes();
+ if (parameters != null && parameters.length > 0)
{
- parameterTypes[i] = parameters[i].getName();
+ parameterTypes = new String[parameters.length];
+ for (int i = 0; i < parameters.length; i++)
+ {
+ parameterTypes[i] = parameters[i].getName();
- if (trace)
- log.finest("Interface Parameter=" + parameters[i].getName());
+ if (trace)
+ log.finest("Interface Parameter=" + parameters[i].getName());
+ }
}
- }
- for (Object annotation : methodAnnotations)
- {
- processAnnotation(annotation,
- AnnotationType.METHOD,
- ctClass.getName(), method.getName(), parameterTypes,
- result);
+ for (Object annotation : methodAnnotations)
+ {
+ processAnnotation(annotation,
+ AnnotationType.METHOD,
+ ctClass.getName(), method.getName(), parameterTypes,
+ result);
+ }
}
}
}
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/BinaryLoader.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/BinaryLoader.java 2009-08-12 20:50:18 UTC (rev 92283)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/BinaryLoader.java 2009-08-12 21:05:20 UTC (rev 92284)
@@ -48,7 +48,7 @@
* @return The scanning representation; <code>null</code> if no representation
* can be created
*/
- public Scan loadJBossAnnotation(InputStream is)
+ public static Scan loadJBossAnnotation(InputStream is)
{
Scan result = null;
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/XMLLoader.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/XMLLoader.java 2009-08-12 20:50:18 UTC (rev 92283)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/XMLLoader.java 2009-08-12 21:05:20 UTC (rev 92284)
@@ -61,7 +61,7 @@
* @return The scanning representation; <code>null</code> if no representation
* can be created
*/
- public Scan loadJBossAnnotation(InputStream is)
+ public static Scan loadJBossAnnotation(InputStream is)
{
Scan result = null;
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java 2009-08-12 20:50:18 UTC (rev 92283)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java 2009-08-12 21:05:20 UTC (rev 92284)
@@ -27,9 +27,12 @@
import org.jboss.annotations.AnnotationType;
import org.jboss.annotations.impl.AbstractAnnotationScanner;
import org.jboss.annotations.impl.AnnotationRepositoryImpl;
+import org.jboss.annotations.impl.Scan;
+import org.jboss.annotations.impl.ScanClass;
import java.io.Closeable;
import java.io.IOException;
+import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -42,6 +45,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -80,184 +84,236 @@
{
URLClassLoader cl = SecurityActions.createURLCLassLoader(urls, null);
- List<String> classes = getClassNames(urls);
- if (classes != null)
+ for (URL u : urls)
{
- for (String className : classes)
+ JarFile jar = null;
+ try
{
- try
+ List<String> classes = getClassNames(new URL[] {u});
+ if (classes != null)
{
- Class clz = Class.forName(className, false, cl);
+ File jarFile = new File(u.toURI());
+ jar = new JarFile(jarFile);
- if (trace)
- log.finest("Class=" + clz.getName());
+ Scan scan = getScan(jar);
- if (!clz.isAnnotation() &&
- (!Modifier.isAbstract(clz.getModifiers()) || clz.isInterface()))
+ for (String className : classes)
{
- java.lang.annotation.Annotation[] classAnnotations = clz.getAnnotations();
- if (classAnnotations != null)
+ try
{
- for (java.lang.annotation.Annotation annotation : classAnnotations)
- {
- processAnnotation(annotation,
- AnnotationType.CLASS,
- clz.getName(), null, null,
- result);
- }
- }
+ Class clz = Class.forName(className, false, cl);
- Constructor[] constructors = clz.getDeclaredConstructors();
- if (constructors != null)
- {
- for (Constructor constructor : constructors)
- {
- if (trace)
- log.finest("Constructor=" + constructor.getName());
+ ScanClass scanClass = null;
+ if (scan != null)
+ scanClass = scan.getClass(clz.getName());
- java.lang.annotation.Annotation[] constructorAnnotations =
- constructor.getDeclaredAnnotations();
+ if (trace)
+ log.finest("Class=" + clz.getName());
- if (constructorAnnotations != null)
+ if (!clz.isAnnotation() &&
+ (!Modifier.isAbstract(clz.getModifiers()) || clz.isInterface()))
+ {
+ java.lang.annotation.Annotation[] classAnnotations = clz.getAnnotations();
+ if (classAnnotations != null)
{
- String[] parameterTypes = null;
- Class[] parameters = constructor.getParameterTypes();
- if (parameters != null && parameters.length > 0)
+ for (java.lang.annotation.Annotation annotation : classAnnotations)
{
- parameterTypes = new String[parameters.length];
- for (int i = 0; i < parameters.length; i++)
- {
- parameterTypes[i] = parameters[i].getName();
-
- if (trace)
- log.finest("Parameter=" + parameters[i].getName());
- }
- }
-
- for (java.lang.annotation.Annotation annotation : constructorAnnotations)
- {
- processAnnotation(annotation, AnnotationType.CONSTRUCTOR,
- clz.getName(), null, parameterTypes,
+ processAnnotation(annotation,
+ AnnotationType.CLASS,
+ clz.getName(), null, null,
result);
}
}
- }
- }
-
- Method[] methods = clz.getDeclaredMethods();
- if (methods != null)
- {
- for (Method method : methods)
- {
- if (trace)
- log.finest("Method=" + method.getName());
-
- java.lang.annotation.Annotation[] methodAnnotations = method.getDeclaredAnnotations();
- if (methodAnnotations != null)
+
+ if (!clz.isInterface())
{
- String[] parameterTypes = null;
- Class[] parameters = method.getParameterTypes();
- if (parameters != null && parameters.length > 0)
+ Constructor[] constructors = clz.getDeclaredConstructors();
+ if (constructors != null)
{
- parameterTypes = new String[parameters.length];
- for (int i = 0; i < parameters.length; i++)
+ for (Constructor constructor : constructors)
{
- parameterTypes[i] = parameters[i].getName();
+ if (trace)
+ log.finest("Constructor=" + constructor.getName());
- if (trace)
- log.finest("Parameter=" + parameters[i].getName());
+ String[] parameterTypes = null;
+ Class[] parameters = constructor.getParameterTypes();
+ if (parameters != null && parameters.length > 0)
+ {
+ parameterTypes = new String[parameters.length];
+ for (int i = 0; i < parameters.length; i++)
+ {
+ parameterTypes[i] = parameters[i].getName();
+
+ if (trace)
+ log.finest("Parameter=" + parameters[i].getName());
+ }
+ }
+
+ if (scanClass == null || scanClass.hasConstructor(parameterTypes))
+ {
+ java.lang.annotation.Annotation[] constructorAnnotations =
+ constructor.getDeclaredAnnotations();
+
+ if (constructorAnnotations != null)
+ {
+ for (java.lang.annotation.Annotation annotation : constructorAnnotations)
+ {
+ processAnnotation(annotation, AnnotationType.CONSTRUCTOR,
+ clz.getName(), null, parameterTypes,
+ result);
+ }
+ }
+ }
}
}
-
- for (java.lang.annotation.Annotation annotation : methodAnnotations)
- {
- processAnnotation(annotation, AnnotationType.METHOD,
- clz.getName(), method.getName(), parameterTypes,
- result);
- }
}
- }
- }
- Field[] fields = clz.getDeclaredFields();
- if (fields != null)
- {
- for (Field field : fields)
- {
- if (trace)
- log.finest("Field=" + field.getName());
-
- java.lang.annotation.Annotation[] fieldAnnotations = field.getDeclaredAnnotations();
- if (fieldAnnotations != null)
+ Method[] methods = clz.getDeclaredMethods();
+ if (methods != null)
{
- for (java.lang.annotation.Annotation annotation : fieldAnnotations)
+ for (Method method : methods)
{
- processAnnotation(annotation, AnnotationType.FIELD,
- clz.getName(), field.getName(), null,
- result);
+ if (trace)
+ log.finest("Method=" + method.getName());
+
+ String[] parameterTypes = null;
+ Class[] parameters = method.getParameterTypes();
+ if (parameters != null && parameters.length > 0)
+ {
+ parameterTypes = new String[parameters.length];
+ for (int i = 0; i < parameters.length; i++)
+ {
+ parameterTypes[i] = parameters[i].getName();
+
+ if (trace)
+ log.finest("Parameter=" + parameters[i].getName());
+ }
+ }
+
+ if (scanClass == null || scanClass.hasMethod(method.getName(), parameterTypes))
+ {
+ java.lang.annotation.Annotation[] methodAnnotations = method.getDeclaredAnnotations();
+ if (methodAnnotations != null)
+ {
+ for (java.lang.annotation.Annotation annotation : methodAnnotations)
+ {
+ processAnnotation(annotation, AnnotationType.METHOD,
+ clz.getName(), method.getName(), parameterTypes,
+ result);
+ }
+ }
+ }
}
}
- }
- }
- Class[] interfaces = clz.getInterfaces();
- if (interfaces != null)
- {
- for (Class interfaceClass : interfaces)
- {
- java.lang.annotation.Annotation[] interfaceAnnotations = interfaceClass.getAnnotations();
- if (interfaceAnnotations != null)
+ if (!clz.isInterface())
{
- for (java.lang.annotation.Annotation annotation : interfaceAnnotations)
+ Field[] fields = clz.getDeclaredFields();
+ if (fields != null)
{
- processAnnotation(annotation,
- AnnotationType.CLASS,
- clz.getName(), null, null,
- result);
+ for (Field field : fields)
+ {
+ if (trace)
+ log.finest("Field=" + field.getName());
+
+ if (scanClass == null || scanClass.hasField(field.getName()))
+ {
+ java.lang.annotation.Annotation[] fieldAnnotations = field.getDeclaredAnnotations();
+ if (fieldAnnotations != null)
+ {
+ for (java.lang.annotation.Annotation annotation : fieldAnnotations)
+ {
+ processAnnotation(annotation, AnnotationType.FIELD,
+ clz.getName(), field.getName(), null,
+ result);
+ }
+ }
+ }
+ }
}
}
- Method[] interfaceMethods = interfaceClass.getDeclaredMethods();
- if (interfaceMethods != null)
+ Class[] interfaces = clz.getInterfaces();
+ if (interfaces != null)
{
- for (Method method : interfaceMethods)
+ for (Class interfaceClass : interfaces)
{
- if (trace)
- log.finest("Interface Method=" + method.getName());
-
- java.lang.annotation.Annotation[] methodAnnotations = method.getDeclaredAnnotations();
- if (methodAnnotations != null)
+ if (!interfaceClass.getName().startsWith("java."))
{
- String[] parameterTypes = null;
- Class[] parameters = method.getParameterTypes();
- if (parameters != null && parameters.length > 0)
+ java.lang.annotation.Annotation[] interfaceAnnotations = interfaceClass.getAnnotations();
+ if (interfaceAnnotations != null)
{
- parameterTypes = new String[parameters.length];
- for (int i = 0; i < parameters.length; i++)
+ for (java.lang.annotation.Annotation annotation : interfaceAnnotations)
{
- parameterTypes[i] = parameters[i].getName();
-
- if (trace)
- log.finest("Interface Parameter=" + parameters[i].getName());
+ processAnnotation(annotation,
+ AnnotationType.CLASS,
+ clz.getName(), null, null,
+ result);
}
}
- for (java.lang.annotation.Annotation annotation : methodAnnotations)
+ Method[] interfaceMethods = interfaceClass.getDeclaredMethods();
+ if (interfaceMethods != null)
{
- processAnnotation(annotation, AnnotationType.METHOD,
- clz.getName(), method.getName(), parameterTypes,
- result);
+ for (Method method : interfaceMethods)
+ {
+ if (trace)
+ log.finest("Interface Method=" + method.getName());
+
+ java.lang.annotation.Annotation[] methodAnnotations = method.getDeclaredAnnotations();
+ if (methodAnnotations != null)
+ {
+ String[] parameterTypes = null;
+ Class[] parameters = method.getParameterTypes();
+ if (parameters != null && parameters.length > 0)
+ {
+ parameterTypes = new String[parameters.length];
+ for (int i = 0; i < parameters.length; i++)
+ {
+ parameterTypes[i] = parameters[i].getName();
+
+ if (trace)
+ log.finest("Interface Parameter=" + parameters[i].getName());
+ }
+ }
+
+ for (java.lang.annotation.Annotation annotation : methodAnnotations)
+ {
+ processAnnotation(annotation, AnnotationType.METHOD,
+ clz.getName(), method.getName(), parameterTypes,
+ result);
+ }
+ }
+ }
}
}
}
}
}
}
+ catch (Throwable t)
+ {
+ // Ignore
+ }
}
}
- catch (Throwable t)
+ }
+ catch (Throwable t)
+ {
+ // Shouldn't happen - nothing we can do
+ }
+ finally
+ {
+ if (jar != null)
{
- // Shouldn't happen - nothing we can do
+ try
+ {
+ jar.close();
+ }
+ catch (IOException ioe)
+ {
+ // Ignore
+ }
}
}
}
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java 2009-08-12 20:50:18 UTC (rev 92283)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java 2009-08-12 21:05:20 UTC (rev 92284)
@@ -26,9 +26,12 @@
import org.jboss.annotations.AnnotationRepository;
import org.jboss.annotations.impl.AbstractJavassistAnnotationScanner;
import org.jboss.annotations.impl.AnnotationRepositoryImpl;
+import org.jboss.annotations.impl.Scan;
+import org.jboss.annotations.impl.ScanClass;
import java.io.Closeable;
import java.io.IOException;
+import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
@@ -36,6 +39,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -91,25 +95,64 @@
}
}
- List<String> classes = getClassNames(urls);
- if (classes != null)
+
+ for (URL u : urls)
{
- for (String className : classes)
+ List<String> classes = getClassNames(new URL[] {u});
+ if (classes != null)
{
+ JarFile jar = null;
try
{
- CtClass ctClass = cp.get(className);
+ File jarFile = new File(u.toURI());
+ jar = new JarFile(jarFile);
- if (ctClass.getClassFile2().getMajorVersion() >= ClassFile.JAVA_5 && !ctClass.isAnnotation() &&
- (!Modifier.isAbstract(ctClass.getModifiers()) || ctClass.isInterface()))
+ Scan scan = getScan(jar);
+
+ for (String className : classes)
{
- processClass(ctClass, result);
+ try
+ {
+ CtClass ctClass = cp.get(className);
+
+ if (ctClass.getClassFile2().getMajorVersion() >= ClassFile.JAVA_5 && !ctClass.isAnnotation() &&
+ (!Modifier.isAbstract(ctClass.getModifiers()) || ctClass.isInterface()))
+ {
+ if (scan == null || scan.hasClass(ctClass.getName()))
+ {
+ ScanClass scanClass = null;
+
+ if (scan != null)
+ scanClass = scan.getClass(ctClass.getName());
+
+ processClass(ctClass, scanClass, result);
+ }
+ }
+ }
+ catch (NotFoundException nfe)
+ {
+ // Shouldn't happen - nothing we can do
+ }
}
}
- catch (NotFoundException nfe)
+ catch (Throwable t)
{
- // Shouldn't happen - nothing we can do
+ // Ignore
}
+ finally
+ {
+ if (jar != null)
+ {
+ try
+ {
+ jar.close();
+ }
+ catch (IOException ioe)
+ {
+ // Ignore
+ }
+ }
+ }
}
}
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java 2009-08-12 20:50:18 UTC (rev 92283)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java 2009-08-12 21:05:20 UTC (rev 92284)
@@ -26,6 +26,8 @@
import org.jboss.annotations.AnnotationRepository;
import org.jboss.annotations.impl.AbstractJavassistAnnotationScanner;
import org.jboss.annotations.impl.AnnotationRepositoryImpl;
+import org.jboss.annotations.impl.Scan;
+import org.jboss.annotations.impl.ScanClass;
import java.io.Closeable;
import java.io.File;
@@ -96,11 +98,15 @@
for (URL u : urls)
{
+ JarFile jar = null;
try
{
Boolean isJava5 = null;
File jarFile = new File(u.toURI());
- JarFile jar = new JarFile(jarFile);
+ jar = new JarFile(jarFile);
+
+ Scan scan = getScan(jar);
+
Enumeration<JarEntry> entries = jar.entries();
while ((isJava5 == null || isJava5.booleanValue()) && entries.hasMoreElements())
@@ -130,17 +136,37 @@
if (isJava5.booleanValue() && !ctClass.isAnnotation() &&
(!Modifier.isAbstract(ctClass.getModifiers()) || ctClass.isInterface()))
{
- processClass(ctClass, result);
+ if (scan == null || scan.hasClass(ctClass.getName()))
+ {
+ ScanClass scanClass = null;
+
+ if (scan != null)
+ scanClass = scan.getClass(ctClass.getName());
+
+ processClass(ctClass, scanClass, result);
+ }
}
}
}
-
- jar.close();
}
catch (Throwable t)
{
// Ignore
}
+ finally
+ {
+ if (jar != null)
+ {
+ try
+ {
+ jar.close();
+ }
+ catch (IOException ioe)
+ {
+ // Ignore
+ }
+ }
+ }
}
if (cl != null && cl instanceof Closeable)
More information about the jboss-cvs-commits
mailing list