Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / panelGroup / loaders / PanelGroupLoaderFromExtensionPoint.java @ 27723

History | View | Annotate | Download (4.67 KB)

1
/* 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.io.Serializable;
23
import java.util.ArrayList;
24
import java.util.Iterator;
25
import java.util.Map;
26

    
27
import org.apache.log4j.Logger;
28
import org.gvsig.gui.beans.panelGroup.exceptions.ListCouldntLoadPanelException;
29
import org.gvsig.gui.beans.panelGroup.exceptions.PanelBaseException;
30
import org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader;
31
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
32
import org.gvsig.gui.beans.panelGroup.panels.IPanel;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
35
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
36

    
37
import com.iver.andami.PluginServices;
38

    
39
/**
40
 * <p>
41
 * Panel loader version that loads {@link AbstractPanel AbstractPanel} classes
42
 * registered as a extension point.
43
 * </p>
44
 *
45
 * @see IPanelGroupLoader
46
 *
47
 * @version 15/10/2007
48
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
49
 */
50
public class PanelGroupLoaderFromExtensionPoint implements IPanelGroupLoader, Serializable {
51
        private static final long serialVersionUID = 6810333457209196344L;
52

    
53
        /**
54
         * Extension point id
55
         */
56
        private String id;
57

    
58
        /**
59
         * <p>
60
         * Initializes this loader.
61
         * </p>
62
         *
63
         * @param id
64
         *            extension point identifier
65
         */
66
        public PanelGroupLoaderFromExtensionPoint(String id) {
67
                this.id = id;
68
        }
69

    
70
        /*
71
         * (non-Javadoc)
72
         * @see org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader#loadPanels(java.util.ArrayList)
73
         */
74
        public void loadPanels(ArrayList<IPanel> panels) throws ListCouldntLoadPanelException {
75
                if (id == null) {
76
                        return;
77
                }
78

    
79
                ExtensionPointManager ePManager = ToolsLocator
80
                                .getExtensionPointManager();
81
                ListCouldntLoadPanelException lCLPException = null;
82
                Iterator<Extension> iterator = null;
83

    
84
                try {
85
                        if (!ePManager.has(id)) {
86
                                return;
87
                        }
88

    
89
                        iterator = ePManager.get(id).iterator();
90
                } catch (Exception e) {
91
                        Logger.getLogger(getClass().getName()).debug(PluginServices.getText(this, "panel_loading_exception"), e);
92

    
93
                        if ( lCLPException == null ) {
94
                                lCLPException = new ListCouldntLoadPanelFromExtensionPointException();
95
                        }
96

    
97
                        lCLPException.add(e);
98
                }
99

    
100
                AbstractPanel panel = null;
101

    
102
                while (iterator.hasNext()) {
103
                        try {
104

    
105
                                panel = (AbstractPanel) ((iterator.next()).create());
106
                                panels.add(panel);
107
                        } catch (Exception e) {
108
                                Logger.getLogger(getClass().getName()).debug(PluginServices.getText(this, "panel_loading_exception"), e);
109

    
110
                                if ( lCLPException == null ) {
111
                                        lCLPException = new ListCouldntLoadPanelFromExtensionPointException();
112
                                }
113

    
114
                                PanelBaseException bew = null;
115

    
116
                                if (panel == null) {
117
                                        bew = new PanelBaseException(e, "");
118
                                } else {
119
                                        bew = new PanelBaseException(e, panel.getLabel());
120
                                }
121

    
122
                                lCLPException.add(bew);
123
                        }
124
                }
125

    
126
                if ( lCLPException != null ) {
127
                        throw lCLPException;
128
                }
129

    
130
        }
131

    
132
        /**
133
         * <p>
134
         * Exception produced when fails the load of a panel by a loader of type
135
         * <code>PanelGroupLoaderFromExtensionPoint</code>.
136
         * </p>
137
         *
138
         * @version 27/11/2007
139
         * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
140
         */
141
        public class ListCouldntLoadPanelFromExtensionPointException extends ListCouldntLoadPanelException {
142
                private static final long serialVersionUID = -1513294728326593385L;
143

    
144
                private static final String formatString = "Couldn't load some panels from an extension point of classes:";
145
                private static final String messageKey = "couldnt_load_panels_from_extension_point_exception";
146

    
147
                /**
148
                 * <p>
149
                 * Creates an initializes a new instance of
150
                 * <code>ListCouldntLoadPanelFromExtensionPointException</code>.
151
                 * </p>
152
                 */
153
                public ListCouldntLoadPanelFromExtensionPointException() {
154
                        super(formatString, messageKey, serialVersionUID);
155
                }
156

    
157
                /*
158
                 * (non-Javadoc)
159
                 *
160
                 * @see org.gvsig.tools.exceptions.BaseException#values()
161
                 */
162
                protected Map<String, String> values() {
163
                        return null;
164
                }
165
        }
166
}