Ejemplo n.º 1
0
  public void release(Object component) throws ComponentLifecycleException {
    if (component == null) {
      return;
    }

    ComponentManager componentManager =
        componentManagerManager.findComponentManagerByComponentInstance(component);

    if (componentManager == null) {
      if (parentContainer != null) {
        parentContainer.release(component);
      } else {
        getLogger()
            .warn(
                "Component manager not found for returned component. Ignored. component="
                    + component);
      }
    } else {
      componentManager.release(component);

      if (componentManager.getConnections() <= 0) {
        componentManagerManager.unassociateComponentWithComponentManager(component);
      }
    }
  }
Ejemplo n.º 2
0
  public void execute(Object object, ComponentManager manager, ClassRealm lookupRealm)
      throws PhaseExecutionException {
    try {
      ComponentDescriptor<?> descriptor = manager.getComponentDescriptor();

      String configuratorId = descriptor.getComponentConfigurator();

      if (StringUtils.isEmpty(configuratorId)) {
        configuratorId = DEFAULT_CONFIGURATOR_ID;
      }

      ComponentConfigurator componentConfigurator =
          manager.getContainer().lookup(ComponentConfigurator.class, configuratorId);

      PlexusConfiguration configuration =
          manager.getContainer().getConfigurationSource().getConfiguration(descriptor);

      if (configuration != null) {
        ClassRealm realm = manager.getRealm();

        componentConfigurator.configureComponent(object, configuration, realm);
      }
    } catch (ComponentLookupException e) {
      throw new PhaseExecutionException(
          "Unable to auto-configure component as its configurator could not be found", e);
    } catch (ComponentConfigurationException e) {
      throw new PhaseExecutionException("Unable to auto-configure component", e);
    }
  }
Ejemplo n.º 3
0
  public void resume(Object component) throws ComponentLifecycleException {
    if (component == null) {
      return;
    }

    ComponentManager componentManager =
        componentManagerManager.findComponentManagerByComponentInstance(component);

    componentManager.resume(component);
  }
Ejemplo n.º 4
0
  public Object lookup(String componentKey) throws ComponentLookupException {
    Object component = null;

    ComponentManager componentManager =
        componentManagerManager.findComponentManagerByComponentKey(componentKey);

    // The first time we lookup a component a component manager will not exist so we ask the
    // component manager manager to create a component manager for us.

    if (componentManager == null) {
      ComponentDescriptor descriptor = componentRepository.getComponentDescriptor(componentKey);

      if (descriptor == null) {
        if (parentContainer != null) {
          return parentContainer.lookup(componentKey);
        }

        getLogger().error("Nonexistent component: " + componentKey);

        String message =
            "Component descriptor cannot be found in the component repository: "
                + componentKey
                + ".";

        throw new ComponentLookupException(message);
      }

      componentManager = createComponentManager(descriptor);
    }

    try {
      component = componentManager.getComponent();
    } catch (ComponentInstantiationException e) {
      throw new ComponentLookupException(
          "Unable to lookup component '" + componentKey + "', it could not be created", e);
    } catch (ComponentLifecycleException e) {
      throw new ComponentLookupException(
          "Unable to lookup component '" + componentKey + "', it could not be started", e);
    }

    componentManagerManager.associateComponentWithComponentManager(component, componentManager);

    return component;
  }