KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2006 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.Iterator JavaDoc;
25 import java.util.LinkedList JavaDoc;
26
27 import org.java.plugin.registry.Documentation;
28 import org.java.plugin.registry.Extension;
29 import org.java.plugin.registry.ExtensionPoint;
30 import org.java.plugin.registry.Library;
31 import org.java.plugin.registry.PluginAttribute;
32 import org.java.plugin.registry.PluginDescriptor;
33 import org.java.plugin.registry.PluginFragment;
34 import org.java.plugin.registry.PluginPrerequisite;
35 import org.java.plugin.registry.PluginRegistry;
36 import org.java.plugin.registry.Version;
37
38 /**
39  * @version $Id: MockPluginDescriptor.java,v 1.2 2006/09/14 18:10:39 ddimon Exp $
40  */

41 public class MockPluginDescriptor extends MockIdentity implements
42         PluginDescriptor {
43     private URL JavaDoc location;
44     private String JavaDoc pluginClassName;
45     private PluginRegistry registry;
46     private String JavaDoc vendor;
47     private Version version;
48     private String JavaDoc docsPath;
49     private Documentation documentation;
50     private LinkedList JavaDoc attributes = new LinkedList JavaDoc();
51     private LinkedList JavaDoc extensions = new LinkedList JavaDoc();
52     private LinkedList JavaDoc extPoints = new LinkedList JavaDoc();
53     private LinkedList JavaDoc fragments = new LinkedList JavaDoc();
54     private LinkedList JavaDoc libraries = new LinkedList JavaDoc();
55     private LinkedList JavaDoc prerequisites = new LinkedList JavaDoc();
56     
57     /**
58      * No-arguments constructor.
59      */

60     public MockPluginDescriptor() {
61         // no-op
62
}
63
64     /**
65      * @param id plug-in ID
66      */

67     public MockPluginDescriptor(final String JavaDoc id) {
68         setId(id);
69     }
70
71     /**
72      * @param id plug-in ID
73      * @param aVersion plug-in version
74      */

75     public MockPluginDescriptor(final String JavaDoc id, final Version aVersion) {
76         setId(id);
77         setVersion(aVersion);
78     }
79
80     /**
81      * @see org.java.plugin.registry.PluginDescriptor#getAttribute(
82      * java.lang.String)
83      */

84     public PluginAttribute getAttribute(final String JavaDoc id) {
85         for (Iterator JavaDoc it = attributes.iterator(); it.hasNext();) {
86             PluginAttribute attr = (PluginAttribute) it.next();
87             if (attr.getId().equals(id)) {
88                 return attr;
89             }
90         }
91         throw new IllegalArgumentException JavaDoc("unknown attribute ID " + id); //$NON-NLS-1$
92
}
93
94     /**
95      * @see org.java.plugin.registry.PluginDescriptor#getAttributes()
96      */

97     public Collection JavaDoc getAttributes() {
98         return Collections.unmodifiableCollection(attributes);
99     }
100
101     /**
102      * @see org.java.plugin.registry.PluginDescriptor#getAttributes(
103      * java.lang.String)
104      */

105     public Collection JavaDoc getAttributes(final String JavaDoc id) {
106         LinkedList JavaDoc result = new LinkedList JavaDoc();
107         for (Iterator JavaDoc it = attributes.iterator(); it.hasNext();) {
108             PluginAttribute attr = (PluginAttribute) it.next();
109             if (attr.getId().equals(id)) {
110                 result.add(attr);
111             }
112         }
113         return result;
114     }
115     
116     /**
117      * @param attribute attribute to add
118      * @return this instance
119      */

120     public MockPluginDescriptor addAttribute(final PluginAttribute attribute) {
121         attributes.add(attribute);
122         return this;
123     }
124
125     /**
126      * @see org.java.plugin.registry.PluginDescriptor#getExtension(
127      * java.lang.String)
128      */

129     public Extension getExtension(final String JavaDoc id) {
130         for (Iterator JavaDoc it = extensions.iterator(); it.hasNext();) {
131             Extension ext = (Extension) it.next();
132             if (ext.getId().equals(id)) {
133                 return ext;
134             }
135         }
136         throw new IllegalArgumentException JavaDoc("unknown extension ID " + id); //$NON-NLS-1$
137
}
138
139     /**
140      * @see org.java.plugin.registry.PluginDescriptor#getExtensionPoint(
141      * java.lang.String)
142      */

143     public ExtensionPoint getExtensionPoint(final String JavaDoc id) {
144         for (Iterator JavaDoc it = extPoints.iterator(); it.hasNext();) {
145             ExtensionPoint extPoint = (ExtensionPoint) it.next();
146             if (extPoint.getId().equals(id)) {
147                 return extPoint;
148             }
149         }
150         throw new IllegalArgumentException JavaDoc("unknown extension point ID " + id); //$NON-NLS-1$
151
}
152
153     /**
154      * @see org.java.plugin.registry.PluginDescriptor#getExtensionPoints()
155      */

156     public Collection JavaDoc getExtensionPoints() {
157         return Collections.unmodifiableCollection(extPoints);
158     }
159
160     /**
161      * @see org.java.plugin.registry.PluginDescriptor#getExtensions()
162      */

163     public Collection JavaDoc getExtensions() {
164         return Collections.unmodifiableCollection(extensions);
165     }
166     
167     /**
168      * @param extPoint extension point to add
169      * @return this instance
170      */

171     public MockPluginDescriptor addExtensionPoint(
172             final ExtensionPoint extPoint) {
173         extPoints.add(extPoint);
174         return this;
175     }
176     
177     /**
178      * @param extension extension to add
179      * @return this instance
180      */

181     public MockPluginDescriptor addExtension(final Extension extension) {
182         extensions.add(extension);
183         return this;
184     }
185
186     /**
187      * @see org.java.plugin.registry.PluginDescriptor#getFragments()
188      */

189     public Collection JavaDoc getFragments() {
190         return Collections.unmodifiableCollection(fragments);
191     }
192     
193     /**
194      * @param fragment plug-in fragment to add
195      * @return this instance
196      */

197     public MockPluginDescriptor addFragment(final PluginFragment fragment) {
198         fragments.add(fragment);
199         return this;
200     }
201
202     /**
203      * @see org.java.plugin.registry.PluginDescriptor#getLibraries()
204      */

205     public Collection JavaDoc getLibraries() {
206         return Collections.unmodifiableCollection(libraries);
207     }
208     
209     /**
210      * @param library library to add
211      * @return this instance
212      */

213     public MockPluginDescriptor addLibrary(final Library library) {
214         libraries.add(library);
215         return this;
216     }
217
218     /**
219      * @see org.java.plugin.registry.PluginDescriptor#getLibrary(
220      * java.lang.String)
221      */

222     public Library getLibrary(final String JavaDoc id) {
223         for (Iterator JavaDoc it = libraries.iterator(); it.hasNext();) {
224             Library lib = (Library) it.next();
225             if (lib.getId().equals(id)) {
226                 return lib;
227             }
228         }
229         throw new IllegalArgumentException JavaDoc("unknown library ID " + id); //$NON-NLS-1$
230
}
231
232     /**
233      * @see org.java.plugin.registry.PluginDescriptor#getLocation()
234      */

235     public URL JavaDoc getLocation() {
236         return location;
237     }
238     
239     /**
240      * @param value the location to set
241      * @return this instance
242      */

243     public MockPluginDescriptor setLocation(final URL JavaDoc value) {
244         location = value;
245         return this;
246     }
247
248     /**
249      * @see org.java.plugin.registry.PluginDescriptor#getPluginClassName()
250      */

251     public String JavaDoc getPluginClassName() {
252         return pluginClassName;
253     }
254     
255     /**
256      * @param value the plug-in class name to set
257      * @return this instance
258      */

259     public MockPluginDescriptor setPluginClassName(final String JavaDoc value) {
260         pluginClassName = value;
261         return this;
262     }
263
264     /**
265      * @see org.java.plugin.registry.PluginDescriptor#getPrerequisite(
266      * java.lang.String)
267      */

268     public PluginPrerequisite getPrerequisite(final String JavaDoc id) {
269         for (Iterator JavaDoc it = prerequisites.iterator(); it.hasNext();) {
270             PluginPrerequisite pre = (PluginPrerequisite) it.next();
271             if (pre.getId().equals(id)) {
272                 return pre;
273             }
274         }
275         throw new IllegalArgumentException JavaDoc(
276                 "unknown plug-in prerequisite ID " + id); //$NON-NLS-1$
277
}
278
279     /**
280      * @see org.java.plugin.registry.PluginDescriptor#getPrerequisites()
281      */

282     public Collection JavaDoc getPrerequisites() {
283         return Collections.unmodifiableCollection(prerequisites);
284     }
285     
286     /**
287      * @param pre plug-in prerequisite to add
288      * @return this instance
289      */

290     public MockPluginDescriptor addPrerequisite(final PluginPrerequisite pre) {
291         prerequisites.add(pre);
292         return this;
293     }
294
295     /**
296      * @see org.java.plugin.registry.PluginDescriptor#getRegistry()
297      */

298     public PluginRegistry getRegistry() {
299         return registry;
300     }
301     
302     /**
303      * @param value the registry to set
304      * @return this instance
305      */

306     public MockPluginDescriptor setRegistry(final PluginRegistry value) {
307         registry = value;
308         return this;
309     }
310
311     /**
312      * @see org.java.plugin.registry.PluginDescriptor#getVendor()
313      */

314     public String JavaDoc getVendor() {
315         return vendor;
316     }
317     
318     /**
319      * @param value the vendor to set
320      * @return this instance
321      */

322     public MockPluginDescriptor setVendor(final String JavaDoc value) {
323         vendor = value;
324         return this;
325     }
326
327     /**
328      * @see org.java.plugin.registry.PluginDescriptor#getVersion()
329      */

330     public Version getVersion() {
331         return version;
332     }
333     
334     /**
335      * @param value the version to set
336      * @return this instance
337      */

338     public MockPluginDescriptor setVersion(final Version value) {
339         version = value;
340         return this;
341     }
342
343     /**
344      * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
345      */

346     public String JavaDoc getUniqueId() {
347         return getId() + '@' + getVersion();
348     }
349
350     /**
351      * @see org.java.plugin.registry.Documentable#getDocsPath()
352      */

353     public String JavaDoc getDocsPath() {
354         return docsPath;
355     }
356     
357     /**
358      * @param value the docs path to set
359      * @return this instance
360      */

361     public MockPluginDescriptor setDocsPath(final String JavaDoc value) {
362         docsPath = value;
363         return this;
364     }
365
366     /**
367      * @see org.java.plugin.registry.Documentable#getDocumentation()
368      */

369     public Documentation getDocumentation() {
370         return documentation;
371     }
372     
373     /**
374      * @param value the documentation to set
375      * @return this instance
376      */

377     public MockPluginDescriptor setDocumentation(final Documentation value) {
378         documentation = value;
379         return this;
380     }
381 }
382
Popular Tags