1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.registry.impl; |
12 | |
|
13 | |
import org.mule.registry.Library; |
14 | |
import org.mule.registry.Registry; |
15 | |
import org.mule.registry.RegistryComponent; |
16 | |
import org.mule.registry.RegistryDescriptor; |
17 | |
import org.mule.registry.RegistryException; |
18 | |
import org.mule.util.FileUtils; |
19 | |
|
20 | |
import java.util.ArrayList; |
21 | |
import java.util.Collection; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.List; |
24 | |
|
25 | |
public abstract class AbstractLibrary extends AbstractEntry implements Library |
26 | |
{ |
27 | |
|
28 | |
protected List components; |
29 | |
protected List classPathElements; |
30 | |
protected boolean isClassLoaderParentFirst; |
31 | |
protected RegistryDescriptor descriptor; |
32 | |
|
33 | |
protected AbstractLibrary(Registry registry) |
34 | |
{ |
35 | 0 | super(registry); |
36 | 0 | this.components = new ArrayList(); |
37 | 0 | } |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public RegistryComponent[] getComponents() |
45 | |
{ |
46 | 0 | Collection c = new ArrayList(); |
47 | 0 | for (Iterator it = this.components.iterator(); it.hasNext();) |
48 | |
{ |
49 | 0 | String ref = (String)it.next(); |
50 | 0 | RegistryComponent comp = getRegistry().getComponent(ref); |
51 | 0 | c.add(comp); |
52 | |
} |
53 | 0 | return (RegistryComponent[])c.toArray(new RegistryComponent[c.size()]); |
54 | |
} |
55 | |
|
56 | |
public void addComponent(RegistryComponent component) |
57 | |
{ |
58 | 0 | this.components.add(component.getName()); |
59 | 0 | } |
60 | |
|
61 | |
public void removeComponent(RegistryComponent component) |
62 | |
{ |
63 | 0 | this.components.remove(component.getName()); |
64 | 0 | } |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
protected void checkDescriptor() throws RegistryException |
72 | |
{ |
73 | 0 | super.checkDescriptor(); |
74 | |
|
75 | 0 | if (!getDescriptor().isSharedLibrary()) |
76 | |
{ |
77 | 0 | throw new RegistryException("shared library should be set"); |
78 | |
} |
79 | 0 | } |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public synchronized void install() throws RegistryException |
87 | |
{ |
88 | 0 | if (!getCurrentState().equals(UNKNOWN)) |
89 | |
{ |
90 | 0 | throw new RegistryException("Illegal status: " + getCurrentState()); |
91 | |
} |
92 | |
try |
93 | |
{ |
94 | 0 | doInstall(); |
95 | |
} |
96 | 0 | catch (Exception e) |
97 | |
{ |
98 | 0 | throw new RegistryException(e); |
99 | 0 | } |
100 | |
|
101 | 0 | setCurrentState(SHUTDOWN); |
102 | 0 | } |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public synchronized void uninstall() throws RegistryException |
110 | |
{ |
111 | 0 | if (!getCurrentState().equals(SHUTDOWN)) |
112 | |
{ |
113 | 0 | throw new RegistryException("Illegal status: " + getCurrentState()); |
114 | |
} |
115 | |
try |
116 | |
{ |
117 | 0 | doUninstall(); |
118 | |
} |
119 | 0 | catch (Exception e) |
120 | |
{ |
121 | 0 | throw new RegistryException(e); |
122 | 0 | } |
123 | 0 | FileUtils.deleteTree(FileUtils.newFile(getInstallRoot())); |
124 | 0 | getRegistry().removeLibrary(this); |
125 | 0 | setCurrentState(UNKNOWN); |
126 | 0 | } |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public List getClassPathElements() |
134 | |
{ |
135 | 0 | return this.classPathElements; |
136 | |
} |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
public boolean isClassLoaderParentFirst() |
144 | |
{ |
145 | 0 | return this.isClassLoaderParentFirst; |
146 | |
} |
147 | |
|
148 | |
public void setDescriptor(RegistryDescriptor descriptor) |
149 | |
{ |
150 | 0 | this.descriptor = descriptor; |
151 | 0 | } |
152 | |
|
153 | |
protected abstract void doInstall() throws Exception; |
154 | |
|
155 | |
protected abstract void doUninstall() throws Exception; |
156 | |
} |