开发者

Seam - list all components

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.

@开发者_StackOverflow中文版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


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());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜