private Object getTrueInstance(ComponentAdapter ad) { if (compAdapters.contains(ad)) return ad.getComponentInstance(this); return getP(ad); }
/** * Loads a binding with a specifc class into a context. * * @param bindingClass The class of the binding. * @param context The context which is to contain the binding. * @return The binding object of the associated type, otherwise null if no such binding could be * created. */ public Binding loadBinding(QName qName, Class bindingClass, PicoContainer context) { // instantiate within the given context ComponentAdapter adapter = new ConstructorInjectionComponentAdapter(qName, bindingClass); return (Binding) adapter.getComponentInstance(context); }
/** * Loads a binding with a specifc QName into a context. * * @param qName The qualified name of the type of the binding object. * @param context The context which is to contain the binding. * @return The binding object of the associated type, otherwise null if no such binding could be * created. */ public Binding loadBinding(QName qName, PicoContainer context) { Object o = bindings.get(qName); if (o == null) { return null; } if (o instanceof ComponentAdapter) { return (Binding) ((ComponentAdapter) o).getComponentInstance(context); } if (o instanceof Class) { return loadBinding(qName, (Class) o, context); } return (Binding) o; }
/** * This method will usually create a new instance each time it is called * * @param name * component name * @return object new instance */ public Object getComponentNewInstance(String name) { Debug.logVerbose("[JdonFramework]getComponentNewInstance: name=" + name, module); ComponentAdapter componentAdapter = container.getComponentAdapter(name); if (componentAdapter == null) { Debug.logWarning("[JdonFramework]Not find the component in container :" + name, module); return null; } return componentAdapter.getComponentInstance(container); }
public T getComponentInstance() throws PicoInitializationException, PicoIntrospectionException { @SuppressWarnings("unchecked") final T componentInstance = (T) delegate.getComponentInstance(); return componentInstance; }
public Object get() { if (componentInstance == null) { componentInstance = delegate.getComponentInstance(container); } return componentInstance; }
public Object getComponentInstance(PicoContainer container) throws PicoInitializationException, PicoIntrospectionException { return delegate.getComponentInstance(container); }
ParserDelegate delegate = (ParserDelegate) adapter.getComponentInstance(context);
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { final Object delegatedInstance = delegate.getComponentInstance(pico,null); if (method.equals(ReflectionUtils.equals)) { // necessary for JDK 1.3 return args[0] != null && args[0].equals(delegatedInstance); } else { try { return method.invoke(delegatedInstance, args); } catch (final InvocationTargetException e) { throw e.getTargetException(); } } } }
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { final Object delegatedInstance = delegate.getComponentInstance(pico); if (method.equals(ReflectionUtils.equals)) { // necessary for JDK 1.3 return new Boolean(args[0] != null && args[0].equals(delegatedInstance)); } else { try { return method.invoke(delegatedInstance, args); } catch (final InvocationTargetException e) { throw e.getTargetException(); } } } }
/** * in case component adapter is JNDIExposed, poke it gently and * it will create component and register it to JNDI if not already * done. */ @Override public void visitComponentAdapter(final ComponentAdapter componentAdapter) { super.visitComponentAdapter(componentAdapter); if(componentAdapter instanceof JNDIExposed) { componentAdapter.getComponentInstance(container,null); } }
/** * Loads a binding with a specifc class into a context. * * @param bindingClass The class of the binding. * @param context The context which is to contain the binding. * * @return The binding object of the associated type, otherwise null if * no such binding could be created. * */ public Binding loadBinding(QName qName, Class bindingClass, MutablePicoContainer context) { //instantiate within the given context ComponentAdapter adapter = new ConstructorInjectionComponentAdapter( qName, bindingClass ); return (Binding) adapter.getComponentInstance( context ); }
/** * Loads a binding with a specifc class into a context. * * @param bindingClass The class of the binding. * @param context The context which is to contain the binding. * * @return The binding object of the associated type, otherwise null if * no such binding could be created. * */ public Binding loadBinding(Class bindingClass, MutablePicoContainer context) { ComponentAdapter adapter = container.getComponentAdapterOfType(bindingClass); if ( adapter == null ) { return null; } return (Binding) adapter.getComponentInstance( context ); }
@Override protected <T> Collection<T> getComponentsInternal(final Class<T> iface) { final Collection<T> implementations = new ArrayList<T>(); final PicoContainer picoContainer = ComponentManager.getInstance().getContainer(); final List componentAdaptersOfType = picoContainer.getComponentAdaptersOfType(iface); for (final Iterator iterator = componentAdaptersOfType.iterator(); iterator.hasNext();) { final ComponentAdapter componentAdapter = (ComponentAdapter) iterator.next(); implementations.add((T) componentAdapter.getComponentInstance()); } return implementations; }
@Override protected <T> Collection<T> getComponentsInternal(Class<T> iface) { Collection<T> implementations = new ArrayList<T>(); PicoContainer picoContainer = ComponentManager.getInstance().getContainer(); List componentAdaptersOfType = picoContainer.getComponentAdaptersOfType(iface); for (Iterator iterator = componentAdaptersOfType.iterator(); iterator.hasNext();) { ComponentAdapter componentAdapter = (ComponentAdapter) iterator.next(); implementations.add((T) componentAdapter.getComponentInstance()); } return implementations; } }
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; } }
/** * Returns all the components currently inside Pico which are instances of the given class, mapping them to their * component key. * * @param iface The class to search for * @return a map, mapping the component key, to the instances of the clas registered in JIRA's pico container. */ public static <T> Map<String, T> getComponentsOfTypeMap(final Class<T> iface) { final PicoContainer picoContainer = getInstance().getContainer(); final List<ComponentAdapter<T>> componentAdaptersOfType = picoContainer.getComponentAdapters(iface); final Map<String, T> implementations = new HashMap<String, T>(); for (final ComponentAdapter<T> componentAdapter : componentAdaptersOfType) { final T componentInstance = iface.cast(componentAdapter.getComponentInstance(picoContainer)); implementations.put(String.valueOf(componentAdapter.getComponentKey()), componentInstance); } return Collections.unmodifiableMap(implementations); }
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { Object componentInstance = getDelegate().getComponentInstance(container); ComponentMonitor componentMonitor = currentMonitor(); try { componentMonitor.invoking(method, componentInstance); long startTime = System.currentTimeMillis(); Object object = method.invoke(componentInstance, args); componentMonitor.invoked(method, componentInstance, System.currentTimeMillis() - startTime); return object; } catch (final InvocationTargetException ite) { componentMonitor.invocationFailed(method, componentInstance, ite); throw ite.getTargetException(); } } });
private void registerEventComponents() { EventPublisher eventPublisher = getComponent(EventPublisher.class); Set<Object> registeredListeners = Sets.newIdentityHashSet(); Collection<ComponentAdapter<?>> componentAdapters = getContainer().getComponentAdapters(); for (ComponentAdapter<?> componentAdapter : componentAdapters) { Class<?> componentKey = componentAdapter.getComponentImplementation(); if (componentKey.getAnnotation(EventComponent.class) != null) { Object instance = componentAdapter.getComponentInstance(container.getPicoContainer(), ComponentAdapter.NOTHING.class); if (registeredListeners.add(instance)) { eventPublisher.register(instance); } } } }