comparison artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java @ 7099:24f153ad1f40 generator-refactoring

Use pre-converted diagram attributes now.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 23 Sep 2013 12:28:22 +0200
parents f0731aa7b735
children 038a04e001d7
comparison
equal deleted inserted replaced
7098:7dc31a235232 7099:24f153ad1f40
21 import org.dive4elements.artifacts.CallContext; 21 import org.dive4elements.artifacts.CallContext;
22 22
23 import org.dive4elements.river.artifacts.resources.Resources; 23 import org.dive4elements.river.artifacts.resources.Resources;
24 import org.dive4elements.river.artifacts.D4EArtifact; 24 import org.dive4elements.river.artifacts.D4EArtifact;
25 25
26 import org.dive4elements.artifacts.common.utils.ElementConverter;
27
26 public class DiagramAttributes 28 public class DiagramAttributes
29 implements ElementConverter
27 { 30 {
28 private static Logger log = Logger.getLogger(DiagramAttributes.class); 31 private static Logger log = Logger.getLogger(DiagramAttributes.class);
32
33 public class Instance {
34
35 private List<Processor> processors;
36
37 public Instance() {
38 processors = createProcessors();
39 }
40
41 private List<Processor> createProcessors() {
42 List<Processor> processors =
43 new ArrayList<Processor>(axesProcessors.size());
44 for (AxisProcessor ap: axesProcessors) {
45 Processor pr = ap.createProcessor();
46 if (pr != null) {
47 processors.add(pr);
48 }
49 }
50 return processors;
51 }
52
53 public Processor getProcessorForAxisName(String axisName) {
54 for (Processor pr: processors) {
55 String aName = pr.getAxisName();
56 if (aName != null && axisName.equals(aName)) {
57 return pr;
58 }
59 }
60 return null;
61 }
62
63 public List<Processor> getProcessors() {
64 return processors;
65 }
66
67 public Title getTitle() {
68 return DiagramAttributes.this.getTitle();
69 }
70
71 public Title getSubtitle() {
72 return DiagramAttributes.this.getSubtitle();
73 }
74
75 public Title getDomainAxisTitle() {
76 return DiagramAttributes.this.getDomainAxisTitle();
77 }
78
79 public int getAxisIndex(String axisName) {
80 return DiagramAttributes.this.getAxisIndex(axisName);
81 }
82
83 public String getAxisName(int index) {
84 return DiagramAttributes.this.getAxisName(index);
85 }
86
87 public List<AxisAttributes> getAxesAttributes() {
88 return DiagramAttributes.this.getAxesAttributes();
89 }
90 } // class Instance
29 91
30 public static class AxisAttributes { 92 public static class AxisAttributes {
31 private String name; 93 private String name;
32 private boolean isLeftAlign; 94 private boolean isLeftAlign;
33 private boolean forceAlign; 95 private boolean forceAlign;
63 public boolean includeZero() { 125 public boolean includeZero() {
64 return includeZero; 126 return includeZero;
65 } 127 }
66 } // class AxisAttributes 128 } // class AxisAttributes
67 129
130 public static class AxisProcessor {
131
132 private Class<Processor> processorClass;
133 private String axisName;
134
135 public AxisProcessor(Class<Processor> processorClass, String axisName) {
136 this.processorClass = processorClass;
137 this.axisName = axisName;
138 }
139
140 public Processor createProcessor() {
141 try {
142 Processor pr = processorClass.newInstance();
143 pr.setAxisName(axisName);
144 return pr;
145 }
146 catch (InstantiationException ie) {
147 log.error(ie, ie);
148 }
149 catch (IllegalAccessException iae) {
150 log.error(iae, iae);
151 }
152 return null;
153 }
154
155 } // class AxisProcessor
156
68 public static class Argument { 157 public static class Argument {
69 private String expression; 158 private String expression;
70 private String type; 159 private String type;
71 160
72 public Argument() { 161 public Argument() {
144 return Resources.getMsg(context.getMeta(), key, def, args); 233 return Resources.getMsg(context.getMeta(), key, def, args);
145 } 234 }
146 } // class Title 235 } // class Title
147 236
148 private List<AxisAttributes> axesAttrs; 237 private List<AxisAttributes> axesAttrs;
149 private List<Processor> processors; 238 private List<AxisProcessor> axesProcessors;
150 239
151 private Title title; 240 private Title title;
152 private Title subtitle; 241 private Title subtitle;
153 private Title domainAxisTitle; 242 private Title domainAxisTitle;
154 243
155 public DiagramAttributes() { 244 public DiagramAttributes() {
156 axesAttrs = new ArrayList<AxisAttributes>(5); 245 axesAttrs = new ArrayList<AxisAttributes>(5);
157 processors = new ArrayList<Processor>(5); 246 axesProcessors = new ArrayList<AxisProcessor>(5);
158 } 247 }
159 248
160 public DiagramAttributes(Element config) { 249 @Override
161 this(); 250 public Object convert(Element config) {
162 parseAxis(config); 251 parseAxis(config);
163 parseProcessors(config); 252 parseProcessors(config);
164 parseTitle(config); 253 parseTitle(config);
165 parseSubtitle(config); 254 parseSubtitle(config);
166 parseDomainAxisTitle(config); 255 parseDomainAxisTitle(config);
256 return this;
167 } 257 }
168 258
169 public List<AxisAttributes> getAxesAttributes() { 259 public List<AxisAttributes> getAxesAttributes() {
170 return axesAttrs; 260 return axesAttrs;
171 } 261 }
195 name, isleftAlign, forceAlign, 285 name, isleftAlign, forceAlign,
196 includeZero.equals("true"))); 286 includeZero.equals("true")));
197 } 287 }
198 } 288 }
199 289
200 public List<Processor> getProcessors() { 290 public List<AxisProcessor> getAxesProcessors() {
201 return processors; 291 return axesProcessors;
202 } 292 }
203 293
204 public Title getTitle() { 294 public Title getTitle() {
205 return title; 295 return title;
206 } 296 }
223 if (className.isEmpty() || axisName.isEmpty()) { 313 if (className.isEmpty() || axisName.isEmpty()) {
224 continue; 314 continue;
225 } 315 }
226 316
227 try { 317 try {
228 Processor processor = 318 Class<Processor> processorClass =
229 (Processor)Class.forName(className).newInstance(); 319 (Class<Processor>)Class.forName(className);
230 processor.setAxisName(axisName); 320 axesProcessors.add(new AxisProcessor(processorClass, axisName));
231 processors.add(processor);
232 } 321 }
233 catch (ClassNotFoundException cnfe) { 322 catch (ClassNotFoundException cnfe) {
234 log.error(cnfe, cnfe); 323 log.error(cnfe, cnfe);
235 }
236 catch (InstantiationException ie) {
237 log.error(ie, ie);
238 }
239 catch (IllegalAccessException ia) {
240 log.error(ia, ia);
241 }
242 catch (ClassCastException cce) {
243 log.error(cce, cce);
244 } 324 }
245 } 325 }
246 } 326 }
247 327
248 private void parseTitle(Element config) { 328 private void parseTitle(Element config) {
283 } 363 }
284 } 364 }
285 return -1; 365 return -1;
286 } 366 }
287 367
288 public Processor getProcessorForAxisName(String axisName) {
289 for (Processor pr: processors) {
290 if (pr.getAxisName().equals(axisName)) {
291 return pr;
292 }
293 }
294 return null;
295 }
296
297 public String getAxisName(int index) { 368 public String getAxisName(int index) {
298 AxisAttributes att = axesAttrs.get(index); 369 return index < 0 || index >= axesAttrs.size()
299 if (att == null) { 370 ? "" // null?
300 return ""; /* null? */ 371 : axesAttrs.get(index).getName();
301 }
302 return att.getName();
303 } 372 }
304 } 373 }
305 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 374 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org