KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > registry > impl > AbstractLibrary


1 /*
2  * $Id: AbstractLibrary.java 3937 2006-11-20 16:04:25Z lajos $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
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 JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 public abstract class AbstractLibrary extends AbstractEntry implements Library
26 {
27
28     protected List JavaDoc components;
29     protected List JavaDoc classPathElements;
30     protected boolean isClassLoaderParentFirst;
31     protected RegistryDescriptor descriptor;
32
33     protected AbstractLibrary(Registry registry)
34     {
35         super(registry);
36         this.components = new ArrayList JavaDoc();
37     }
38
39     /*
40      * (non-Javadoc)
41      *
42      * @see org.mule.jbi.registry.Library#getReferringComponents()
43      */

44     public RegistryComponent[] getComponents()
45     {
46         Collection JavaDoc c = new ArrayList JavaDoc();
47         for (Iterator JavaDoc it = this.components.iterator(); it.hasNext();)
48         {
49             String JavaDoc ref = (String JavaDoc)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      * (non-Javadoc)
68      *
69      * @see org.mule.jbi.registry.mule.AbstractEntry#checkDescriptor()
70      */

71     protected void checkDescriptor() throws RegistryException
72     {
73         super.checkDescriptor();
74         // Check that it is a service assembly
75
if (!getDescriptor().isSharedLibrary())
76         {
77             throw new RegistryException("shared library should be set");
78         }
79     }
80
81     /*
82      * (non-Javadoc)
83      *
84      * @see javax.jbi.management.LifeCycleMBean#start()
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 JavaDoc e)
97         {
98             throw new RegistryException(e);
99         }
100         // Set current state
101
setCurrentState(SHUTDOWN);
102     }
103
104     /*
105      * (non-Javadoc)
106      *
107      * @see javax.jbi.management.LifeCycleMBean#start()
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 JavaDoc 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      * (non-Javadoc)
130      *
131      * @see org.mule.jbi.registry.Library#getClassPathElements()
132      */

133     public List JavaDoc getClassPathElements()
134     {
135         return this.classPathElements;
136     }
137
138     /*
139      * (non-Javadoc)
140      *
141      * @see org.mule.jbi.registry.Library#isClassLoaderParentFirst()
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 JavaDoc;
154
155     protected abstract void doUninstall() throws Exception JavaDoc;
156 }
157
Popular Tags