001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.components.util;
018
019 import java.util.Iterator;
020 import java.util.Map;
021
022 import javax.jbi.JBIException;
023 import javax.jbi.component.Bootstrap;
024 import javax.jbi.component.InstallationContext;
025 import javax.management.ObjectName;
026
027 import org.w3c.dom.DocumentFragment;
028
029 import org.apache.commons.logging.Log;
030 import org.apache.commons.logging.LogFactory;
031 import org.apache.servicemix.jbi.NotInitialisedYetException;
032 import org.apache.servicemix.jbi.container.ActivationSpec;
033 import org.springframework.beans.BeansException;
034 import org.springframework.context.ApplicationContext;
035 import org.springframework.context.ApplicationContextAware;
036
037 /**
038 * A Spring implementation of the {@link Bootstrap}
039 *
040 * @version $Revision: 564374 $
041 */
042 public class SpringBootstrap implements Bootstrap, ApplicationContextAware {
043
044 private static final Log LOG = LogFactory.getLog(SpringBootstrap.class);
045
046 private InstallationContext installContext;
047
048 private ObjectName extensionMBeanName;
049
050 private ApplicationContext applicationContext;
051
052 public void init(InstallationContext ctx) throws JBIException {
053 this.installContext = ctx;
054 }
055
056 public void cleanUp() throws JBIException {
057 }
058
059 public ObjectName getExtensionMBeanName() {
060 return extensionMBeanName;
061 }
062
063 public void onInstall() throws JBIException {
064 if (installContext == null) {
065 throw new NotInitialisedYetException();
066 }
067 DocumentFragment fragment = installContext.getInstallationDescriptorExtension();
068 if (fragment != null) {
069 LOG.debug("Installation Descriptor Extension Found");
070 } else {
071 LOG.debug("Installation Descriptor Extension Not Found !");
072 }
073 // lets load this from Spring...
074 Map map = applicationContext.getBeansOfType(ActivationSpec.class, false, false);
075 for (Iterator iter = map.values().iterator(); iter.hasNext();) {
076 ActivationSpec spec = (ActivationSpec) iter.next();
077 LOG.debug("Registering " + spec.getComponentName());
078 }
079 }
080
081 public void onUninstall() throws JBIException {
082 }
083
084 public InstallationContext getInstallContext() {
085 return installContext;
086 }
087
088 public void setApplicationContext(ApplicationContext appCtx) throws BeansException {
089 this.applicationContext = appCtx;
090 }
091 }