本文整理汇总了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);
}
示例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);
}
示例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);
}