KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > framework > SharedLibrary


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.jbi.framework;
18
19 import java.beans.PropertyChangeListener JavaDoc;
20 import java.io.File JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22 import java.net.URL JavaDoc;
23
24 import javax.management.JMException JavaDoc;
25 import javax.management.MBeanAttributeInfo JavaDoc;
26 import javax.management.MBeanOperationInfo JavaDoc;
27
28 import org.apache.servicemix.jbi.deployment.ClassPath;
29 import org.apache.servicemix.jbi.management.AttributeInfoHelper;
30 import org.apache.servicemix.jbi.management.MBeanInfoProvider;
31 import org.apache.xbean.classloader.JarFileClassLoader;
32
33 public class SharedLibrary implements SharedLibraryMBean, MBeanInfoProvider {
34
35     private org.apache.servicemix.jbi.deployment.SharedLibrary library;
36     private File JavaDoc installationDir;
37     private ClassLoader JavaDoc classLoader;
38     
39     public SharedLibrary(org.apache.servicemix.jbi.deployment.SharedLibrary library,
40                          File JavaDoc installationDir) {
41         this.library = library;
42         this.installationDir = installationDir;
43         this.classLoader = createClassLoader();
44     }
45
46     /**
47      * @return the library
48      */

49     public org.apache.servicemix.jbi.deployment.SharedLibrary getLibrary() {
50         return library;
51     }
52     
53     public ClassLoader JavaDoc getClassLoader() {
54         return this.classLoader;
55     }
56     
57     protected ClassLoader JavaDoc createClassLoader() {
58         boolean parentFirst = library.isParentFirstClassLoaderDelegation();
59         // Make the current ClassLoader the parent
60
ClassLoader JavaDoc parent = getClass().getClassLoader();
61         
62         ClassPath cp = library.getSharedLibraryClassPath();
63         String JavaDoc[] classPathNames = cp.getPathElements();
64         URL JavaDoc[] urls = new URL JavaDoc[classPathNames.length];
65         for (int i = 0; i < classPathNames.length; i++) {
66             File JavaDoc file = new File JavaDoc(installationDir, classPathNames[i]);
67             try {
68                 urls[i] = file.toURL();
69             } catch (MalformedURLException JavaDoc e) {
70                 throw new IllegalArgumentException JavaDoc(classPathNames[i], e);
71             }
72         }
73         return new JarFileClassLoader(
74                         getName(),
75                         urls,
76                         parent,
77                         !parentFirst,
78                         new String JavaDoc[0],
79                         new String JavaDoc[] { "java.", "javax." });
80     }
81
82     public String JavaDoc getDescription() {
83         return library.getIdentification().getDescription();
84     }
85
86     public String JavaDoc getName() {
87         return library.getIdentification().getName();
88     }
89
90     public Object JavaDoc getObjectToManage() {
91         return this;
92     }
93
94     public MBeanAttributeInfo JavaDoc[] getAttributeInfos() throws JMException JavaDoc {
95         AttributeInfoHelper helper = new AttributeInfoHelper();
96         helper.addAttribute(getObjectToManage(), "name", "name of the service unit");
97         helper.addAttribute(getObjectToManage(), "description", "description of the service unit");
98         return helper.getAttributeInfos();
99     }
100
101     public MBeanOperationInfo JavaDoc[] getOperationInfos() throws JMException JavaDoc {
102         return null;
103     }
104
105     public String JavaDoc getSubType() {
106         return null;
107     }
108
109     public String JavaDoc getType() {
110         return "SharedLibrary";
111     }
112
113     public void setPropertyChangeListener(PropertyChangeListener JavaDoc l) {
114         // We do not fire property events, so need to keep
115
// a reference
116
}
117
118 }
119
Popular Tags