KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > tools > mocks > MockPluginRegistry


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2006-2007 Dmitry Olshansky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *****************************************************************************/

19 package org.java.plugin.tools.mocks;
20
21 import java.net.URL JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.LinkedList JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import org.java.plugin.PathResolver;
29 import org.java.plugin.registry.ExtensionPoint;
30 import org.java.plugin.registry.IntegrityCheckReport;
31 import org.java.plugin.registry.PluginDescriptor;
32 import org.java.plugin.registry.PluginFragment;
33 import org.java.plugin.registry.PluginRegistry;
34 import org.java.plugin.registry.Version;
35 import org.java.plugin.registry.xml.PluginRegistryImpl;
36 import org.java.plugin.util.ExtendedProperties;
37
38 /**
39  * @version $Id: MockPluginRegistry.java,v 1.3 2007/01/05 13:29:32 ddimon Exp $
40  */

41 public class MockPluginRegistry implements PluginRegistry {
42     private IntegrityCheckReport integrityCheckReport;
43     private PluginRegistryImpl xmlRegistryImpl;
44     private LinkedList JavaDoc listeners = new LinkedList JavaDoc();
45     private IntegrityCheckReport registrationReport;
46     private HashMap JavaDoc extensionPoints = new HashMap JavaDoc();
47     private HashMap JavaDoc pluginDescriptors = new HashMap JavaDoc();
48     private LinkedList JavaDoc pluginFragments = new LinkedList JavaDoc();
49
50     /**
51      * @see org.java.plugin.registry.PluginRegistry#checkIntegrity(
52      * org.java.plugin.PathResolver)
53      */

54     public IntegrityCheckReport checkIntegrity(
55             final PathResolver pathResolver) {
56         return integrityCheckReport;
57     }
58
59     /**
60      * @see org.java.plugin.registry.PluginRegistry#checkIntegrity(
61      * org.java.plugin.PathResolver, boolean)
62      */

63     public IntegrityCheckReport checkIntegrity(final PathResolver pathResolver,
64             final boolean includeRegistrationReport) {
65         return integrityCheckReport;
66     }
67     
68     /**
69      * @param value the integrity check report to set
70      * @return this instance
71      */

72     public MockPluginRegistry setIntegrityCheckReport(
73             final IntegrityCheckReport value) {
74         integrityCheckReport = value;
75         return this;
76     }
77
78     /**
79      * @see org.java.plugin.registry.PluginRegistry#configure(
80      * org.java.plugin.util.ExtendedProperties)
81      */

82     public void configure(final ExtendedProperties config) {
83         // no-op
84
}
85
86     /**
87      * @see org.java.plugin.registry.PluginRegistry#extractId(
88      * java.lang.String)
89      */

90     public String JavaDoc extractId(final String JavaDoc uniqueId) {
91         if (xmlRegistryImpl == null) {
92             xmlRegistryImpl = new PluginRegistryImpl();
93         }
94         return xmlRegistryImpl.extractId(uniqueId);
95     }
96
97     /**
98      * @see org.java.plugin.registry.PluginRegistry#extractPluginId(
99      * java.lang.String)
100      */

101     public String JavaDoc extractPluginId(final String JavaDoc uniqueId) {
102         if (xmlRegistryImpl == null) {
103             xmlRegistryImpl = new PluginRegistryImpl();
104         }
105         return xmlRegistryImpl.extractPluginId(uniqueId);
106     }
107
108     /**
109      * @see org.java.plugin.registry.PluginRegistry#extractVersion(
110      * java.lang.String)
111      */

112     public Version extractVersion(final String JavaDoc uniqueId) {
113         if (xmlRegistryImpl == null) {
114             xmlRegistryImpl = new PluginRegistryImpl();
115         }
116         return xmlRegistryImpl.extractVersion(uniqueId);
117     }
118
119     /**
120      * @see org.java.plugin.registry.PluginRegistry#getDependingPlugins(
121      * org.java.plugin.registry.PluginDescriptor)
122      */

123     public Collection JavaDoc getDependingPlugins(final PluginDescriptor descr) {
124         // no-op
125
return Collections.EMPTY_LIST;
126     }
127
128     /**
129      * @see org.java.plugin.registry.PluginRegistry#getExtensionPoint(
130      * java.lang.String, java.lang.String)
131      */

132     public ExtensionPoint getExtensionPoint(String JavaDoc pluginId, String JavaDoc pointId) {
133         String JavaDoc uid = makeUniqueId(pluginId, pointId);
134         ExtensionPoint result = (ExtensionPoint) extensionPoints.get(uid);
135         if (result == null) {
136             throw new IllegalArgumentException JavaDoc(
137                     "unknown extenssion point UID " + uid); //$NON-NLS-1$
138
}
139         return result;
140     }
141
142     /**
143      * @see org.java.plugin.registry.PluginRegistry#getExtensionPoint(
144      * java.lang.String)
145      */

146     public ExtensionPoint getExtensionPoint(String JavaDoc uniqueId) {
147         ExtensionPoint result = (ExtensionPoint) extensionPoints.get(uniqueId);
148         if (result == null) {
149             throw new IllegalArgumentException JavaDoc(
150                     "unknown extenssion point UID " + uniqueId); //$NON-NLS-1$
151
}
152         return result;
153     }
154     
155     /**
156      * @param extPoint extension point to add
157      * @return this instance
158      */

159     public MockPluginRegistry addExtensionPoint(final ExtensionPoint extPoint) {
160         extensionPoints.put(extPoint.getUniqueId(), extPoint);
161         return this;
162     }
163
164     /**
165      * @see org.java.plugin.registry.PluginRegistry#getPluginDescriptor(
166      * java.lang.String)
167      */

168     public PluginDescriptor getPluginDescriptor(final String JavaDoc pluginId) {
169         PluginDescriptor result =
170             (PluginDescriptor) pluginDescriptors.get(pluginId);
171         if (result == null) {
172             throw new IllegalArgumentException JavaDoc(
173                     "unknown plug-in ID " + pluginId); //$NON-NLS-1$
174
}
175         return result;
176     }
177
178     /**
179      * @see org.java.plugin.registry.PluginRegistry#getPluginDescriptors()
180      */

181     public Collection JavaDoc getPluginDescriptors() {
182         return Collections.unmodifiableCollection(pluginDescriptors.values());
183     }
184     
185     /**
186      * @param descr plug-in descriptor to add
187      * @return this instance
188      */

189     public MockPluginRegistry addPluginDescriptor(
190             final PluginDescriptor descr) {
191         pluginDescriptors.put(descr.getId(), descr);
192         return this;
193     }
194
195     /**
196      * @see org.java.plugin.registry.PluginRegistry#getPluginFragments()
197      */

198     public Collection JavaDoc getPluginFragments() {
199         return Collections.unmodifiableCollection(pluginFragments);
200     }
201     
202     /**
203      * @param fragment plug-in fragment to add
204      * @return this instance
205      */

206     public MockPluginRegistry addPluginFragment(final PluginFragment fragment) {
207         pluginFragments.add(fragment);
208         return this;
209     }
210     
211     /**
212      * @see org.java.plugin.registry.PluginRegistry#getRegistrationReport()
213      */

214     public IntegrityCheckReport getRegistrationReport() {
215         return registrationReport;
216     }
217     
218     /**
219      * @param value the registration report to set
220      * @return this instance
221      */

222     public MockPluginRegistry setRegistrationReport(
223             final IntegrityCheckReport value) {
224         registrationReport = value;
225         return this;
226     }
227
228     /**
229      * @see org.java.plugin.registry.PluginRegistry#isExtensionPointAvailable(
230      * java.lang.String, java.lang.String)
231      */

232     public boolean isExtensionPointAvailable(final String JavaDoc pluginId,
233             final String JavaDoc pointId) {
234         return extensionPoints.containsKey(makeUniqueId(pluginId, pointId));
235     }
236
237     /**
238      * @see org.java.plugin.registry.PluginRegistry#isExtensionPointAvailable(
239      * java.lang.String)
240      */

241     public boolean isExtensionPointAvailable(final String JavaDoc uniqueId) {
242         return extensionPoints.containsKey(uniqueId);
243     }
244
245     /**
246      * @see org.java.plugin.registry.PluginRegistry#isPluginDescriptorAvailable(
247      * java.lang.String)
248      */

249     public boolean isPluginDescriptorAvailable(final String JavaDoc pluginId) {
250         return pluginDescriptors.containsKey(pluginId);
251     }
252
253     /**
254      * @see org.java.plugin.registry.PluginRegistry#makeUniqueId(
255      * java.lang.String, java.lang.String)
256      */

257     public String JavaDoc makeUniqueId(final String JavaDoc pluginId, final String JavaDoc elementId) {
258         if (xmlRegistryImpl == null) {
259             xmlRegistryImpl = new PluginRegistryImpl();
260         }
261         return xmlRegistryImpl.makeUniqueId(pluginId, elementId);
262     }
263
264     /**
265      * @see org.java.plugin.registry.PluginRegistry#makeUniqueId(
266      * java.lang.String, org.java.plugin.registry.Version)
267      */

268     public String JavaDoc makeUniqueId(final String JavaDoc pluginId, final Version version) {
269         if (xmlRegistryImpl == null) {
270             xmlRegistryImpl = new PluginRegistryImpl();
271         }
272         return xmlRegistryImpl.makeUniqueId(pluginId, version);
273     }
274
275     /**
276      * @see org.java.plugin.registry.PluginRegistry#readManifestInfo(
277      * java.net.URL)
278      */

279     public ManifestInfo readManifestInfo(final URL JavaDoc manifest) {
280         // no-op
281
return null;
282     }
283
284     /**
285      * @see org.java.plugin.registry.PluginRegistry#register(java.net.URL[])
286      */

287     public Map JavaDoc register(final URL JavaDoc[] manifests) {
288         // no-op
289
return Collections.EMPTY_MAP;
290     }
291
292     /**
293      * @see org.java.plugin.registry.PluginRegistry#registerListener(
294      * org.java.plugin.registry.PluginRegistry.RegistryChangeListener)
295      */

296     public void registerListener(final RegistryChangeListener listener) {
297         listeners.add(listener);
298     }
299
300     /**
301      * @see org.java.plugin.registry.PluginRegistry#unregister(
302      * java.lang.String[])
303      */

304     public Collection JavaDoc unregister(final String JavaDoc[] ids) {
305         // no-op
306
return Collections.EMPTY_LIST;
307     }
308
309     /**
310      * @see org.java.plugin.registry.PluginRegistry#unregisterListener(
311      * org.java.plugin.registry.PluginRegistry.RegistryChangeListener)
312      */

313     public void unregisterListener(final RegistryChangeListener listener) {
314         listeners.remove(listener);
315     }
316 }
317
Popular Tags