KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > geronimo > ServiceAssembly


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.geronimo;
18
19 import java.io.File JavaDoc;
20 import java.net.URI JavaDoc;
21 import java.net.URL JavaDoc;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.geronimo.gbean.GBeanInfo;
26 import org.apache.geronimo.gbean.GBeanInfoBuilder;
27 import org.apache.geronimo.gbean.GBeanLifecycle;
28 import org.apache.servicemix.jbi.deployment.Descriptor;
29 import org.apache.servicemix.jbi.deployment.DescriptorFactory;
30
31 public class ServiceAssembly implements GBeanLifecycle {
32
33     private static final Log log = LogFactory.getLog(ServiceAssembly.class);
34     
35     private String JavaDoc name;
36     private Container container;
37     private URI JavaDoc rootDir;
38     
39     public ServiceAssembly(String JavaDoc name,
40                            Container container,
41                            URL JavaDoc configurationBaseUrl) throws Exception JavaDoc {
42         this.name = name;
43         this.container = container;
44         //TODO is there a simpler way to do this?
45
if (configurationBaseUrl.getProtocol().equalsIgnoreCase("file")) {
46             this.rootDir = new URI JavaDoc("file", configurationBaseUrl.getPath(), null);
47         } else {
48             this.rootDir = URI.create(configurationBaseUrl.toString());
49         }
50         log.info("Created JBI service assembly: " + name);
51     }
52     
53     public void doStart() throws Exception JavaDoc {
54         log.info("doStart called for JBI service assembly: " + name);
55         container.register(this);
56     }
57
58     public void doStop() throws Exception JavaDoc {
59         log.info("doStop called for JBI service assembly: " + name);
60         container.unregister(this);
61     }
62
63     public void doFail() {
64         log.info("doFail called for JBI service assembly: " + name);
65     }
66     
67     public URI JavaDoc getRootDir() {
68         return rootDir;
69     }
70     
71     public String JavaDoc getName() {
72         return name;
73     }
74     
75     public Descriptor getDescriptor() throws Exception JavaDoc {
76         return DescriptorFactory.buildDescriptor(new File JavaDoc(new File JavaDoc(rootDir), "install"));
77     }
78
79     public static final GBeanInfo GBEAN_INFO;
80
81     static {
82         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("JBIServiceAssembly", ServiceAssembly.class, "JBIServiceAssembly");
83         infoFactory.addAttribute("name", String JavaDoc.class, true);
84         infoFactory.addReference("container", Container.class);
85         infoFactory.addAttribute("configurationBaseUrl", URL JavaDoc.class, true);
86         infoFactory.setConstructor(new String JavaDoc[] {"name", "container", "configurationBaseUrl" });
87         GBEAN_INFO = infoFactory.getBeanInfo();
88     }
89
90     public static GBeanInfo getGBeanInfo() {
91         return GBEAN_INFO;
92     }
93     
94 }
95
Popular Tags