001: /*****************************************************************************
002: * Java Plug-in Framework (JPF)
003: * Copyright (C) 2006-2007 Dmitry Olshansky
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *****************************************************************************/package org.java.plugin.tools.mocks;
019:
020: import java.net.URL;
021: import java.util.Collection;
022: import java.util.Collections;
023: import java.util.LinkedList;
024: import org.java.plugin.registry.Documentation;
025: import org.java.plugin.registry.Extension;
026: import org.java.plugin.registry.ExtensionPoint;
027: import org.java.plugin.registry.Library;
028: import org.java.plugin.registry.PluginAttribute;
029: import org.java.plugin.registry.PluginDescriptor;
030: import org.java.plugin.registry.PluginFragment;
031: import org.java.plugin.registry.PluginPrerequisite;
032: import org.java.plugin.registry.PluginRegistry;
033: import org.java.plugin.registry.Version;
034:
035: /**
036: * @version $Id$
037: */
038: public class MockPluginDescriptor extends MockIdentity implements
039: PluginDescriptor {
040: private URL location;
041: private String pluginClassName;
042: private PluginRegistry registry;
043: private String vendor;
044: private Version version;
045: private String docsPath;
046: private Documentation<PluginDescriptor> documentation;
047: private LinkedList<PluginAttribute> attributes = new LinkedList<PluginAttribute>();
048: private LinkedList<Extension> extensions = new LinkedList<Extension>();
049: private LinkedList<ExtensionPoint> extPoints = new LinkedList<ExtensionPoint>();
050: private LinkedList<PluginFragment> fragments = new LinkedList<PluginFragment>();
051: private LinkedList<Library> libraries = new LinkedList<Library>();
052: private LinkedList<PluginPrerequisite> prerequisites = new LinkedList<PluginPrerequisite>();
053:
054: /**
055: * No-arguments constructor.
056: */
057: public MockPluginDescriptor() {
058: // no-op
059: }
060:
061: /**
062: * @param id plug-in ID
063: */
064: public MockPluginDescriptor(final String id) {
065: setId(id);
066: }
067:
068: /**
069: * @param id plug-in ID
070: * @param aVersion plug-in version
071: */
072: public MockPluginDescriptor(final String id, final Version aVersion) {
073: setId(id);
074: setVersion(aVersion);
075: }
076:
077: /**
078: * @see org.java.plugin.registry.PluginDescriptor#getAttribute(
079: * java.lang.String)
080: */
081: public PluginAttribute getAttribute(final String id) {
082: for (PluginAttribute attr : attributes) {
083: if (attr.getId().equals(id))
084: return attr;
085: }
086: throw new IllegalArgumentException("unknown attribute ID " + id); //$NON-NLS-1$
087: }
088:
089: /**
090: * @see org.java.plugin.registry.PluginDescriptor#getAttributes()
091: */
092: public Collection<PluginAttribute> getAttributes() {
093: return Collections.unmodifiableCollection(attributes);
094: }
095:
096: /**
097: * @see org.java.plugin.registry.PluginDescriptor#getAttributes(
098: * java.lang.String)
099: */
100: public Collection<PluginAttribute> getAttributes(final String id) {
101: LinkedList<PluginAttribute> result = new LinkedList<PluginAttribute>();
102: for (PluginAttribute attr : attributes) {
103: if (attr.getId().equals(id)) {
104: result.add(attr);
105: }
106: }
107: return result;
108: }
109:
110: /**
111: * @param attribute attribute to add
112: * @return this instance
113: */
114: public MockPluginDescriptor addAttribute(
115: final PluginAttribute attribute) {
116: attributes.add(attribute);
117: return this ;
118: }
119:
120: /**
121: * @see org.java.plugin.registry.PluginDescriptor#getExtension(
122: * java.lang.String)
123: */
124: public Extension getExtension(final String id) {
125: for (Extension ext : extensions) {
126: if (ext.getId().equals(id)) {
127: return ext;
128: }
129: }
130: throw new IllegalArgumentException("unknown extension ID " + id); //$NON-NLS-1$
131: }
132:
133: /**
134: * @see org.java.plugin.registry.PluginDescriptor#getExtensionPoint(
135: * java.lang.String)
136: */
137: public ExtensionPoint getExtensionPoint(final String id) {
138: for (ExtensionPoint extPoint : extPoints) {
139: if (extPoint.getId().equals(id)) {
140: return extPoint;
141: }
142: }
143: throw new IllegalArgumentException(
144: "unknown extension point ID " + id); //$NON-NLS-1$
145: }
146:
147: /**
148: * @see org.java.plugin.registry.PluginDescriptor#getExtensionPoints()
149: */
150: public Collection<ExtensionPoint> getExtensionPoints() {
151: return Collections.unmodifiableCollection(extPoints);
152: }
153:
154: /**
155: * @see org.java.plugin.registry.PluginDescriptor#getExtensions()
156: */
157: public Collection<Extension> getExtensions() {
158: return Collections.unmodifiableCollection(extensions);
159: }
160:
161: /**
162: * @param extPoint extension point to add
163: * @return this instance
164: */
165: public MockPluginDescriptor addExtensionPoint(
166: final ExtensionPoint extPoint) {
167: extPoints.add(extPoint);
168: return this ;
169: }
170:
171: /**
172: * @param extension extension to add
173: * @return this instance
174: */
175: public MockPluginDescriptor addExtension(final Extension extension) {
176: extensions.add(extension);
177: return this ;
178: }
179:
180: /**
181: * @see org.java.plugin.registry.PluginDescriptor#getFragments()
182: */
183: public Collection<PluginFragment> getFragments() {
184: return Collections.unmodifiableCollection(fragments);
185: }
186:
187: /**
188: * @param fragment plug-in fragment to add
189: * @return this instance
190: */
191: public MockPluginDescriptor addFragment(
192: final PluginFragment fragment) {
193: fragments.add(fragment);
194: return this ;
195: }
196:
197: /**
198: * @see org.java.plugin.registry.PluginDescriptor#getLibraries()
199: */
200: public Collection<Library> getLibraries() {
201: return Collections.unmodifiableCollection(libraries);
202: }
203:
204: /**
205: * @param library library to add
206: * @return this instance
207: */
208: public MockPluginDescriptor addLibrary(final Library library) {
209: libraries.add(library);
210: return this ;
211: }
212:
213: /**
214: * @see org.java.plugin.registry.PluginDescriptor#getLibrary(
215: * java.lang.String)
216: */
217: public Library getLibrary(final String id) {
218: for (Library lib : libraries) {
219: if (lib.getId().equals(id)) {
220: return lib;
221: }
222: }
223: throw new IllegalArgumentException("unknown library ID " + id); //$NON-NLS-1$
224: }
225:
226: /**
227: * @see org.java.plugin.registry.PluginDescriptor#getLocation()
228: */
229: public URL getLocation() {
230: return location;
231: }
232:
233: /**
234: * @param value the location to set
235: * @return this instance
236: */
237: public MockPluginDescriptor setLocation(final URL value) {
238: location = value;
239: return this ;
240: }
241:
242: /**
243: * @see org.java.plugin.registry.PluginDescriptor#getPluginClassName()
244: */
245: public String getPluginClassName() {
246: return pluginClassName;
247: }
248:
249: /**
250: * @param value the plug-in class name to set
251: * @return this instance
252: */
253: public MockPluginDescriptor setPluginClassName(final String value) {
254: pluginClassName = value;
255: return this ;
256: }
257:
258: /**
259: * @see org.java.plugin.registry.PluginDescriptor#getPrerequisite(
260: * java.lang.String)
261: */
262: public PluginPrerequisite getPrerequisite(final String id) {
263: for (PluginPrerequisite pre : prerequisites) {
264: if (pre.getId().equals(id)) {
265: return pre;
266: }
267: }
268: throw new IllegalArgumentException(
269: "unknown plug-in prerequisite ID " + id); //$NON-NLS-1$
270: }
271:
272: /**
273: * @see org.java.plugin.registry.PluginDescriptor#getPrerequisites()
274: */
275: public Collection<PluginPrerequisite> getPrerequisites() {
276: return Collections.unmodifiableCollection(prerequisites);
277: }
278:
279: /**
280: * @param pre plug-in prerequisite to add
281: * @return this instance
282: */
283: public MockPluginDescriptor addPrerequisite(
284: final PluginPrerequisite pre) {
285: prerequisites.add(pre);
286: return this ;
287: }
288:
289: /**
290: * @see org.java.plugin.registry.PluginDescriptor#getRegistry()
291: */
292: public PluginRegistry getRegistry() {
293: return registry;
294: }
295:
296: /**
297: * @param value the registry to set
298: * @return this instance
299: */
300: public MockPluginDescriptor setRegistry(final PluginRegistry value) {
301: registry = value;
302: return this ;
303: }
304:
305: /**
306: * @see org.java.plugin.registry.PluginDescriptor#getVendor()
307: */
308: public String getVendor() {
309: return vendor;
310: }
311:
312: /**
313: * @param value the vendor to set
314: * @return this instance
315: */
316: public MockPluginDescriptor setVendor(final String value) {
317: vendor = value;
318: return this ;
319: }
320:
321: /**
322: * @see org.java.plugin.registry.PluginDescriptor#getVersion()
323: */
324: public Version getVersion() {
325: return version;
326: }
327:
328: /**
329: * @param value the version to set
330: * @return this instance
331: */
332: public MockPluginDescriptor setVersion(final Version value) {
333: version = value;
334: return this ;
335: }
336:
337: /**
338: * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
339: */
340: public String getUniqueId() {
341: return getId() + '@' + getVersion();
342: }
343:
344: /**
345: * @see org.java.plugin.registry.Documentable#getDocsPath()
346: */
347: public String getDocsPath() {
348: return docsPath;
349: }
350:
351: /**
352: * @param value the docs path to set
353: * @return this instance
354: */
355: public MockPluginDescriptor setDocsPath(final String value) {
356: docsPath = value;
357: return this ;
358: }
359:
360: /**
361: * @see org.java.plugin.registry.Documentable#getDocumentation()
362: */
363: public Documentation<PluginDescriptor> getDocumentation() {
364: return documentation;
365: }
366:
367: /**
368: * @param value the documentation to set
369: * @return this instance
370: */
371: public MockPluginDescriptor setDocumentation(
372: final Documentation<PluginDescriptor> value) {
373: documentation = value;
374: return this;
375: }
376: }
|