Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / panelGroup / loaders / PanelGroupLoaderFromExtensionPoint.java @ 40558

History | View | Annotate | Download (4.9 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.panelGroup.loaders;
25

    
26
import java.io.Serializable;
27
import java.util.ArrayList;
28
import java.util.Iterator;
29
import java.util.Map;
30

    
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.gui.beans.panelGroup.exceptions.ListCouldntLoadPanelException;
33
import org.gvsig.gui.beans.panelGroup.exceptions.PanelBaseException;
34
import org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader;
35
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
36
import org.gvsig.gui.beans.panelGroup.panels.IPanel;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
39
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
42

    
43

    
44
/**
45
 * <p>
46
 * Panel loader version that loads {@link AbstractPanel AbstractPanel} classes
47
 * registered as a extension point.
48
 * </p>
49
 *
50
 * @see IPanelGroupLoader
51
 *
52
 * @version 15/10/2007
53
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
54
 */
55
public class PanelGroupLoaderFromExtensionPoint implements IPanelGroupLoader, Serializable {
56
    private static final Logger logger = LoggerFactory
57
            .getLogger(PanelGroupLoaderFromExtensionPoint.class);
58
    
59
        private static final long serialVersionUID = 6810333457209196344L;
60

    
61
        /**
62
         * Extension point id
63
         */
64
        private String id;
65

    
66
        /**
67
         * <p>
68
         * Initializes this loader.
69
         * </p>
70
         *
71
         * @param id
72
         *            extension point identifier
73
         */
74
        public PanelGroupLoaderFromExtensionPoint(String id) {
75
                this.id = id;
76
        }
77

    
78
        /*
79
         * (non-Javadoc)
80
         * @see org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader#loadPanels(java.util.ArrayList)
81
         */
82
        public void loadPanels(ArrayList<IPanel> panels) throws ListCouldntLoadPanelException {
83
                if (id == null) {
84
                        return;
85
                }
86

    
87
                ExtensionPointManager ePManager = ToolsLocator
88
                                .getExtensionPointManager();
89
                ListCouldntLoadPanelException lCLPException = null;
90
                Iterator<Extension> iterator = null;
91

    
92
                try {
93
                        if (!ePManager.has(id)) {
94
                                return;
95
                        }
96

    
97
                        iterator = ePManager.get(id).iterator();
98
                } catch (Exception e) {
99
                        logger.debug(PluginServices
100
                    .getText(this, "panel_loading_exception"), e);
101

    
102
                        if ( lCLPException == null ) {
103
                                lCLPException = new ListCouldntLoadPanelFromExtensionPointException();
104
                        }
105

    
106
                        lCLPException.add(e);
107
                }
108

    
109
                AbstractPanel panel = null;
110

    
111
                while (iterator.hasNext()) {
112
                        try {
113

    
114
                                panel = (AbstractPanel) ((iterator.next()).create());
115
                                panels.add(panel);
116
                        } catch (Exception e) {
117
                                logger.debug(PluginServices.getText(this,
118
                        "panel_loading_exception"), e);
119

    
120
                                if ( lCLPException == null ) {
121
                                        lCLPException = new ListCouldntLoadPanelFromExtensionPointException();
122
                                }
123

    
124
                                PanelBaseException bew = null;
125

    
126
                                if (panel == null) {
127
                                        bew = new PanelBaseException(e, "");
128
                                } else {
129
                                        bew = new PanelBaseException(e, panel.getLabel());
130
                                }
131

    
132
                                lCLPException.add(bew);
133
                        }
134
                }
135

    
136
                if ( lCLPException != null ) {
137
                        throw lCLPException;
138
                }
139

    
140
        }
141

    
142
        /**
143
         * <p>
144
         * Exception produced when fails the load of a panel by a loader of type
145
         * <code>PanelGroupLoaderFromExtensionPoint</code>.
146
         * </p>
147
         *
148
         * @version 27/11/2007
149
         * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
150
         */
151
        public class ListCouldntLoadPanelFromExtensionPointException extends ListCouldntLoadPanelException {
152
                private static final long serialVersionUID = -1513294728326593385L;
153

    
154
                private static final String formatString = "Couldn't load some panels from an extension point of classes:";
155
                private static final String messageKey = "couldnt_load_panels_from_extension_point_exception";
156

    
157
                /**
158
                 * <p>
159
                 * Creates an initializes a new instance of
160
                 * <code>ListCouldntLoadPanelFromExtensionPointException</code>.
161
                 * </p>
162
                 */
163
                public ListCouldntLoadPanelFromExtensionPointException() {
164
                        super(formatString, messageKey, serialVersionUID);
165
                }
166

    
167
                /*
168
                 * (non-Javadoc)
169
                 *
170
                 * @see org.gvsig.tools.exceptions.BaseException#values()
171
                 */
172
                protected Map<String, String> values() {
173
                        return null;
174
                }
175
        }
176
}