comparison artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java @ 8892:87a242425467

Introduced ChartExtender that allows to tweak the charts for very specific use cases.
author gernotbelger
date Thu, 15 Feb 2018 13:46:35 +0100
parents f87f435df856
children 55e2155ab52d
comparison
equal deleted inserted replaced
8891:f431aec10d2c 8892:87a242425467
7 */ 7 */
8 8
9 package org.dive4elements.river.exports; 9 package org.dive4elements.river.exports;
10 10
11 import java.util.ArrayList; 11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Collections;
12 import java.util.List; 14 import java.util.List;
13 15
14 import org.w3c.dom.Element; 16 import org.w3c.dom.Element;
15 import org.w3c.dom.NodeList; 17 import org.w3c.dom.NodeList;
16 18
79 return retval; 81 return retval;
80 } 82 }
81 83
82 public List<Processor> getProcessors() { 84 public List<Processor> getProcessors() {
83 return processors; 85 return processors;
86 }
87
88 public Collection<ChartExtender> getExtenders() {
89 return DiagramAttributes.this.getExtenders();
84 } 90 }
85 91
86 public Title getTitle() { 92 public Title getTitle() {
87 return DiagramAttributes.this.getTitle(); 93 return DiagramAttributes.this.getTitle();
88 } 94 }
343 } 349 }
344 } // class Title 350 } // class Title
345 351
346 private List<AxisAttributes> axesAttrs; 352 private List<AxisAttributes> axesAttrs;
347 private List<AxisProcessor> axesProcessors; 353 private List<AxisProcessor> axesProcessors;
354 private List<ChartExtender> extenders = new ArrayList<>();
348 355
349 private Title title; 356 private Title title;
350 private Title subtitle; 357 private Title subtitle;
351 358
352 private DomainAxisAttributes domainAxis; 359 private DomainAxisAttributes domainAxis;
361 parseAxis(config); 368 parseAxis(config);
362 parseProcessors(config); 369 parseProcessors(config);
363 parseTitle(config); 370 parseTitle(config);
364 parseSubtitle(config); 371 parseSubtitle(config);
365 parseDomainAxis(config); 372 parseDomainAxis(config);
373 parseExtenders(config);
366 return this; 374 return this;
367 } 375 }
368 376
369 public List<AxisAttributes> getAxesAttributes() { 377 public List<AxisAttributes> getAxesAttributes() {
370 return axesAttrs; 378 return axesAttrs;
457 } 465 }
458 466
459 public List<AxisProcessor> getAxesProcessors() { 467 public List<AxisProcessor> getAxesProcessors() {
460 return axesProcessors; 468 return axesProcessors;
461 } 469 }
470
471 public Collection<ChartExtender> getExtenders() {
472 return Collections.unmodifiableCollection(extenders);
473 }
462 474
463 public Title getTitle() { 475 public Title getTitle() {
464 return title; 476 return title;
465 } 477 }
466 478
488 (Class<Processor>)Class.forName(className); 500 (Class<Processor>)Class.forName(className);
489 axesProcessors.add(new AxisProcessor(processorClass, axisName)); 501 axesProcessors.add(new AxisProcessor(processorClass, axisName));
490 } 502 }
491 catch (ClassNotFoundException cnfe) { 503 catch (ClassNotFoundException cnfe) {
492 log.error(cnfe, cnfe); 504 log.error(cnfe, cnfe);
505 }
506 }
507 }
508
509 private void parseExtenders(final Element config) {
510 final NodeList processorNodes = config.getElementsByTagName("chartextender");
511
512 for (int i = 0, N = processorNodes.getLength(); i < N; ++i) {
513 final Element extenderElement = (Element)processorNodes.item(i);
514 final String className = extenderElement.getAttribute("class").trim();
515 if (className.isEmpty() ) {
516 log.error("chartextender missing 'class' attribute");
517 continue;
518 }
519
520 try {
521 final Class<?> protoclass = Class.forName(className);
522 if( !ChartExtender.class.isAssignableFrom(protoclass) ) {
523 log.error(String.format( "Chart extender must implement interface ChartExtender: %s", className) );
524 continue;
525 }
526
527 final ChartExtender extender = (ChartExtender) protoclass.newInstance();
528 extenders.add(extender);
529 }
530 catch (ClassNotFoundException | InstantiationException | IllegalAccessException cnfe) {
531 log.error(String.format( "Failed to load or create chartextender class: %s", className ), cnfe);
493 } 532 }
494 } 533 }
495 } 534 }
496 535
497 private void parseTitle(Element config) { 536 private void parseTitle(Element config) {

http://dive4elements.wald.intevation.org