当前位置: 首页>>代码示例>>Java>>正文


Java PicoContainer.getComponentInstance方法代码示例

本文整理汇总了Java中org.picocontainer.PicoContainer.getComponentInstance方法的典型用法代码示例。如果您正苦于以下问题:Java PicoContainer.getComponentInstance方法的具体用法?Java PicoContainer.getComponentInstance怎么用?Java PicoContainer.getComponentInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.picocontainer.PicoContainer的用法示例。


在下文中一共展示了PicoContainer.getComponentInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPicoContainer

import org.picocontainer.PicoContainer; //导入方法依赖的package包/类
public void testPicoContainer() {
// cut:start-1
    DefaultPicoContainer dc = new DefaultPicoContainer();
    try {
      // Register BaseRenderEngine as an Implementation
      // of RenderEngine
      dc.registerComponentImplementation(
          RenderEngine.class,
          BaseRenderEngine.class);
    } catch (Exception e) {
      log.error("Could not register component.");
    }

    // now only work with container
    PicoContainer container = dc;

    // Only ask for RenderEngine, we automatically
    // get an available object
    // that implements RenderEngine
    RenderEngine engine = (RenderEngine)
      container.getComponentInstance(RenderEngine.class);
    RenderContext context = new BaseRenderContext();
    String result = engine.render("__SnipSnap__", context);
// cut:end-1
    assertEquals("Rendered with PicoContainer.", "<b class=\"bold\">SnipSnap</b>", result);
  }
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:27,代码来源:PicoContainerExample.java

示例2: testPicoWithInitialRenderContext

import org.picocontainer.PicoContainer; //导入方法依赖的package包/类
public void testPicoWithInitialRenderContext() {
// cut:start-2
    DefaultPicoContainer dc = new DefaultPicoContainer();
    try {
      InitialRenderContext initialContext =
          new BaseInitialRenderContext();
      initialContext.set(RenderContext.OUTPUT_LOCALE,
                         new Locale("mywiki", "mywiki"));
      dc.registerComponentInstance(InitialRenderContext.class,
                                   initialContext);
      dc.registerComponentImplementation(RenderEngine.class,
                                         BaseRenderEngine.class);
    } catch (Exception e) {
      log.error("Could not register component.");
    }
// cut:end-2
    // now only work with container
    PicoContainer container = dc;

    // Only ask for RenderEngine, we automatically
    // get an available object
    // that implements RenderEngine
    RenderEngine engine = (RenderEngine)
      container.getComponentInstance(RenderEngine.class);

    assertNotNull("Component found.", engine);
    RenderContext context = new BaseRenderContext();
    String result = engine.render("__SnipSnap__", context);
    assertEquals("Rendered with PicoContainer and otherwiki Locale.",
                 "<b class=\"mybold\">SnipSnap</b>", result);

  }
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:33,代码来源:PicoContainerExample.java

示例3: execute

import org.picocontainer.PicoContainer; //导入方法依赖的package包/类
public void execute(Writer writer, SnipMacroParameter params)
  throws IllegalArgumentException, IOException {

  SnipRenderContext context = params.getSnipRenderContext();
  Snip snip = (Snip)
      context.getAttribute(SnipRenderContext.SNIP);
  PicoContainer container = (PicoContainer)
    context.getAttribute(SnipRenderContext.CONTAINER);

  MessageService service = (MessageService)
    container.getComponentInstance(MessageService.class);
  Message message = new Message("SNIP_VIEWED",
                                snip.getName());
  service.send(message);
}
 
开发者ID:thinkberg,项目名称:snipsnap,代码行数:16,代码来源:MessageSendMacro.java


注:本文中的org.picocontainer.PicoContainer.getComponentInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。