本文整理汇总了Java中org.picocontainer.PicoContainer类的典型用法代码示例。如果您正苦于以下问题:Java PicoContainer类的具体用法?Java PicoContainer怎么用?Java PicoContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PicoContainer类属于org.picocontainer包,在下文中一共展示了PicoContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: instantiateExtension
import org.picocontainer.PicoContainer; //导入依赖的package包/类
@NotNull
protected Object instantiateExtension(String implementationClass, @NotNull PicoContainer picoContainer) throws ClassNotFoundException {
if (factoryClass != null) {
ExtensionFactory factory = instantiate(factoryClass, picoContainer);
return factory.createInstance(factoryArgument, implementationClass);
}
else {
if (implementationClass == null) {
throw new RuntimeException("implementation class is not specified for unknown language extension point, " +
"plugin id: " +
(myPluginDescriptor == null ? "<not available>" : myPluginDescriptor.getPluginId()) + ". " +
"Check if 'implementationClass' attribute is specified");
}
//noinspection unchecked
return instantiate(implementationClass, picoContainer);
}
}
示例2: 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);
}
示例3: createPicoContatiner
import org.picocontainer.PicoContainer; //导入依赖的package包/类
private MutablePicoContainer createPicoContatiner() {
final MutablePicoContainer picoContainer = new PicoBuilder()
.withBehaviors(new OptInCaching())
.withComponentFactory(new CompositeInjection(new AnnotatedFieldInjection(Inject.class)))
.build();
picoContainer.addComponent(PicoContainer.class, picoContainer);
picoContainer.as(Characteristics.CACHE).addComponent(Pico2InjectContext.class);
picoContainer.as(Characteristics.CACHE).addComponent(TestLazySingleton.class);
picoContainer.as(Characteristics.CACHE).addComponent(TestEagerSingleton.class);
picoContainer.addComponent(TestPrototype.class);
picoContainer.addComponent("key", "value");
return picoContainer;
}
示例4: ConfigurableEP
import org.picocontainer.PicoContainer; //导入依赖的package包/类
protected ConfigurableEP(PicoContainer picoContainer, @Nullable Project project) {
myProject = project;
myPicoContainer = picoContainer;
myFactory = new AtomicNotNullLazyValue<NullableFactory<T>>() {
@NotNull
@Override
protected NullableFactory<T> compute() {
if (providerClass != null) {
return new InstanceFromProviderFactory();
}
else if (instanceClass != null) {
return new NewInstanceFactory();
}
else if (implementationClass != null) {
return new ImplementationFactory();
}
throw new RuntimeException();
}
};
}
示例5: instantiateExtension
import org.picocontainer.PicoContainer; //导入依赖的package包/类
protected Object instantiateExtension(final String implementationClass, final PicoContainer picoContainer) throws ClassNotFoundException {
if (factoryClass != null) {
ExtensionFactory factory = instantiate(factoryClass, picoContainer);
return factory.createInstance(factoryArgument, implementationClass);
}
else {
if (implementationClass == null) {
throw new RuntimeException("implementation class is not specified for unknown language extension point, " +
"plugin id: " +
(myPluginDescriptor == null ? "<not available>" : myPluginDescriptor.getPluginId()) + ". " +
"Check if 'implementationClass' attribute is specified");
}
//noinspection unchecked
return instantiate(implementationClass, picoContainer);
}
}
示例6: registerExtension
import org.picocontainer.PicoContainer; //导入依赖的package包/类
@Override
public void registerExtension(@NotNull final PluginDescriptor pluginDescriptor, @NotNull final Element extensionElement) {
final PluginId pluginId = pluginDescriptor.getPluginId();
String epName = extractEPName(extensionElement);
ExtensionComponentAdapter adapter;
final PicoContainer container = getPluginContainer(pluginId.getIdString());
final ExtensionPointImpl extensionPoint = getExtensionPoint(epName);
if (extensionPoint.getKind() == ExtensionPoint.Kind.INTERFACE) {
String implClass = extensionElement.getAttributeValue("implementation");
if (implClass == null) {
throw new RuntimeException("'implementation' attribute not specified for '" + epName + "' extension in '" + pluginId.getIdString() + "' plugin");
}
adapter = new ExtensionComponentAdapter(implClass, extensionElement, container, pluginDescriptor, shouldDeserializeInstance(extensionElement));
}
else {
adapter = new ExtensionComponentAdapter(extensionPoint.getClassName(), extensionElement, container, pluginDescriptor, true);
}
myExtensionElement2extension.put(extensionElement, adapter);
internalGetPluginContainer().registerComponent(adapter);
extensionPoint.registerExtensionAdapter(adapter);
}
示例7: MockComponentManager
import org.picocontainer.PicoContainer; //导入依赖的package包/类
public MockComponentManager(@Nullable PicoContainer parent, @NotNull Disposable parentDisposable) {
myPicoContainer = new IdeaPicoContainer(parent) {
private Set<Object> myDisposableComponents = new ConcurrentHashSet<Object>();
@Override
@Nullable
public Object getComponentInstance(final Object componentKey) {
final Object o = super.getComponentInstance(componentKey);
if (o instanceof Disposable && o != MockComponentManager.this) {
if (myDisposableComponents.add(o))
Disposer.register(MockComponentManager.this, (Disposable)o);
}
return o;
}
};
myPicoContainer.registerComponentInstance(this);
Disposer.register(parentDisposable, this);
}
示例8: ConfigurableEP
import org.picocontainer.PicoContainer; //导入依赖的package包/类
protected ConfigurableEP(PicoContainer picoContainer, @Nullable Project project) {
myProject = project;
myPicoContainer = picoContainer;
myFactory = new AtomicNotNullLazyValue<NullableFactory<T>>() {
@Nonnull
@Override
protected NullableFactory<T> compute() {
if (providerClass != null) {
return new InstanceFromProviderFactory();
}
else if (instanceClass != null) {
return new NewInstanceFactory();
}
else if (implementationClass != null) {
return new ImplementationFactory();
}
throw new RuntimeException();
}
};
}
示例9: MockComponentManager
import org.picocontainer.PicoContainer; //导入依赖的package包/类
public MockComponentManager(@Nullable PicoContainer parent, @Nonnull Disposable parentDisposable) {
myPicoContainer = new DefaultPicoContainer(parent) {
private final Set<Object> myDisposableComponents = ContainerUtil.newConcurrentSet();
@Override
@Nullable
public Object getComponentInstance(final Object componentKey) {
final Object o = super.getComponentInstance(componentKey);
if (o instanceof Disposable && o != MockComponentManager.this) {
if (myDisposableComponents.add(o))
Disposer.register(MockComponentManager.this, (Disposable)o);
}
return o;
}
};
myPicoContainer.registerComponentInstance(this);
Disposer.register(parentDisposable, this);
}
示例10: main
import org.picocontainer.PicoContainer; //导入依赖的package包/类
/**
* Run the migrations for the given system name
*
* @param arguments the command line arguments, if any
* @throws Exception if anything goes wrong
*/
public static void main(final String[] arguments) throws Exception
{
AutopatchRegistry registry = new AutopatchRegistry();
PicoContainer pico = registry.configureContainer();
JdbcMigrationLauncherFactory launcherFactory = new JdbcMigrationLauncherFactoryLoader().createFactory();
StandaloneMigrationLauncher migrationLauncher = pico.getComponent(StandaloneMigrationLauncher.class);
migrationLauncher.getMigrationUtil().setLauncherFactory(launcherFactory);
migrationLauncher.run(arguments);
registry.destroyContainer();
}
示例11: configureContainer
import org.picocontainer.PicoContainer; //导入依赖的package包/类
public PicoContainer configureContainer(){
pico = new DefaultPicoContainer();
pico.addComponent(StandaloneMigrationLauncher.class);
pico.addComponent(MigrationUtil.class);
pico.start();
return pico;
}
示例12: resolveInstance
import org.picocontainer.PicoContainer; //导入依赖的package包/类
@Override
public Object resolveInstance(PicoContainer container, ComponentAdapter adapter, Class expectedType) {
if (clazz.isAssignableFrom(expectedType)) {
return obj;
}
return super.resolveInstance(container, adapter, expectedType);
}
示例13: ConfigurableEP
import org.picocontainer.PicoContainer; //导入依赖的package包/类
protected ConfigurableEP(PicoContainer picoContainer, @Nullable Project project) {
myProject = project;
myPicoContainer = picoContainer;
myProducer = new AtomicNotNullLazyValue<ObjectProducer>() {
@NotNull
@Override
protected ObjectProducer compute() {
try {
if (providerClass != null) {
return new ProviderProducer((ConfigurableProvider)instantiate(providerClass, myPicoContainer));
}
if (instanceClass != null) {
return new ClassProducer(myPicoContainer, findClass(instanceClass));
}
if (implementationClass != null) {
return new ClassProducer(myPicoContainer, findClass(implementationClass));
}
throw new RuntimeException("configurable class name is not set");
}
catch (AssertionError error) {
LOG.error(error);
}
catch (LinkageError error) {
LOG.error(error);
}
catch (Exception exception) {
LOG.error(exception);
}
return new ObjectProducer();
}
};
}
示例14: cloneTemplates
import org.picocontainer.PicoContainer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@NotNull
private List<T> cloneTemplates(@NotNull Collection<T> templates) {
List<T> result = new ArrayList<T>(templates.size());
PicoContainer container = ApplicationManager.getApplication().getPicoContainer();
for (T template : templates) {
Class<? extends T> aClass = (Class<? extends T>)template.getClass();
T clone = (T)new ConstructorInjectionComponentAdapter(aClass.getName(), aClass).getComponentInstance(container);
result.add(clone);
}
return result;
}
示例15: ExtensionsAreaImpl
import org.picocontainer.PicoContainer; //导入依赖的package包/类
public ExtensionsAreaImpl(String areaClass, AreaInstance areaInstance, PicoContainer parentPicoContainer, @NotNull LogProvider logger) {
myCreationTrace = DEBUG_REGISTRATION ? new Throwable("Area creation trace") : null;
myAreaClass = areaClass;
myAreaInstance = areaInstance;
myPicoContainer = new DefaultPicoContainer(parentPicoContainer);
myLogger = logger;
initialize();
}