Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java @ 17:5a6b6a3debc7
Integrated logging into artifact database.
artifacts/trunk@33 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 08 Sep 2009 06:29:52 +0000 |
parents | 635310c6a20e |
children | 1259d192e3c3 |
comparison
equal
deleted
inserted
replaced
16:635310c6a20e | 17:5a6b6a3debc7 |
---|---|
6 import java.util.ArrayList; | 6 import java.util.ArrayList; |
7 | 7 |
8 import de.intevation.artifacts.ArtifactFactory; | 8 import de.intevation.artifacts.ArtifactFactory; |
9 import de.intevation.artifacts.ArtifactContextFactory; | 9 import de.intevation.artifacts.ArtifactContextFactory; |
10 | 10 |
11 import org.apache.log4j.Logger; | |
12 | |
11 /** | 13 /** |
12 * Bootstrap facility for the global context and the artifact factories. | 14 * Bootstrap facility for the global context and the artifact factories. |
13 * | 15 * |
14 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) | 16 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
15 */ | 17 */ |
16 public class FactoryBootstrap | 18 public class FactoryBootstrap |
17 { | 19 { |
20 private static Logger logger = Logger.getLogger(FactoryBootstrap.class); | |
21 | |
18 public static final String CONTEXT_FACTORY = | 22 public static final String CONTEXT_FACTORY = |
19 "/artifact-database/factories/context-factory/text()"; | 23 "/artifact-database/factories/context-factory/text()"; |
20 | 24 |
21 public static final String DEFAULT_CONTEXT_FACTORY = | 25 public static final String DEFAULT_CONTEXT_FACTORY = |
22 "de.intevation.artifactdatabase.DefaultArtifactContextFactory"; | 26 "de.intevation.artifactdatabase.DefaultArtifactContextFactory"; |
40 try { | 44 try { |
41 Class clazz = Class.forName(className); | 45 Class clazz = Class.forName(className); |
42 factory = (ArtifactContextFactory)clazz.newInstance(); | 46 factory = (ArtifactContextFactory)clazz.newInstance(); |
43 } | 47 } |
44 catch (ClassNotFoundException cnfe) { | 48 catch (ClassNotFoundException cnfe) { |
45 cnfe.printStackTrace(System.err); | 49 logger.error(cnfe.getLocalizedMessage(), cnfe); |
46 } | 50 } |
47 catch (InstantiationException ie) { | 51 catch (InstantiationException ie) { |
48 ie.printStackTrace(System.err); | 52 logger.error(ie.getLocalizedMessage(), ie); |
49 } | 53 } |
50 catch (ClassCastException cce) { | 54 catch (ClassCastException cce) { |
51 cce.printStackTrace(System.err); | 55 logger.error(cce.getLocalizedMessage(), cce); |
52 } | 56 } |
53 catch (IllegalAccessException iae) { | 57 catch (IllegalAccessException iae) { |
54 iae.printStackTrace(System.err); | 58 logger.error(iae.getLocalizedMessage(), iae); |
55 } | 59 } |
56 | 60 |
57 if (factory == null) { | 61 if (factory == null) { |
58 factory = new DefaultArtifactContextFactory(); | 62 factory = new DefaultArtifactContextFactory(); |
59 } | 63 } |
65 ArrayList loadedFactories = new ArrayList(); | 69 ArrayList loadedFactories = new ArrayList(); |
66 | 70 |
67 NodeList nodes = Config.getNodeSetXPath(ARTIFACT_FACTORIES); | 71 NodeList nodes = Config.getNodeSetXPath(ARTIFACT_FACTORIES); |
68 | 72 |
69 if (nodes == null) { | 73 if (nodes == null) { |
70 System.err.println("ERROR: no factories found"); | 74 logger.warn("No factories found"); |
71 return; | 75 return; |
72 } | 76 } |
73 | 77 |
74 Document config = Config.getConfig(); | 78 Document config = Config.getConfig(); |
75 | 79 |
81 try { | 85 try { |
82 Class clazz = Class.forName(className); | 86 Class clazz = Class.forName(className); |
83 factory = (ArtifactFactory)clazz.newInstance(); | 87 factory = (ArtifactFactory)clazz.newInstance(); |
84 } | 88 } |
85 catch (ClassNotFoundException cnfe) { | 89 catch (ClassNotFoundException cnfe) { |
86 cnfe.printStackTrace(System.err); | 90 logger.error(cnfe.getLocalizedMessage(), cnfe); |
87 } | 91 } |
88 catch (InstantiationException ie) { | 92 catch (InstantiationException ie) { |
89 ie.printStackTrace(System.err); | 93 logger.error(ie.getLocalizedMessage(), ie); |
90 } | 94 } |
91 catch (ClassCastException cce) { | 95 catch (ClassCastException cce) { |
92 cce.printStackTrace(System.err); | 96 logger.error(cce.getLocalizedMessage(), cce); |
93 } | 97 } |
94 catch (IllegalAccessException iae) { | 98 catch (IllegalAccessException iae) { |
95 iae.printStackTrace(System.err); | 99 logger.error(iae.getLocalizedMessage(), iae); |
96 } | 100 } |
97 | 101 |
98 if (factory != null) { | 102 if (factory != null) { |
99 factory.setup(config,nodes.item(i)); | 103 factory.setup(config,nodes.item(i)); |
100 loadedFactories.add(factory); | 104 loadedFactories.add(factory); |