Package org.servicemix.client

Source Code of org.servicemix.client.SpringServiceUnitManager

/**
*
* Copyright 2005 Unity Systems, LLC. http://www.unity-systems.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.servicemix.client;

import javax.jbi.JBIException;
import javax.jbi.component.ServiceUnitManager;
import javax.jbi.management.DeploymentException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;

/**
*
* The Spring JBI ServiceUnitManager implementation
*
* @author <a href="mailto:pdodds@unity-systems.com">Philip Dodds </a>
*
*/
public class SpringServiceUnitManager implements ServiceUnitManager {

  private static final Log log = LogFactory
      .getLog(SpringServiceUnitManager.class.getName());

  private SpringComponent component;

  /**
   * Default constructor takes the parent component
   *
   * @param component
   *            The parent component
   */
  public SpringServiceUnitManager(SpringComponent component) {
    this.component = component;
  }

  /**
   * Configures spring context underneath the LifeCycle
   *
   * @param serviceUnitName
   *            The name of the service unit
   * @param serviceUnitRootDirectory
   *            The service unit's root directory
   */
  private void configureSpring(String serviceUnitName,
      String serviceUnitRootDirectory) {
    log
        .debug("Initializing base service unit manager, for spring configuration");
    if (SpringBuilder.hasSpringXml(serviceUnitRootDirectory)) {
      ApplicationContext context = SpringBuilder
          .getSpringBeans(serviceUnitRootDirectory);
      component.getSpringRegistry().addServiceUnitSpringContext(
          serviceUnitName, context);
    }
  }

  /*
   * (non-Javadoc)
   *
   * @see javax.jbi.component.ServiceUnitManager#deploy(java.lang.String,
   *      java.lang.String)
   */
  public String deploy(String serviceUnitName, String serviceUnitRootDirectory)
      throws DeploymentException {
    return null;
  }

  /*
   * (non-Javadoc)
   *
   * @see javax.jbi.component.ServiceUnitManager#init(java.lang.String,
   *      java.lang.String)
   */
  public void init(String serviceUnitName, String serviceUnitRootDirectory)
      throws DeploymentException {
    configureSpring(serviceUnitName, serviceUnitRootDirectory);
    component.getSpringRegistry().getEndPointRegistry()
        .loadServiceUnitServices(serviceUnitRootDirectory,
            serviceUnitName);
  }

  /*
   * (non-Javadoc)
   *
   * @see javax.jbi.component.ServiceUnitManager#shutDown(java.lang.String)
   */
  public void shutDown(String serviceUnitName) throws DeploymentException {

  }

  /*
   * (non-Javadoc)
   *
   * @see javax.jbi.component.ServiceUnitManager#start(java.lang.String)
   */
  public void start(String serviceUnitName) throws DeploymentException {
    try {
      component.getEndPointRegistry().activeServiceUnitEndpoints(
          serviceUnitName);
    } catch (JBIException e) {
      throw new DeploymentException(
          "Unable to activate service unit endpoints for "
              + serviceUnitName, e);
    }
  }

  /*
   * (non-Javadoc)
   *
   * @see javax.jbi.component.ServiceUnitManager#stop(java.lang.String)
   */
  public void stop(String serviceUnitName) throws DeploymentException {
    try {
      if (component.getSpringRegistry().getServiceUnitLifeCycle(
          serviceUnitName) != null) {
        component.getSpringRegistry().getServiceUnitLifeCycle(
            serviceUnitName).stop();
      }
      component.getEndPointRegistry().deactiveServiceUnitEndpoints(
          serviceUnitName);
    } catch (JBIException e) {
      throw new DeploymentException(
          "Unable to deactivate service unit endpoints for "
              + serviceUnitName, e);
    }
  }

  /*
   * (non-Javadoc)
   *
   * @see javax.jbi.component.ServiceUnitManager#undeploy(java.lang.String,
   *      java.lang.String)
   */
  public String undeploy(String serviceUnitName,
      String serviceUnitRootDirectory) throws DeploymentException {
    return null;
  }
}
TOP

Related Classes of org.servicemix.client.SpringServiceUnitManager

TOP
Copyright © 2018 www.massapi.com. 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.