comparison artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java @ 7073:beb9e94f04d3 generator-refactoring

Allow comma separated names in "names" attribute in out generators to allow registering for more than one name. Old "name" attribute is removed.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 20 Sep 2013 15:42:21 +0200
parents 4e597d435398
children a2abd87c0d3b
comparison
equal deleted inserted replaced
7072:4e597d435398 7073:beb9e94f04d3
330 int idx = 0; 330 int idx = 0;
331 331
332 for (int i = 0; i < num; i++) { 332 for (int i = 0; i < num; i++) {
333 Element item = (Element)outGenerators.item(i); 333 Element item = (Element)outGenerators.item(i);
334 334
335 String name = item.getAttribute("name"); 335 String name = item.getAttribute("names");
336 String clazz = item.getAttribute("class"); 336 String clazz = item.getAttribute("class");
337 337
338 if (name.isEmpty() || clazz.isEmpty()) { 338 if (name.isEmpty() || clazz.isEmpty()) {
339 continue; 339 continue;
340 } 340 }
341 341
342 Class<OutGenerator> generatorClass = null;
343
342 try { 344 try {
343 generators.put( 345 generatorClass = (Class<OutGenerator>)Class.forName(clazz);
344 name,
345 new Pair<Class<OutGenerator>, Element>(
346 (Class<OutGenerator>)Class.forName(clazz), item));
347
348 idx++;
349 } 346 }
350 catch (ClassNotFoundException cnfe) { 347 catch (ClassNotFoundException cnfe) {
351 logger.warn(cnfe, cnfe); 348 logger.warn(cnfe, cnfe);
349 continue;
350 }
351
352 Pair<Class<OutGenerator>, Element> pair =
353 new Pair<Class<OutGenerator>, Element>(generatorClass, item);
354
355 for (String key: name.split("[\\s,]")) {
356 if (!(key = key.trim()).isEmpty()) {
357 generators.put(key, pair);
358 idx++;
359 }
352 } 360 }
353 } 361 }
354 362
355 logger.info("Successfully loaded " + idx + " output generators."); 363 logger.info("Successfully loaded " + idx + " output generators.");
356 context.put(RiverContext.OUTGENERATORS_KEY, generators); 364 context.put(RiverContext.OUTGENERATORS_KEY, generators);

http://dive4elements.wald.intevation.org