Seam - list all components

爱⌒轻易说出口 提交于 2020-01-13 18:11:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!