Announcement Announcement Module
Collapse
No announcement yet.
AOP and common attributes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP and common attributes

    Good Day,

    I have an method interceptor that retrieves the meta data attributes of a parameter to determine the validation that should be applied to it.

    The problem is that the ProxyFactory wants a Interface for the object.

    Code:
    public interface IInvitation {
    	/**
    	 * @param email
    	 * @@.email com.connext.attributes.ValidateEmail ()
    	 */
    	public abstract void setEmail(final String email);
    }
    Code:
    public class Invitation implements IInvitation {
    	private String m_email = null;
    	/**
    	 * @param email
    	 */
    	public void setEmail(final String email) {
    		m_email = email;
    	}
    }
    This means that as the example shows, the attributes need to be applied to the interface instead of the implementation class.

    Here is my method interceptor

    Code:
    public class ValidationInterceptor implements MethodInterceptor {
    
    	public final Object invoke(final MethodInvocation invocation) throws Throwable {
    		
    		Method method = invocation.getMethod();
    		
    		System.out.println(method.getName());
    			
    		Class[] paramTypes = method.getParameterTypes();
    		for &#40;int i = 0; i < paramTypes.length; i++&#41; &#123;
    			
    			if &#40;Attributes.hasParameterAttributeType&#40;method, i, ValidateEmail.class&#41;&#41; &#123;
    				System.out.println&#40;"Has validate email"&#41;;
    			&#125;
    		&#125;
    		
    		return invocation.proceed&#40;&#41;;
    	&#125;
    &#125;
    Does anyone know how I can apply the attributes the the implementation class so that I can read it in this interceptor?

  • #2
    Sorted, in the method interceptor's invoke method, do the following...

    Code:
    Class targetClass = &#40;invocation.getThis&#40;&#41; != null&#41; ? invocation.getThis&#40;&#41;.getClass&#40;&#41; &#58; null;
    This source was taken from the TransactionInterceptor.

    Comment

    Working...
    X