root / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / fmap / core / symbols / SymbolFactory.java @ 8516
History | View | Annotate | Download (3.25 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: SymbolFactory.java 8516 2006-11-06 07:34:21Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2006-11-06 07:33:54 jaume
|
47 |
* javadoc, source style
|
48 |
*
|
49 |
* Revision 1.1 2006/10/30 19:30:35 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
*
|
53 |
*/
|
54 |
package com.iver.cit.gvsig.fmap.core.symbols; |
55 |
|
56 |
import com.iver.andami.messages.NotificationManager; |
57 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
58 |
import com.iver.utiles.NotExistInXMLEntity; |
59 |
import com.iver.utiles.XMLEntity; |
60 |
|
61 |
/**
|
62 |
* Factory for obtaining ISymbols of any kind from several sources like.
|
63 |
* <ol>
|
64 |
* <li>
|
65 |
* <b>XMLEntity's</b> that, at least, contains a full class name
|
66 |
* string property that defines which class handles such symbol.
|
67 |
* </li>
|
68 |
* </ol>
|
69 |
*
|
70 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
71 |
*/
|
72 |
public class SymbolFactory { |
73 |
/**
|
74 |
* Factory that allows to create ISymbol from an ISymbol xml
|
75 |
* descriptor. A barely specific XMLEntity object
|
76 |
*/
|
77 |
public static ISymbol createFromXML(XMLEntity xml) { |
78 |
String className = null; |
79 |
try {
|
80 |
className = xml.getStringProperty("className");
|
81 |
} catch (NotExistInXMLEntity e) {
|
82 |
NotificationManager. |
83 |
addError("Symbol class name not set.\n" +
|
84 |
" Maybe you forgot to add the" +
|
85 |
" putProperty(\"className\", yourClassName)" +
|
86 |
" call in the getXMLEntity method of your symbol", e);
|
87 |
} |
88 |
|
89 |
Class clazz = null; |
90 |
ISymbol sym = null;
|
91 |
|
92 |
try {
|
93 |
clazz = Class.forName(className);
|
94 |
sym = (ISymbol) clazz.newInstance(); |
95 |
sym.setXMLEntity(xml); |
96 |
} catch (InstantiationException e) { |
97 |
NotificationManager. |
98 |
addError("Trying to instantiate an interface" +
|
99 |
" or abstract class + "+className, e);
|
100 |
} catch (IllegalAccessException e) { |
101 |
NotificationManager.addError(null, e);
|
102 |
} catch (ClassNotFoundException e) { |
103 |
NotificationManager.addError("No class called " + className +
|
104 |
" was found.\nCheck the following.\n" +
|
105 |
"\t- The fullname of the class you're looking " +
|
106 |
"for matches the value in the className " +
|
107 |
"property of the XMLEntity ("+className+").\n" + |
108 |
"\t- The jar file containing your symbol class is in" +
|
109 |
"the application classpath", e);
|
110 |
} |
111 |
return sym;
|
112 |
} |
113 |
} |