01: package net.refractions.udig.mapgraphic;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import net.refractions.udig.catalog.CatalogPlugin;
07: import net.refractions.udig.core.internal.ExtensionPointProcessor;
08: import net.refractions.udig.core.internal.ExtensionPointUtil;
09:
10: import org.eclipse.core.runtime.IConfigurationElement;
11: import org.eclipse.core.runtime.IExtension;
12:
13: public class MapGraphicFactory {
14:
15: private static final MapGraphicFactory instance = new MapGraphicFactory();
16:
17: public static MapGraphicFactory getInstance() {
18: return instance;
19: }
20:
21: private MapGraphicFactory() {
22: //private constructor
23: }
24:
25: public MapGraphic createMapGraphic(String id) {
26: Processor p = new Processor(id);
27: ExtensionPointUtil.process(MapGraphicPlugin.getDefault(),
28: MapGraphic.XPID, p);
29:
30: if (p.mg.isEmpty())
31: return null;
32:
33: try {
34: return (MapGraphic) p.mg.get(0).createExecutableExtension(
35: "class"); //$NON-NLS-1$
36: } catch (Throwable t) {
37: CatalogPlugin.log(t.getLocalizedMessage(), t);
38: }
39:
40: return null;
41: }
42:
43: public List<IConfigurationElement> getMapGraphics() {
44: Processor p = new Processor();
45: ExtensionPointUtil.process(MapGraphicPlugin.getDefault(),
46: MapGraphic.XPID, p);
47:
48: return p.mg;
49: }
50: }
51:
52: class Processor implements ExtensionPointProcessor {
53:
54: String id;
55: List<IConfigurationElement> mg = new ArrayList<IConfigurationElement>();
56:
57: Processor() {
58: this (null);
59: }
60:
61: Processor(String id) {
62: this .id = id;
63: }
64:
65: public void process(IExtension extension,
66: IConfigurationElement element) throws Exception {
67: try {
68: String theId = element.getAttribute("id"); //$NON-NLS-1$
69: if (id == null || id.equals(theId)) {
70: mg.add(element);
71: }
72: } catch (Throwable t) {
73: CatalogPlugin.log(t.getLocalizedMessage(), t);
74: }
75:
76: }
77:
78: }
|