Package org.servicemix.client

Source Code of org.servicemix.client.DescriptorFactory

/**
*
* 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.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.servicemix.jbi.config.spring.XBeanProcessor;
import org.servicemix.jbi.deployment.Descriptor;
import org.xbean.spring.context.FileSystemXmlApplicationContext;

import java.util.Arrays;

/**
*
* Factory that be used to build a POJO representation of the JBI descriptor
*
* @author <a href="mailto:pdodds@unity-systems.com">Philip Dodds </a>
*
*/
public class DescriptorFactory {

  private static final String DESCRIPTOR_FILE = "jbi.xml";

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

  private static final String META_INF = "/META-INF";

  /**
   * Returns a descriptor in POJO form for a given <i>ComponentContext</i>
   *
   * @param installRoot
   *            The root of the installation
   * @return The deployment descriptor
   */
   public static Descriptor getDescriptor(String installRoot) {
       Descriptor root = null;
       File descriptor = new File(installRoot + META_INF, DESCRIPTOR_FILE);
       log.debug("Checking for descriptor " + descriptor.getAbsolutePath());
       if (descriptor.exists()) {
           try {
               Thread.currentThread().setContextClassLoader(Descriptor.class.getClassLoader());
               FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("file:///"
                       + descriptor.getAbsolutePath(),
                       Arrays.asList(new Object[] { new XBeanProcessor()}));
               root = (Descriptor) context.getBean("jbi");
               log.debug("Parsed descriptor " + root);
           } catch (Throwable e) {
               throw new RuntimeException("Unable to parse the jbi.xml", e);
           }
       } else {
           throw new RuntimeException("Descriptor file: " + descriptor + " doesn't exist");
       }
       return root;
   }

  /**
   * Returns true if a JBI descriptor exists in this installation root
   *
   * @param installRoot
   *            The installation root
   * @return True if a jbi.xml exists
   */
  public static boolean hasDescriptor(String installRoot) {
    return new File(installRoot + META_INF, DESCRIPTOR_FILE).exists();
  }
}
TOP

Related Classes of org.servicemix.client.DescriptorFactory

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.