问题
I would like to get a list of all the components so that I can further process them. Is this possible, if so, how can I do that? I don't believe I can observe all postCreate events since it is simply an exact match and not a regular expression.
@Observer("org.jboss.seam.postCreate.")
You can only observe those events and not * as it is put into a map where the key is a string.
Any ideas?
Walter
回答1:
As said
I would like to get a list of all the components
For each class declared as a component, Seam creates a component definition and stashes it away in the application scope. Its naming convention follows The pattern
- <COMPONENT_NAME>.component
So you can use
/**
* Metamodel class for component classes
*
* Similar to org.springframework.beans.factory.config.BeanDefinition used by Spring
*/
org.jboss.seam.Component
Context context = Contexts.getApplicationContext();
for (String name: context.getNames()) {
Object object = context.get(name);
if(object instanceof org.jboss.seam.Component) {
Component component = (Component) object;
System.out.println(component.getName());
System.out.println(component.getType());
System.out.println(component.getScope());
System.out.println(component.getTimeout());
System.out.println(component.isStartup());
System.out.println(component.isSynchronize());
}
}
If you want to retrieve a desired component, you can use
Object object = Component.getInstance(component.getName());
来源:https://stackoverflow.com/questions/2838787/seam-list-all-components