Re: [jboss-dev-forums] [JBoss Microcontainer Development] - Issues using Javassist TypeInfoFactory in other projects
by Kabir Khan
Kabir Khan [http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the discussion
"Issues using Javassist TypeInfoFactory in other projects"
To view the discussion, visit: http://community.jboss.org/message/534708#534708
--------------------------------------------------------------
> Kabir Khan wrote:
>
> Another issue is that dynamically created classes are not found in the classpools.
Rather than all the fancy BytecodeRecorder stuff, I am simply delegating to the IntrospectionTypeInfoFactory if the class can not be found in the classpool:
[kabir ~/sourcecontrol/jboss-reflect/trunk/jboss-reflect]
$svn diff
Index: src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
===================================================================
--- src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java (revision 103127)
+++ src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java (working copy)
@@ -49,6 +49,7 @@
import org.jboss.reflect.plugins.AnnotationValueImpl;
import org.jboss.reflect.plugins.EnumConstantInfoImpl;
import org.jboss.reflect.plugins.GenericsUtil;
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
import org.jboss.reflect.plugins.javassist.classpool.ClassPoolFactory;
import org.jboss.reflect.plugins.javassist.classpool.DefaultClassPoolFactory;
import org.jboss.reflect.spi.AnnotationInfo;
@@ -284,11 +285,33 @@
}
catch(NotFoundException nfe)
{
- throw new ClassNotFoundException(nfe.getMessage());
+ return delegateToIntrospectionImplementation(cl, name);
}
}
/**
+ * Proxies, whether
+ * <ul>
+ * <li>JDK dynamic proxies</li>
+ * <li>javassist ProxyFactory proxies - created by calling ClassLoader.defineClass()</li>
+ * </ul>
+ * are not visible to the javassist classpools, and neither will classes generated by cglib or other
+ * frameworks, so try to load up the class from the reflect implementation.
+ *
+ * @param cl the classloader
+ * @param name the name of the class
+ * @return the info
+ * @throws ClassNotFoundException when the class cannot be found
+ */
+ private TypeInfo delegateToIntrospectionImplementation(ClassLoader cl, String name) throws ClassNotFoundException
+ {
+ //Check the class has been loaded
+ cl.loadClass(name);
+ IntrospectionTypeInfoFactory factory = new IntrospectionTypeInfoFactory();
+ return factory.getTypeInfo(name, cl);
+ }
+
+ /**
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/534708#534708]
Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
14 years, 9 months
Re: [jboss-dev-forums] [JBoss Transactions Development] - beanifying the config
by Jonathan Halliday
Jonathan Halliday [http://community.jboss.org/people/jhalliday] replied to the discussion
"beanifying the config"
To view the discussion, visit: http://community.jboss.org/message/534687#534687
--------------------------------------------------------------
I think it's about time for another round...
Many of the remaining static initializers are concerned with taking a property value from an EnvironmentBean and using it to instantiate a class or classes e.g.
String checkedActionFactory = arjPropertyManager.getCoordinatorEnvironmentBean().getCheckedActionFactory();
Class factory = Thread.currentThread().getContextClassLoader().loadClass(checkedActionFactory);
CheckedActionFactory _checkedActionFactory = (CheckedActionFactory) factory.newInstance();
I'd like something that gives better control over
a) dynamic changes - it should not be necessary to reload the class (which basically means restarting the server) to change the effective value. Actually this is not just an issue for Class type properties and should probably be discussed separately.
b) type safety - ideally we'd detect problems at the point setCheckedActionFactory was called
c) class loading, particularly with regard to availability of the class and supply of any parameters it may need.
I'm mulling over a few alternatives, such as adding a typed version of the getter to the EnvironmentBean
CheckedActionFactory _checkedActionFactory = arjPropertyManager.getCoordinatorEnvironmentBean().getCheckedActionFactoryInstance();
and having some form of update synchronization between that and the setCheckedActionFactory(String) method. That may be sync on write i.e. instantiate the class at the point its stringified name is supplied, or it may be lazy. It may also be desirable to add a typed setter to the EnvironmentBean:
public class CoordinatorEnvironmentBean {
public void setCheckedActionFactoryInstance(CheckedActionFactory instance) {...}
although then we have also to tackle the reverse update of the String value from the class. However, it would allow for better beans wiring by DI frameworks compared to the current situation. In particular, the CheckedActionFactory impl could require ctor params and have those wired by the DI farmework, which is not possible with the current loading mechanism.
Anybody care to venture an opinion before I pick an implementation alternative at random?
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/534687#534687]
Start a new discussion in JBoss Transactions Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
14 years, 9 months
Re: [jboss-dev-forums] [JBoss Microcontainer Development] - Issues using Javassist TypeInfoFactory in other projects
by Kabir Khan
Kabir Khan [http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the discussion
"Issues using Javassist TypeInfoFactory in other projects"
To view the discussion, visit: http://community.jboss.org/message/534679#534679
--------------------------------------------------------------
It looks like ReflectMethodImpl.setMethod() and ReflectFieldImpl.setField() do that already:
RMI:
public void setMethod(Method method)
{
boolean isDeclaringClassPublic = true;
if (method != null)
{
accessCheck(Modifier.isPublic(method.getModifiers()));
isDeclaringClassPublic = isDeclaringClassPublic(method);
accessCheck(isDeclaringClassPublic);
}
this.method = method;
if (method != null && (isPublic() == false || isDeclaringClassPublic == false))
setAccessible();
}
RFI:
public void setField(Field field)
{
if (field != null)
accessCheck(Modifier.isPublic(field.getModifiers()));
this.field = field;
if (isPublic() == false && field != null)
setAccessible();
}
Commenting out the whole block which threw the exception for JavassistMethodInfo, and setAccessible=true for ReflectMethodInfoImpl, works with both modes
org.jboss.test.kernel.deployment.support.StaticInjector:
private void injectToMethod(Class<?> clazz, String method, Object value, Class<?> signature, boolean isPublic) throws Throwable
{
ClassInfo classInfo = configurator.getClassInfo(clazz);
MethodInfo mi = Config.findMethodInfo(classInfo, method, new String[]{signature.getName()}, true, isPublic);
// if (isPublic == false)
// {
// // TODO - move this into Reflection?
// if (mi instanceof ReflectMethodInfoImpl)
// {
// ReflectMethodInfoImpl rmi = (ReflectMethodInfoImpl)mi;
// Method m = rmi.getMethod();
// m.setAccessible(true);
// }
// else
// throw new IllegalArgumentException("Cannot set accessible on method info: " + mi);
// }
mi.invoke(null, new Object[]{value});
}
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/534679#534679]
Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
14 years, 9 months