/** * Returns the first current monitor found in the ComponentAdapterFactory, * the component adapters and the child containers, if these support a * ComponentMonitorStrategy. {@inheritDoc} * * @throws PicoIntrospectionException * if no component monitor is found in container or its children */ public ComponentMonitor currentMonitor() { if (componentAdapterFactory instanceof ComponentMonitorStrategy) { return ((ComponentMonitorStrategy) componentAdapterFactory).currentMonitor(); } for (Iterator i = compAdapters.iterator(); i.hasNext();) { Object adapter = i.next(); if (adapter instanceof ComponentMonitorStrategy) { return ((ComponentMonitorStrategy) adapter).currentMonitor(); } } for (Iterator i = children.iterator(); i.hasNext();) { Object child = i.next(); if (child instanceof ComponentMonitorStrategy) { return ((ComponentMonitorStrategy) child).currentMonitor(); } } throw new PicoIntrospectionException("No component monitor found in container or its children"); }
protected Object invoke(final Object target) { final Method method = getMethod(); try { componentMonitor.invoking(method, target); final long startTime = System.currentTimeMillis(); super.invoke(target); componentMonitor.invoked(method, target, System.currentTimeMillis() - startTime); } catch (final PicoIntrospectionException e) { componentMonitor.invocationFailed(method, target, (Exception)e.getCause()); throw e; } return Void.TYPE; }
private Class[] verifyInterfacesOnly(Class[] classes) { for (int i = 0; i < classes.length; i++) { if(!classes[i].isInterface()) { throw new PicoIntrospectionException("Class keys must be interfaces. " + classes[i] + " is not an interface."); } } return classes; }
public void verify(PicoContainer container) { org.jacorb.orb.ORB jorb = (org.jacorb.orb.ORB) container.getComponentInstance(ORB.class); if (jorb == null) { throw new PicoIntrospectionException("Need JacORB ORB"); } } }
/** * Returns delegate's current monitor if the delegate supports * a component monitor strategy. * {@inheritDoc} * @throws PicoIntrospectionException if no component monitor is found in delegate */ public ComponentMonitor currentMonitor() { if ( delegate instanceof ComponentMonitorStrategy ){ return ((ComponentMonitorStrategy)delegate).currentMonitor(); } throw new PicoIntrospectionException("No component monitor found in delegate"); }
protected Object invoke(final Object target) { final Method method = getMethod(); try { method.invoke(target, getArguments()); } catch (IllegalArgumentException e) { throw new PicoIntrospectionException("Can't call " + method.getName() + " on " + target, e); } catch (IllegalAccessException e) { throw new PicoIntrospectionException("Can't call " + method.getName() + " on " + target, e); } catch (InvocationTargetException e) { throw new PicoIntrospectionException("Failed when calling " + method.getName() + " on " + target, e .getTargetException()); } return Void.TYPE; } }
/** * {@inheritDoc} * * @see org.picocontainer.Parameter#verify(org.picocontainer.PicoContainer, * org.picocontainer.ComponentAdapter, java.lang.Class) */ public void verify(PicoContainer container, ComponentAdapter adapter, Class expectedType) throws PicoException { if (!checkPrimitive(expectedType) && !expectedType.isInstance(value)) { throw new PicoIntrospectionException(expectedType.getClass().getName() + " is not assignable from " + value.getClass().getName()); } }
if (!isCompatible) { if (!proxyFactory.canProxy(type)) { throw new PicoIntrospectionException("Cannot create proxy for type " + type.getName()); delegationType.getMethod(method.getName(), method.getParameterTypes()); } catch (final NoSuchMethodException e) { throw new PicoIntrospectionException("Cannot create proxy for type " + type.getName() + ", because of incompatible method "
/** * Returns the first current monitor found in the ComponentAdapterFactory, the component adapters * and the child containers, if these support a ComponentMonitorStrategy. * {@inheritDoc} * @throws PicoIntrospectionException if no component monitor is found in container or its children */ public ComponentMonitor currentMonitor() { if (componentAdapterFactory instanceof ComponentMonitorStrategy) { return ((ComponentMonitorStrategy) componentAdapterFactory).currentMonitor(); } for ( Iterator i = componentAdapters.iterator(); i.hasNext(); ){ Object adapter = i.next(); if ( adapter instanceof ComponentMonitorStrategy ) { return ((ComponentMonitorStrategy)adapter).currentMonitor(); } } for (Iterator i = children.iterator(); i.hasNext();) { Object child = i.next(); if (child instanceof ComponentMonitorStrategy) { return ((ComponentMonitorStrategy) child).currentMonitor(); } } throw new PicoIntrospectionException("No component monitor found in container or its children"); }
final private Class[] getInterfaces() { final Object componentKey = getComponentKey(); final Class[] interfaces; if (componentKey instanceof Class && ((Class)componentKey).isInterface()) { interfaces = new Class[]{(Class)componentKey}; } else { final Set allInterfaces = ReflectionUtils.getAllInterfaces(getComponentImplementation()); interfaces = (Class[])allInterfaces.toArray(new Class[allInterfaces.size()]); } if (interfaces.length == 0) { throw new PicoIntrospectionException("Can't proxy implementation for " + getComponentImplementation().getName() + ". It does not implement any interfaces."); } return interfaces; }
if (componentAdapters.isEmpty()) { if (!emptyCollection) { throw new PicoIntrospectionException(expectedType.getName() + " not resolvable, no components of type " + getValueType(expectedType).getName() throw new PicoIntrospectionException(expectedType.getName() + " is not a collective type");
/** * Resolve the parameter for the expected type. The method will return <code>null</code> * If the expected type is not one of the collection types {@link Array}, * {@link Collection}or {@link Map}. An empty collection is only a valid resolution, if * the <code>emptyCollection</code> flag was set. * * @param container {@inheritDoc} * @param adapter {@inheritDoc} * @param expectedType {@inheritDoc} * @return the instance of the collection type or <code>null</code> * @throws PicoInitializationException {@inheritDoc} */ public Object resolveInstance(PicoContainer container, ComponentAdapter adapter, Class expectedType) { // type check is done in isResolvable Object result = null; final Class collectionType = getCollectionType(expectedType); if (collectionType != null) { final Map adapterMap = getMatchingComponentAdapters(container, adapter, componentKeyType, getValueType(expectedType)); if (Array.class.isAssignableFrom(collectionType)) { result = getArrayInstance(container, expectedType, adapterMap); } else if (Map.class.isAssignableFrom(collectionType)) { result = getMapInstance(container, expectedType, adapterMap); } else if (Collection.class.isAssignableFrom(collectionType)) { result = getCollectionInstance(container, expectedType, adapterMap); } else { throw new PicoIntrospectionException(expectedType.getName() + " is not a collective type"); } } return result; }
public Object getComponentInstance(final PicoContainer container) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException { Object componentKey = getDelegate().getComponentKey(); Class[] classes = null; if (componentKey instanceof Class && ((Class) getDelegate().getComponentKey()).isInterface()) { classes = new Class[]{(Class) getDelegate().getComponentKey()}; } else if (componentKey instanceof Class[]) { classes = (Class[]) componentKey; } else { if(strict) { throw new PicoIntrospectionException("In strict mode, " + getClass().getName() + " only allows components registered with interface keys (java.lang.Class or java.lang.Class[])"); } return getDelegate().getComponentInstance(container); } Class[] interfaces = verifyInterfacesOnly(classes); return createProxy(interfaces, container, getDelegate().getComponentImplementation().getClassLoader()); }