@Override public boolean isLazy(ComponentAdapter<?> adapter) { return adapter.getComponentImplementation().getAnnotation(EagerStart.class) == null; } };
private static void assertAddedExtensions(ComponentContainer container, Class... classes) { Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters(); assertThat(adapters) .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + classes.length); Stream<Class> installedExtensions = adapters.stream() .map(t -> (Class) t.getComponentImplementation()) .filter(t -> !PropertyDefinitions.class.isAssignableFrom(t) && t != ComponentContainer.class); assertThat(installedExtensions) .contains(classes) .hasSize(classes.length); }
public List getComponentAdaptersOfType(Class componentType) { if (componentType == null) { return Collections.EMPTY_LIST; } List found = new ArrayList(); for (Iterator iterator = getComponentAdapters().iterator(); iterator.hasNext();) { ComponentAdapter componentAdapter = (ComponentAdapter) iterator.next(); if (componentType.isAssignableFrom(componentAdapter.getComponentImplementation())) { found.add(componentAdapter); } } return found; }
public List getComponentInstancesOfType(Class componentType) throws PicoException { if (componentType == null) { return Collections.EMPTY_LIST; } List result = new ArrayList(); Map adapterToInstanceMap = new HashMap(); for (Iterator iterator = compAdapters.iterator(); iterator.hasNext();) { ComponentAdapter componentAdapter = (ComponentAdapter) iterator.next(); if (componentType.isAssignableFrom(componentAdapter.getComponentImplementation())) { Object componentInstance = getInstance(componentAdapter); adapterToInstanceMap.put(componentAdapter, componentInstance); // This is to ensure all are added. (Indirect dependencies will // be added // from InstantiatingComponentAdapter). result.add(componentInstance); } } return result; }
public ComponentAdapter getComponentAdapterOfType(Class componentType) { // See http://jira.codehaus.org/secure/ViewIssue.jspa?key=PICO-115 ComponentAdapter adapterByKey = getComponentAdapter(componentType); if (adapterByKey != null) { return adapterByKey; } List found = getComponentAdaptersOfType(componentType); if (found.size() == 1) { return ((ComponentAdapter) found.get(0)); } else if (found.size() == 0) { if (parent != null) { return parent.getComponentAdapterOfType(componentType); } else { return null; } } else { Class[] foundClasses = new Class[found.size()]; for (int i = 0; i < foundClasses.length; i++) { ComponentAdapter componentAdapter = (ComponentAdapter) found.get(i); foundClasses[i] = componentAdapter.getComponentImplementation(); } throw new AmbiguousComponentResolutionException(componentType, foundClasses); } }
public Class getComponentClass(String name) { Debug.logVerbose("[JdonFramework]getComponentClass: name=" + name, module); ComponentAdapter componentAdapter = container.getComponentAdapter(name); if (componentAdapter == null) Debug.logVerbose("[JdonFramework]Not find the component in container :" + name, module); return componentAdapter.getComponentImplementation(); }
public ComponentAdapter registerComponent(ComponentAdapter componentAdapter) { if (componentAdapter instanceof DecoratingComponentAdapter) { componentAdapter = ((DecoratingComponentAdapter) componentAdapter).getDelegate(); } Object key = componentAdapter.getComponentKey(); if (componentAdapter instanceof InstanceComponentAdapter) { Object instance = ((InstanceComponentAdapter) componentAdapter).getComponentInstance(null); put(key, instance); } else { Class implementation = componentAdapter.getComponentImplementation(); put(key, implementation); } return componentAdapter; }
public Class<? extends T> getComponentImplementation() { @SuppressWarnings("unchecked") final Class<? extends T> componentImplementation = delegate.getComponentImplementation(); return componentImplementation; }
public Class getComponentImplementation() { return delegate.getComponentImplementation(); }
@Override public boolean evaluate(final ComponentAdapter adapter) { return type == adapter.getComponentImplementation(); }
public boolean evaluate(ComponentAdapter adapter) { return type == adapter.getComponentImplementation(); }
@Override public boolean isLazy(ComponentAdapter<?> adapter) { return adapter.getComponentImplementation().getAnnotation(EagerStart.class) == null; } };
public UnsatisfiableDependenciesException(ComponentAdapter instantiatingComponentAdapter, Set unsatisfiableDependencies, PicoContainer leafContainer) { super(instantiatingComponentAdapter.getComponentImplementation().getName() + " has unsatisfiable dependencies: " + unsatisfiableDependencies + " where " + leafContainer + " was the leaf container being asked for dependencies."); this.instantiatingComponentAdapter = instantiatingComponentAdapter; this.unsatisfiableDependencies = unsatisfiableDependencies; this.unsatisfiedDependencyType = null; this.leafContainer = leafContainer; }
public UnsatisfiableDependenciesException(ComponentAdapter instantiatingComponentAdapter, Class unsatisfiedDependencyType, Set unsatisfiableDependencies, PicoContainer leafContainer) { super(instantiatingComponentAdapter.getComponentImplementation().getName() + " has unsatisfied dependency: " + unsatisfiedDependencyType +" among unsatisfiable dependencies: "+unsatisfiableDependencies + " where " + leafContainer + " was the leaf container being asked for dependencies."); this.instantiatingComponentAdapter = instantiatingComponentAdapter; this.unsatisfiableDependencies = unsatisfiableDependencies; this.unsatisfiedDependencyType = unsatisfiedDependencyType; this.leafContainer = leafContainer; }
@Override public boolean evaluate(final ComponentAdapter adapter) { return type.isAssignableFrom(adapter.getComponentImplementation()); }
public List getComponentAdaptersOfType(Class componentType) { if (componentType == null) { return Collections.EMPTY_LIST; } List found = new ArrayList(); for (Iterator iterator = getComponentAdapters().iterator(); iterator.hasNext();) { ComponentAdapter componentAdapter = (ComponentAdapter) iterator.next(); if (componentType.isAssignableFrom(componentAdapter.getComponentImplementation())) { found.add(componentAdapter); } } return found; }
public CachingComponentAdapter(ComponentAdapter delegate, ObjectReference instanceReference) { super(delegate); this.instanceReference = instanceReference; this.disposed = false; this.started = false; this.delegateHasLifecylce = delegate instanceof LifecycleStrategy && ((LifecycleStrategy) delegate).hasLifecycle(delegate.getComponentImplementation()); }
@Override protected List<Class<?>> stepsTypes() { List<Class<?>> types = new ArrayList<>(); for (ComponentAdapter<?> adapter : parent.getComponentAdapters()) { if (hasAnnotatedMethods(adapter.getComponentImplementation())) { types.add(adapter.getComponentImplementation()); } } return types; }
public Object remove(Object o) { ComponentAdapter adapter = mutablePicoContainer.unregisterComponent(o); if (adapter != null) { // if previously an instance was registered, return it, otherwise return the type return adapter instanceof InstanceComponentAdapter ? adapter .getComponentInstance(mutablePicoContainer) : adapter .getComponentImplementation(); } else { return null; } }
public Object remove(final Object o) { ComponentAdapter adapter = mutablePicoContainer.removeComponent(o); if (adapter != null) { // if previously an instance was registered, return it, otherwise return the type return adapter instanceof InstanceAdapter ? adapter .getComponentInstance(mutablePicoContainer, ComponentAdapter.NOTHING.class) : adapter .getComponentImplementation(); } else { return null; } }