private Object getP(ComponentAdapter adapter) { if (parent != null) { return parent.getComponentInstance(adapter.getComponentKey()); } return null; }
/** * {@inheritDoc} This method can be used to override the ComponentAdapter * created by the {@link ComponentAdapterFactory} passed to the constructor * of this container. */ public ComponentAdapter registerComponent(ComponentAdapter componentAdapter) throws DuplicateComponentKeyRegistrationException { Object componentKey = componentAdapter.getComponentKey(); if (compKeyAdapters.containsKey(componentKey)) { throw new DuplicateComponentKeyRegistrationException(componentKey); } compAdapters.add(componentAdapter); compKeyAdapters.put(componentKey, componentAdapter); return componentAdapter; }
/** * modify this method of old DefaultPicocontainer * * @param componentAdapter * @return */ public Object getInstance(ComponentAdapter componentAdapter) { Object componentKey = componentAdapter.getComponentKey(); Object instance = compKeyInstances.get(componentKey); if (instance == null) { instance = loadSaveInstance(componentAdapter, componentKey); } return instance; }
public ComponentAdapter unregisterComponentByInstance(Object componentInstance) { Collection componentAdapters = getComponentAdapters(); for (Iterator iterator = componentAdapters.iterator(); iterator.hasNext();) { ComponentAdapter componentAdapter = (ComponentAdapter) iterator.next(); if (getInstance(componentAdapter).equals(componentInstance)) { return unregisterComponent(componentAdapter.getComponentKey()); } } return null; }
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 Object getComponentKey() { return delegate.getComponentKey(); }
@Override public boolean evaluate(final ComponentAdapter adapter) { return key.equals(adapter.getComponentKey()); }
@Override public boolean evaluate(final ComponentAdapter adapter) { return type.isAssignableFrom(adapter.getComponentKey().getClass()); }
@Override public <T> ComponentAdapter<T> removeComponentByInstance(final T componentInstance) { // We don't actually ever call this method ATM, but anyway... ComponentAdapter<T> removedComponent = delegatePicoContainer.removeComponentByInstance(componentInstance); if (removedComponent != null) { componentCache.remove(removedComponent.getComponentKey()); } return removedComponent; }
void register(final ComponentAdapter componentAdapter) { final Object key = componentAdapter.getComponentKey(); if (key instanceof Class<?>) { register((Class<?>) key); } }
private Object[] getArrayInstance(final PicoContainer container, final Class expectedType, final Map adapterList) { final Object[] result = (Object[]) Array.newInstance(expectedType.getComponentType(), adapterList.size()); int i = 0; for (final Iterator iterator = adapterList.values().iterator(); iterator.hasNext();) { final ComponentAdapter componentAdapter = (ComponentAdapter) iterator.next(); result[i] = container.getComponentInstance(componentAdapter.getComponentKey()); i++; } return result; }
public Set keySet() { Set<Object> set = new HashSet<Object>(); Collection<ComponentAdapter<?>> adapters = mutablePicoContainer.getComponentAdapters(); for (final ComponentAdapter<?> adapter : adapters) { set.add(adapter.getComponentKey()); } return Collections.unmodifiableSet(set); }
/** * construct reference itself using vanilla initial context. * JNDI name is stringified component key * @param delegate * delegate adapter * @throws NamingException */ public JNDIExposed(final ComponentAdapter<T> delegate) throws NamingException { super(delegate, new JNDIObjectReference<Stored.Instance<T>>(delegate.getComponentKey() .toString(), new InitialContext())); }
public Set keySet() { Set set = new HashSet(); Collection adapters = mutablePicoContainer.getComponentAdapters(); for (final Iterator iter = adapters.iterator(); iter.hasNext();) { final ComponentAdapter adapter = (ComponentAdapter)iter.next(); set.add(adapter.getComponentKey()); } return Collections.unmodifiableSet(set); }
private void removeAllComponents() { List<ComponentAdapter<?>> componentAdapters = Lists.newArrayList(wrappedContainer.getComponentAdapters()); for (ComponentAdapter adapter : componentAdapters) { wrappedContainer.removeComponent(adapter.getComponentKey()); } } }
public ComponentAdapter unregisterComponentByInstance(Object componentInstance) { Collection componentAdapters = getComponentAdapters(); for (Iterator iterator = componentAdapters.iterator(); iterator.hasNext();) { ComponentAdapter componentAdapter = (ComponentAdapter) iterator.next(); if (getInstance(componentAdapter).equals(componentInstance)) { return unregisterComponent(componentAdapter.getComponentKey()); } } return null; }
public Object resolveInstance(PicoContainer container, ComponentAdapter adapter, Class expectedType) { final ComponentAdapter componentAdapter = resolveAdapter(container, adapter, expectedType); if (componentAdapter != null) { return container.getComponentInstance(componentAdapter.getComponentKey()); } return null; }
@Override public MutablePicoContainer addAdapter(final ComponentAdapter<?> componentAdapter, final Properties properties) { super.addAdapter(componentAdapter, properties); if (componentAdapter.findAdapterOfType(InstanceAdapter.class) != null) { this.instanceRegistrations.add(componentAdapter); } else { this.addStoredReference(componentAdapter.getComponentKey()); } return this; }
@Override public MutablePicoContainer addAdapter(final ComponentAdapter<?> componentAdapter) { super.addAdapter(componentAdapter); if (componentAdapter.findAdapterOfType(InstanceAdapter.class) != null) { this.instanceRegistrations.add(componentAdapter); } else { this.addStoredReference(componentAdapter.getComponentKey()); } return this; }
@Override public <T> void instantiated(PicoContainer container, ComponentAdapter<T> componentAdapter, Constructor<T> constructor, Object instantiated, Object[] injected, long duration) { final TypeNameExtractor extractor = container.getComponent(TypeNameExtractor.class); Object object = componentAdapter.getComponentKey(); if (object instanceof Class<?>) { Class<?> type = (Class<?>) object; setter.setAttribute(extractor.nameFor(type), instantiated); } else if (instantiated != null){ setter.setAttribute(extractor.nameFor(instantiated.getClass()), instantiated); } } }