Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / panelGroup / loaders / PanelGroupLoaderFromExtensionPoint.java @ 15734

History | View | Annotate | Download (2.78 KB)

1 15734 vcaballero
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program 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
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
20
package com.iver.cit.gvsig.panelGroup.loaders;
21
22
import java.util.ArrayList;
23
import java.util.Iterator;
24
25
import org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader;
26
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
27
28
import com.iver.utiles.extensionPoints.ExtensionPoint;
29
import com.iver.utiles.extensionPoints.ExtensionPoints;
30
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
31
32
/**
33
 * <p>Panel loader version that loads {@link AbstractPanel AbstractPanel} classes registered
34
 *  as a extension point.</p>
35
 *
36
 * @see IPanelGroupLoader
37
 *
38
 * @version 15/10/2007
39
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
40
 */
41
public class PanelGroupLoaderFromExtensionPoint implements IPanelGroupLoader {
42
        /**
43
         * Extension point id
44
         */
45
        private String id;
46
47
        /**
48
         * <p>Initializes this loader.</p>
49
         *
50
         * @param id extension point identifier
51
         */
52
        public PanelGroupLoaderFromExtensionPoint(String id) {
53
                this.id = id;
54
        }
55
56
        /*
57
         * (non-Javadoc)
58
         * @see org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader#loadPanels()
59
         */
60
        public AbstractPanel[] loadPanels() throws Exception {
61
                if (id == null)
62
                        return null;
63
64
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
65
                ExtensionPoint extensionPoint = (ExtensionPoint) extensionPoints.get(id);
66
67
                if (extensionPoint == null)
68
                        return null;
69
70
                Iterator iterator = extensionPoint.keySet().iterator();
71
                ArrayList<AbstractPanel> panels = new ArrayList<AbstractPanel>();
72
                Exception lastException = null;
73
                String key;
74
                Class class_type;
75
76
                while (iterator.hasNext()) {
77
                        try {
78
                                key = (String) iterator.next();
79
80
                                class_type = ((Class) extensionPoint.get(key));
81
82
                                if ((class_type != null) && (AbstractPanel.class.isAssignableFrom(class_type))) {
83
                                        panels.add((AbstractPanel) class_type.getConstructor().newInstance());
84
                                }
85
                        } catch (Exception e) {
86
                                lastException = e;
87
                        }
88
                }
89
90
                return panels.toArray(new AbstractPanel[panels.size()]);
91
        }
92
}