001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.core.internal;
018:
019: import java.util.ArrayList;
020: import java.util.Arrays;
021: import java.util.List;
022: import java.util.Map;
023: import java.util.WeakHashMap;
024:
025: import org.eclipse.core.runtime.IConfigurationElement;
026: import org.eclipse.core.runtime.IExtension;
027: import org.eclipse.core.runtime.IExtensionPoint;
028: import org.eclipse.core.runtime.IExtensionRegistry;
029: import org.eclipse.core.runtime.ILog;
030: import org.eclipse.core.runtime.Platform;
031: import org.eclipse.core.runtime.Status;
032: import org.osgi.framework.Bundle;
033:
034: /**
035: * Process an extention point.
036: *
037: * @author jeichar
038: * @since 0.6.0
039: */
040: public class ExtensionPointList extends
041: ArrayList<IConfigurationElement> {
042:
043: /** <code>serialVersionUID</code> field */
044: private static final long serialVersionUID = ExtensionPointList.class
045: .hashCode();
046:
047: /**
048: * Construct <code>ExtensionPointIterator</code>.
049: */
050: private ExtensionPointList(String xpid) {
051: IExtensionRegistry registry = Platform.getExtensionRegistry();
052: IExtensionPoint extensionPoint = registry
053: .getExtensionPoint(xpid);
054: if (extensionPoint == null)
055: return;
056:
057: // For each extension ...
058: for (IExtension extension : extensionPoint.getExtensions()) {
059: try {
060: addAll(Arrays.asList(extension
061: .getConfigurationElements()));
062: } catch (Exception e) {
063: Bundle bundle = Platform.getBundle(extensionPoint
064: .getNamespace());
065: if (bundle == null) {
066: if (CorePlugin.getDefault().isDebugging()) {
067: System.out
068: .println("Could not locate bundle for " + extensionPoint.getNamespace()); //$NON-NLS-1$
069: }
070: bundle = CorePlugin.getDefault().getBundle();
071: }
072: ILog log = Platform.getLog(bundle);
073: log.log(new Status(Status.ERROR, extension
074: .getNamespace(), 0, extensionPoint
075: .getNamespace()
076: + Messages.ExtensionPointList_problem + e, e));
077: }
078: }
079: }
080:
081: private static Map<String, List<IConfigurationElement>> cache = new WeakHashMap<String, List<IConfigurationElement>>();
082:
083: /**
084: * Gets a ExtensionPointList for the provided extensionPoint
085: *
086: * @param extensionPointId id of the extension point to get the list of extensions for.
087: * @return
088: */
089: public static List<IConfigurationElement> getExtensionPointList(
090: String extensionPointId) {
091: List<IConfigurationElement> list = cache.get(extensionPointId);
092: if (list == null) {
093: list = new ExtensionPointList(extensionPointId);
094: cache.put(extensionPointId, list);
095: }
096:
097: list = new ArrayList<IConfigurationElement>(list);
098: return list;
099: }
100: }
|