1 17 package org.apache.servicemix.jbi.framework; 18 19 import java.beans.PropertyChangeListener ; 20 import java.io.File ; 21 import java.net.MalformedURLException ; 22 import java.net.URL ; 23 24 import javax.management.JMException ; 25 import javax.management.MBeanAttributeInfo ; 26 import javax.management.MBeanOperationInfo ; 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 installationDir; 37 private ClassLoader classLoader; 38 39 public SharedLibrary(org.apache.servicemix.jbi.deployment.SharedLibrary library, 40 File installationDir) { 41 this.library = library; 42 this.installationDir = installationDir; 43 this.classLoader = createClassLoader(); 44 } 45 46 49 public org.apache.servicemix.jbi.deployment.SharedLibrary getLibrary() { 50 return library; 51 } 52 53 public ClassLoader getClassLoader() { 54 return this.classLoader; 55 } 56 57 protected ClassLoader createClassLoader() { 58 boolean parentFirst = library.isParentFirstClassLoaderDelegation(); 59 ClassLoader parent = getClass().getClassLoader(); 61 62 ClassPath cp = library.getSharedLibraryClassPath(); 63 String [] classPathNames = cp.getPathElements(); 64 URL [] urls = new URL [classPathNames.length]; 65 for (int i = 0; i < classPathNames.length; i++) { 66 File file = new File (installationDir, classPathNames[i]); 67 try { 68 urls[i] = file.toURL(); 69 } catch (MalformedURLException e) { 70 throw new IllegalArgumentException (classPathNames[i], e); 71 } 72 } 73 return new JarFileClassLoader( 74 getName(), 75 urls, 76 parent, 77 !parentFirst, 78 new String [0], 79 new String [] { "java.", "javax." }); 80 } 81 82 public String getDescription() { 83 return library.getIdentification().getDescription(); 84 } 85 86 public String getName() { 87 return library.getIdentification().getName(); 88 } 89 90 public Object getObjectToManage() { 91 return this; 92 } 93 94 public MBeanAttributeInfo [] getAttributeInfos() throws JMException { 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 [] getOperationInfos() throws JMException { 102 return null; 103 } 104 105 public String getSubType() { 106 return null; 107 } 108 109 public String getType() { 110 return "SharedLibrary"; 111 } 112 113 public void setPropertyChangeListener(PropertyChangeListener l) { 114 } 117 118 } 119 | Popular Tags |