Package org.servicemix.client

Source Code of org.servicemix.client.SpringBuilder

/**
*
* 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 java.io.File;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
*
* A helper class that is able to take an installation root and look for a
* spring configuration XML
*
* @author <a href="mailto:pdodds@unity-systems.com">Philip Dodds </a>
*
*/
public class SpringBuilder {

  private static final String SPRING_CONFIG = "jbi-spring.xml";

  /**
   * Checks whether a META-INF/spring-jbi.xml exists under the
   * installationRoot
   *
   * @param installationRoot
   *            The installation root from the JBI container
   * @return True if META-INF/spring-jbi.xml exists
   */
  public static boolean hasSpringXml(String installationRoot) {
    return getSpringConfigFile(installationRoot).exists();
  }

  /**
   * Loads the META-INF/spring-jbi.xml as an ApplicationContext
   *
   * @param installationRoot
   *            The installation root from the JBI container
   * @return The generated ApplicationContext from Spring
   */
  public static ApplicationContext getSpringBeans(String installationRoot) {
    Thread.currentThread().setContextClassLoader(
        SpringBuilder.class.getClassLoader());
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(
        getSpringConfigFile(installationRoot).getAbsolutePath());
    return context;
  }

  /**
   * Helper method that creates a Java File object pointing at the config file
   *
   * @param installationRoot
   * @return
   */
  private static File getSpringConfigFile(String installationRoot) {
    return new File(installationRoot + "/META-INF", SPRING_CONFIG);
  }
}
TOP

Related Classes of org.servicemix.client.SpringBuilder

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.