List of usage examples for java.lang.reflect Proxy getInvocationHandler
@CallerSensitive public static InvocationHandler getInvocationHandler(Object proxy) throws IllegalArgumentException
From source file:org.qi4j.runtime.value.ValueInstance.java
public static ValueInstance getValueInstance(ValueComposite composite) { return (ValueInstance) Proxy.getInvocationHandler(composite); }
From source file:com.googlecode.easymockrule.EasyMockUtils.java
private static ObjectMethodsFilter getInvocationHandler(Object mock) { return (ObjectMethodsFilter) Proxy.getInvocationHandler(mock); }
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} *///from ww w .j av a2 s . c o 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: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;/*from www.j a va 2 s . co 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:de.xwic.appkit.core.model.EntityModelFactory.java
/** * Returns true if the specified entity is a EntityModel implementation. * @param entity/*from www . j a va2 s.c o m*/ * @return */ public static boolean isModel(IEntity entity) { return (Proxy.isProxyClass(entity.getClass()) && Proxy.getInvocationHandler(entity) instanceof EntityModelInvocationHandler); }
From source file:net.heartsome.license.webservice.ServiceUtilTest.java
public static IService getService() throws MalformedURLException { // Service srvcModel = new // ObjectServiceFactory().create(IService.class); // XFireProxyFactory factory = new XFireProxyFactory(XFireFactory // .newInstance().getXFire()); ///*from ww w. ja v a 2 s . co m*/ // IService srvc = (IService) factory.create(srvcModel, // Constants.CONNECT_URL); // return srvc; ProtocolSocketFactory easy = new EasySSLProtocolSocketFactory(); Protocol protocol = new Protocol(HTTP_TYPE, easy, PORT); Protocol.registerProtocol(HTTP_TYPE, protocol); Service serviceModel = new ObjectServiceFactory().create(IService.class, SERVICE_NAME, SERVICE_NAMESPACE, null); IService service = (IService) new XFireProxyFactory().create(serviceModel, SERVICE_URL); Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient(); client.addOutHandler(new DOMOutHandler()); client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED, Boolean.FALSE); client.setProperty(CommonsHttpMessageSender.DISABLE_EXPECT_CONTINUE, "1"); client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "0"); return service; }
From source file:cognition.pipeline.data.helper.ClobHelper.java
private String getString(Object expectedClob) { SerializableClobProxy clobProxy = (SerializableClobProxy) Proxy.getInvocationHandler(expectedClob); Clob wrappedClob = clobProxy.getWrappedClob(); try {// ww w . ja va2 s.com return wrappedClob.getSubString(1, (int) wrappedClob.length()); } catch (SQLException e) { e.printStackTrace(); return "error: could not retrieve text"; } }
From source file:com.gs.jrpip.client.SessionAwareFastServletProxyFactoryTest.java
public void testCreateSession() throws MalformedURLException { SessionAwareFastServletProxyFactory factory = new SessionAwareFastServletProxyFactory(); factory.setUseLocalService(false);/*from www . jav a2 s . com*/ Echo echo = factory.create(Echo.class, this.getJrpipUrl()); FastServletProxyInvocationHandler invocationHandler = (FastServletProxyInvocationHandler) Proxy .getInvocationHandler(echo); Cookie[] cookies = invocationHandler.getCookies(); Assert.assertEquals(1, cookies.length); TestCase.assertEquals("JSESSIONID", cookies[0].getName()); }
From source file:cognition.pipeline.data.helper.BlobHelper.java
private byte[] getBytesFromSerializableBlob(Object serializableBlobProxy) { SerializableBlobProxy blobProxy = (SerializableBlobProxy) Proxy.getInvocationHandler(serializableBlobProxy); Blob wrappedBlob = blobProxy.getWrappedBlob(); try {//from www.j a v a2 s . c o m byte[] bytes = wrappedBlob.getBytes(1, (int) wrappedBlob.length()); if (bytes != null) { if (bytes.length == 0) { return null; } } return bytes; } catch (SQLException e) { e.printStackTrace(); } return null; }
From source file:de.xwic.appkit.core.model.EntityModelFactory.java
/** * Returns the original entity.//w w w .ja v a2 s .c o m * @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(); }