Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java @ 155:f797093c60bd
Made a (single one) artifact collection factory configurable.
artifacts/trunk@1380 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 03 Mar 2011 09:51:09 +0000 |
parents | 147610c43863 |
children | b2115f484edb |
comparison
equal
deleted
inserted
replaced
154:1a72f08ce8d7 | 155:f797093c60bd |
---|---|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. | 6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
7 */ | 7 */ |
8 | 8 |
9 package de.intevation.artifactdatabase; | 9 package de.intevation.artifactdatabase; |
10 | 10 |
11 import de.intevation.artifacts.ArtifactCollectionFactory; | |
11 import de.intevation.artifacts.ArtifactContextFactory; | 12 import de.intevation.artifacts.ArtifactContextFactory; |
12 import de.intevation.artifacts.ArtifactFactory; | 13 import de.intevation.artifacts.ArtifactFactory; |
13 import de.intevation.artifacts.ServiceFactory; | 14 import de.intevation.artifacts.ServiceFactory; |
14 import de.intevation.artifacts.UserFactory; | 15 import de.intevation.artifacts.UserFactory; |
15 | 16 |
61 /** | 62 /** |
62 * XPath to figure out the class name of the user factory from global | 63 * XPath to figure out the class name of the user factory from global |
63 * configuration. | 64 * configuration. |
64 */ | 65 */ |
65 public static final String USER_FACTORY = | 66 public static final String USER_FACTORY = |
66 "/artfifact-database/factories/user-factory"; | 67 "/artifact-database/factories/user-factory"; |
67 | 68 |
68 /** | 69 /** |
69 * The name of the default user factory. | 70 * The name of the default user factory. |
70 */ | 71 */ |
71 public static final String DEFAULT_USER_FACTORY = | 72 public static final String DEFAULT_USER_FACTORY = |
72 "de.intevation.artifactdatabase.DefaultUserFactory"; | 73 "de.intevation.artifactdatabase.DefaultUserFactory"; |
74 | |
75 /** | |
76 * XPath to figure out the class name of the collection factory from global | |
77 * configuration. | |
78 */ | |
79 public static final String COLLECTION_FACTORY = | |
80 "/artifact-database/factories/collection-factory"; | |
81 | |
82 /** | |
83 * The name of the default user factory. | |
84 */ | |
85 public static final String DEFAULT_COLLECTION_FACTORY = | |
86 "de.intevation.artifactdatabase.DefaultArtifactCollectionFactory"; | |
73 | 87 |
74 /** | 88 /** |
75 * XPath to figure out the secret used to sign the artifact exports | 89 * XPath to figure out the secret used to sign the artifact exports |
76 * made by the artfifact database server. | 90 * made by the artfifact database server. |
77 */ | 91 */ |
107 * The factory that is used to create and list users. | 121 * The factory that is used to create and list users. |
108 */ | 122 */ |
109 protected UserFactory userFactory; | 123 protected UserFactory userFactory; |
110 | 124 |
111 /** | 125 /** |
126 * The factory that is used to create new artifact collections. | |
127 */ | |
128 protected ArtifactCollectionFactory collectionFactory; | |
129 | |
130 /** | |
112 * byte array holding the export signing secret. | 131 * byte array holding the export signing secret. |
113 */ | 132 */ |
114 protected byte [] exportSecret; | 133 protected byte [] exportSecret; |
115 | 134 |
116 | 135 |
149 | 168 |
150 logger.info("Using class '" + factory.getClass().getName() | 169 logger.info("Using class '" + factory.getClass().getName() |
151 + "' for context creation."); | 170 + "' for context creation."); |
152 | 171 |
153 context = factory.createArtifactContext(Config.getConfig()); | 172 context = factory.createArtifactContext(Config.getConfig()); |
173 } | |
174 | |
175 | |
176 /** | |
177 * Scans the global configuration to load the configured collection factory | |
178 * and sets it up. | |
179 */ | |
180 protected void loadCollectionFactory() { | |
181 | |
182 logger.info("loading collection factory."); | |
183 | |
184 Node factory = Config.getNodeXPath(COLLECTION_FACTORY); | |
185 | |
186 String className = Config.getStringXPath( | |
187 factory, "text()", DEFAULT_COLLECTION_FACTORY); | |
188 | |
189 try { | |
190 Class clazz = Class.forName(className); | |
191 collectionFactory = (ArtifactCollectionFactory) clazz.newInstance(); | |
192 | |
193 collectionFactory.setup(Config.getConfig(), factory); | |
194 } | |
195 catch (ClassNotFoundException cnfe) { | |
196 logger.error(cnfe.getLocalizedMessage(), cnfe); | |
197 } | |
198 catch (InstantiationException ie) { | |
199 logger.error(ie.getLocalizedMessage(), ie); | |
200 } | |
201 catch (ClassCastException cce) { | |
202 logger.error(cce.getLocalizedMessage(), cce); | |
203 } | |
204 catch (IllegalAccessException iae) { | |
205 logger.error(iae.getLocalizedMessage(), iae); | |
206 } | |
154 } | 207 } |
155 | 208 |
156 /** | 209 /** |
157 * Scans the global configuration to load the configured | 210 * Scans the global configuration to load the configured |
158 * artifact factories and sets them up. | 211 * artifact factories and sets them up. |
309 * Loads all the dynamic classes configured by the global configuration. | 362 * Loads all the dynamic classes configured by the global configuration. |
310 */ | 363 */ |
311 public void boot() { | 364 public void boot() { |
312 setupExportSecret(); | 365 setupExportSecret(); |
313 buildContext(); | 366 buildContext(); |
367 loadCollectionFactory(); | |
314 loadArtifactFactories(); | 368 loadArtifactFactories(); |
315 loadServiceFactories(); | 369 loadServiceFactories(); |
316 loadUserFactory(); | 370 loadUserFactory(); |
317 } | 371 } |
318 | 372 |
319 /** | 373 /** |
374 * Returns the artifact collection factory. | |
375 * | |
376 * @return the artifact collection factory. | |
377 */ | |
378 public ArtifactCollectionFactory getArtifactCollectionFactory() { | |
379 return collectionFactory; | |
380 } | |
381 | |
382 /** | |
320 * Returns the list of ready to use artifact factories. | 383 * Returns the list of ready to use artifact factories. |
321 * @return The list of artifact factories. | 384 * @return The list of artifact factories. |
322 */ | 385 */ |
323 public ArtifactFactory [] getArtifactFactories() { | 386 public ArtifactFactory [] getArtifactFactories() { |
324 return artifactFactories; | 387 return artifactFactories; |