/** * retrieve object from JNDI if possible */ public T get() { try { return (T) context.lookup(name); } catch(NameNotFoundException e) { // this is not error, but normal situation - nothing // was stored yet return null; } catch (NamingException e) { throw new PicoCompositionException("unable to resolve jndi name:" + name, e); } }
log.error(e.getMessage(), e); if (e.getCause() != null) log.error("Cause: " + e.getCause(), e.getCause());
private Reader getResource(String resource) { ClassLoader classLoader = getClassLoader(); InputStream stream = classLoader.getResourceAsStream(resource); if (stream == null) { throw new PicoCompositionException("Resource " + resource + " not found in classloader " + classLoader); } return new InputStreamReader(stream); }
public Class<?> getActionClass(String className) throws PicoCompositionException { try { return loadClass(className); } catch (ClassNotFoundException e) { throw new PicoCompositionException("Action class '" + className + "' not found", e); } }
public Class<?> getActionClass(String className) throws PicoCompositionException { try { return loadClass(className); } catch (ClassNotFoundException e) { throw new PicoCompositionException("Action class '" + className + "' not found", e); } }
/** * Returns the */ public T getComponentInstance(final PicoContainer container, final Type into) throws PicoCompositionException { try { return (T) factoryMethod.invoke(targetInstance); } catch (RuntimeException e) { throw new PicoCompositionException( "Error invoking delegate for object construction", e); } }
/** * Get the class to do compostition with - from a "webapp-composer-class" config param * from web.xml : * * <context-param> * <param-name>webapp-composer-class</param-name> * <param-value>com.yourcompany.YourWebappComposer</param-value> * </context-param> * * @param context * @return */ protected WebappComposer loadComposer(ServletContext context) { String composerClassName = context.getInitParameter(WEBAPP_COMPOSER_CLASS); try { return (WebappComposer) Thread.currentThread().getContextClassLoader().loadClass(composerClassName) .newInstance(); } catch (Exception e) { throw new PicoCompositionException("Failed to load webapp composer class " + composerClassName + ": ensure the context-param '" + WEBAPP_COMPOSER_CLASS + "' is configured in the web.xml.", e); } }
private Parameter[] createChildParameters(ClassLoadingPicoContainer container, Element element) throws ClassNotFoundException, MalformedURLException { List<Parameter> parametersList = new ArrayList<Parameter>(); NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i) instanceof Element) { Element childElement = (Element) children.item(i); if (PARAMETER.equals(childElement.getNodeName())) { parametersList.add(createParameter(container, childElement)); } if (PARAMETER_ZERO.equals(childElement.getNodeName())) { //Check: We can't check everything here since we aren't schema validating //But it will at least catch some goofs. if (!parametersList.isEmpty()) { throw new PicoCompositionException("Cannot mix other parameters with '" + PARAMETER_ZERO +"' nodes." ); } return Parameter.ZERO; } } } Parameter[] parameters = null; if (!parametersList.isEmpty()) { parameters = parametersList.toArray(new Parameter[parametersList.size()]); } return parameters; }
private XMLComponentInstanceFactory createComponentInstanceFactory(String factoryClass) { if ( notSet(factoryClass)) { // no factory has been specified for the node // return globally defined factory for the container - if there is one if (componentInstanceFactory != null) { return componentInstanceFactory; } factoryClass = DEFAULT_COMPONENT_INSTANCE_FACTORY; } // using a PicoContainer is overkill here. try { return (XMLComponentInstanceFactory)getClassLoader().loadClass(factoryClass).newInstance(); } catch (InstantiationException e) { throw new PicoCompositionException(e); } catch (IllegalAccessException e) { throw new PicoCompositionException(e); } catch (ClassNotFoundException e) { throw new PicoClassNotFoundException(factoryClass, e); } }
throw new PicoCompositionException("can't instantiate " + o); } catch (IllegalAccessException e) { throw new PicoCompositionException("illegal access " + o); } catch (NoSuchMethodException e) {
if (!isCompatible) { if (!proxyFactory.canProxy(type)) { throw new PicoCompositionException("Cannot create proxy for type " + type.getName()); delegationType.getMethod(method.getName(), method.getParameterTypes()); } catch (final NoSuchMethodException e) { throw new PicoCompositionException("Cannot create proxy for type " + type.getName() + ", because of incompatible method "
@Override public <T> ComponentAdapter<T> addComponentAdapter( final ComponentMonitor componentMonitor, final LifecycleStrategy lifecycleStrategy, final Properties componentProperties, final ComponentAdapter<T> adapter) { try { return new JNDIExposed<T>(super.addComponentAdapter( componentMonitor, lifecycleStrategy, componentProperties, adapter)); } catch (NamingException e) { throw new PicoCompositionException( "unable to create JNDI behaviour", e); } }
@Override public <T> ComponentAdapter<T> removeComponent(final Object componentKey) { ComponentAdapter< T > result= null; try { result = super.removeComponent(componentKey); } catch (PicoCompositionException e) { //Help with debugging any lifecycle errors. throw new PicoCompositionException("There was an error removing component by key: '" + componentKey + "'",e); } if (result != null) { removeLocalReferences(result); } return result; }
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 PicoCompositionException("Can't proxy implementation for " + getComponentImplementation().getName() + ". It does not implement any interfaces."); } return interfaces; }
@Override public <T> ComponentAdapter<T> createComponentAdapter( final ComponentMonitor componentMonitor, final LifecycleStrategy lifecycleStrategy, final Properties componentProperties, final Object componentKey, final Class<T> componentImplementation, final Parameter... parameters) throws PicoCompositionException { // TODO Auto-generated method stub ComponentAdapter<T> componentAdapter = super.createComponentAdapter( componentMonitor, lifecycleStrategy, componentProperties, componentKey, componentImplementation, parameters); try { return new JNDIExposed<T>(componentAdapter); } catch (NamingException e) { throw new PicoCompositionException( "unable to create JNDI behaviour", e); } }
throw new PicoCompositionException("Cannot mix other parameters with '" + PARAMETER_ZERO +"' nodes." );
throw new PicoCompositionException("unable to bind to jndi name:" + name, e);
throw new PicoCompositionException("Registering MBean failed", exception);
private MutablePicoContainer createMutablePicoContainer(PicoContainer parentContainer, ContainerOptions containerOptions) throws PicoCompositionException { boolean caching = containerOptions.isCaching(); boolean inherit = containerOptions.isInheritParentBehaviors(); String monitorName = containerOptions.getMonitorName(); String componentFactoryName = containerOptions.getComponentFactoryName(); if (inherit) { if (!(parentContainer instanceof MutablePicoContainer)) { throw new PicoCompositionException("For behavior inheritance to be used, the parent picocontainer must be of type MutablePicoContainer"); } MutablePicoContainer parentPico = (MutablePicoContainer)parentContainer; return parentPico.makeChildContainer(); } ScriptedBuilder builder = new ScriptedBuilder(parentContainer); if (caching) builder.withCaching(); return builder .withClassLoader(getClassLoader()) .withLifecycle() .withComponentFactory(componentFactoryName) .withMonitor(monitorName) .build(); }
private MutablePicoContainer createMutablePicoContainer(PicoContainer parentContainer, ContainerOptions containerOptions) throws PicoCompositionException { boolean caching = containerOptions.isCaching(); boolean inherit = containerOptions.isInheritParentBehaviors(); String monitorName = containerOptions.getMonitorName(); String componentFactoryName = containerOptions.getComponentFactoryName(); if (inherit) { if (!(parentContainer instanceof MutablePicoContainer)) { throw new PicoCompositionException("For behavior inheritance to be used, the parent picocontainer must be of type MutablePicoContainer"); } MutablePicoContainer parentPico = (MutablePicoContainer)parentContainer; return parentPico.makeChildContainer(); } ScriptedBuilder builder = new ScriptedBuilder(parentContainer); if (caching) builder.withCaching(); return builder .withClassLoader(getClassLoader()) .withLifecycle() .withComponentFactory(componentFactoryName) .withMonitor(monitorName) .build(); }