[jboss-cvs] JBossAS SVN: r92280 - in projects/annotations/trunk/core/src/main: java/org/jboss/annotations/impl and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 12 14:30:47 EDT 2009
Author: jesper.pedersen
Date: 2009-08-12 14:30:46 -0400 (Wed, 12 Aug 2009)
New Revision: 92280
Added:
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/Scan.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/ScanClass.java
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/XMLLoader.java
Modified:
projects/annotations/trunk/core/src/main/java/org/jboss/annotations/Annotation.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
projects/annotations/trunk/core/src/main/resources/jboss-annotation.xsd
Log:
[JBANN-10] Create the JBoss Annotations XSD (Part 1)
Modified: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/Annotation.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/Annotation.java 2009-08-12 17:27:56 UTC (rev 92279)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/Annotation.java 2009-08-12 18:30:46 UTC (rev 92280)
@@ -169,7 +169,7 @@
boolean result = true;
- result = annotation.getClass().getName().equals(a.getAnnotation().getClass().getName());
+ result = annotation.getClass().equals(a.getAnnotation().getClass());
if (result)
result = type.equals(a.getType());
Added: 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 (rev 0)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractAnnotationScanner.java 2009-08-12 18:30:46 UTC (rev 92280)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, 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.annotations.impl;
+
+import org.jboss.annotations.AnnotationRepository;
+import org.jboss.annotations.AnnotationScanner;
+import org.jboss.annotations.util.ClassScanner;
+import org.jboss.annotations.util.JarScanner;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An abstract annotation scanner - base class
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public abstract class AbstractAnnotationScanner implements AnnotationScanner
+{
+ private static Logger log;
+ private static boolean trace;
+
+ /**
+ * Constructor
+ * @param logger The logger name
+ */
+ public AbstractAnnotationScanner(String logger)
+ {
+ log = Logger.getLogger(logger);
+ trace = log.isLoggable(Level.FINEST);
+ }
+
+ /**
+ * Get all the class names
+ * @param urls The urls to be scanned
+ * @return The names
+ */
+ protected List<String> getClassNames(URL[] urls)
+ {
+ List<String> result = new ArrayList<String>();
+
+ for (URL url : urls)
+ {
+ try
+ {
+ log.fine("Checking " + url);
+
+ if ("file".equals(url.getProtocol()))
+ {
+ long start = 0;
+ if (log.isLoggable(Level.FINE))
+ start = System.currentTimeMillis();
+
+ File f = new File(url.getFile());
+
+ List<String> classFiles = null;
+
+ if (url.getPath().endsWith("/"))
+ {
+ classFiles = ClassScanner.scan(f);
+ }
+ else if (url.getPath().endsWith(".jar"))
+ {
+ classFiles = JarScanner.scan(f);
+ }
+
+ if (classFiles != null)
+ {
+ result.addAll(classFiles);
+ }
+
+ if (log.isLoggable(Level.FINE))
+ {
+ long end = System.currentTimeMillis();
+ log.fine("Retrieving classes took " + (end - start) + " ms for " + url.getFile());
+ }
+ }
+ else
+ {
+ log.warning("Protocol not supported: " + url);
+ }
+ }
+ catch (Exception e)
+ {
+ // Nothing we can do
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Scan
+ * @param urls The URLs with class files
+ * @return The map of annotations
+ */
+ public AnnotationRepository scan(URL[] urls)
+ {
+ return scan(urls, (ClassLoader)null);
+ }
+
+ /**
+ * Scan using additional classloader to resolve annotation class definitions
+ * @param urls The URLs with .class .files
+ * @param cls Additional class loaders
+ * @return The annotation repository
+ */
+ public abstract AnnotationRepository scan(URL[] urls, ClassLoader... cls);
+}
Added: 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 (rev 0)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/AbstractJavassistAnnotationScanner.java 2009-08-12 18:30:46 UTC (rev 92280)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, 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.annotations.impl;
+
+import org.jboss.annotations.Annotation;
+import org.jboss.annotations.AnnotationType;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An abstract annotation scanner - base class
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public abstract class AbstractJavassistAnnotationScanner extends AbstractAnnotationScanner
+{
+ private static Logger log;
+ private static boolean trace;
+
+ /**
+ * Constructor
+ * @param logger The logger name
+ */
+ public AbstractJavassistAnnotationScanner(String logger)
+ {
+ super(logger);
+
+ log = Logger.getLogger(logger);
+ trace = log.isLoggable(Level.FINEST);
+ }
+
+
+ /**
+ * Add an annotation to the result map
+ * @param annotation The annotation
+ * @param type The annotation type
+ * @param className The class name
+ * @param memberName The member name
+ * @param parameterTypes The parameter types
+ * @param map The result map
+ */
+ protected void processAnnotation(Object annotation,
+ AnnotationType type, String className, String memberName, String[] parameterTypes,
+ Map<String, Collection<Annotation>> map)
+ {
+ Class annotationClass = annotation.getClass().getInterfaces()[0];
+
+ Annotation a = new Annotation(annotationClass.cast(annotation),
+ type,
+ className, memberName, parameterTypes);
+
+ if (trace)
+ log.finest("Annotation=" + a);
+
+ String key = annotationClass.getName();
+ Collection<Annotation> l = map.get(key);
+ if (l == null)
+ l = new HashSet<Annotation>();
+
+ if (!l.contains(a))
+ l.add(a);
+
+ map.put(key, l);
+ }
+}
Added: 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 (rev 0)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/BinaryLoader.java 2009-08-12 18:30:46 UTC (rev 92280)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, 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.annotations.impl;
+
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.util.logging.Logger;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * The binary loader class
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class BinaryLoader
+{
+ private static Logger log = Logger.getLogger(BinaryLoader.class.getName());
+
+ /**
+ * Constructor
+ */
+ private BinaryLoader()
+ {
+ }
+
+ /**
+ * Loads the internal representation of the jboss-annotation.xml file
+ * @param is The input stream for the binary file
+ * @return The scanning representation; <code>null</code> if no representation
+ * can be created
+ */
+ public Scan loadJBossAnnotation(InputStream is)
+ {
+ Scan result = null;
+
+ try
+ {
+ GZIPInputStream gis = new GZIPInputStream(is);
+ ObjectInputStream ois = new ObjectInputStream(gis);
+
+ result = (Scan)ois.readObject();
+ }
+ catch (Throwable t)
+ {
+ log.finest(t.getMessage());
+ }
+
+ return result;
+ }
+}
Added: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/Scan.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/Scan.java (rev 0)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/Scan.java 2009-08-12 18:30:46 UTC (rev 92280)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, 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.annotations.impl;
+
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * A class that represents which classes that should be scanned
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class Scan implements Serializable
+{
+ /** Serial version UID */
+ private static final long serialVersionUID = 1L;
+
+ /** Exclude all classes */
+ private boolean excludeAll;
+
+ /** The data */
+ private Map<String, ScanClass> data;
+
+ /**
+ * Constructor
+ * @param excludeAll Exclude all classes
+ * @param data The data - fully qualified class name and ScanClass instance
+ */
+ public Scan(boolean excludeAll, Map<String, ScanClass> data)
+ {
+ if (data == null)
+ throw new IllegalArgumentException("Data is null");
+
+ this.excludeAll = excludeAll;
+ this.data = data;
+ }
+
+ /**
+ * Is exclude all
+ * @return True if all classes should be excluded; otherwise false
+ */
+ public boolean isExcludeAll()
+ {
+ return excludeAll;
+ }
+
+ /**
+ * Should the specified class be scanned ?
+ * @param clz The fully qualified class name
+ * @return True if the scanning should include the class; otherwise false
+ */
+ public boolean hasClass(String clz)
+ {
+ if (clz == null)
+ throw new IllegalArgumentException("Clz is null");
+
+ return data.containsKey(clz);
+ }
+
+ /**
+ * Get the scan class data
+ * @param clz The fully qualified class name
+ * @return The data; <code>null</null> if the class is not found
+ */
+ public ScanClass getClass(String clz)
+ {
+ if (clz == null)
+ throw new IllegalArgumentException("Clz is null");
+
+ return data.get(clz);
+ }
+}
Added: projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/ScanClass.java
===================================================================
--- projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/ScanClass.java (rev 0)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/ScanClass.java 2009-08-12 18:30:46 UTC (rev 92280)
@@ -0,0 +1,185 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, 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.annotations.impl;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Represents a class that should be scanned
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class ScanClass implements Serializable
+{
+ /** Serial version UID */
+ private static final long serialVersionUID = 1L;
+
+ /** The class name */
+ private String className;
+
+ /** Fields */
+ private Set<String> fields;
+
+ /** Constructor parameters */
+ private List<String[]> constructors;
+
+ /** Methods */
+ private Map<String, List<String[]>> methods;
+
+ /**
+ * Constructor
+ * @param className The fuly qualified class name
+ */
+ public ScanClass(String className)
+ {
+ this.className = className;
+ this.fields = null;
+ this.constructors = null;
+ this.methods = null;
+ }
+
+ /**
+ * Add a field
+ * @param name The field name
+ */
+ public void addField(String name)
+ {
+ if (fields == null)
+ fields = new HashSet<String>();
+
+ fields.add(name);
+ }
+
+ /**
+ * Has field
+ * @param name The field name
+ * @return True if the field should be scanned; otherwise false
+ */
+ public boolean hasField(String name)
+ {
+ return fields.contains(name);
+ }
+
+ /**
+ * Add a constructor
+ * @param parameters The parameters; <code>null</code> for default constructor
+ */
+ public void addConstructor(String[] parameters)
+ {
+ if (constructors == null)
+ constructors = new ArrayList<String[]>();
+
+ if (parameters == null)
+ {
+ parameters = new String[0];
+ }
+
+ constructors.add(parameters);
+ }
+
+ /**
+ * Has constructor
+ * @param parameters The parameters; <code>null</code> for default constructor
+ * @return True if the constructor should be scanned; otherwise false
+ */
+ public boolean hasConstructor(String[] parameters)
+ {
+ if (constructors == null)
+ return false;
+
+ if (parameters == null)
+ {
+ parameters = new String[0];
+ }
+
+ boolean found = false;
+ for (int i = 0; !found && i < constructors.size(); i++)
+ {
+ String[] current = constructors.get(i);
+ found = Arrays.equals(current, parameters);
+ }
+
+ return found;
+ }
+
+ /**
+ * Add a method
+ * @param name The method name
+ * @param parameters The parameters; <code>null</code> for none
+ */
+ public void addMethod(String name, String[] parameters)
+ {
+ if (methods == null)
+ methods = new HashMap<String, List<String[]>>();
+
+ List<String[]> l = methods.get(name);
+ if (l == null)
+ l = new ArrayList<String[]>();
+
+ if (parameters == null)
+ {
+ parameters = new String[0];
+ }
+
+ l.add(parameters);
+
+ methods.put(name, l);
+ }
+
+ /**
+ * Has method
+ * @param name The method name
+ * @param parameters The parameters; <code>null</code> for none
+ * @return True if the method should be scanned; otherwise false
+ */
+ public boolean hasMethod(String name, String[] parameters)
+ {
+ if (methods == null)
+ return false;
+
+ List<String[]> l = methods.get(name);
+
+ if (l == null)
+ return false;
+
+ if (parameters == null)
+ {
+ parameters = new String[0];
+ }
+
+ boolean found = false;
+ for (int i = 0; !found && i < l.size(); i++)
+ {
+ String[] current = l.get(i);
+ found = Arrays.equals(current, parameters);
+ }
+
+ return found;
+ }
+}
Added: 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 (rev 0)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/impl/XMLLoader.java 2009-08-12 18:30:46 UTC (rev 92280)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, 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.annotations.impl;
+
+import org.jboss.annotations.xml.ClassType;
+import org.jboss.annotations.xml.ConstructorType;
+import org.jboss.annotations.xml.FieldType;
+import org.jboss.annotations.xml.JbossAnnotation;
+import org.jboss.annotations.xml.MethodType;
+import org.jboss.annotations.xml.ParameterType;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
+
+/**
+ * The XML loader class
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class XMLLoader
+{
+ private static Logger log = Logger.getLogger(XMLLoader.class.getName());
+
+ /**
+ * Constructor
+ */
+ private XMLLoader()
+ {
+ }
+
+ /**
+ * Loads a jboss-annotation.xml and transforms it into the internal
+ * scanning representation
+ * @param is The input stream for the XML file
+ * @return The scanning representation; <code>null</code> if no representation
+ * can be created
+ */
+ public Scan loadJBossAnnotation(InputStream is)
+ {
+ Scan result = null;
+
+ try
+ {
+ Map<String, ScanClass> data = new HashMap<String, ScanClass>();
+
+ JAXBContext fileJc = JAXBContext.newInstance("org.jboss.annotations.xml");
+ Unmarshaller fileU = fileJc.createUnmarshaller();
+ JbossAnnotation ja = (JbossAnnotation)fileU.unmarshal(is);
+
+ boolean excludeAll = ja.isExcludeAll();
+
+ if (ja.getScan() != null)
+ {
+ List<ClassType> lCt = ja.getScan().getClazz();
+ for (ClassType ct : lCt)
+ {
+ ScanClass sc = new ScanClass(ct.getName());
+
+ for (FieldType ft : ct.getField())
+ {
+ sc.addField(ft.getValue());
+ }
+
+ for (ConstructorType con : ct.getConstructor())
+ {
+ String[] parameters = null;
+
+ if (con.getParameter().size() > 0)
+ {
+ parameters = new String[con.getParameter().size()];
+ for (int i = 0; i < con.getParameter().size(); i++)
+ {
+ ParameterType pt = con.getParameter().get(i);
+ parameters[i] = pt.getValue();
+ }
+ }
+
+ sc.addConstructor(parameters);
+ }
+
+ for (MethodType mt : ct.getMethod())
+ {
+ String[] parameters = null;
+
+ if (mt.getParameter().size() > 0)
+ {
+ parameters = new String[mt.getParameter().size()];
+ for (int i = 0; i < mt.getParameter().size(); i++)
+ {
+ ParameterType pt = mt.getParameter().get(i);
+ parameters[i] = pt.getValue();
+ }
+ }
+
+ sc.addMethod(mt.getName(), parameters);
+ }
+ }
+ }
+
+ result = new Scan(excludeAll, data);
+ }
+ catch (Throwable t)
+ {
+ log.finest(t.getMessage());
+ }
+
+ return result;
+ }
+}
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 17:27:56 UTC (rev 92279)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javalangreflect/JavaClass.java 2009-08-12 18:30:46 UTC (rev 92280)
@@ -24,14 +24,11 @@
import org.jboss.annotations.Annotation;
import org.jboss.annotations.AnnotationRepository;
-import org.jboss.annotations.AnnotationScanner;
import org.jboss.annotations.AnnotationType;
+import org.jboss.annotations.impl.AbstractAnnotationScanner;
import org.jboss.annotations.impl.AnnotationRepositoryImpl;
-import org.jboss.annotations.util.ClassScanner;
-import org.jboss.annotations.util.JarScanner;
import java.io.Closeable;
-import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@@ -39,7 +36,6 @@
import java.lang.reflect.Modifier;
import java.net.URL;
import java.net.URLClassLoader;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
@@ -53,7 +49,7 @@
* An annotation scanner using java.lang.reflect
* @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
*/
-public class JavaClass implements AnnotationScanner
+public class JavaClass extends AbstractAnnotationScanner
{
private static Logger log = Logger.getLogger(JavaClass.class.getName());
private static boolean trace = log.isLoggable(Level.FINEST);
@@ -63,21 +59,12 @@
*/
public JavaClass()
{
+ super(JavaClass.class.getName());
}
/**
* Scan
* @param urls The URLs with class files
- * @return The map of annotations
- */
- public AnnotationRepository scan(URL[] urls)
- {
- return scan(urls, (ClassLoader)null);
- }
-
- /**
- * Scan
- * @param urls The URLs with class files
* @param cls Additional class loaders
* @return The map of annotations
*/
@@ -308,67 +295,6 @@
}
/**
- * Get all the class names
- * @param urls The urls to be scanned
- * @return The names
- */
- private List<String> getClassNames(URL[] urls)
- {
- List<String> result = new ArrayList<String>();
-
- for (URL url : urls)
- {
- try
- {
- log.fine("Checking " + url);
-
- if ("file".equals(url.getProtocol()))
- {
- long start = 0;
-
- if (log.isLoggable(Level.FINE))
- start = System.currentTimeMillis();
-
-
- File f = new File(url.getFile());
-
- List<String> classFiles = null;
-
- if (url.getPath().endsWith("/"))
- {
- classFiles = ClassScanner.scan(f);
- }
- else if (url.getPath().endsWith(".jar"))
- {
- classFiles = JarScanner.scan(f);
- }
-
- if (classFiles != null)
- {
- result.addAll(classFiles);
- }
-
- if (log.isLoggable(Level.FINE))
- {
- long end = System.currentTimeMillis();
- log.fine("Retrieving classes took " + (end - start) + " ms for " + url.getFile());
- }
- }
- else
- {
- log.warning("Protocol not supported: " + url);
- }
- }
- catch (Exception e)
- {
- // Nothing we can do
- }
- }
-
- return result;
- }
-
- /**
* Add an annotation to the result map
* @param annotation The annotation
* @param type The annotation type
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 17:27:56 UTC (rev 92279)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistclasspool/JavassistClassPool.java 2009-08-12 18:30:46 UTC (rev 92280)
@@ -24,22 +24,17 @@
import org.jboss.annotations.Annotation;
import org.jboss.annotations.AnnotationRepository;
-import org.jboss.annotations.AnnotationScanner;
import org.jboss.annotations.AnnotationType;
+import org.jboss.annotations.impl.AbstractJavassistAnnotationScanner;
import org.jboss.annotations.impl.AnnotationRepositoryImpl;
-import org.jboss.annotations.util.ClassScanner;
-import org.jboss.annotations.util.JarScanner;
import java.io.Closeable;
-import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
@@ -59,7 +54,7 @@
* An annotation scanner using Javassist's ClassLoader
* @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
*/
-public class JavassistClassPool implements AnnotationScanner
+public class JavassistClassPool extends AbstractJavassistAnnotationScanner
{
private static Logger log = Logger.getLogger(JavassistClassPool.class.getName());
private static boolean trace = log.isLoggable(Level.FINEST);
@@ -69,21 +64,12 @@
*/
public JavassistClassPool()
{
+ super(JavassistClassPool.class.getName());
}
/**
* Scan
* @param urls The URLs with class files
- * @return The map of annotations
- */
- public AnnotationRepository scan(URL[] urls)
- {
- return scan(urls, (ClassLoader)null);
- }
-
- /**
- * Scan
- * @param urls The URLs with class files
* @param cls Additional class loaders
* @return The map of annotations
*/
@@ -333,96 +319,4 @@
return new AnnotationRepositoryImpl(result);
}
-
- /**
- * Get all the class names
- * @param urls The urls to be scanned
- * @return The names
- */
- private List<String> getClassNames(URL[] urls)
- {
- List<String> result = new ArrayList<String>();
-
- for (URL url : urls)
- {
- try
- {
- log.fine("Checking " + url);
-
- if ("file".equals(url.getProtocol()))
- {
- long start = 0;
- if (log.isLoggable(Level.FINE))
- start = System.currentTimeMillis();
-
- File f = new File(url.getFile());
-
- List<String> classFiles = null;
-
- if (url.getPath().endsWith("/"))
- {
- classFiles = ClassScanner.scan(f);
- }
- else if (url.getPath().endsWith(".jar"))
- {
- classFiles = JarScanner.scan(f);
- }
-
- if (classFiles != null)
- {
- result.addAll(classFiles);
- }
-
- if (log.isLoggable(Level.FINE))
- {
- long end = System.currentTimeMillis();
- log.fine("Retrieving classes took " + (end - start) + " ms for " + url.getFile());
- }
- }
- else
- {
- log.warning("Protocol not supported: " + url);
- }
- }
- catch (Exception e)
- {
- // Nothing we can do
- }
- }
-
- return result;
- }
-
- /**
- * Add an annotation to the result map
- * @param annotations The annotations
- * @param type The annotation type
- * @param className The class name
- * @param memberName The member name
- * @param parameterTypes The parameter types
- * @param map The result map
- */
- private void processAnnotation(Object annotation,
- AnnotationType type, String className, String memberName, String[] parameterTypes,
- Map<String, Collection<Annotation>> map)
- {
- Class annotationClass = annotation.getClass().getInterfaces()[0];
-
- Annotation a = new Annotation(annotationClass.cast(annotation),
- type,
- className, memberName, parameterTypes);
-
- if (trace)
- log.finest("Annotation=" + a);
-
- String key = annotationClass.getName();
- Collection<Annotation> l = map.get(key);
- if (l == null)
- l = new HashSet<Annotation>();
-
- if (!l.contains(a))
- l.add(a);
-
- map.put(key, l);
- }
}
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 17:27:56 UTC (rev 92279)
+++ projects/annotations/trunk/core/src/main/java/org/jboss/annotations/javassistinputstream/JavassistInputStream.java 2009-08-12 18:30:46 UTC (rev 92280)
@@ -24,8 +24,8 @@
import org.jboss.annotations.Annotation;
import org.jboss.annotations.AnnotationRepository;
-import org.jboss.annotations.AnnotationScanner;
import org.jboss.annotations.AnnotationType;
+import org.jboss.annotations.impl.AbstractJavassistAnnotationScanner;
import org.jboss.annotations.impl.AnnotationRepositoryImpl;
import java.io.Closeable;
@@ -38,7 +38,6 @@
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -58,7 +57,7 @@
* An annotation scanner using Javassist and InputStream
* @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
*/
-public class JavassistInputStream implements AnnotationScanner
+public class JavassistInputStream extends AbstractJavassistAnnotationScanner
{
private static Logger log = Logger.getLogger(JavassistInputStream.class.getName());
private static boolean trace = log.isLoggable(Level.FINEST);
@@ -68,21 +67,12 @@
*/
public JavassistInputStream()
{
+ super(JavassistInputStream.class.getName());
}
/**
* Scan
* @param urls The URLs with class files
- * @return The map of annotations
- */
- public AnnotationRepository scan(URL[] urls)
- {
- return scan(urls, (ClassLoader)null);
- }
-
- /**
- * Scan
- * @param urls The URLs with class files
* @param cls Additional class loaders
* @return The map of annotations
*/
@@ -359,37 +349,4 @@
return new AnnotationRepositoryImpl(result);
}
-
- /**
- * Add an annotation to the result map
- * @param annotations The annotations
- * @param type The annotation type
- * @param className The class name
- * @param memberName The member name
- * @param parameterTypes The parameter types
- * @param map The result map
- */
- private void processAnnotation(Object annotation,
- AnnotationType type, String className, String memberName, String[] parameterTypes,
- Map<String, Collection<Annotation>> map)
- {
- Class annotationClass = annotation.getClass().getInterfaces()[0];
-
- Annotation a = new Annotation(annotationClass.cast(annotation),
- type,
- className, memberName, parameterTypes);
-
- if (trace)
- log.finest("Annotation=" + a);
-
- String key = annotationClass.getName();
- Collection<Annotation> l = map.get(key);
- if (l == null)
- l = new HashSet<Annotation>();
-
- if (!l.contains(a))
- l.add(a);
-
- map.put(key, l);
- }
}
Modified: projects/annotations/trunk/core/src/main/resources/jboss-annotation.xsd
===================================================================
--- projects/annotations/trunk/core/src/main/resources/jboss-annotation.xsd 2009-08-12 17:27:56 UTC (rev 92279)
+++ projects/annotations/trunk/core/src/main/resources/jboss-annotation.xsd 2009-08-12 18:30:46 UTC (rev 92280)
@@ -1,16 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
+
<!--
JBoss Annotations XML Schema
-->
-<xsd:schema xmlns:wpdl="http://www.jboss.org/annotations" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+<xsd:schema xmlns:annotation="http://www.jboss.org/annotations" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xsd:complexType name="fieldType">
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:token">
+ </xsd:extension>
+ </xsd:simpleContent>
+ </xsd:complexType>
+
+ <xsd:complexType name="parameterType">
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:token">
+ </xsd:extension>
+ </xsd:simpleContent>
+ </xsd:complexType>
+
+ <xsd:complexType name="constructorType">
+ <xsd:sequence>
+ <xsd:element name="parameter" type="parameterType" maxOccurs="unbounded" minOccurs="0"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="methodType">
+ <xsd:sequence>
+ <xsd:element name="parameter" type="parameterType" maxOccurs="unbounded" minOccurs="0"/>
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:token" use="required"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="classType">
+ <xsd:sequence>
+ <xsd:element name="field" type="fieldType" maxOccurs="unbounded" minOccurs="0"/>
+ <xsd:element name="constructor" type="constructorType" maxOccurs="unbounded" minOccurs="0"/>
+ <xsd:element name="method" type="methodType" maxOccurs="unbounded" minOccurs="0"/>
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:token" use="required"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="scanType">
+ <xsd:sequence>
+ <xsd:element name="class" type="classType" maxOccurs="unbounded" minOccurs="0"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
<xsd:element name="jboss-annotation">
<xsd:complexType>
<xsd:sequence>
- <xsd:element name="include" type="xsd:token" maxOccurs="unbounded" minOccurs="0"/>
- <xsd:element name="exclude" type="xsd:token" maxOccurs="unbounded" minOccurs="0"/>
+ <xsd:element name="scan" type="scanType" maxOccurs="1" minOccurs="0"/>
</xsd:sequence>
- <xsd:attribute name="include-all" type="xsd:boolean" default="false"/>
<xsd:attribute name="exclude-all" type="xsd:boolean" default="true"/>
</xsd:complexType>
</xsd:element>
More information about the jboss-cvs-commits
mailing list