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 super(registry);
36 this.components = new ArrayList();
37 }
38
39
40
41
42
43
44 public RegistryComponent[] getComponents()
45 {
46 Collection c = new ArrayList();
47 for (Iterator it = this.components.iterator(); it.hasNext();)
48 {
49 String ref = (String)it.next();
50 RegistryComponent comp = getRegistry().getComponent(ref);
51 c.add(comp);
52 }
53 return (RegistryComponent[])c.toArray(new RegistryComponent[c.size()]);
54 }
55
56 public void addComponent(RegistryComponent component)
57 {
58 this.components.add(component.getName());
59 }
60
61 public void removeComponent(RegistryComponent component)
62 {
63 this.components.remove(component.getName());
64 }
65
66
67
68
69
70
71 protected void checkDescriptor() throws RegistryException
72 {
73 super.checkDescriptor();
74
75 if (!getDescriptor().isSharedLibrary())
76 {
77 throw new RegistryException("shared library should be set");
78 }
79 }
80
81
82
83
84
85
86 public synchronized void install() throws RegistryException
87 {
88 if (!getCurrentState().equals(UNKNOWN))
89 {
90 throw new RegistryException("Illegal status: " + getCurrentState());
91 }
92 try
93 {
94 doInstall();
95 }
96 catch (Exception e)
97 {
98 throw new RegistryException(e);
99 }
100
101 setCurrentState(SHUTDOWN);
102 }
103
104
105
106
107
108
109 public synchronized void uninstall() throws RegistryException
110 {
111 if (!getCurrentState().equals(SHUTDOWN))
112 {
113 throw new RegistryException("Illegal status: " + getCurrentState());
114 }
115 try
116 {
117 doUninstall();
118 }
119 catch (Exception e)
120 {
121 throw new RegistryException(e);
122 }
123 FileUtils.deleteTree(FileUtils.newFile(getInstallRoot()));
124 getRegistry().removeLibrary(this);
125 setCurrentState(UNKNOWN);
126 }
127
128
129
130
131
132
133 public List getClassPathElements()
134 {
135 return this.classPathElements;
136 }
137
138
139
140
141
142
143 public boolean isClassLoaderParentFirst()
144 {
145 return this.isClassLoaderParentFirst;
146 }
147
148 public void setDescriptor(RegistryDescriptor descriptor)
149 {
150 this.descriptor = descriptor;
151 }
152
153 protected abstract void doInstall() throws Exception;
154
155 protected abstract void doUninstall() throws Exception;
156 }