Package net.sourceforge.javautil.interceptor

Source Code of net.sourceforge.javautil.interceptor.InterceptorUtil

package net.sourceforge.javautil.interceptor;

import net.sourceforge.javautil.common.reflection.cache.ClassCache;
import net.sourceforge.javautil.common.reflection.cache.ClassField;
import net.sourceforge.javautil.interceptor.type.InterceptorProxyTypeInterceptor;

/**
* Utility for dealing with interceptor's.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public class InterceptorUtil {
 
  /**
   * @param instance The instance from which to extract the interceptor
   * @return The interceptor manager, or null if the instance is not an interceptor generated by this API/framework
   *
   * @see InterceptorCompiler
   */
  public static IInterceptorManager getManager (Object instance) {
    ClassField field = ClassCache.getFor(instance.getClass()).getField(InterceptorProxyTypeInterceptor.INTERCEPTOR_FIELD_NAME);
    if (field != null && field.getFieldType() == IInterceptorManager.class) {
      field.ensureAccessibility();
      return (IInterceptorManager) field.getValue(instance);
    }
    return null;
  }

}
TOP

Related Classes of net.sourceforge.javautil.interceptor.InterceptorUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.