Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java @ 7040:f3cdc620b666 generator-refactoring
Added first version of diagram attribute parser.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 18 Sep 2013 16:20:59 +0200 |
parents | |
children | 599d3c48474c |
comparison
equal
deleted
inserted
replaced
7039:d9fda41b4ec4 | 7040:f3cdc620b666 |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.exports; | |
10 | |
11 import java.util.ArrayList; | |
12 import java.util.List; | |
13 | |
14 import org.w3c.dom.Element; | |
15 import org.w3c.dom.NodeList; | |
16 | |
17 import org.dive4elements.river.exports.process.Processor; | |
18 | |
19 import org.apache.log4j.Logger; | |
20 | |
21 public class DiagramAttributes | |
22 { | |
23 private static Logger log = Logger.getLogger(DiagramAttributes.class); | |
24 | |
25 public class AxisAttributes { | |
26 // TODO: More Attributes | |
27 private String name; | |
28 | |
29 public AxisAttributes() { | |
30 } | |
31 | |
32 public AxisAttributes(String name) { | |
33 this.name = name; | |
34 } | |
35 | |
36 public String getName() { | |
37 return name; | |
38 } | |
39 } // class AxisAttributes | |
40 | |
41 public class AxisProcessor { | |
42 private Processor processor; | |
43 private String axisName; | |
44 | |
45 public AxisProcessor() { | |
46 } | |
47 | |
48 public AxisProcessor(Processor processor, String axisName) { | |
49 this.processor = processor; | |
50 this.axisName = axisName; | |
51 } | |
52 | |
53 public Processor getProcessor() { | |
54 return processor; | |
55 } | |
56 | |
57 public getAxisName() { | |
58 return axisName; | |
59 } | |
60 } // class AxisProcessor | |
61 | |
62 private List<AxisAttributes> axesAttrs; | |
63 private List<AxisProcessor> axesProcessors; | |
64 | |
65 public DiagramAttributes() { | |
66 axesAttrs = new ArrayList<AxisAttributes>(5); | |
67 axesProcessors = new ArrayList<AxisProcessor>(5); | |
68 } | |
69 | |
70 public DiagramAttributes(Element config) { | |
71 this(); | |
72 parseAxis(config); | |
73 parseProcessors(config); | |
74 } | |
75 | |
76 private void parseAxis(Element config) { | |
77 NodeList axisNodes = config.getElementsByTagName("axis"); | |
78 | |
79 for (int i = 0, N = axisNodes.getLength(); i < N; ++i) { | |
80 Element axisElement = (Element)axisNodes.item(i); | |
81 String name = axisElement.getAttribute("name").trim(); | |
82 if (!name.isEmpty()) { | |
83 axesAttrs.add(new AxisAttributes(name)); | |
84 } | |
85 } | |
86 } | |
87 | |
88 public List<AxisProcessor> getAxesProcessors() { | |
89 return axesProcessors; | |
90 } | |
91 | |
92 private void parseProcessors(Element config) { | |
93 NodeList processorNodes = config.getElementsByTagName("processor"); | |
94 | |
95 for (int i = 0, N = processorNodes.getLength(); i < N; ++i) { | |
96 Element processorElement = (Element)processorNodes.item(i); | |
97 String className = processorElement.getAttribute("class").trim(); | |
98 String axisName = processorElement.getAttribute("axis").trim(); | |
99 if (className.isEmpty() || axisName.isEmpty()) { | |
100 continue; | |
101 } | |
102 | |
103 try { | |
104 Processor processor = | |
105 (Processor)Class.forName(className).newInstance(); | |
106 axesProcessors.add(new AxisProcessor(processor, axisName)); | |
107 } | |
108 catch (ClassNotFoundException cnfe) { | |
109 log.error(cnfe, cnfe); | |
110 } | |
111 catch (InstantiationException ie) { | |
112 log.error(ie, ie); | |
113 } | |
114 catch (IllegalAccessException ia) { | |
115 log.error(ia, ia); | |
116 } | |
117 catch (ClassCastException cce) { | |
118 log.error(cce, cce); | |
119 } | |
120 } | |
121 } | |
122 } | |
123 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |