Skip to content

Commit

Permalink
Merge pull request #114 from caelum/javassist-fixes
Browse files Browse the repository at this point in the history
Some javassist fixes
  • Loading branch information
garcia-jj committed Sep 24, 2013
2 parents f07a220 + 2a004f7 commit c5e3255
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions vraptor-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<version>0.9.2</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
<version>3.18.0-GA</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,10 @@ public JavassistProxifier(InstanceCreator instanceCreator) {
}

@Override
@SuppressWarnings("rawtypes")
public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) {
final ProxyFactory factory = new ProxyFactory();
factory.setFilter(IGNORE_BRIDGE_AND_OBJECT_METHODS);
Class rawType = type;
if (isProxyClass(type)) {
rawType = type.getSuperclass();
}
Class<?> rawType = extractRawType(type);

if (type.isInterface()) {
factory.setInterfaces(new Class[] { rawType });
Expand All @@ -91,21 +87,33 @@ public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) {
Object proxyInstance = instanceCreator.instanceFor(proxyClass);
setHandler(proxyInstance, handler);

logger.debug("a proxy for {} is created as {}", type, proxyClass);
logger.debug("a proxy for {} was created as {}", type, proxyClass);

return type.cast(proxyInstance);
}

private <T> Class<?> extractRawType(Class<T> type) {
return isProxyType(type) ? type.getSuperclass() : type;
}

@Override
public boolean isProxy(Object o) {
return o != null && isProxyClass(o.getClass());
return o != null && isProxyType(o.getClass());
}

@Override
public boolean isProxyType(Class<?> type) {
return isProxyClass(type) || org.jboss.weld.bean.proxy.ProxyFactory.isProxy(type);
boolean proxy = isProxyClass(type) || isWeldProxy(type);
logger.debug("Class {} is proxy: {}", type.getName(), proxy);

return proxy;
}

// FIXME only works with weld, and can throws ClassNotFoundException in another CDI implementations
private boolean isWeldProxy(Class<?> type) {
return org.jboss.weld.bean.proxy.ProxyFactory.isProxy(type);
}

private <T> void setHandler(Object proxyInstance, final MethodInvocation<? super T> handler) {
ProxyObject proxyObject = (ProxyObject) proxyInstance;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ public interface Proxifier {
* @param o The object to test
* @return <code>true</code> if the object is a proxy, false otherwise.
*/
public abstract boolean isProxyType(Class<?> type);
boolean isProxyType(Class<?> type);
}

0 comments on commit c5e3255

Please sign in to comment.