KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Collection JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.LinkedList JavaDoc;
26
27 import org.java.plugin.registry.Extension;
28 import org.java.plugin.registry.ExtensionPoint;
29
30 /**
31  * @version $Id: MockExtensionPoint.java,v 1.2 2006/09/14 18:10:39 ddimon Exp $
32  */

33 public class MockExtensionPoint extends MockPluginElement implements
34         ExtensionPoint {
35     private String JavaDoc multiplicity;
36     private String JavaDoc parentExtensionPointId;
37     private String JavaDoc parentPluginId;
38     private boolean isValid = true;
39     private LinkedList JavaDoc availableExtensions = new LinkedList JavaDoc();
40     private LinkedList JavaDoc connectedExtensions = new LinkedList JavaDoc();
41     private LinkedList JavaDoc descendants = new LinkedList JavaDoc();
42     private LinkedList JavaDoc parameterDefinitions = new LinkedList JavaDoc();
43     private HashSet JavaDoc predecessors = new HashSet JavaDoc();
44
45     /**
46      * @see org.java.plugin.registry.ExtensionPoint#getAvailableExtension(
47      * java.lang.String)
48      */

49     public Extension getAvailableExtension(final String JavaDoc uniqueId) {
50         for (Iterator JavaDoc it = availableExtensions.iterator(); it.hasNext();) {
51             Extension ext = (Extension) it.next();
52             if (ext.getUniqueId().equals(uniqueId)) {
53                 return ext;
54             }
55         }
56         throw new IllegalArgumentException JavaDoc("extension UID " //$NON-NLS-1$
57
+ uniqueId + " not available"); //$NON-NLS-1$
58
}
59
60     /**
61      * @see org.java.plugin.registry.ExtensionPoint#getAvailableExtensions()
62      */

63     public Collection JavaDoc getAvailableExtensions() {
64         return Collections.unmodifiableCollection(availableExtensions);
65     }
66
67     /**
68      * @see org.java.plugin.registry.ExtensionPoint#getConnectedExtension(
69      * java.lang.String)
70      */

71     public Extension getConnectedExtension(final String JavaDoc uniqueId) {
72         for (Iterator JavaDoc it = connectedExtensions.iterator(); it.hasNext();) {
73             Extension ext = (Extension) it.next();
74             if (ext.getUniqueId().equals(uniqueId)) {
75                 return ext;
76             }
77         }
78         throw new IllegalArgumentException JavaDoc("extension UID " //$NON-NLS-1$
79
+ uniqueId + " not connected"); //$NON-NLS-1$
80
}
81
82     /**
83      * @see org.java.plugin.registry.ExtensionPoint#getConnectedExtensions()
84      */

85     public Collection JavaDoc getConnectedExtensions() {
86         return Collections.unmodifiableCollection(connectedExtensions);
87     }
88     
89     /**
90      * @param extension extension to add
91      * @param isConnected if <code>true</code> extension will be marked as
92      * "connected" also
93      * @return this instance
94      */

95     public MockExtensionPoint addExtension(final Extension extension,
96             final boolean isConnected) {
97         availableExtensions.add(extension);
98         if (isConnected) {
99             connectedExtensions.add(extension);
100         }
101         return this;
102     }
103
104     /**
105      * @see org.java.plugin.registry.ExtensionPoint#getDescendants()
106      */

107     public Collection JavaDoc getDescendants() {
108         return Collections.unmodifiableCollection(descendants);
109     }
110     
111     /**
112      * @param extension descendant extension to add
113      * @return this instance
114      */

115     public MockExtensionPoint addParameter(final Extension extension) {
116         descendants.add(extension);
117         return this;
118     }
119
120     /**
121      * @see org.java.plugin.registry.ExtensionPoint#getMultiplicity()
122      */

123     public String JavaDoc getMultiplicity() {
124         return multiplicity;
125     }
126     
127     /**
128      * @param value the multiplicity to set
129      * @return this instance
130      */

131     public MockExtensionPoint setMultiplicity(final String JavaDoc value) {
132         multiplicity = value;
133         return this;
134     }
135
136     /**
137      * @see org.java.plugin.registry.ExtensionPoint#getParameterDefinition(
138      * java.lang.String)
139      */

140     public ParameterDefinition getParameterDefinition(String JavaDoc id) {
141         for (Iterator JavaDoc it = parameterDefinitions.iterator(); it.hasNext();) {
142             ParameterDefinition paramDef = (ParameterDefinition) it.next();
143             if (paramDef.getId().equals(id)) {
144                 return paramDef;
145             }
146         }
147         throw new IllegalArgumentException JavaDoc(
148                 "unknown parameter definition ID " + id); //$NON-NLS-1$
149
}
150
151     /**
152      * @see org.java.plugin.registry.ExtensionPoint#getParameterDefinitions()
153      */

154     public Collection JavaDoc getParameterDefinitions() {
155         return Collections.unmodifiableCollection(parameterDefinitions);
156     }
157     
158     /**
159      * @param parameterDefinition parameter definition to add
160      * @return this instance
161      */

162     public MockExtensionPoint addParameterDefinition(
163             final ParameterDefinition parameterDefinition) {
164         parameterDefinitions.add(parameterDefinition);
165         return this;
166     }
167
168     /**
169      * @see org.java.plugin.registry.ExtensionPoint#getParentExtensionPointId()
170      */

171     public String JavaDoc getParentExtensionPointId() {
172         return parentExtensionPointId;
173     }
174     
175     /**
176      * @param pluginId the parent plug-in id to set
177      * @param extensionPointId the parent extension point id to set
178      * @return this instance
179      */

180     public MockExtensionPoint setParentExtensionPoint(final String JavaDoc pluginId,
181             final String JavaDoc extensionPointId) {
182         parentPluginId = pluginId;
183         parentExtensionPointId = extensionPointId;
184         predecessors.add(pluginId + '@' + extensionPointId);
185         return this;
186     }
187
188     /**
189      * @see org.java.plugin.registry.ExtensionPoint#getParentPluginId()
190      */

191     public String JavaDoc getParentPluginId() {
192         return parentPluginId;
193     }
194
195     /**
196      * @see org.java.plugin.registry.ExtensionPoint#isExtensionAvailable(
197      * java.lang.String)
198      */

199     public boolean isExtensionAvailable(final String JavaDoc uniqueId) {
200         for (Iterator JavaDoc it = availableExtensions.iterator(); it.hasNext();) {
201             Extension ext = (Extension) it.next();
202             if (ext.getUniqueId().equals(uniqueId)) {
203                 return true;
204             }
205         }
206         return false;
207     }
208
209     /**
210      * @see org.java.plugin.registry.ExtensionPoint#isExtensionConnected(
211      * java.lang.String)
212      */

213     public boolean isExtensionConnected(final String JavaDoc uniqueId) {
214         for (Iterator JavaDoc it = connectedExtensions.iterator(); it.hasNext();) {
215             Extension ext = (Extension) it.next();
216             if (ext.getUniqueId().equals(uniqueId)) {
217                 return true;
218             }
219         }
220         return false;
221     }
222
223     /**
224      * @see org.java.plugin.registry.ExtensionPoint#isSuccessorOf(
225      * org.java.plugin.registry.ExtensionPoint)
226      */

227     public boolean isSuccessorOf(final ExtensionPoint extensionPoint) {
228         return predecessors.contains(extensionPoint.getUniqueId());
229     }
230     
231     /**
232      * @param pluginId predecessor plug-in ID to add
233      * @param extensionPointId predecessor extension point ID to add
234      * @return this instance
235      */

236     public MockExtensionPoint addPredecessors(final String JavaDoc pluginId,
237             final String JavaDoc extensionPointId) {
238         predecessors.add(pluginId + '@' + extensionPointId);
239         return this;
240     }
241
242     /**
243      * @see org.java.plugin.registry.ExtensionPoint#isValid()
244      */

245     public boolean isValid() {
246         return isValid;
247     }
248     
249     /**
250      * @param value the valid flag to set
251      * @return this instance
252      */

253     public MockExtensionPoint setValid(final boolean value) {
254         isValid = value;
255         return this;
256     }
257
258     /**
259      * @see org.java.plugin.registry.UniqueIdentity#getUniqueId()
260      */

261     public String JavaDoc getUniqueId() {
262         return getDeclaringPluginDescriptor().getId() + '@' + getId();
263     }
264 }
265
Popular Tags