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.geronimo;
018
019 import java.io.File;
020 import java.net.URI;
021 import java.net.URL;
022
023 import org.apache.commons.logging.Log;
024 import org.apache.commons.logging.LogFactory;
025 import org.apache.geronimo.gbean.GBeanInfo;
026 import org.apache.geronimo.gbean.GBeanInfoBuilder;
027 import org.apache.geronimo.gbean.GBeanLifecycle;
028 import org.apache.servicemix.jbi.deployment.Descriptor;
029 import org.apache.servicemix.jbi.deployment.DescriptorFactory;
030
031 public class ServiceAssembly implements GBeanLifecycle {
032
033 private static final Log log = LogFactory.getLog(ServiceAssembly.class);
034
035 private String name;
036 private Container container;
037 private URI rootDir;
038
039 public ServiceAssembly(String name,
040 Container container,
041 URL configurationBaseUrl) throws Exception {
042 this.name = name;
043 this.container = container;
044 //TODO is there a simpler way to do this?
045 if (configurationBaseUrl.getProtocol().equalsIgnoreCase("file")) {
046 this.rootDir = new URI("file", configurationBaseUrl.getPath(), null);
047 } else {
048 this.rootDir = URI.create(configurationBaseUrl.toString());
049 }
050 log.info("Created JBI service assembly: " + name);
051 }
052
053 public void doStart() throws Exception {
054 log.info("doStart called for JBI service assembly: " + name);
055 container.register(this);
056 }
057
058 public void doStop() throws Exception {
059 log.info("doStop called for JBI service assembly: " + name);
060 container.unregister(this);
061 }
062
063 public void doFail() {
064 log.info("doFail called for JBI service assembly: " + name);
065 }
066
067 public URI getRootDir() {
068 return rootDir;
069 }
070
071 public String getName() {
072 return name;
073 }
074
075 public Descriptor getDescriptor() throws Exception {
076 return DescriptorFactory.buildDescriptor(new File(new File(rootDir), "install"));
077 }
078
079 public static final GBeanInfo GBEAN_INFO;
080
081 static {
082 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("JBIServiceAssembly", ServiceAssembly.class, "JBIServiceAssembly");
083 infoFactory.addAttribute("name", String.class, true);
084 infoFactory.addReference("container", Container.class);
085 infoFactory.addAttribute("configurationBaseUrl", URL.class, true);
086 infoFactory.setConstructor(new String[] {"name", "container", "configurationBaseUrl" });
087 GBEAN_INFO = infoFactory.getBeanInfo();
088 }
089
090 public static GBeanInfo getGBeanInfo() {
091 return GBEAN_INFO;
092 }
093
094 }