Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java Mon Sep 23 12:21:59 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java Mon Sep 23 12:28:22 2013 +0200 @@ -23,10 +23,72 @@ import org.dive4elements.river.artifacts.resources.Resources; import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.artifacts.common.utils.ElementConverter; + public class DiagramAttributes +implements ElementConverter { private static Logger log = Logger.getLogger(DiagramAttributes.class); + public class Instance { + + private List<Processor> processors; + + public Instance() { + processors = createProcessors(); + } + + private List<Processor> createProcessors() { + List<Processor> processors = + new ArrayList<Processor>(axesProcessors.size()); + for (AxisProcessor ap: axesProcessors) { + Processor pr = ap.createProcessor(); + if (pr != null) { + processors.add(pr); + } + } + return processors; + } + + public Processor getProcessorForAxisName(String axisName) { + for (Processor pr: processors) { + String aName = pr.getAxisName(); + if (aName != null && axisName.equals(aName)) { + return pr; + } + } + return null; + } + + public List<Processor> getProcessors() { + return processors; + } + + public Title getTitle() { + return DiagramAttributes.this.getTitle(); + } + + public Title getSubtitle() { + return DiagramAttributes.this.getSubtitle(); + } + + public Title getDomainAxisTitle() { + return DiagramAttributes.this.getDomainAxisTitle(); + } + + public int getAxisIndex(String axisName) { + return DiagramAttributes.this.getAxisIndex(axisName); + } + + public String getAxisName(int index) { + return DiagramAttributes.this.getAxisName(index); + } + + public List<AxisAttributes> getAxesAttributes() { + return DiagramAttributes.this.getAxesAttributes(); + } + } // class Instance + public static class AxisAttributes { private String name; private boolean isLeftAlign; @@ -65,6 +127,33 @@ } } // class AxisAttributes + public static class AxisProcessor { + + private Class<Processor> processorClass; + private String axisName; + + public AxisProcessor(Class<Processor> processorClass, String axisName) { + this.processorClass = processorClass; + this.axisName = axisName; + } + + public Processor createProcessor() { + try { + Processor pr = processorClass.newInstance(); + pr.setAxisName(axisName); + return pr; + } + catch (InstantiationException ie) { + log.error(ie, ie); + } + catch (IllegalAccessException iae) { + log.error(iae, iae); + } + return null; + } + + } // class AxisProcessor + public static class Argument { private String expression; private String type; @@ -146,7 +235,7 @@ } // class Title private List<AxisAttributes> axesAttrs; - private List<Processor> processors; + private List<AxisProcessor> axesProcessors; private Title title; private Title subtitle; @@ -154,16 +243,17 @@ public DiagramAttributes() { axesAttrs = new ArrayList<AxisAttributes>(5); - processors = new ArrayList<Processor>(5); + axesProcessors = new ArrayList<AxisProcessor>(5); } - public DiagramAttributes(Element config) { - this(); + @Override + public Object convert(Element config) { parseAxis(config); parseProcessors(config); parseTitle(config); parseSubtitle(config); parseDomainAxisTitle(config); + return this; } public List<AxisAttributes> getAxesAttributes() { @@ -197,8 +287,8 @@ } } - public List<Processor> getProcessors() { - return processors; + public List<AxisProcessor> getAxesProcessors() { + return axesProcessors; } public Title getTitle() { @@ -225,23 +315,13 @@ } try { - Processor processor = - (Processor)Class.forName(className).newInstance(); - processor.setAxisName(axisName); - processors.add(processor); + Class<Processor> processorClass = + (Class<Processor>)Class.forName(className); + axesProcessors.add(new AxisProcessor(processorClass, axisName)); } catch (ClassNotFoundException cnfe) { log.error(cnfe, cnfe); } - catch (InstantiationException ie) { - log.error(ie, ie); - } - catch (IllegalAccessException ia) { - log.error(ia, ia); - } - catch (ClassCastException cce) { - log.error(cce, cce); - } } } @@ -285,21 +365,10 @@ return -1; } - public Processor getProcessorForAxisName(String axisName) { - for (Processor pr: processors) { - if (pr.getAxisName().equals(axisName)) { - return pr; - } - } - return null; - } - public String getAxisName(int index) { - AxisAttributes att = axesAttrs.get(index); - if (att == null) { - return ""; /* null? */ - } - return att.getName(); + return index < 0 || index >= axesAttrs.size() + ? "" // null? + : axesAttrs.get(index).getName(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :