Comment #49 on issue 62 by ericaro: Lifecycle support
http://code.google.com/p/google-guice/issues/detail?id=62
for the one expecting the feature, here is a "snipper" of mine:
//annotatedMethods is a simple method that return a list of any methods
(and super ones, that has the given annotation)
public static <T extends Annotation> List<Method> annotatedMethods(Class<?>
target, Class<T> annotationClass) {
List<Method> methods = new ArrayList<Method>();
while (target != null) {
for (Method m : target.getDeclaredMethods()) {
T annotated = m.getAnnotation(annotationClass);
if (annotated != null) {
methods.add(m);
}
}
target = target.getSuperclass();
}
return methods;
}
// the type listener itself
public class JFormDesignerTypeListener implements TypeListener {
public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T>
typeEncounter) {
Class<? super T> raw = typeLiteral.getRawType();
List<Method> methods = annotatedMethods(raw,
PostConstruct.class);
typeEncounter.register(new JFormDesignerInjector<T>(methods));
}
}
//and the JFormDesignerInjector :
class JFormDesignerInjector<T> implements MembersInjector<T> {
private List<Method> methods;
public JFormDesignerInjector(List<Method> methods) {
super();
this.methods = methods;
}
/**
* @param t
*/
public void injectMembers(final T t) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
for (Method m : methods) {
try {
m.setAccessible(true);
m.invoke(t, null);
} catch
(InvocationTargetException ite) {
assert false : "Static
Exception Occurred. @PostConstructor Method raises an exception:" +
t.getClass() + ":" + m.getName() + " raises :" +
ite.getTargetException() + " : " + ite.getTargetException().getMessage();
} catch (Throwable e) {
assert false : "Static Exception Occurred. @See logs for more details
in: " + JFormDesignerInjector.this.getClass().getName() + " " +
e.getMessage();
}
}
}
});
}
I've tried to simplified my actual code ( in fact I've mixed bean
injections from JFormDesigner and @PostConstructor ).
The main idea here is to use the swing invokelater to handle the
PostConstructor. this is quite nice for "swing" requirements ( as I had ).
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.