1 19 package org.java.plugin.tools.mocks; 20 21 import java.net.URL ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.Iterator ; 25 import java.util.LinkedList ; 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 41 public class MockPluginDescriptor extends MockIdentity implements 42 PluginDescriptor { 43 private URL location; 44 private String pluginClassName; 45 private PluginRegistry registry; 46 private String vendor; 47 private Version version; 48 private String docsPath; 49 private Documentation documentation; 50 private LinkedList attributes = new LinkedList (); 51 private LinkedList extensions = new LinkedList (); 52 private LinkedList extPoints = new LinkedList (); 53 private LinkedList fragments = new LinkedList (); 54 private LinkedList libraries = new LinkedList (); 55 private LinkedList prerequisites = new LinkedList (); 56 57 60 public MockPluginDescriptor() { 61 } 63 64 67 public MockPluginDescriptor(final String id) { 68 setId(id); 69 } 70 71 75 public MockPluginDescriptor(final String id, final Version aVersion) { 76 setId(id); 77 setVersion(aVersion); 78 } 79 80 84 public PluginAttribute getAttribute(final String id) { 85 for (Iterator 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 ("unknown attribute ID " + id); } 93 94 97 public Collection getAttributes() { 98 return Collections.unmodifiableCollection(attributes); 99 } 100 101 105 public Collection getAttributes(final String id) { 106 LinkedList result = new LinkedList (); 107 for (Iterator 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 120 public MockPluginDescriptor addAttribute(final PluginAttribute attribute) { 121 attributes.add(attribute); 122 return this; 123 } 124 125 129 public Extension getExtension(final String id) { 130 for (Iterator 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 ("unknown extension ID " + id); } 138 139 143 public ExtensionPoint getExtensionPoint(final String id) { 144 for (Iterator 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 ("unknown extension point ID " + id); } 152 153 156 public Collection getExtensionPoints() { 157 return Collections.unmodifiableCollection(extPoints); 158 } 159 160 163 public Collection getExtensions() { 164 return Collections.unmodifiableCollection(extensions); 165 } 166 167 171 public MockPluginDescriptor addExtensionPoint( 172 final ExtensionPoint extPoint) { 173 extPoints.add(extPoint); 174 return this; 175 } 176 177 181 public MockPluginDescriptor addExtension(final Extension extension) { 182 extensions.add(extension); 183 return this; 184 } 185 186 189 public Collection getFragments() { 190 return Collections.unmodifiableCollection(fragments); 191 } 192 193 197 public MockPluginDescriptor addFragment(final PluginFragment fragment) { 198 fragments.add(fragment); 199 return this; 200 } 201 202 205 public Collection getLibraries() { 206 return Collections.unmodifiableCollection(libraries); 207 } 208 209 213 public MockPluginDescriptor addLibrary(final Library library) { 214 libraries.add(library); 215 return this; 216 } 217 218 222 public Library getLibrary(final String id) { 223 for (Iterator 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 ("unknown library ID " + id); } 231 232 235 public URL getLocation() { 236 return location; 237 } 238 239 243 public MockPluginDescriptor setLocation(final URL value) { 244 location = value; 245 return this; 246 } 247 248 251 public String getPluginClassName() { 252 return pluginClassName; 253 } 254 255 259 public MockPluginDescriptor setPluginClassName(final String value) { 260 pluginClassName = value; 261 return this; 262 } 263 264 268 public PluginPrerequisite getPrerequisite(final String id) { 269 for (Iterator 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 ( 276 "unknown plug-in prerequisite ID " + id); } 278 279 282 public Collection getPrerequisites() { 283 return Collections.unmodifiableCollection(prerequisites); 284 } 285 286 290 public MockPluginDescriptor addPrerequisite(final PluginPrerequisite pre) { 291 prerequisites.add(pre); 292 return this; 293 } 294 295 298 public PluginRegistry getRegistry() { 299 return registry; 300 } 301 302 306 public MockPluginDescriptor setRegistry(final PluginRegistry value) { 307 registry = value; 308 return this; 309 } 310 311 314 public String getVendor() { 315 return vendor; 316 } 317 318 322 public MockPluginDescriptor setVendor(final String value) { 323 vendor = value; 324 return this; 325 } 326 327 330 public Version getVersion() { 331 return version; 332 } 333 334 338 public MockPluginDescriptor setVersion(final Version value) { 339 version = value; 340 return this; 341 } 342 343 346 public String getUniqueId() { 347 return getId() + '@' + getVersion(); 348 } 349 350 353 public String getDocsPath() { 354 return docsPath; 355 } 356 357 361 public MockPluginDescriptor setDocsPath(final String value) { 362 docsPath = value; 363 return this; 364 } 365 366 369 public Documentation getDocumentation() { 370 return documentation; 371 } 372 373 377 public MockPluginDescriptor setDocumentation(final Documentation value) { 378 documentation = value; 379 return this; 380 } 381 } 382 | Popular Tags |