接缝 - 列出所有组件 [英] Seam - list all components

查看:49
本文介绍了接缝 - 列出所有组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得所有组件的列表,以便我可以进一步处理它们.这是可能的,如果是这样,我该怎么做?我不相信我可以观察到所有 postCreate 事件,因为它只是一个完全匹配而不是正则表达式.

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.")

@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.

有什么想法吗?

沃尔特

推荐答案

如上所述

我想获得所有组件的列表

I would like to get a list of all the components

对于每个声明为组件的类,Seam 创建一个组件定义并将其隐藏在应用范围中.它的命名约定遵循 模式

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

所以你可以使用

/**
  * 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());

这篇关于接缝 - 列出所有组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆