1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.launcher;
12
13 import org.mule.module.reboot.MuleContainerBootstrapUtils;
14 import org.mule.util.FileUtils;
15 import org.mule.util.SystemUtils;
16
17 import java.io.File;
18 import java.net.URL;
19 import java.util.Collection;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24
25
26
27 public class MuleSharedDomainClassLoader extends GoodCitizenClassLoader
28 {
29
30 protected transient Log logger = LogFactory.getLog(getClass());
31
32 private final String domain = "undefined";
33
34 @SuppressWarnings("unchecked")
35 public MuleSharedDomainClassLoader(String domain, ClassLoader parent)
36 {
37 super(new URL[0], parent);
38 try
39 {
40 File domainDir = new File(MuleContainerBootstrapUtils.getMuleHome(), "lib/shared/" + domain);
41 if (!domainDir.exists())
42 {
43 throw new IllegalArgumentException(
44 String.format("Shared ClassLoader Domain '%s' doesn't exist", domain));
45 }
46
47 if (!domainDir.canRead())
48 {
49 throw new IllegalArgumentException(
50 String.format("Shared ClassLoader Domain '%s' is not accessible", domain));
51 }
52
53 Collection<File> jars = FileUtils.listFiles(domainDir, new String[] {"jar"}, false);
54
55 if (logger.isDebugEnabled())
56 {
57 {
58 StringBuilder sb = new StringBuilder();
59 sb.append("Loading Shared ClassLoader Domain: ").append(domain).append(SystemUtils.LINE_SEPARATOR);
60 sb.append("=============================").append(SystemUtils.LINE_SEPARATOR);
61
62 for (File jar : jars)
63 {
64 sb.append(jar.toURI().toURL()).append(SystemUtils.LINE_SEPARATOR);
65 }
66
67 sb.append("=============================").append(SystemUtils.LINE_SEPARATOR);
68
69 logger.debug(sb.toString());
70 }
71 }
72
73 for (File jar : jars)
74 {
75 addURL(jar.toURI().toURL());
76 }
77 }
78 catch (Throwable t)
79 {
80 throw new RuntimeException(t);
81 }
82 }
83
84 public String getDomain()
85 {
86 return domain;
87 }
88
89 @Override
90 public String toString()
91 {
92 return String.format("%s[%s]@%s", getClass().getName(),
93 domain,
94 Integer.toHexString(System.identityHashCode(this)));
95 }
96
97 }