Skip to content
Browse files

Removing AnnotatedMethodReader

Interceptor methods with inconsistent signatures throw exception
Add deferral indicator for ClassMetadata and MethodMetadata interceptors, indicating whether the backing class and method should be used directly or interceptor metadata processing should be performed based on method signatures.
  • Loading branch information...
1 parent 6d09129 commit f803fd229d29e8e751ae8407b2fe59c9cd75a3b8 @mbogoevici committed Feb 1, 2011
View
2 src/main/java/org/jboss/interceptor/builder/InterceptionModelImpl.java
@@ -73,7 +73,7 @@ public InterceptionModelImpl(T interceptedEntity)
*/
public List<InterceptorMetadata<I>> getInterceptors(InterceptionType interceptionType, MethodMetadata method)
{
- return getInterceptors(interceptionType, MethodSignature.of(method.getJavaMethod()));
+ return getInterceptors(interceptionType, method.getMethodReference().getMethodSignature());
}
public List<InterceptorMetadata<I>> getInterceptors(InterceptionType interceptionType, Method method)
View
17 src/main/java/org/jboss/interceptor/builder/MethodReference.java
@@ -34,14 +34,17 @@
private MethodSignature methodSignature;
+ private String returnTypeName;
+
/**
* @param declaringClassName
* @param methodSignature
*/
- public MethodReference(String declaringClassName, MethodSignature methodSignature)
+ public MethodReference(String declaringClassName, MethodSignature methodSignature, String returnType)
{
this.declaringClassName = declaringClassName;
this.methodSignature = methodSignature;
+ this.returnTypeName = returnType;
}
/**
@@ -52,15 +55,9 @@ public MethodReference(String declaringClassName, MethodSignature methodSignatur
*/
public static MethodReference of(Method method)
{
- return new MethodReference(method.getDeclaringClass().getName(), MethodSignature.of(method));
- }
-
- public static MethodReference of(MethodMetadata method)
- {
- return new MethodReference(method.getJavaMethod().getDeclaringClass().getName(), MethodSignature.of(method.getJavaMethod()));
+ return new MethodReference(method.getDeclaringClass().getName(), MethodSignature.of(method), method.getReturnType().getName());
}
-
public String getDeclaringClassName()
{
return declaringClassName;
@@ -105,4 +102,8 @@ public int hashCode()
return result;
}
+ public String getReturnTypeName()
+ {
+ return returnTypeName;
+ }
}
View
3 src/main/java/org/jboss/interceptor/builder/MethodSignature.java
@@ -27,6 +27,8 @@
* A simplified representation of a method signature, that can be used as a key instead of the
* {@link Method} itself. Argument types are represented by {@link String values}
*
+ * Note: equals() and hashCode() will be based only the method name and argument types
+ *
* @author Marius Bogoevici
*/
public class MethodSignature implements Serializable
@@ -57,6 +59,7 @@ public static MethodSignature of(Method m)
String methodName = m.getName();
Class<?>[] parameterTypes = m.getParameterTypes();
String[] argTypeNames = toNames(parameterTypes);
+
return new MethodSignature(methodName, argTypeNames);
}
View
62 src/main/java/org/jboss/interceptor/reader/AbstractMethodMetadata.java
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.reader;
+
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.interceptor.builder.MethodReference;
+import org.jboss.interceptor.spi.metadata.MethodMetadata;
+import org.jboss.interceptor.spi.model.InterceptionType;
+import org.jboss.interceptor.spi.model.InterceptionTypeRegistry;
+
+/**
+ * @author Marius Bogoevici
+ */
+public abstract class AbstractMethodMetadata implements MethodMetadata
+{
+ protected Set<InterceptionType> supportedInterceptorTypes = new HashSet<InterceptionType>();
+
+ protected void initSupportedInterceptionTypes()
+ {
+ for (InterceptionType interceptionType : InterceptionTypeRegistry.getSupportedInterceptionTypes())
+ {
+ if (interceptionAnnotationExists(interceptionType))
+ {
+ supportedInterceptorTypes.add(interceptionType);
+ }
+ }
+ }
+
+ protected abstract boolean interceptionAnnotationExists(InterceptionType interceptionType);
+
+ public Set<InterceptionType> getSupportedInterceptionTypes()
+ {
+ return supportedInterceptorTypes;
+ }
+
+ public boolean isDeferringReflection()
+ {
+ return false;
+ }
+
+ public abstract Method getJavaMethod();
+
+ public abstract MethodReference getMethodReference();
+}
View
135 src/main/java/org/jboss/interceptor/reader/DefaultMethodMetadata.java
@@ -1,135 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, 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.reader;
-
-import java.io.ObjectStreamException;
-import java.io.Serializable;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.jboss.interceptor.builder.MethodReference;
-import org.jboss.interceptor.proxy.InterceptorException;
-import org.jboss.interceptor.spi.metadata.MethodMetadata;
-import org.jboss.interceptor.spi.model.InterceptionType;
-import org.jboss.interceptor.spi.model.InterceptionTypeRegistry;
-import org.jboss.interceptor.util.ReflectionUtils;
-
-/**
- * Represents information about an interceptor method
- *
- * @author Marius Bogoevici
- */
-public class DefaultMethodMetadata<M> implements MethodMetadata, Serializable
-{
-
- private static final long serialVersionUID = -4538617003189564552L;
-
- private Method javaMethod;
-
- private Set<InterceptionType> supportedInterceptorTypes = new HashSet<InterceptionType>();
-
- private DefaultMethodMetadata(M methodReference, AnnotatedMethodReader<M> annotationReader)
- {
- this.javaMethod = annotationReader.getJavaMethod(methodReference);
- for (InterceptionType interceptionType: InterceptionTypeRegistry.getSupportedInterceptionTypes())
- {
- if (annotationReader.getAnnotation(InterceptionTypeRegistry.getAnnotationClass(interceptionType), methodReference) != null)
- {
- supportedInterceptorTypes.add(interceptionType);
- }
- }
- }
-
- private DefaultMethodMetadata(Set<InterceptionType> interceptionTypes, Method method)
- {
- this.supportedInterceptorTypes = interceptionTypes;
- this.javaMethod = method;
- }
-
- public static <M> MethodMetadata of(M methodReference, AnnotatedMethodReader<M> methodReader)
- {
- return new DefaultMethodMetadata(methodReference, methodReader);
- }
-
- public static MethodMetadata of(Method method)
- {
- return new DefaultMethodMetadata(method, new ReflectiveAnnotatedMethodReader());
- }
-
-
- public Set<InterceptionType> getSupportedInterceptionTypes()
- {
- return supportedInterceptorTypes;
- }
-
- public Method getJavaMethod()
- {
- return javaMethod;
- }
-
- public Class<?> getReturnType()
- {
- return javaMethod.getReturnType();
- }
-
- private Object writeReplace()
- {
- return new DefaultMethodMetadataSerializationProxy(supportedInterceptorTypes, MethodReference.of(this));
- }
-
-
- private static class DefaultMethodMetadataSerializationProxy implements Serializable
- {
- private Set<InterceptionType> supportedInterceptionTypes;
- private MethodReference methodReference;
-
- private DefaultMethodMetadataSerializationProxy(Set<InterceptionType> supportedInterceptionTypes, MethodReference methodReference)
- {
- this.supportedInterceptionTypes = supportedInterceptionTypes;
- this.methodReference = methodReference;
- }
-
- private Object readResolve() throws ObjectStreamException
- {
- ClassLoader classLoader = ReflectionUtils.getThreadContextClassLoader(true);
- Method method = null;
- try
- {
- String[] argumentTypeNames = methodReference.getMethodSignature().getArgumentTypeNames();
- List<Class<?>> argumentTypes = new ArrayList<Class<?>>();
- for (String argumentTypeName : argumentTypeNames)
- {
- argumentTypes.add(classLoader.loadClass(argumentTypeName));
- }
- Class<?>[] argumentTypesArray = argumentTypes.toArray(new Class<?>[argumentTypes.size()]);
- method = classLoader.loadClass(methodReference.getDeclaringClassName())
- .getDeclaredMethod(methodReference.getMethodSignature().getMethodName(), argumentTypesArray);
- }
- catch (Exception e)
- {
- throw new InterceptorException(e);
- }
- return new DefaultMethodMetadata(supportedInterceptionTypes, method);
- }
-
- }
-
-}
View
115 src/main/java/org/jboss/interceptor/reader/InterceptorMetadataUtils.java
@@ -60,92 +60,104 @@ public static InterceptorMetadata readMetadataForTargetClass(ClassMetadata<?> cl
return new SimpleInterceptorMetadata(ClassMetadataInterceptorReference.of(classMetadata), true, buildInterceptorMethodMap(classMetadata, true));
}
- public static boolean isInterceptorMethod(InterceptionType interceptionType, MethodMetadata method, boolean forTargetClass)
+ public static boolean validateInterceptorMethod(InterceptionType interceptionType, MethodMetadata method, boolean forTargetClass)
{
+ // is the method annotated with an interceptor annotation?
if (!method.getSupportedInterceptionTypes().contains(interceptionType))
{
return false;
}
+ int parameterCount = method.getMethodReference().getMethodSignature().getArgumentTypeNames().length;
+
+ // the method is annotated correctly, but is its signature valid?
if (interceptionType.isLifecycleCallback())
{
- if (!Void.TYPE.equals(method.getReturnType()))
+ if (!isReturningVoid(method))
{
- if (LOG.isWarnEnabled())
- {
- LOG.warn(getStandardIgnoredMessage(interceptionType, method.getJavaMethod()) + "does not have a void return type");
- }
- return false;
+ throw new InterceptorMethodSignatureException(getErrorMessage(interceptionType, method.getJavaMethod()) + "does not have a void return type");
}
- Class<?>[] parameterTypes = method.getJavaMethod().getParameterTypes();
- if (forTargetClass && parameterTypes.length != 0)
+ if (forTargetClass && parameterCount != 0)
{
- if (LOG.isWarnEnabled())
- {
- LOG.warn(getStandardIgnoredMessage(interceptionType, method.getJavaMethod()) + "is defined on the target class and does not have 0 arguments");
- }
- return false;
+ throw new InterceptorMethodSignatureException(getErrorMessage(interceptionType, method.getJavaMethod()) + "is defined on the target class and does not have 0 arguments");
}
- if (!forTargetClass && parameterTypes.length != 1)
+ if (!forTargetClass && parameterCount != 1)
{
- if (LOG.isWarnEnabled())
- {
- LOG.warn(getStandardIgnoredMessage(interceptionType, method.getJavaMethod()) + "does not have exactly one parameter");
- }
- return false;
+ throw new InterceptorMethodSignatureException(getErrorMessage(interceptionType, method.getJavaMethod()) + "does not have exactly one parameter");
}
- if (parameterTypes.length == 1 && !InvocationContext.class.isAssignableFrom(parameterTypes[0]))
+ if (!forTargetClass && !hasSingleInvocationContextArgument(method))
{
- if (LOG.isWarnEnabled())
- {
- LOG.warn(getStandardIgnoredMessage(interceptionType, method.getJavaMethod()) + "its single argument is not a " + InvocationContext.class.getName());
- }
- return false;
+ throw new InterceptorMethodSignatureException(getErrorMessage(interceptionType, method.getJavaMethod()) + "its single argument is not a " + InvocationContext.class.getName());
}
-
- return true;
}
else
{
- if (!Object.class.equals(method.getReturnType()))
+ if (!isReturningObject(method))
{
- if (LOG.isWarnEnabled())
- {
- LOG.warn(getStandardIgnoredMessage(interceptionType, method.getJavaMethod()) + "does not return a " + OBJECT_CLASS_NAME);
- }
- return false;
+ throw new InterceptorMethodSignatureException(getErrorMessage(interceptionType, method.getJavaMethod()) + "does not return a " + OBJECT_CLASS_NAME);
}
- Class<?>[] parameterTypes = method.getJavaMethod().getParameterTypes();
+ String[] parameterTypes = method.getMethodReference().getMethodSignature().getArgumentTypeNames();
if (parameterTypes.length != 1)
{
- if (LOG.isWarnEnabled())
- {
- LOG.debug(getStandardIgnoredMessage(interceptionType, method.getJavaMethod()) + "does not have exactly 1 parameter");
- }
- return false;
+ throw new InterceptorMethodSignatureException(getErrorMessage(interceptionType, method.getJavaMethod()) + "does not have exactly 1 parameter");
}
- if (!InvocationContext.class.isAssignableFrom(parameterTypes[0]))
+ if (!hasSingleInvocationContextArgument(method))
{
- if (LOG.isWarnEnabled())
- {
- LOG.debug(getStandardIgnoredMessage(interceptionType, method.getJavaMethod()) + "does not have a " + InvocationContext.class.getName() + " parameter ");
- }
- return false;
+ throw new InterceptorMethodSignatureException(getErrorMessage(interceptionType, method.getJavaMethod()) + "does not have a " + InvocationContext.class.getName() + " parameter ");
}
+ }
+ return true;
+ }
- return true;
+ private static boolean isReturningObject(MethodMetadata method)
+ {
+ if (!method.isDeferringReflection())
+ {
+ return Object.class.equals(method.getJavaMethod().getReturnType());
+ }
+ else
+ {
+ return OBJECT_CLASS_NAME.equals(method.getMethodReference().getReturnTypeName());
+ }
+ }
+
+ private static boolean isReturningVoid(MethodMetadata method)
+ {
+ if (!method.isDeferringReflection())
+ {
+ return void.class.equals(method.getJavaMethod().getReturnType());
+ }
+ else
+ {
+ return "void".equals(method.getMethodReference().getReturnTypeName());
}
}
- static String getStandardIgnoredMessage(InterceptionType interceptionType, Method method)
+ private static boolean hasSingleInvocationContextArgument(MethodMetadata methodMetadata)
+ {
+ // if the reflective information is not available on the method metadata object, we check the argument type by name
+ // otherwise we allow for subclasses of InvocationContext to be present as well
+ if (methodMetadata.isDeferringReflection())
+ {
+ return methodMetadata.getMethodReference().getMethodSignature().getArgumentTypeNames().length == 1
+ && methodMetadata.getMethodReference().getMethodSignature().getArgumentTypeNames()[0].equals(InvocationContext.class.getName());
+ }
+ else
+ {
+ return methodMetadata.getJavaMethod().getParameterTypes().length == 1
+ && InvocationContext.class.isAssignableFrom(methodMetadata.getJavaMethod().getParameterTypes()[0]);
+ }
+ }
+
+ static String getErrorMessage(InterceptionType interceptionType, Method method)
{
return "Method " + method.getName() + " defined on class " + method.getDeclaringClass().getName()
+ " will not be used for interception, since it is not defined according to the specification. It is annotated with @"
@@ -170,7 +182,7 @@ static String getStandardIgnoredMessage(InterceptionType interceptionType, Metho
{
for (InterceptionType interceptionType : InterceptionTypeRegistry.getSupportedInterceptionTypes())
{
- if (isInterceptorMethod(interceptionType, method, forTargetClass))
+ if (validateInterceptorMethod(interceptionType, method, forTargetClass))
{
if (methodMap.get(interceptionType) == null)
{
@@ -188,7 +200,10 @@ static String getStandardIgnoredMessage(InterceptionType interceptionType, Metho
// final methods are treated separately, as a final method cannot override another method nor be
// overridden
ReflectionUtils.ensureAccessible(method.getJavaMethod());
- if (!foundMethods.contains(methodReference) && Modifier.isPrivate(method.getJavaMethod().getModifiers()));
+ if (!foundMethods.contains(methodReference) && Modifier.isPrivate(method.getJavaMethod().getModifiers()))
+ {
+ ;
+ }
{
methodMap.get(interceptionType).add(0, method);
}
View
28 ...rceptor/reader/AnnotatedMethodReader.java → .../InterceptorMethodSignatureException.java
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * Copyright 2011, 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.
*
@@ -17,15 +17,27 @@
package org.jboss.interceptor.reader;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
/**
- * Allows entities to define their own strategy of reading metadata from an object
+ * @author Marius Bogoevici
*/
-public interface AnnotatedMethodReader<M>
+public class InterceptorMethodSignatureException extends RuntimeException
{
- Annotation getAnnotation(Class<? extends Annotation> annotationClass, M methodReference);
+ public InterceptorMethodSignatureException()
+ {
+ }
+
+ public InterceptorMethodSignatureException(String s)
+ {
+ super(s);
+ }
+
+ public InterceptorMethodSignatureException(String s, Throwable throwable)
+ {
+ super(s, throwable);
+ }
- Method getJavaMethod(M methodReference);
+ public InterceptorMethodSignatureException(Throwable throwable)
+ {
+ super(throwable);
+ }
}
View
46 src/main/java/org/jboss/interceptor/reader/ReflectiveAnnotatedMethodReader.java
@@ -1,46 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, 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.reader;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
-/**
- * A trivial implementation for handling methods
- * @author
- */
-public class ReflectiveAnnotatedMethodReader implements AnnotatedMethodReader<Method>
-{
- private static ReflectiveAnnotatedMethodReader INSTANCE = new ReflectiveAnnotatedMethodReader();
-
- public static AnnotatedMethodReader<Method> getInstance()
- {
- return INSTANCE;
- }
-
- public Annotation getAnnotation(Class<? extends Annotation> annotationClass, Method methodReference)
- {
- return methodReference.getAnnotation(annotationClass);
- }
-
- public Method getJavaMethod(Method methodReference)
- {
- // this looks a bit of an excessive indirection, but it is designed to accomodate the case when the
- // method is wrapped in a more generic structure, like the CDI AnnotatedType
- return methodReference;
- }
-}
View
13 src/main/java/org/jboss/interceptor/reader/ReflectiveClassMetadata.java
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * Copyright 2011, 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.
*
@@ -46,7 +46,7 @@ private ReflectiveClassMetadata(Class<T> clazz)
return new ReflectiveClassMetadata<T>(clazz);
}
- public String getClassName()
+ public String getJavaClassName()
{
return clazz.getName();
}
@@ -62,7 +62,7 @@ public String getClassName()
@Override
protected MethodMetadata wrapObject(Method method)
{
- return DefaultMethodMetadata.of(method);
+ return ReflectiveMethodMetadata.of(method);
}
};
}
@@ -72,7 +72,12 @@ protected MethodMetadata wrapObject(Method method)
public Class<T> getJavaClass()
{
return clazz;
- }
+ }
+
+ public boolean isDeferringReflection()
+ {
+ return false;
+ }
@SuppressWarnings({ "unchecked", "rawtypes" })
public ClassMetadata<?> getSuperclass()
View
73 src/main/java/org/jboss/interceptor/reader/ReflectiveMethodMetadata.java
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, 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.reader;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+import org.jboss.interceptor.builder.MethodReference;
+import org.jboss.interceptor.spi.metadata.MethodMetadata;
+import org.jboss.interceptor.spi.model.InterceptionType;
+import org.jboss.interceptor.spi.model.InterceptionTypeRegistry;
+
+/**
+ * Represents information about an interceptor method
+ *
+ * @author Marius Bogoevici
+ */
+public class ReflectiveMethodMetadata extends AbstractMethodMetadata implements Serializable
+{
+
+ private static final long serialVersionUID = -4538617003189564552L;
+
+ private transient Method javaMethod;
+
+ private MethodReference methodReference;
+
+ private ReflectiveMethodMetadata(Method javaMethod)
+ {
+ this.javaMethod = javaMethod;
+ this.methodReference = MethodReference.of(javaMethod);
+ initSupportedInterceptionTypes();
+ }
+
+ @Override
+ protected boolean interceptionAnnotationExists(InterceptionType interceptionType)
+ {
+ return this.javaMethod.getAnnotation(InterceptionTypeRegistry.getAnnotationClass(interceptionType)) != null;
+ }
+
+ public static MethodMetadata of(Method method)
+ {
+ return new ReflectiveMethodMetadata(method);
+ }
+
+
+ @Override
+ public Method getJavaMethod()
+ {
+ return javaMethod;
+ }
+
+ @Override
+ public MethodReference getMethodReference()
+ {
+ return methodReference;
+ }
+
+}
View
25 src/main/java/org/jboss/interceptor/spi/metadata/ClassMetadata.java
@@ -28,11 +28,32 @@
*/
public interface ClassMetadata<T> extends Serializable
{
+ /**
+ * Behaves similarly to {@link Class#getDeclaredMethods()}, but returns {@link MethodMetadata} allowing
+ * implementors to use other mechanisms than reflection to provide information about methods
+ *
+ * @return
+ */
Iterable<MethodMetadata> getDeclaredMethods();
-
+
+ /**
+ * Return true if the implementation will return class data lazily (i.e. when invoking {@link #getJavaClass()})
+ * Implementations that return true may not provide information about the actual {@link Class} at all, or invoking
+ * {@link #getJavaClass()} may be expensive.
+ *
+ */
+ boolean isDeferringReflection();
+
+ /**
+ * Return the actual class that is backing the ClassMetadata, if available
+ *
+ * @return
+ *
+ * Note: this method is optional. If not supported or expensive, {@link #isDeferringReflection()} must return true
+ */
Class<T> getJavaClass();
- String getClassName();
+ String getJavaClassName();
ClassMetadata<?> getSuperclass();
View
30 src/main/java/org/jboss/interceptor/spi/metadata/MethodMetadata.java
@@ -17,6 +17,7 @@
package org.jboss.interceptor.spi.metadata;
+import org.jboss.interceptor.builder.MethodReference;
import org.jboss.interceptor.spi.model.InterceptionType;
import java.lang.reflect.Method;
@@ -31,10 +32,35 @@
*/
public interface MethodMetadata
{
+
+ /**
+ * Return true if the implementation will return class data lazily (i.e. when invoking {@link #getJavaMethod()})
+ * Implementations that return true may not provide information about the actual {@link Method} at all, or invoking
+ * {@link #getJavaMethod()} may be expensive.
+ *
+ */
+ boolean isDeferringReflection();
+
+ /**
+ * Return the {@link Method} that is backing this instance, if available
+ *
+ * @return
+ *
+ * Note: this method is optional. If not supported or expensive, {@link #isDeferringReflection()} must return true
+ */
Method getJavaMethod();
- Set<InterceptionType> getSupportedInterceptionTypes();
+ /**
+ * A reference to the method that is backing this instance
+ * @return
+ */
+ MethodReference getMethodReference();
- Class<?> getReturnType();
+ /**
+ * The interception types that this method supports
+ *
+ * @return
+ */
+ Set<InterceptionType> getSupportedInterceptionTypes();
}
View
2 src/test/java/org/jboss/interceptors/metadata/InterceptorClassMetadataTestCase.java
@@ -194,7 +194,7 @@ public void testInterceptorClassMetaData()
ClassMetadata<?> interceptorClass = interceptorWithAllInterceptionTypes.getInterceptorReference().getClassMetadata();
Assert.assertNotNull("ClassMetadata not found on interceptor metadata created out of class: " + InterceptorWithAllMethods.class, interceptorClass);
- Assert.assertEquals("Unexpected ClassMetadata found on interceptor metadata created out of class: " + InterceptorWithAllMethods.class, InterceptorWithAllMethods.class.getName(), interceptorClass.getClassName());
+ Assert.assertEquals("Unexpected ClassMetadata found on interceptor metadata created out of class: " + InterceptorWithAllMethods.class, InterceptorWithAllMethods.class.getName(), interceptorClass.getJavaClassName());
}

0 comments on commit f803fd2

Please sign in to comment.
Something went wrong with that request. Please try again.