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.util.Collection;
021: import java.util.Collections;
022: import java.util.HashSet;
023: import java.util.LinkedList;
024: import org.java.plugin.registry.Extension;
025: import org.java.plugin.registry.ExtensionMultiplicity;
026: import org.java.plugin.registry.ExtensionPoint;
027:
028: /**
029: * @version $Id$
030: */
031: public class MockExtensionPoint extends
032: MockPluginElement<ExtensionPoint> implements ExtensionPoint {
033: private ExtensionMultiplicity multiplicity;
034: private String parentExtensionPointId;
035: private String parentPluginId;
036: private boolean isValid = true;
037: private LinkedList<Extension> availableExtensions = new LinkedList<Extension>();
038: private LinkedList<Extension> connectedExtensions = new LinkedList<Extension>();
039: private LinkedList<ExtensionPoint> descendants = new LinkedList<ExtensionPoint>();
040: private LinkedList<ParameterDefinition> parameterDefinitions = new LinkedList<ParameterDefinition>();
041: private HashSet<String> predecessors = new HashSet<String>();
042:
043: /**
044: * @see org.java.plugin.registry.ExtensionPoint#getAvailableExtension(
045: * java.lang.String)
046: */
047: public Extension getAvailableExtension(final String uniqueId) {
048: for (Extension ext : availableExtensions) {
049: if (ext.getUniqueId().equals(uniqueId)) {
050: return ext;
051: }
052: }
053: throw new IllegalArgumentException("extension UID " //$NON-NLS-1$
054: + uniqueId + " not available"); //$NON-NLS-1$
055: }
056:
057: /**
058: * @see org.java.plugin.registry.ExtensionPoint#getAvailableExtensions()
059: */
060: public Collection<Extension> getAvailableExtensions() {
061: return Collections.unmodifiableCollection(availableExtensions);
062: }
063:
064: /**
065: * @see org.java.plugin.registry.ExtensionPoint#getConnectedExtension(
066: * java.lang.String)
067: */
068: public Extension getConnectedExtension(final String uniqueId) {
069: for (Extension ext : connectedExtensions) {
070: if (ext.getUniqueId().equals(uniqueId)) {
071: return ext;
072: }
073: }
074: throw new IllegalArgumentException("extension UID " //$NON-NLS-1$
075: + uniqueId + " not connected"); //$NON-NLS-1$
076: }
077:
078: /**
079: * @see org.java.plugin.registry.ExtensionPoint#getConnectedExtensions()
080: */
081: public Collection<Extension> getConnectedExtensions() {
082: return Collections.unmodifiableCollection(connectedExtensions);
083: }
084:
085: /**
086: * @param extension extension to add
087: * @param isConnected if <code>true</code> extension will be marked as
088: * "connected" also
089: * @return this instance
090: */
091: public MockExtensionPoint addExtension(final Extension extension,
092: final boolean isConnected) {
093: availableExtensions.add(extension);
094: if (isConnected) {
095: connectedExtensions.add(extension);
096: }
097: return this ;
098: }
099:
100: /**
101: * @see org.java.plugin.registry.ExtensionPoint#getDescendants()
102: */
103: public Collection<ExtensionPoint> getDescendants() {
104: return Collections.unmodifiableCollection(descendants);
105: }
106:
107: /**
108: * @param extensionPoint descendant extension to add
109: * @return this instance
110: */
111: public MockExtensionPoint addParameter(
112: final ExtensionPoint extensionPoint) {
113: descendants.add(extensionPoint);
114: return this ;
115: }
116:
117: /**
118: * @see org.java.plugin.registry.ExtensionPoint#getMultiplicity()
119: */
120: public ExtensionMultiplicity getMultiplicity() {
121: return multiplicity;
122: }
123:
124: /**
125: * @param value the multiplicity to set
126: * @return this instance
127: */
128: public MockExtensionPoint setMultiplicity(
129: final ExtensionMultiplicity value) {
130: multiplicity = value;
131: return this ;
132: }
133:
134: /**
135: * @see org.java.plugin.registry.ExtensionPoint#getParameterDefinition(
136: * java.lang.String)
137: */
138: public ParameterDefinition getParameterDefinition(String id) {
139: for (ParameterDefinition paramDef : parameterDefinitions) {
140: if (paramDef.getId().equals(id)) {
141: return paramDef;
142: }
143: }
144: throw new IllegalArgumentException(
145: "unknown parameter definition ID " + id); //$NON-NLS-1$
146: }
147:
148: /**
149: * @see org.java.plugin.registry.ExtensionPoint#getParameterDefinitions()
150: */
151: public Collection<ParameterDefinition> getParameterDefinitions() {
152: return Collections.unmodifiableCollection(parameterDefinitions);
153: }
154:
155: /**
156: * @param parameterDefinition parameter definition to add
157: * @return this instance
158: */
159: public MockExtensionPoint addParameterDefinition(
160: final ParameterDefinition parameterDefinition) {
161: parameterDefinitions.add(parameterDefinition);
162: return this ;
163: }
164:
165: /**
166: * @see org.java.plugin.registry.ExtensionPoint#getParentExtensionPointId()
167: */
168: public String getParentExtensionPointId() {
169: return parentExtensionPointId;
170: }
171:
172: /**
173: * @param pluginId the parent plug-in id to set
174: * @param extensionPointId the parent extension point id to set
175: * @return this instance
176: */
177: public MockExtensionPoint setParentExtensionPoint(
178: final String pluginId, final String extensionPointId) {
179: parentPluginId = pluginId;
180: parentExtensionPointId = extensionPointId;
181: predecessors.add(pluginId + '@' + extensionPointId);
182: return this ;
183: }
184:
185: /**
186: * @see org.java.plugin.registry.ExtensionPoint#getParentPluginId()
187: */
188: public String getParentPluginId() {
189: return parentPluginId;
190: }
191:
192: /**
193: * @see org.java.plugin.registry.ExtensionPoint#isExtensionAvailable(
194: * java.lang.String)
195: */
196: public boolean isExtensionAvailable(final String uniqueId) {
197: for (Extension ext : availableExtensions) {
198: if (ext.getUniqueId().equals(uniqueId)) {
199: return true;
200: }
201: }
202: return false;
203: }
204:
205: /**
206: * @see org.java.plugin.registry.ExtensionPoint#isExtensionConnected(
207: * java.lang.String)
208: */
209: public boolean isExtensionConnected(final String uniqueId) {
210: for (Extension ext : connectedExtensions) {
211: if (ext.getUniqueId().equals(uniqueId)) {
212: return true;
213: }
214: }
215: return false;
216: }
217:
218: /**
219: * @see org.java.plugin.registry.ExtensionPoint#isSuccessorOf(
220: * org.java.plugin.registry.ExtensionPoint)
221: */
222: public boolean isSuccessorOf(final ExtensionPoint extensionPoint) {
223: return predecessors.contains(extensionPoint.getUniqueId());
224: }
225:
226: /**
227: * @param pluginId predecessor plug-in ID to add
228: * @param extensionPointId predecessor extension point ID to add
229: * @return this instance
230: */
231: public MockExtensionPoint addPredecessors(final String pluginId,
232: final String extensionPointId) {
233: predecessors.add(pluginId + '@' + extensionPointId);
234: return this ;
235: }
236:
237: /**
238: * @see org.java.plugin.registry.ExtensionPoint#isValid()
239: */
240: public boolean isValid() {
241: return isValid;
242: }
243:
244: /**
245: * @param value the valid flag to set
246: * @return this instance
247: */
248: public MockExtensionPoint setValid(final boolean value) {
249: isValid = value;
250: return this ;
251: }
252:
253: /**
254: * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
255: */
256: public String getUniqueId() {
257: return getDeclaringPluginDescriptor().getId() + '@' + getId();
258: }
259: }
|