Revision 8516 trunk/extensions/extGraph_predes/src/com/iver/cit/gvsig/fmap/core/symbols/SymbolFactory.java

View differences:

SymbolFactory.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.1  2006-10-30 19:30:35  jaume
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
47 50
* *** empty log message ***
48 51
*
49 52
*
50 53
*/
51 54
package com.iver.cit.gvsig.fmap.core.symbols;
52 55

  
56
import com.iver.andami.messages.NotificationManager;
53 57
import com.iver.cit.gvsig.fmap.core.ISymbol;
58
import com.iver.utiles.NotExistInXMLEntity;
54 59
import com.iver.utiles.XMLEntity;
55 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
 */
56 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
		}
57 88

  
58
	public static ISymbol createFromXML(XMLEntity xml) {
59
		Class clazz;
89
		Class clazz = null;
60 90
		ISymbol sym = null;
61 91

  
62 92
		try {
63
			clazz = Class.forName(xml.getStringProperty("className"));
93
			clazz = Class.forName(className);
64 94
			sym = (ISymbol) clazz.newInstance();
65 95
			sym.setXMLEntity(xml);
66 96
		} catch (InstantiationException e) {
67
			// TODO Auto-generated catch block
68
			e.printStackTrace();
97
			NotificationManager.
98
				addError("Trying to instantiate an interface" +
99
						" or abstract class + "+className, e);
69 100
		} catch (IllegalAccessException e) {
70
			// TODO Auto-generated catch block
71
			e.printStackTrace();
101
			NotificationManager.addError(null, e);
72 102
		} catch (ClassNotFoundException e) {
73
			// TODO Auto-generated catch block
74
			e.printStackTrace();
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);
75 110
		}
76 111
		return sym;
77 112
	}

Also available in: Unified diff