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.HashMap;
024: import java.util.LinkedList;
025: import java.util.Map;
026:
027: import org.java.plugin.PathResolver;
028: import org.java.plugin.registry.ExtensionPoint;
029: import org.java.plugin.registry.Identity;
030: import org.java.plugin.registry.IntegrityCheckReport;
031: import org.java.plugin.registry.ManifestInfo;
032: import org.java.plugin.registry.PluginDescriptor;
033: import org.java.plugin.registry.PluginFragment;
034: import org.java.plugin.registry.PluginRegistry;
035: import org.java.plugin.registry.Version;
036: import org.java.plugin.registry.xml.PluginRegistryImpl;
037: import org.java.plugin.util.ExtendedProperties;
038:
039: /**
040: * @version $Id: MockPluginRegistry.java,v 1.4 2007/03/03 17:16:22 ddimon Exp $
041: */
042: public class MockPluginRegistry implements PluginRegistry {
043: private IntegrityCheckReport integrityCheckReport;
044: private PluginRegistryImpl xmlRegistryImpl;
045: private LinkedList<RegistryChangeListener> listeners = new LinkedList<RegistryChangeListener>();
046: private IntegrityCheckReport registrationReport;
047: private HashMap<String, ExtensionPoint> extensionPoints = new HashMap<String, ExtensionPoint>();
048: private HashMap<String, PluginDescriptor> pluginDescriptors = new HashMap<String, PluginDescriptor>();
049: private LinkedList<PluginFragment> pluginFragments = new LinkedList<PluginFragment>();
050:
051: /**
052: * @see org.java.plugin.registry.PluginRegistry#checkIntegrity(
053: * org.java.plugin.PathResolver)
054: */
055: public IntegrityCheckReport checkIntegrity(
056: final PathResolver pathResolver) {
057: return integrityCheckReport;
058: }
059:
060: /**
061: * @see org.java.plugin.registry.PluginRegistry#checkIntegrity(
062: * org.java.plugin.PathResolver, boolean)
063: */
064: public IntegrityCheckReport checkIntegrity(
065: final PathResolver pathResolver,
066: final boolean includeRegistrationReport) {
067: return integrityCheckReport;
068: }
069:
070: /**
071: * @param value the integrity check report to set
072: * @return this instance
073: */
074: public MockPluginRegistry setIntegrityCheckReport(
075: final IntegrityCheckReport value) {
076: integrityCheckReport = value;
077: return this ;
078: }
079:
080: /**
081: * @see org.java.plugin.registry.PluginRegistry#configure(
082: * org.java.plugin.util.ExtendedProperties)
083: */
084: public void configure(final ExtendedProperties config) {
085: // no-op
086: }
087:
088: /**
089: * @see org.java.plugin.registry.PluginRegistry#extractId(
090: * java.lang.String)
091: */
092: public String extractId(final String uniqueId) {
093: if (xmlRegistryImpl == null) {
094: xmlRegistryImpl = new PluginRegistryImpl();
095: }
096: return xmlRegistryImpl.extractId(uniqueId);
097: }
098:
099: /**
100: * @see org.java.plugin.registry.PluginRegistry#extractPluginId(
101: * java.lang.String)
102: */
103: public String extractPluginId(final String uniqueId) {
104: if (xmlRegistryImpl == null) {
105: xmlRegistryImpl = new PluginRegistryImpl();
106: }
107: return xmlRegistryImpl.extractPluginId(uniqueId);
108: }
109:
110: /**
111: * @see org.java.plugin.registry.PluginRegistry#extractVersion(
112: * java.lang.String)
113: */
114: public Version extractVersion(final String uniqueId) {
115: if (xmlRegistryImpl == null) {
116: xmlRegistryImpl = new PluginRegistryImpl();
117: }
118: return xmlRegistryImpl.extractVersion(uniqueId);
119: }
120:
121: /**
122: * @see org.java.plugin.registry.PluginRegistry#getDependingPlugins(
123: * org.java.plugin.registry.PluginDescriptor)
124: */
125: public Collection<PluginDescriptor> getDependingPlugins(
126: final PluginDescriptor descr) {
127: // no-op
128: return Collections.emptyList();
129: }
130:
131: /**
132: * @see org.java.plugin.registry.PluginRegistry#getExtensionPoint(
133: * java.lang.String, java.lang.String)
134: */
135: public ExtensionPoint getExtensionPoint(String pluginId,
136: String pointId) {
137: String uid = makeUniqueId(pluginId, pointId);
138: ExtensionPoint result = extensionPoints.get(uid);
139: if (result == null) {
140: throw new IllegalArgumentException(
141: "unknown extenssion point UID " + uid); //$NON-NLS-1$
142: }
143: return result;
144: }
145:
146: /**
147: * @see org.java.plugin.registry.PluginRegistry#getExtensionPoint(
148: * java.lang.String)
149: */
150: public ExtensionPoint getExtensionPoint(String uniqueId) {
151: ExtensionPoint result = extensionPoints.get(uniqueId);
152: if (result == null) {
153: throw new IllegalArgumentException(
154: "unknown extenssion point UID " + uniqueId); //$NON-NLS-1$
155: }
156: return result;
157: }
158:
159: /**
160: * @param extPoint extension point to add
161: * @return this instance
162: */
163: public MockPluginRegistry addExtensionPoint(
164: final ExtensionPoint extPoint) {
165: extensionPoints.put(extPoint.getUniqueId(), extPoint);
166: return this ;
167: }
168:
169: /**
170: * @see org.java.plugin.registry.PluginRegistry#getPluginDescriptor(
171: * java.lang.String)
172: */
173: public PluginDescriptor getPluginDescriptor(final String pluginId) {
174: PluginDescriptor result = pluginDescriptors.get(pluginId);
175: if (result == null) {
176: throw new IllegalArgumentException(
177: "unknown plug-in ID " + pluginId); //$NON-NLS-1$
178: }
179: return result;
180: }
181:
182: /**
183: * @see org.java.plugin.registry.PluginRegistry#getPluginDescriptors()
184: */
185: public Collection<PluginDescriptor> getPluginDescriptors() {
186: return Collections.unmodifiableCollection(pluginDescriptors
187: .values());
188: }
189:
190: /**
191: * @param descr plug-in descriptor to add
192: * @return this instance
193: */
194: public MockPluginRegistry addPluginDescriptor(
195: final PluginDescriptor descr) {
196: pluginDescriptors.put(descr.getId(), descr);
197: return this ;
198: }
199:
200: /**
201: * @see org.java.plugin.registry.PluginRegistry#getPluginFragments()
202: */
203: public Collection<PluginFragment> getPluginFragments() {
204: return Collections.unmodifiableCollection(pluginFragments);
205: }
206:
207: /**
208: * @param fragment plug-in fragment to add
209: * @return this instance
210: */
211: public MockPluginRegistry addPluginFragment(
212: final PluginFragment fragment) {
213: pluginFragments.add(fragment);
214: return this ;
215: }
216:
217: /**
218: * @see org.java.plugin.registry.PluginRegistry#getRegistrationReport()
219: */
220: public IntegrityCheckReport getRegistrationReport() {
221: return registrationReport;
222: }
223:
224: /**
225: * @param value the registration report to set
226: * @return this instance
227: */
228: public MockPluginRegistry setRegistrationReport(
229: final IntegrityCheckReport value) {
230: registrationReport = value;
231: return this ;
232: }
233:
234: /**
235: * @see org.java.plugin.registry.PluginRegistry#isExtensionPointAvailable(
236: * java.lang.String, java.lang.String)
237: */
238: public boolean isExtensionPointAvailable(final String pluginId,
239: final String pointId) {
240: return extensionPoints.containsKey(makeUniqueId(pluginId,
241: pointId));
242: }
243:
244: /**
245: * @see org.java.plugin.registry.PluginRegistry#isExtensionPointAvailable(
246: * java.lang.String)
247: */
248: public boolean isExtensionPointAvailable(final String uniqueId) {
249: return extensionPoints.containsKey(uniqueId);
250: }
251:
252: /**
253: * @see org.java.plugin.registry.PluginRegistry#isPluginDescriptorAvailable(
254: * java.lang.String)
255: */
256: public boolean isPluginDescriptorAvailable(final String pluginId) {
257: return pluginDescriptors.containsKey(pluginId);
258: }
259:
260: /**
261: * @see org.java.plugin.registry.PluginRegistry#makeUniqueId(
262: * java.lang.String, java.lang.String)
263: */
264: public String makeUniqueId(final String pluginId,
265: final String elementId) {
266: if (xmlRegistryImpl == null) {
267: xmlRegistryImpl = new PluginRegistryImpl();
268: }
269: return xmlRegistryImpl.makeUniqueId(pluginId, elementId);
270: }
271:
272: /**
273: * @see org.java.plugin.registry.PluginRegistry#makeUniqueId(
274: * java.lang.String, org.java.plugin.registry.Version)
275: */
276: public String makeUniqueId(final String pluginId,
277: final Version version) {
278: if (xmlRegistryImpl == null) {
279: xmlRegistryImpl = new PluginRegistryImpl();
280: }
281: return xmlRegistryImpl.makeUniqueId(pluginId, version);
282: }
283:
284: /**
285: * @see org.java.plugin.registry.PluginRegistry#readManifestInfo(
286: * java.net.URL)
287: */
288: public ManifestInfo readManifestInfo(final URL manifest) {
289: // no-op
290: return null;
291: }
292:
293: /**
294: * @see org.java.plugin.registry.PluginRegistry#register(java.net.URL[])
295: */
296: public Map<String, Identity> register(final URL[] manifests) {
297: // no-op
298: return Collections.emptyMap();
299: }
300:
301: /**
302: * @see org.java.plugin.registry.PluginRegistry#registerListener(
303: * org.java.plugin.registry.PluginRegistry.RegistryChangeListener)
304: */
305: public void registerListener(final RegistryChangeListener listener) {
306: listeners.add(listener);
307: }
308:
309: /**
310: * @see org.java.plugin.registry.PluginRegistry#unregister(
311: * java.lang.String[])
312: */
313: public Collection<String> unregister(final String[] ids) {
314: // no-op
315: return Collections.emptyList();
316: }
317:
318: /**
319: * @see org.java.plugin.registry.PluginRegistry#unregisterListener(
320: * org.java.plugin.registry.PluginRegistry.RegistryChangeListener)
321: */
322: public void unregisterListener(final RegistryChangeListener listener) {
323: listeners.remove(listener);
324: }
325: }
|