@Override public boolean isProxy(Class<?> clazz) { return ProxyFactory.isProxyClass(clazz); }
public static Class<?> getNonProxyImplementationClassIfNecessary(Class<?> candidate) { Class<?> response = candidate; //TODO Although unusual, there are other proxy types in Hibernate than just javassist proxies (Broadleaf defaults to javassist). //At some point, should try to account for those here in a performant way. if (ProxyFactory.isProxyClass(candidate)) { //TODO This is not ideal. While this works consistently, I don't think it's guaranteed that the proxy classname //will always have this format in the future. We'll at least throw an exception if our formatting detection fails //so that we're aware of it. if (!candidate.getName().contains(JAVASSIST_PROXY_KEY_PHRASE)) { throw new ProxyDetectionException(String.format("Cannot determine the original implementation class for " + "the javassist proxy. Expected to find the keyphrase (%s) in the proxy classname (%s).", JAVASSIST_PROXY_KEY_PHRASE, candidate.getName())); } String implName = candidate.getName().substring(0, candidate.getName().lastIndexOf(JAVASSIST_PROXY_KEY_PHRASE)); try { response = Class.forName(implName); } catch (ClassNotFoundException e) { throw ExceptionHelper.refineException(e); } } return response; }
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException { Class cl = desc.forClass(); if (ProxyFactory.isProxyClass(cl)) { writeBoolean(true); Class superClass = cl.getSuperclass(); Class[] interfaces = cl.getInterfaces(); byte[] signature = ProxyFactory.getFilterSignature(cl); String name = superClass.getName(); writeObject(name); // we don't write the marker interface ProxyObject writeInt(interfaces.length - 1); for (int i = 0; i < interfaces.length; i++) { Class interfaze = interfaces[i]; if (interfaze != ProxyObject.class && interfaze != Proxy.class) { name = interfaces[i].getName(); writeObject(name); } } writeInt(signature.length); write(signature); } else { writeBoolean(false); super.writeClassDescriptor(desc); } } }
@Override protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException { Class<?> cl = desc.forClass(); if (ProxyFactory.isProxyClass(cl)) { writeBoolean(true); Class<?> superClass = cl.getSuperclass(); Class<?>[] interfaces = cl.getInterfaces(); byte[] signature = ProxyFactory.getFilterSignature(cl); String name = superClass.getName(); writeObject(name); // we don't write the marker interface ProxyObject writeInt(interfaces.length - 1); for (int i = 0; i < interfaces.length; i++) { Class<?> interfaze = interfaces[i]; if (interfaze != ProxyObject.class && interfaze != Proxy.class) { name = interfaces[i].getName(); writeObject(name); } } writeInt(signature.length); write(signature); } else { writeBoolean(false); super.writeClassDescriptor(desc); } } }
public static boolean isProxy(Object o) { return isKunderaProxy(o) || isHibernateProxy(o) || ProxyFactory.isProxyClass(o.getClass()); }
@Override public boolean isProxy(Class<?> clazz) { return ProxyFactory.isProxyClass(clazz); }
@Override public boolean isProxy(Class<?> clazz) { return ProxyFactory.isProxyClass(clazz); }
/** * Checks if the target class is already proxied */ private static <T> Class<? extends Object> getTargetClassIfProxied(Class<T> clazz) { if (ProxyFactory.isProxyClass(clazz)) clazz = (Class<T>) clazz.getSuperclass(); return clazz; }
private static Class getBeanType(Class clazz) { if (!ProxyFactory.isProxyClass(clazz)) { return clazz; } return clazz.getSuperclass(); } }
private static Class getBeanType(Class clazz) { if (!ProxyFactory.isProxyClass(clazz)) { return clazz; } return clazz.getSuperclass(); } }
public static Class<?> getRealClass( Class<?> klass ) { if ( ProxyFactory.isProxyClass( klass ) ) { klass = klass.getSuperclass(); } return klass; }
public static Class<?> getRealClass( Class<?> klass ) { if ( ProxyFactory.isProxyClass( klass ) ) { klass = klass.getSuperclass(); } while ( PersistentCollection.class.isAssignableFrom( klass ) ) { klass = klass.getSuperclass(); } return klass; }
@Override public boolean isProxyType(Class<?> type) { boolean proxy = isProxyClass(type) || CDIProxies.isCDIProxy(type); logger.debug("Class {} is proxy: {}", type.getName(), proxy); return proxy; }
public static boolean isLazyMethodProxyfied(final Entity e) { return ProxyFactory.isProxyClass(e.getClass()) && ProxyFactory.getHandler((Proxy) e) instanceof LazyMethodHandler; }
public static boolean isLazyMethodProxyfied(final Entity e) { return ProxyFactory.isProxyClass(e.getClass()) && ProxyFactory.getHandler((Proxy) e) instanceof LazyMethodHandler; }
protected Class<?> extractFromProxy(InvocationContext ctx) { Class<?> proxyClass = ctx.getTarget().getClass(); if (ProxyFactory.isProxyClass(proxyClass)) { if (isInterfaceProxy(proxyClass)) { return extractFromInterface(proxyClass); } else { return proxyClass.getSuperclass(); } } return proxyClass; }
private Entity proxifyEntity(final Entity entity) { if (entity == null) { return null; } final ProxyFactory factory = new ProxyFactory(); Class<?> classForProxy = entity.getClass(); //It's not possible to create a Proxy on a Proxy //Here Entity can already be an Hibernate Proxy if (ProxyFactory.isProxyClass(classForProxy)) { classForProxy = classForProxy.getSuperclass(); } factory.setSuperclass(classForProxy); factory.setFilter(new AllMethodFilter()); try { return (Entity) factory.create(new Class<?>[0], new Object[0], new LazyMethodHandler(entity, lazyLoader)); } catch (final Exception e) { throw new RuntimeException("Error when proxifying object", e); } }
private Entity proxifyEntity(final Entity entity) { if (entity == null) { return null; } final ProxyFactory factory = new ProxyFactory(); Class<?> classForProxy = entity.getClass(); //It's not possible to create a Proxy on a Proxy //Here Entity can already be an Hibernate Proxy if (ProxyFactory.isProxyClass(classForProxy)) { classForProxy = classForProxy.getSuperclass(); } factory.setSuperclass(classForProxy); factory.setFilter(new AllMethodFilter()); try { return (Entity) factory.create(new Class<?>[0], new Object[0], new LazyMethodHandler(entity, lazyLoader)); } catch (final Exception e) { throw new RuntimeException("Error when proxifying object", e); } }
private static <T> T createProxyInstance(Class<T> entityType, MethodHandlerChain handlerChain) { ProxyFactory factory = new ProxyFactory(); if (ProxyFactory.isProxyClass(entityType)) { factory.setInterfaces(getNonProxyInterfaces(entityType)); factory.setSuperclass(entityType.getSuperclass()); } else { factory.setSuperclass(entityType); } factory.setFilter(handlerChain); Class<?> clazz = factory.createClass(); T proxy = instantiateClass(clazz); ((Proxy) proxy).setHandler(handlerChain); return proxy; }
private static <T> T createProxyInstance(Class<T> entityType, MethodHandlerChain handlerChain) { ProxyFactory factory = new ProxyFactory(); if (ProxyFactory.isProxyClass(entityType)) { factory.setInterfaces(getNonProxyInterfaces(entityType)); factory.setSuperclass(entityType.getSuperclass()); } else { factory.setSuperclass(entityType); } factory.setFilter(handlerChain); Class<?> clazz = factory.createClass(); T proxy = instantiateClass(clazz); ((Proxy) proxy).setHandler(handlerChain); return proxy; }