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 | 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 | 17025 | vcaballero | import java.io.Serializable; |
23 | 15734 | vcaballero | import java.util.ArrayList; |
24 | import java.util.Iterator; |
||
25 | 17025 | vcaballero | import java.util.Map; |
26 | 15734 | vcaballero | |
27 | 17743 | vcaballero | import org.apache.log4j.Logger; |
28 | 17025 | vcaballero | import org.gvsig.gui.beans.panelGroup.exceptions.ListCouldntLoadPanelException; |
29 | 17543 | jmvivo | import org.gvsig.gui.beans.panelGroup.exceptions.PanelBaseException; |
30 | 15734 | vcaballero | import org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader; |
31 | import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
||
32 | 17025 | vcaballero | import org.gvsig.gui.beans.panelGroup.panels.IPanel; |
33 | 24956 | jmvivo | import org.gvsig.tools.ToolsLocator; |
34 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
35 | import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
||
36 | 15734 | vcaballero | |
37 | 17743 | vcaballero | import com.iver.andami.PluginServices; |
38 | 15734 | vcaballero | |
39 | /**
|
||
40 | 23214 | jmvivo | * <p>
|
41 | * Panel loader version that loads {@link AbstractPanel AbstractPanel} classes
|
||
42 | * registered as a extension point.
|
||
43 | * </p>
|
||
44 | 24956 | jmvivo | *
|
45 | 15734 | vcaballero | * @see IPanelGroupLoader
|
46 | 24956 | jmvivo | *
|
47 | 15734 | vcaballero | * @version 15/10/2007
|
48 | 23214 | jmvivo | * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
49 | 15734 | vcaballero | */
|
50 | 17025 | vcaballero | public class PanelGroupLoaderFromExtensionPoint implements IPanelGroupLoader, Serializable { |
51 | 17543 | jmvivo | private static final long serialVersionUID = 6810333457209196344L; |
52 | 17025 | vcaballero | |
53 | 15734 | vcaballero | /**
|
54 | * Extension point id
|
||
55 | */
|
||
56 | private String id; |
||
57 | 23214 | jmvivo | |
58 | 15734 | vcaballero | /**
|
59 | 23214 | jmvivo | * <p>
|
60 | * Initializes this loader.
|
||
61 | * </p>
|
||
62 | 24956 | jmvivo | *
|
63 | 23214 | jmvivo | * @param id
|
64 | * extension point identifier
|
||
65 | 15734 | vcaballero | */
|
66 | public PanelGroupLoaderFromExtensionPoint(String id) { |
||
67 | this.id = id;
|
||
68 | } |
||
69 | |||
70 | /*
|
||
71 | * (non-Javadoc)
|
||
72 | 17543 | jmvivo | * @see org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader#loadPanels(java.util.ArrayList)
|
73 | 15734 | vcaballero | */
|
74 | 17543 | jmvivo | public void loadPanels(ArrayList<IPanel> panels) throws ListCouldntLoadPanelException { |
75 | 23214 | jmvivo | if (id == null) { |
76 | 17543 | jmvivo | return;
|
77 | 23214 | jmvivo | } |
78 | 15734 | vcaballero | |
79 | 24956 | jmvivo | ExtensionPointManager ePManager = ToolsLocator |
80 | .getExtensionPointManager(); |
||
81 | 17543 | jmvivo | ListCouldntLoadPanelException lCLPException = null;
|
82 | 24956 | jmvivo | Iterator<Extension> iterator = null; |
83 | 17543 | jmvivo | |
84 | try {
|
||
85 | 24956 | jmvivo | if (!ePManager.has(id)) {
|
86 | 17543 | jmvivo | return;
|
87 | 23214 | jmvivo | } |
88 | 17543 | jmvivo | |
89 | 24956 | jmvivo | iterator = ePManager.get(id).iterator(); |
90 | } catch (Exception e) { |
||
91 | 17743 | vcaballero | Logger.getLogger(getClass().getName()).debug(PluginServices.getText(this, "panel_loading_exception"), e); |
92 | |||
93 | 17543 | jmvivo | if ( lCLPException == null ) { |
94 | lCLPException = new ListCouldntLoadPanelFromExtensionPointException();
|
||
95 | } |
||
96 | |||
97 | lCLPException.add(e); |
||
98 | } |
||
99 | |||
100 | AbstractPanel panel = null;
|
||
101 | 23214 | jmvivo | |
102 | 15734 | vcaballero | while (iterator.hasNext()) {
|
103 | try {
|
||
104 | 23214 | jmvivo | |
105 | 24956 | jmvivo | panel = (AbstractPanel) ((iterator.next()).create()); |
106 | panels.add(panel); |
||
107 | 15734 | vcaballero | } catch (Exception e) { |
108 | 17743 | vcaballero | Logger.getLogger(getClass().getName()).debug(PluginServices.getText(this, "panel_loading_exception"), e); |
109 | |||
110 | 17025 | vcaballero | if ( lCLPException == null ) { |
111 | lCLPException = new ListCouldntLoadPanelFromExtensionPointException();
|
||
112 | } |
||
113 | |||
114 | 17543 | jmvivo | PanelBaseException bew = null;
|
115 | 23214 | jmvivo | |
116 | if (panel == null) { |
||
117 | 17543 | jmvivo | bew = new PanelBaseException(e, ""); |
118 | 23214 | jmvivo | } else {
|
119 | 17543 | jmvivo | bew = new PanelBaseException(e, panel.getLabel());
|
120 | 23214 | jmvivo | } |
121 | 17543 | jmvivo | |
122 | lCLPException.add(bew); |
||
123 | 15734 | vcaballero | } |
124 | } |
||
125 | |||
126 | 17025 | vcaballero | if ( lCLPException != null ) { |
127 | throw lCLPException;
|
||
128 | } |
||
129 | |||
130 | 15734 | vcaballero | } |
131 | 23214 | jmvivo | |
132 | 17025 | vcaballero | /**
|
133 | 23214 | jmvivo | * <p>
|
134 | * Exception produced when fails the load of a panel by a loader of type
|
||
135 | * <code>PanelGroupLoaderFromExtensionPoint</code>.
|
||
136 | * </p>
|
||
137 | 24956 | jmvivo | *
|
138 | 17025 | vcaballero | * @version 27/11/2007
|
139 | 23214 | jmvivo | * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
140 | 17025 | vcaballero | */
|
141 | public class ListCouldntLoadPanelFromExtensionPointException extends ListCouldntLoadPanelException { |
||
142 | private static final long serialVersionUID = -1513294728326593385L; |
||
143 | |||
144 | 27723 | jmvivo | 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 | 17025 | vcaballero | /**
|
148 | 23214 | jmvivo | * <p>
|
149 | * Creates an initializes a new instance of
|
||
150 | * <code>ListCouldntLoadPanelFromExtensionPointException</code>.
|
||
151 | * </p>
|
||
152 | 17025 | vcaballero | */
|
153 | public ListCouldntLoadPanelFromExtensionPointException() {
|
||
154 | 27723 | jmvivo | super(formatString, messageKey, serialVersionUID);
|
155 | 17025 | vcaballero | } |
156 | 23214 | jmvivo | |
157 | 17025 | vcaballero | /*
|
158 | * (non-Javadoc)
|
||
159 | 24956 | jmvivo | *
|
160 | 23214 | jmvivo | * @see org.gvsig.tools.exceptions.BaseException#values()
|
161 | 17025 | vcaballero | */
|
162 | 17543 | jmvivo | protected Map<String, String> values() { |
163 | 17025 | vcaballero | return null; |
164 | } |
||
165 | } |
||
166 | 15734 | vcaballero | } |