1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
/*****************************************************************************
* Java Plug-in Framework (JPF)
* Copyright (C) 2006-2007 Dmitry Olshansky
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
package org.java.plugin.tools.mocks;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import org.java.plugin.registry.Documentation;
import org.java.plugin.registry.Extension;
import org.java.plugin.registry.ExtensionPoint;
import org.java.plugin.registry.Library;
import org.java.plugin.registry.PluginAttribute;
import org.java.plugin.registry.PluginDescriptor;
import org.java.plugin.registry.PluginFragment;
import org.java.plugin.registry.PluginPrerequisite;
import org.java.plugin.registry.PluginRegistry;
import org.java.plugin.registry.Version;
/**
* @version $Id$
*/
public class MockPluginDescriptor extends MockIdentity
implements PluginDescriptor {
private URL location;
private String pluginClassName;
private PluginRegistry registry;
private String vendor;
private Version version;
private String docsPath;
private Documentation<PluginDescriptor> documentation;
private LinkedList<PluginAttribute> attributes = new LinkedList<PluginAttribute>();
private LinkedList<Extension> extensions = new LinkedList<Extension>();
private LinkedList<ExtensionPoint> extPoints = new LinkedList<ExtensionPoint>();
private LinkedList<PluginFragment> fragments = new LinkedList<PluginFragment>();
private LinkedList<Library> libraries = new LinkedList<Library>();
private LinkedList<PluginPrerequisite> prerequisites = new LinkedList<PluginPrerequisite>();
/**
* No-arguments constructor.
*/
public MockPluginDescriptor() {
// no-op
}
/**
* @param id plug-in ID
*/
public MockPluginDescriptor(final String id) {
setId(id);
}
/**
* @param id plug-in ID
* @param aVersion plug-in version
*/
public MockPluginDescriptor(final String id, final Version aVersion) {
setId(id);
setVersion(aVersion);
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getAttribute(
* java.lang.String)
*/
public PluginAttribute getAttribute(final String id) {
for (PluginAttribute attr : attributes) {
if (attr.getId().equals(id))
return attr;
}
throw new IllegalArgumentException("unknown attribute ID " + id); //$NON-NLS-1$
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getAttributes()
*/
public Collection<PluginAttribute> getAttributes() {
return Collections.unmodifiableCollection(attributes);
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getAttributes(
* java.lang.String)
*/
public Collection<PluginAttribute> getAttributes(final String id) {
LinkedList<PluginAttribute> result = new LinkedList<PluginAttribute>();
for (PluginAttribute attr : attributes) {
if (attr.getId().equals(id)) {
result.add(attr);
}
}
return result;
}
/**
* @param attribute attribute to add
* @return this instance
*/
public MockPluginDescriptor addAttribute(final PluginAttribute attribute) {
attributes.add(attribute);
return this;
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getExtension(
* java.lang.String)
*/
public Extension getExtension(final String id) {
for (Extension ext : extensions) {
if (ext.getId().equals(id)) {
return ext;
}
}
throw new IllegalArgumentException("unknown extension ID " + id); //$NON-NLS-1$
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getExtensionPoint(
* java.lang.String)
*/
public ExtensionPoint getExtensionPoint(final String id) {
for (ExtensionPoint extPoint : extPoints) {
if (extPoint.getId().equals(id)) {
return extPoint;
}
}
throw new IllegalArgumentException("unknown extension point ID " + id); //$NON-NLS-1$
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getExtensionPoints()
*/
public Collection<ExtensionPoint> getExtensionPoints() {
return Collections.unmodifiableCollection(extPoints);
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getExtensions()
*/
public Collection<Extension> getExtensions() {
return Collections.unmodifiableCollection(extensions);
}
/**
* @param extPoint extension point to add
* @return this instance
*/
public MockPluginDescriptor addExtensionPoint(
final ExtensionPoint extPoint) {
extPoints.add(extPoint);
return this;
}
/**
* @param extension extension to add
* @return this instance
*/
public MockPluginDescriptor addExtension(final Extension extension) {
extensions.add(extension);
return this;
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getFragments()
*/
public Collection<PluginFragment> getFragments() {
return Collections.unmodifiableCollection(fragments);
}
/**
* @param fragment plug-in fragment to add
* @return this instance
*/
public MockPluginDescriptor addFragment(final PluginFragment fragment) {
fragments.add(fragment);
return this;
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getLibraries()
*/
public Collection<Library> getLibraries() {
return Collections.unmodifiableCollection(libraries);
}
/**
* @param library library to add
* @return this instance
*/
public MockPluginDescriptor addLibrary(final Library library) {
libraries.add(library);
return this;
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getLibrary(
* java.lang.String)
*/
public Library getLibrary(final String id) {
for (Library lib : libraries) {
if (lib.getId().equals(id)) {
return lib;
}
}
throw new IllegalArgumentException("unknown library ID " + id); //$NON-NLS-1$
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getLocation()
*/
public URL getLocation() {
return location;
}
/**
* @param value the location to set
* @return this instance
*/
public MockPluginDescriptor setLocation(final URL value) {
location = value;
return this;
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getPluginClassName()
*/
public String getPluginClassName() {
return pluginClassName;
}
/**
* @param value the plug-in class name to set
* @return this instance
*/
public MockPluginDescriptor setPluginClassName(final String value) {
pluginClassName = value;
return this;
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getPrerequisite(
* java.lang.String)
*/
public PluginPrerequisite getPrerequisite(final String id) {
for (PluginPrerequisite pre : prerequisites) {
if (pre.getId().equals(id)) {
return pre;
}
}
throw new IllegalArgumentException(
"unknown plug-in prerequisite ID " + id); //$NON-NLS-1$
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getPrerequisites()
*/
public Collection<PluginPrerequisite> getPrerequisites() {
return Collections.unmodifiableCollection(prerequisites);
}
/**
* @param pre plug-in prerequisite to add
* @return this instance
*/
public MockPluginDescriptor addPrerequisite(final PluginPrerequisite pre) {
prerequisites.add(pre);
return this;
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getRegistry()
*/
public PluginRegistry getRegistry() {
return registry;
}
/**
* @param value the registry to set
* @return this instance
*/
public MockPluginDescriptor setRegistry(final PluginRegistry value) {
registry = value;
return this;
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getVendor()
*/
public String getVendor() {
return vendor;
}
/**
* @param value the vendor to set
* @return this instance
*/
public MockPluginDescriptor setVendor(final String value) {
vendor = value;
return this;
}
/**
* @see org.java.plugin.registry.PluginDescriptor#getVersion()
*/
public Version getVersion() {
return version;
}
/**
* @param value the version to set
* @return this instance
*/
public MockPluginDescriptor setVersion(final Version value) {
version = value;
return this;
}
/**
* @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
*/
public String getUniqueId() {
return getId() + '@' + getVersion();
}
/**
* @see org.java.plugin.registry.Documentable#getDocsPath()
*/
public String getDocsPath() {
return docsPath;
}
/**
* @param value the docs path to set
* @return this instance
*/
public MockPluginDescriptor setDocsPath(final String value) {
docsPath = value;
return this;
}
/**
* @see org.java.plugin.registry.Documentable#getDocumentation()
*/
public Documentation<PluginDescriptor> getDocumentation() {
return documentation;
}
/**
* @param value the documentation to set
* @return this instance
*/
public MockPluginDescriptor setDocumentation(
final Documentation<PluginDescriptor> value) {
documentation = value;
return this;
}
}
|