List of usage examples for java.lang.reflect Proxy isProxyClass
public static boolean isProxyClass(Class<?> cl)
From source file:Main.java
/** * Helper method used to weed out dynamic Proxy types; types that do * not expose concrete method API that we could use to figure out * automatic Bean (property) based serialization. *//* ww w .java 2 s . co m*/ public static boolean isProxyType(Class<?> type) { // Then: well-known proxy (etc) classes if (Proxy.isProxyClass(type)) { return true; } String name = type.getName(); // Hibernate uses proxies heavily as well: if (name.startsWith("net.sf.cglib.proxy.") || name.startsWith("org.hibernate.proxy.")) { return true; } // Not one of known proxies, nope: return false; }
From source file:cat.albirar.framework.dynabean.impl.DynaBeanFactoryUtils.java
/** * Extract a dynaBean from proxy or return directly if isn't proxy. * @param dynaBean The dynabean (proxified or not) <b>REQUIRED</b> * @return The {@link DynaBeanImpl} deproxified if needed * @throws IllegalArgumentException If the dynaBean is not of the class {@link DynaBeanImpl} *//*w ww . jav a 2s .co m*/ public static DynaBeanImpl<?> deproxifyDynabean(Object dynaBean) { Object db; if (Proxy.isProxyClass(dynaBean.getClass())) { db = Proxy.getInvocationHandler(dynaBean); } else { db = dynaBean; } Assert.isTrue(DynaBeanImpl.class.isAssignableFrom(db.getClass()), "The dynaBean should to be a true dynaBean"); return (DynaBeanImpl<?>) db; }
From source file:powermock.examples.logging.JclUser_JMockit_Test.java
@Test public void assertJclMockingWorks() { JclUser tested = new JclUser(); Log logger = Deencapsulation.getField(JclUser.class, Log.class); assertTrue(Proxy.isProxyClass(logger.getClass())); assertEquals("jcl user", tested.getMessage()); }
From source file:net.sf.beanlib.hibernate3.Hibernate3SequenceGenerator.java
/** Returns the next sequence id from the specified sequence and session. */ public static long nextval(final String sequenceName, final Session session) { Object target = session;/* w w w.j a v a2 s . c o m*/ if (Proxy.isProxyClass(session.getClass())) { // Dig out the underlying session. InvocationHandler invocationHandler = Proxy.getInvocationHandler(session); if (invocationHandler instanceof DtoCentricCloseSuppressingInvocationHandler) { // This is faster for we don't need to use reflection. DtoCentricCloseSuppressingInvocationHandler dch = (DtoCentricCloseSuppressingInvocationHandler) invocationHandler; target = dch.getTarget(); } else { Class<?> invocationHandlerClass = invocationHandler.getClass(); Class<?> invocationHandlerDeclaringClass = invocationHandlerClass.getDeclaringClass(); if (invocationHandlerDeclaringClass == HibernateTemplate.class) { String className = invocationHandlerClass.getName(); if (className.endsWith("CloseSuppressingInvocationHandler")) { // Assume this is the private class org.springframework.orm.hibernate3.HibernateTempate$CloseSuppressingInvocationHandler // Dig out the private target. // I know this is bad, but there doesn't seem to be a better way. Oh well. try { Field f = invocationHandlerClass.getDeclaredField("target"); f.setAccessible(true); target = f.get(invocationHandler); } catch (SecurityException e) { throw new RuntimeException(e); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } } } SessionImpl sessionImpl; if (target instanceof SessionImpl) sessionImpl = (SessionImpl) target; else throw new IllegalStateException("Not yet know how to handle the given session!"); IdentifierGenerator idGenerator = createIdentifierGenerator(sequenceName, session); Serializable id = idGenerator.generate(sessionImpl, null); return (Long) id; }
From source file:org.apache.axis.utils.bytecode.ParamNameExtractor.java
/** * Retrieve a list of function parameter names from a method * Returns null if unable to read parameter names (i.e. bytecode not * built with debug)./*from w ww . ja va 2s .c om*/ */ public static String[] getParameterNamesFromDebugInfo(Method method) { // Don't worry about it if there are no params. int numParams = method.getParameterTypes().length; if (numParams == 0) return null; // get declaring class Class c = method.getDeclaringClass(); // Don't worry about it if the class is a Java dynamic proxy if (Proxy.isProxyClass(c)) { return null; } try { // get a parameter reader ParamReader pr = new ParamReader(c); // get the paramter names String[] names = pr.getParameterNames(method); return names; } catch (IOException e) { // log it and leave log.info(Messages.getMessage("error00") + ":" + e); return null; } }
From source file:org.apache.axis2.description.java2wsdl.bytecode.ParamNameExtractor.java
/** * Retrieves a list of function parameter names from a method. * Returns null if unable to read parameter names (i.e. bytecode not * built with debug).//from www.j a v a 2 s . com */ public static String[] getParameterNamesFromDebugInfo(Method method) { // Don't worry about it if there are no params. int numParams = method.getParameterTypes().length; if (numParams == 0) return null; // get declaring class Class c = method.getDeclaringClass(); // Don't worry about it if the class is a Java dynamic proxy if (Proxy.isProxyClass(c)) { return null; } try { // get a parameter reader ParamReader pr = new ParamReader(c); // get the parameter names return pr.getParameterNames(method); } catch (IOException e) { // log it and leave return null; } }
From source file:de.xwic.appkit.core.model.EntityModelFactory.java
/** * Returns true if the specified entity is a EntityModel implementation. * @param entity/* www. j av a 2s .co m*/ * @return */ public static boolean isModel(IEntity entity) { return (Proxy.isProxyClass(entity.getClass()) && Proxy.getInvocationHandler(entity) instanceof EntityModelInvocationHandler); }
From source file:de.xwic.appkit.core.model.EntityModelFactory.java
/** * Returns the original entity./* w w w . j ava2s . c om*/ * @param entityModel * @return */ public static IEntity getOriginalEntity(IEntity entityModel) { if (!Proxy.isProxyClass(entityModel.getClass())) { throw new IllegalArgumentException("entity is not an entityModel"); } Object oIh = Proxy.getInvocationHandler(entityModel); if (!(oIh instanceof EntityModelInvocationHandler)) { throw new IllegalArgumentException("entity is a proxy but not an entityModel"); } EntityModelInvocationHandler emIh = (EntityModelInvocationHandler) oIh; return emIh.getEntityModelImpl().getOriginalEntity(); }
From source file:cat.albirar.framework.dynabean.impl.DynaBeanFactoryUtils.java
/** * Check if the object is a {@link DynaBeanImpl} or a Proxy with a {@link DynaBeanImpl} as a {@link Proxy#getInvocationHandler(Object) invocation handler}. * @param object The object (or proxy)/*from w w w . j a va2 s .c o m*/ * @return true if the object is a {@link DynaBeanImpl} instance or a {@link Proxy} with a {@link DynaBeanImpl} as an invocation handler. Return false otherwise ever if object is null */ public static boolean checkDynaBean(Object object) { if (object != null) { return ((Proxy.isProxyClass(object.getClass()) && DynaBeanImpl.class.isAssignableFrom(Proxy.getInvocationHandler(object).getClass())) || DynaBeanImpl.class.isAssignableFrom(object.getClass())); } return false; }
From source file:io.dyn.core.handler.HandlerMethod.java
public HandlerMethod(Method method, HandlerMethodArgument[] arguments, Guard guard) { this.method = method; ReflectionUtils.makeAccessible(method); this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); ReflectionUtils.makeAccessible(bridgedMethod); this.arguments = arguments; this.guard = guard; this.invocationHandler = (Proxy.isProxyClass(method.getDeclaringClass()) ? Proxy.getInvocationHandler(method.getDeclaringClass()) : null);// w w w . j ava 2s . c o m }