[jboss-cvs] JBossAS SVN: r94032 - in projects/interceptors/trunk: src/main/java/org/jboss/interceptor/model and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Sep 25 15:57:18 EDT 2009
Author: marius.bogoevici
Date: 2009-09-25 15:57:18 -0400 (Fri, 25 Sep 2009)
New Revision: 94032
Added:
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionTypeRegistry.java
Modified:
projects/interceptors/trunk/pom.xml
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionType.java
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/SimpleInterceptionHandler.java
projects/interceptors/trunk/src/test/java/org/jboss/interceptors/InterceptionTest.java
Log:
Allow for dynamic registration of interception types, based on the classpath - i.e. we support as many interception types as we find on the classpath.
Modified: projects/interceptors/trunk/pom.xml
===================================================================
--- projects/interceptors/trunk/pom.xml 2009-09-25 19:07:13 UTC (rev 94031)
+++ projects/interceptors/trunk/pom.xml 2009-09-25 19:57:18 UTC (rev 94032)
@@ -164,6 +164,7 @@
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-api</artifactId>
<version>${version.ejb3.api}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
@@ -195,6 +196,11 @@
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionType.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionType.java 2009-09-25 19:07:13 UTC (rev 94031)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionType.java 2009-09-25 19:57:18 UTC (rev 94032)
@@ -17,32 +17,26 @@
package org.jboss.interceptor.model;
-import javax.interceptor.AroundInvoke;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.ejb.PostActivate;
-import javax.ejb.PrePassivate;
-import java.lang.annotation.Annotation;
-
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
public enum InterceptionType
{
- AROUND_INVOKE(false, AroundInvoke.class),
+
+ AROUND_INVOKE(false, "javax.interceptor.AroundInvoke"),
//AROUND_TIMEOUT(false, AroundTimeout.class),
- POST_CONSTRUCT(true, PostConstruct.class),
- PRE_DESTROY(true, PreDestroy.class),
- POST_ACTIVATE(true, PostActivate.class),
- PRE_PASSIVATE(true, PrePassivate.class);
+ POST_CONSTRUCT(true, "javax.annotation.PostConstruct"),
+ PRE_DESTROY(true, "javax.annotation.PreDestroy"),
+ POST_ACTIVATE(true, "javax.ejb.PostActivate"),
+ PRE_PASSIVATE(true, "javax.ejb.PrePassivate");
private boolean lifecycleCallback;
- private Class<? extends Annotation> associatedAnnotation;
+ private String annotationClassName;
- InterceptionType(boolean lifecycleCallback, Class<? extends Annotation> associatedAnnotation)
+ InterceptionType(boolean lifecycleCallback, String annotationClassName)
{
this.lifecycleCallback = lifecycleCallback;
- this.associatedAnnotation = associatedAnnotation;
+ this.annotationClassName = annotationClassName;
}
public boolean isLifecycleCallback()
@@ -50,8 +44,8 @@
return lifecycleCallback;
}
- public Class<? extends Annotation> getAssociatedAnnotation()
+ public String getAnnotationClassName()
{
- return associatedAnnotation;
+ return annotationClassName;
}
}
Added: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionTypeRegistry.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionTypeRegistry.java (rev 0)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionTypeRegistry.java 2009-09-25 19:57:18 UTC (rev 94032)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.interceptor.model;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
+import java.lang.annotation.Annotation;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public final class InterceptionTypeRegistry
+{
+
+ private static final Log LOG = LogFactory.getLog(InterceptionTypeRegistry.class);
+ private static Map<InterceptionType, Class<? extends Annotation>> interceptionAnnotationClasses;
+
+ static
+ {
+ interceptionAnnotationClasses = new HashMap<InterceptionType, Class<? extends Annotation>>();
+
+ for (InterceptionType interceptionType: InterceptionType.values())
+ {
+ try
+ {
+ interceptionAnnotationClasses.put(interceptionType, (Class<? extends Annotation>) Class.forName(interceptionType.getAnnotationClassName()));
+ } catch (Exception e)
+ {
+ LOG.warn("Class '" + interceptionType.getAnnotationClassName() + "' not found, interception based on it is not enabled" );
+ }
+ }
+ }
+
+ public static Collection<InterceptionType> getSupportedInterceptionTypes()
+ {
+ return interceptionAnnotationClasses.keySet();
+ }
+
+ public static Class<? extends Annotation> getAnnotationClass(InterceptionType interceptionType)
+ {
+ return interceptionAnnotationClasses.get(interceptionType);
+ }
+}
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/SimpleInterceptionHandler.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/SimpleInterceptionHandler.java 2009-09-25 19:07:13 UTC (rev 94031)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/SimpleInterceptionHandler.java 2009-09-25 19:57:18 UTC (rev 94032)
@@ -18,6 +18,7 @@
package org.jboss.interceptor.proxy;
import org.jboss.interceptor.model.InterceptionType;
+import org.jboss.interceptor.model.InterceptionTypeRegistry;
import javax.interceptor.InvocationContext;
import java.lang.reflect.Method;
@@ -44,11 +45,11 @@
this.clazz = (clazz == null) ?interceptorInstance.getClass():clazz;
this.interceptorInstance = interceptorInstance;
- for (InterceptionType interceptionType : InterceptionType.values())
+ for (InterceptionType interceptionType : InterceptionTypeRegistry.getSupportedInterceptionTypes())
{
for (Method method : clazz.getDeclaredMethods())
{
- if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(InvocationContext.class) && method.getAnnotation(interceptionType.getAssociatedAnnotation()) != null)
+ if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(InvocationContext.class) && method.getAnnotation(InterceptionTypeRegistry.getAnnotationClass(interceptionType)) != null)
{
interceptorMethods.put(interceptionType, method);
}
@@ -71,11 +72,11 @@
{
throw new InterceptorException("Cannot create interceptor instance:", e);
}
- for (InterceptionType interceptionType : InterceptionType.values())
+ for (InterceptionType interceptionType : InterceptionTypeRegistry.getSupportedInterceptionTypes())
{
for (Method method : simpleInterceptorClass.getDeclaredMethods())
{
- if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(InvocationContext.class) && method.getAnnotation(interceptionType.getAssociatedAnnotation()) != null)
+ if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(InvocationContext.class) && method.getAnnotation(InterceptionTypeRegistry.getAnnotationClass(interceptionType)) != null)
{
interceptorMethods.put(interceptionType, method);
}
Modified: projects/interceptors/trunk/src/test/java/org/jboss/interceptors/InterceptionTest.java
===================================================================
--- projects/interceptors/trunk/src/test/java/org/jboss/interceptors/InterceptionTest.java 2009-09-25 19:07:13 UTC (rev 94031)
+++ projects/interceptors/trunk/src/test/java/org/jboss/interceptors/InterceptionTest.java 2009-09-25 19:57:18 UTC (rev 94032)
@@ -29,8 +29,8 @@
import org.junit.Before;
import org.junit.Assert;
+import javax.interceptor.InvocationContext;
import javax.interceptor.AroundInvoke;
-import javax.interceptor.InvocationContext;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.Arrays;
More information about the jboss-cvs-commits
mailing list