本文整理汇总了Java中org.picocontainer.defaults.DefaultPicoContainer.getComponentInstance方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultPicoContainer.getComponentInstance方法的具体用法?Java DefaultPicoContainer.getComponentInstance怎么用?Java DefaultPicoContainer.getComponentInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.picocontainer.defaults.DefaultPicoContainer
的用法示例。
在下文中一共展示了DefaultPicoContainer.getComponentInstance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTryPicoContainer2
import org.picocontainer.defaults.DefaultPicoContainer; //导入方法依赖的package包/类
@Test
public void testTryPicoContainer2() {
DefaultPicoContainer rootContainer = new DefaultPicoContainer();
rootContainer.registerComponentImplementation("component1", MyComponent1.class);
rootContainer.registerComponentImplementation("component1.1", MyComponent1.class);
rootContainer.registerComponentImplementation("component2", MyComponent2.class);
rootContainer.registerComponentImplementation(MyTestComponent.class);
MyInterface1 testInstance = new MyInterface1() {
@Override
public void run() {
}
};
rootContainer.registerComponentInstance(testInstance);
MyTestComponent testComponent = (MyTestComponent)rootContainer.getComponentInstance(MyTestComponent.class);
MyComponent2 component2 = (MyComponent2)rootContainer.getComponentInstance("component2");
MyComponent1 component11 = (MyComponent1)rootContainer.getComponentInstance("component1.1");
MyComponent1 component1 = (MyComponent1)rootContainer.getComponentInstance("component1");
assertEquals(testInstance, component1.testObject);
assertEquals(testInstance, component2.testObject);
assertTrue(Arrays.asList(component2.comp1).contains(component1));
assertTrue(Arrays.asList(component2.comp1).contains(component11));
assertTrue(Arrays.asList(testComponent.comp1).contains(component1));
assertTrue(Arrays.asList(testComponent.comp1).contains(component11));
assertEquals(component2, testComponent.comp2);
}
示例2: testTryPicoContainer2
import org.picocontainer.defaults.DefaultPicoContainer; //导入方法依赖的package包/类
public void testTryPicoContainer2() {
DefaultPicoContainer rootContainer = new DefaultPicoContainer();
rootContainer.registerComponentImplementation("component1", MyComponent1.class);
rootContainer.registerComponentImplementation("component1.1", MyComponent1.class);
rootContainer.registerComponentImplementation("component2", MyComponent2.class);
rootContainer.registerComponentImplementation(MyTestComponent.class);
MyInterface1 testInstance = new MyInterface1() {
@Override
public void run() {
}
};
rootContainer.registerComponentInstance(testInstance);
MyTestComponent testComponent = (MyTestComponent)rootContainer.getComponentInstance(MyTestComponent.class);
MyComponent2 component2 = (MyComponent2)rootContainer.getComponentInstance("component2");
MyComponent1 component11 = (MyComponent1)rootContainer.getComponentInstance("component1.1");
MyComponent1 component1 = (MyComponent1)rootContainer.getComponentInstance("component1");
assertEquals(testInstance, component1.testObject);
assertEquals(testInstance, component2.testObject);
assertTrue(Arrays.asList(component2.comp1).contains(component1));
assertTrue(Arrays.asList(component2.comp1).contains(component11));
assertTrue(Arrays.asList(testComponent.comp1).contains(component1));
assertTrue(Arrays.asList(testComponent.comp1).contains(component11));
assertEquals(component2, testComponent.comp2);
}
示例3: testTryPicoContainer
import org.picocontainer.defaults.DefaultPicoContainer; //导入方法依赖的package包/类
@Test
public void testTryPicoContainer() {
DefaultPicoContainer rootContainer = new DefaultPicoContainer();
rootContainer.registerComponentInstance("plugin1", new DefaultPicoContainer(rootContainer));
rootContainer.registerComponentInstance("plugin2", new DefaultPicoContainer(rootContainer));
MutablePicoContainer container1 = (MutablePicoContainer)rootContainer.getComponentInstance("plugin1");
MutablePicoContainer container2 = (MutablePicoContainer)rootContainer.getComponentInstance("plugin2");
container1.registerComponentImplementation("component1", MyComponent1.class);
container1.registerComponentImplementation("component1.1", MyComponent1.class);
container2.registerComponentImplementation("component2", MyComponent2.class);
MyInterface1 testInstance = new MyInterface1() {
@Override
public void run() { }
};
rootContainer.registerComponentInstance(testInstance);
MyComponent1 component1 = (MyComponent1)container1.getComponentInstance("component1");
assertEquals(testInstance, component1.testObject);
rootContainer.registerComponentInstance("component1", component1);
MyComponent1 component11 = (MyComponent1)container1.getComponentInstance("component1.1");
rootContainer.registerComponentInstance("component11", component11);
MyComponent2 component2 = (MyComponent2)container2.getComponentInstance("component2");
assertEquals(testInstance, component2.testObject);
assertTrue(Arrays.asList(component2.comp1).contains(component1));
assertTrue(Arrays.asList(component2.comp1).contains(component11));
rootContainer.registerComponentInstance("component2", component2);
rootContainer.registerComponentImplementation(MyTestComponent.class);
MyTestComponent testComponent = (MyTestComponent)rootContainer.getComponentInstance(MyTestComponent.class);
assertTrue(Arrays.asList(testComponent.comp1).contains(component1));
assertTrue(Arrays.asList(testComponent.comp1).contains(component11));
assertEquals(component2, testComponent.comp2);
}
示例4: testTryPicoContainer
import org.picocontainer.defaults.DefaultPicoContainer; //导入方法依赖的package包/类
public void testTryPicoContainer() {
DefaultPicoContainer rootContainer = new DefaultPicoContainer();
rootContainer.registerComponentInstance("plugin1", new DefaultPicoContainer(rootContainer));
rootContainer.registerComponentInstance("plugin2", new DefaultPicoContainer(rootContainer));
// rootContainer.registerComponentImplementation("plugin2", DefaultPicoContainer.class);
MutablePicoContainer container1 = (MutablePicoContainer)rootContainer.getComponentInstance("plugin1");
MutablePicoContainer container2 = (MutablePicoContainer)rootContainer.getComponentInstance("plugin2");
container1.registerComponentImplementation("component1", MyComponent1.class);
container1.registerComponentImplementation("component1.1", MyComponent1.class);
container2.registerComponentImplementation("component2", MyComponent2.class);
MyInterface1 testInstance = new MyInterface1() {
@Override
public void run() {
}
};
rootContainer.registerComponentInstance(testInstance);
MyComponent1 component1 = (MyComponent1)container1.getComponentInstance("component1");
assertEquals(testInstance, component1.testObject);
rootContainer.registerComponentInstance("component1", component1);
MyComponent1 component11 = (MyComponent1)container1.getComponentInstance("component1.1");
rootContainer.registerComponentInstance("component11", component11);
MyComponent2 component2 = (MyComponent2)container2.getComponentInstance("component2");
assertEquals(testInstance, component2.testObject);
assertTrue(Arrays.asList(component2.comp1).contains(component1));
assertTrue(Arrays.asList(component2.comp1).contains(component11));
rootContainer.registerComponentInstance("component2", component2);
rootContainer.registerComponentImplementation(MyTestComponent.class);
MyTestComponent testComponent = (MyTestComponent)rootContainer.getComponentInstance(MyTestComponent.class);
assertTrue(Arrays.asList(testComponent.comp1).contains(component1));
assertTrue(Arrays.asList(testComponent.comp1).contains(component11));
assertEquals(component2, testComponent.comp2);
}