[jboss-cvs] JBossAS SVN: r104044 - in projects/scanning/trunk: plugins and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Apr 16 07:11:42 EDT 2010
Author: alesj
Date: 2010-04-16 07:11:41 -0400 (Fri, 16 Apr 2010)
New Revision: 104044
Added:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/jsf/
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/jsf/JBossAnnotationProvider.java
Modified:
projects/scanning/trunk/plugins/pom.xml
projects/scanning/trunk/pom.xml
Log:
Add JSF annotation scanning provider.
Modified: projects/scanning/trunk/plugins/pom.xml
===================================================================
--- projects/scanning/trunk/plugins/pom.xml 2010-04-16 09:27:22 UTC (rev 104043)
+++ projects/scanning/trunk/plugins/pom.xml 2010-04-16 11:11:41 UTC (rev 104044)
@@ -64,7 +64,53 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.jboss.mc-int</groupId>
+ <artifactId>jboss-mc-int-servlet</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-vfs</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-structure-spi</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-core-spi</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jboss.deployers</groupId>
+ <artifactId>jboss-deployers-spi</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading-vfs</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jboss.kernel</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-vfs</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-impl</artifactId>
+ </dependency>
+ <dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/jsf/JBossAnnotationProvider.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/jsf/JBossAnnotationProvider.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/jsf/JBossAnnotationProvider.java 2010-04-16 11:11:41 UTC (rev 104044)
@@ -0,0 +1,131 @@
+/*
+ * 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.jsf;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.component.FacesComponent;
+import javax.faces.component.behavior.FacesBehavior;
+import javax.faces.convert.FacesConverter;
+import javax.faces.event.NamedEvent;
+import javax.faces.render.FacesBehaviorRenderer;
+import javax.faces.render.FacesRenderer;
+import javax.servlet.ServletContext;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.lang.reflect.AnnotatedElement;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.mc.servlet.vdf.api.BaseAttachmentVDFConnector;
+import org.jboss.mc.servlet.vdf.spi.VDFConnector;
+import org.jboss.scanning.annotations.spi.AnnotationIndex;
+import org.jboss.scanning.annotations.spi.Element;
+import org.jboss.util.collection.WeakSet;
+
+import com.sun.faces.spi.AnnotationProvider;
+
+/**
+ * Custom JBoss JSf annotation provider.
+ * It uses existing annotations scanning and serves them as a facade over JSF spi.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JBossAnnotationProvider extends AnnotationProvider
+{
+ @SuppressWarnings("unchecked")
+ private static final Set<Class<? extends Annotation>> JSF_ANNOTATIONS = new WeakSet();
+
+ static
+ {
+ JSF_ANNOTATIONS.add(FacesComponent.class);
+ JSF_ANNOTATIONS.add(FacesConverter.class);
+ JSF_ANNOTATIONS.add(FacesRenderer.class);
+ JSF_ANNOTATIONS.add(ManagedBean.class);
+ JSF_ANNOTATIONS.add(NamedEvent.class);
+ JSF_ANNOTATIONS.add(FacesBehavior.class);
+ JSF_ANNOTATIONS.add(FacesBehaviorRenderer.class);
+ }
+
+ /**
+ * The annotations index
+ */
+ private AnnotationIndex index;
+
+ public JBossAnnotationProvider(ServletContext sc)
+ {
+ super(sc);
+ index = readIndex();
+ }
+
+ protected AnnotationIndex readIndex()
+ {
+ VDFConnector<AnnotationIndex> connector = new BaseAttachmentVDFConnector<AnnotationIndex>(sc)
+ {
+ protected Class<AnnotationIndex> getAttachmentType()
+ {
+ return AnnotationIndex.class;
+ }
+ };
+ if (connector.isValid() == false)
+ throw new IllegalArgumentException("No annotation index found in deployment: " + sc);
+
+ return connector.getUtility();
+ }
+
+
+ public Map<Class<? extends Annotation>, Set<Class<?>>> getAnnotatedClasses(Set<URL> urls)
+ {
+ Map<Class<? extends Annotation>, Set<Class<?>>> result = new HashMap<Class<? extends Annotation>, Set<Class<?>>>();
+ for (URL url : urls)
+ {
+ for (Class<? extends Annotation> annotationClass : JSF_ANNOTATIONS)
+ {
+ fillResults(result, annotationClass, url);
+ }
+ }
+ return result;
+ }
+
+ protected <T extends Annotation> void fillResults(Map<Class<? extends Annotation>, Set<Class<?>>> result, Class<T> annotationClass, URL url)
+ {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ result.put(annotationClass, classes);
+
+ String path = url.getPath();
+
+ Target target = annotationClass.getAnnotation(Target.class);
+ ElementType[] types = target.value();
+
+ for (ElementType type : types)
+ {
+ Set<Element<T,AnnotatedElement>> set = index.getAnnotatedClasses(path, annotationClass, type);
+ for (Element elt : set)
+ classes.add(elt.getOwner());
+ }
+ }
+}
Modified: projects/scanning/trunk/pom.xml
===================================================================
--- projects/scanning/trunk/pom.xml 2010-04-16 09:27:22 UTC (rev 104043)
+++ projects/scanning/trunk/pom.xml 2010-04-16 11:11:41 UTC (rev 104044)
@@ -35,7 +35,9 @@
<version.org.jboss.man>2.1.1.SP1</version.org.jboss.man>
<version.org.jboss.classloader>2.2.0.Alpha4</version.org.jboss.classloader>
<version.org.jboss.deployers>2.2.0.Alpha4</version.org.jboss.deployers>
+ <version.org.jboss.mc-int>2.2.0.Alpha2</version.org.jboss.mc-int>
<version.org.jboss.weld-int>6.0.0.Beta11</version.org.jboss.weld-int>
+ <version.javax.faces>2.0.2-FCS</version.javax.faces>
<version.javassist>3.11.0.GA</version.javassist>
<version.ant>1.7.1</version.ant>
<version.hibernate>3.5.0-CR-2</version.hibernate>
@@ -198,11 +200,26 @@
<type>test-jar</type>
</dependency>
<dependency>
+ <groupId>org.jboss.mc-int</groupId>
+ <artifactId>jboss-mc-int-servlet</artifactId>
+ <version>${version.org.jboss.mc-int}</version>
+ </dependency>
+ <dependency>
<groupId>org.jboss.weld.integration</groupId>
<artifactId>weld-jboss-int-deployer</artifactId>
<version>${version.org.jboss.weld-int}</version>
</dependency>
<dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>${version.javax.faces}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-impl</artifactId>
+ <version>${version.javax.faces}</version>
+ </dependency>
+ <dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>${version.javassist}</version>
More information about the jboss-cvs-commits
mailing list