KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.URI JavaDoc;
20 import java.net.URL JavaDoc;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.gbean.GBeanLifecycle;
27
28 public class Component implements GBeanLifecycle {
29
30     private static final Log log = LogFactory.getLog(Component.class);
31
32     private String JavaDoc name;
33
34     private String JavaDoc description;
35
36     private String JavaDoc type;
37
38     private String JavaDoc className;
39
40     private Container container;
41
42     private URI JavaDoc rootDir;
43
44     private URI JavaDoc installDir;
45
46     private URI JavaDoc workDir;
47
48     private javax.jbi.component.Component component;
49
50     private ClassLoader JavaDoc classLoader;
51
52     public Component(String JavaDoc name, String JavaDoc description, String JavaDoc type, String JavaDoc className, Container container,
53                     URL JavaDoc configurationBaseUrl, ClassLoader JavaDoc classLoader) throws Exception JavaDoc {
54         this.name = name;
55         this.description = description;
56         this.type = type;
57         this.className = className;
58         this.container = container;
59         // TODO is there a simpler way to do this?
60
if (configurationBaseUrl.getProtocol().equalsIgnoreCase("file")) {
61             this.rootDir = new URI JavaDoc("file", configurationBaseUrl.getPath(), null);
62         } else {
63             this.rootDir = URI.create(configurationBaseUrl.toString());
64         }
65         this.installDir = rootDir.resolve("install/");
66         this.workDir = rootDir.resolve("workspace/");
67         this.classLoader = classLoader;
68         log.info("Created JBI component: " + name);
69     }
70
71     public void doStart() throws Exception JavaDoc {
72         log.info("doStart called for JBI component: " + name);
73         try {
74             component = (javax.jbi.component.Component) classLoader.loadClass(className).newInstance();
75             container.register(this);
76         } catch (ClassNotFoundException JavaDoc e) {
77             log.error(classLoader);
78         }
79     }
80
81     public void doStop() throws Exception JavaDoc {
82         log.info("doStop called for JBI component: " + name);
83         container.unregister(this);
84         component = null;
85     }
86
87     public void doFail() {
88         log.info("doFail called for JBI component: " + name);
89         component = null;
90     }
91
92     public String JavaDoc getType() {
93         return type;
94     }
95
96     public String JavaDoc getName() {
97         return name;
98     }
99
100     public String JavaDoc getDescription() {
101         return description;
102     }
103
104     public URI JavaDoc getInstallDir() {
105         return installDir;
106     }
107
108     public URI JavaDoc getWorkDir() {
109         return workDir;
110     }
111
112     public URI JavaDoc getRootDir() {
113         return rootDir;
114     }
115
116     public javax.jbi.component.Component getComponent() {
117         return component;
118     }
119
120     public static final GBeanInfo GBEAN_INFO;
121
122     static {
123         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("JBIComponent", Component.class, "JBIComponent");
124         infoFactory.addAttribute("name", String JavaDoc.class, true);
125         infoFactory.addAttribute("description", String JavaDoc.class, true);
126         infoFactory.addAttribute("type", String JavaDoc.class, true);
127         infoFactory.addAttribute("className", String JavaDoc.class, true);
128         infoFactory.addReference("container", Container.class);
129         infoFactory.addAttribute("configurationBaseUrl", URL JavaDoc.class, true);
130         infoFactory.addAttribute("classLoader", ClassLoader JavaDoc.class, false);
131         infoFactory.setConstructor(new String JavaDoc[] { "name", "description", "type", "className", "container",
132                         "configurationBaseUrl", "classLoader" });
133         GBEAN_INFO = infoFactory.getBeanInfo();
134     }
135
136     public static GBeanInfo getGBeanInfo() {
137         return GBEAN_INFO;
138     }
139
140 }
141
Popular Tags