Package org.picocontainer

Examples of org.picocontainer.ComponentMonitor


        }
        return factory;
    }

    private ComponentMonitor createComponentMonitor(Map attributes) {
        final ComponentMonitor monitor = (ComponentMonitor) attributes.remove(COMPONENT_MONITOR);
        if ( monitor == null ){
            return new DelegatingComponentMonitor();
        }
        return monitor;
    }
View Full Code Here


    }

    private MutablePicoContainer createMutablePicoContainer(String cafName, String monitorName, PicoContainer parentContainer) throws PicoCompositionException, ClassNotFoundException {
        MutablePicoContainer container = new DefaultPicoContainer(createComponentAdapterFactory(cafName), parentContainer);
        if ( !notSet(monitorName) ){
            ComponentMonitor monitor = createComponentMonitor(monitorName);
            ((ComponentMonitorStrategy)container).changeMonitor(monitor);
        }
        return container;
    }
View Full Code Here

        }
        return factory;
    }

    private ComponentMonitor createComponentMonitor(Map attributes) {
        final ComponentMonitor monitor = (ComponentMonitor) attributes.remove(COMPONENT_MONITOR);
        if ( monitor == null ){
            return new DelegatingComponentMonitor();
        }
        return monitor;
    }
View Full Code Here

                        }
                    } catch (AmbiguousComponentResolutionException e) {
                        e.setComponent(getComponentImplementation());
                        throw e;
                    }
                    ComponentMonitor componentMonitor = currentMonitor();
                    try {
                        Object[] parameters = getMemberArguments(guardedContainer, ctor);
                        ctor = componentMonitor.instantiating(container, ConstructorInjector.this, ctor);
                        if(ctor == null) {
                            throw new NullPointerException("Component Monitor " + componentMonitor
                                            + " returned a null constructor from method 'instantiating' after passing in " + ctor);
                        }
                        long startTime = System.currentTimeMillis();
                        T inst = instantiate(ctor, parameters);
                        componentMonitor.instantiated(container,
                                                      ConstructorInjector.this,
                                ctor, inst, parameters, System.currentTimeMillis() - startTime);
                        return inst;
                    } catch (InvocationTargetException e) {
                        componentMonitor.instantiationFailed(container, ConstructorInjector.this, ctor, e);
                        if (e.getTargetException() instanceof RuntimeException) {
                            throw (RuntimeException) e.getTargetException();
                        } else if (e.getTargetException() instanceof Error) {
                            throw (Error) e.getTargetException();
                        }
View Full Code Here

            }
        });
    }

    protected Object invokeMethod(Object componentInstance, Method method, Object[] args, PicoContainer container) throws Throwable {
        ComponentMonitor componentMonitor = currentMonitor();
        try {
            componentMonitor.invoking(container, this, method, componentInstance);
            long startTime = System.currentTimeMillis();
            Object object = method.invoke(componentInstance, args);
            componentMonitor.invoked(container,
                                     this,
                                     method, componentInstance, System.currentTimeMillis() - startTime);
            return object;
        } catch (final InvocationTargetException ite) {
            componentMonitor.invocationFailed(method, componentInstance, ite);
            throw ite.getTargetException();
        }
    }
View Full Code Here

        if (instantiationGuard == null) {
            instantiationGuard = new ThreadLocalCyclicDependencyGuard() {
                public Object run() {
                    Method method = getInjectorMethod();
                    T inst = null;
                    ComponentMonitor componentMonitor = currentMonitor();
                    try {
                        componentMonitor.instantiating(container, MethodInjector.this, null);
                        long startTime = System.currentTimeMillis();
                        Object[] parameters = null;
                        inst = getComponentImplementation().newInstance();
                        if (method != null) {
                            parameters = getMemberArguments(guardedContainer, method);
                            invokeMethod(method, parameters, inst, container);
                        }
                        componentMonitor.instantiated(container, MethodInjector.this,
                                                      null, inst, parameters, System.currentTimeMillis() - startTime);
                        return inst;
                    } catch (InstantiationException e) {
                        return caughtInstantiationException(componentMonitor, null, e, container);
                    } catch (IllegalAccessException e) {
View Full Code Here

        if (setters == null) {
            setters = getSetters(getComponentImplementation());
        }

        if (properties != null) {
            ComponentMonitor componentMonitor = currentMonitor();
            Set<String> propertyNames = properties.keySet();
            for (String propertyName : propertyNames) {
                final Object propertyValue = properties.get(propertyName);
                Method setter = setters.get(propertyName);

                Object valueToInvoke = this.getSetterParameter(propertyName, propertyValue, componentInstance, container);

                try {
                    componentMonitor.invoking(container, PropertyApplicator.this, setter, componentInstance);
                    long startTime = System.currentTimeMillis();
                    setter.invoke(componentInstance, valueToInvoke);
                    componentMonitor.invoked(container,
                                             PropertyApplicator.this,
                                             setter, componentInstance, System.currentTimeMillis() - startTime);
                } catch (final Exception e) {
                    componentMonitor.invocationFailed(setter, componentInstance, e);
                    throw new PicoCompositionException("Failed to set property " + propertyName + " to " + propertyValue + ": " + e.getMessage(), e);
                }
            }
        }
        return componentInstance;
View Full Code Here

        } else {
          parentContainer = getSessionContainer(request);
        }

        logger.debug("Request components are {}", requestScoped);
        ComponentMonitor monitor = new AttributeSetterComponentMonitor(new AttributeSetterComponentMonitor.AttributeSetter() {
      public void setAttribute(String name, Object object) {
        request.getRequest().setAttribute(name, object);
      }
    });
    MutablePicoContainer requestContainer = new DefaultPicoContainer(new Caching(),
View Full Code Here

        }
        return false;
    }

    private MutablePicoContainer createSessionContainer(final HttpSession session) {
      ComponentMonitor monitor = new AttributeSetterComponentMonitor(new AttributeSetterComponentMonitor.AttributeSetter() {
      public void setAttribute(String name, Object object) {
        session.setAttribute(name, object);
      }
    });
        MutablePicoContainer sessionContainer = new DefaultPicoContainer(new Caching(),
View Full Code Here

  } else {
    parentContainer = getSessionContainer(request);
  }

  logger.debug("Request components are {}", requestScoped);
  ComponentMonitor monitor = new AttributeSetterComponentMonitor(new AttributeSetterComponentMonitor.AttributeSetter() {
      public void setAttribute(String name, Object object) {
        request.getRequest().setAttribute(name, object);
      }
    });
    MutablePicoContainer requestContainer = new DefaultPicoContainer(new Caching(),
View Full Code Here

TOP

Related Classes of org.picocontainer.ComponentMonitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.