Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 1765:5d8b3880a553
Do not store association of states to facets, let artifacts keep facets in a pure list.
flys-artifacts/trunk@3083 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 26 Oct 2011 12:23:47 +0000 |
parents | 0e748e8972b5 |
children | c62ff9e72cea |
comparison
equal
deleted
inserted
replaced
1764:87c82499b98f | 1765:5d8b3880a553 |
---|---|
83 public static final String OPERATION_SUCCESSFUL = "SUCCESS"; | 83 public static final String OPERATION_SUCCESSFUL = "SUCCESS"; |
84 | 84 |
85 /** The constant string that shows that an operation failed. */ | 85 /** The constant string that shows that an operation failed. */ |
86 public static final String OPERATION_FAILED = "FAILURE"; | 86 public static final String OPERATION_FAILED = "FAILURE"; |
87 | 87 |
88 | |
89 /** The identifier of the current state. */ | 88 /** The identifier of the current state. */ |
90 protected String currentStateId; | 89 protected String currentStateId; |
91 | 90 |
92 /** The identifiers of previous states on a stack. */ | 91 /** The identifiers of previous states on a stack. */ |
93 protected List<String> previousStateIds; | 92 protected List<String> previousStateIds; |
96 protected String name; | 95 protected String name; |
97 | 96 |
98 /** The data that have been inserted into this artifact. */ | 97 /** The data that have been inserted into this artifact. */ |
99 protected Map<String, StateData> data; | 98 protected Map<String, StateData> data; |
100 | 99 |
101 /** The list of facets supported by this artifact. */ | 100 /** The list of facets produced by this artifact. */ |
102 protected Map<String, List<Facet>> facets; | 101 protected List<Facet> facets; |
103 | 102 |
104 /** | 103 /** |
105 * Used to generates "view" on the facets (hides facets not matching the | 104 * Used to generates "view" on the facets (hides facets not matching the |
106 * filter in output of collection); out -> facets. | 105 * filter in output of collection); out -> facets. |
107 */ | 106 */ |
112 * The default constructor that creates an empty FLYSArtifact. | 111 * The default constructor that creates an empty FLYSArtifact. |
113 */ | 112 */ |
114 public FLYSArtifact() { | 113 public FLYSArtifact() { |
115 data = new TreeMap<String, StateData>(); | 114 data = new TreeMap<String, StateData>(); |
116 previousStateIds = new ArrayList<String>(); | 115 previousStateIds = new ArrayList<String>(); |
117 facets = new HashMap<String, List<Facet>>(); | 116 facets = new ArrayList<Facet>(); |
118 } | 117 } |
119 | 118 |
120 | 119 |
121 /** | 120 /** |
122 * Returns the name of the concrete artifact. | 121 * Returns the name of the concrete artifact. |
207 return copy; | 206 return copy; |
208 } | 207 } |
209 | 208 |
210 /** | 209 /** |
211 * Return a copy of the facet mapping. | 210 * Return a copy of the facet mapping. |
212 * @return Mapping of outputnames to facets. | 211 * @return Copy of facets list. |
213 */ | 212 */ |
214 protected Map<String, List<Facet>> cloneFacets() { | 213 protected List<Facet> cloneFacets() { |
215 Map copy = new HashMap<String, List<Facet>>(); | 214 List copy = new ArrayList<Facet>(facets.size()); |
216 | 215 |
217 for (Map.Entry<String, List<Facet>> entry: facets.entrySet()) { | 216 for (Facet facet: facets) { |
218 List<Facet> facets = entry.getValue(); | 217 copy.add(facet.deepCopy()); |
219 List<Facet> facetCopies = new ArrayList<Facet>(facets.size()); | |
220 for (Facet facet: facets) { | |
221 facetCopies.add(facet.deepCopy()); | |
222 } | |
223 copy.put(entry.getKey(), facetCopies); | |
224 } | 218 } |
225 | 219 |
226 return copy; | 220 return copy; |
227 } | 221 } |
228 | 222 |
229 | 223 |
224 /** | |
225 * (called from setup). | |
226 */ | |
230 protected void initialize( | 227 protected void initialize( |
231 Artifact artifact, | 228 Artifact artifact, |
232 Object context, | 229 Object context, |
233 CallMeta callMeta) | 230 CallMeta callMeta) |
234 { | 231 { |
545 | 542 |
546 public Facet getNativeFacet(Facet facet) { | 543 public Facet getNativeFacet(Facet facet) { |
547 String name = facet.getName(); | 544 String name = facet.getName(); |
548 int index = facet.getIndex(); | 545 int index = facet.getIndex(); |
549 | 546 |
550 for (Map.Entry<String, List<Facet>> entry: facets.entrySet()) { | 547 for (Facet f: facets) { |
551 for (Facet f: entry.getValue()) { | 548 if (f.getIndex() == index && f.getName().equals(name)) { |
552 if (f.getIndex() == index && f.getName().equals(name)) { | 549 return f; |
553 return f; | |
554 } | |
555 } | 550 } |
556 } | 551 } |
557 | 552 |
558 logger.warn("Could not find facet: " + name + " at " + index); | 553 logger.warn("Could not find facet: " + name + " at " + index); |
559 return null; | 554 return null; |
727 | 722 |
728 return filtered; | 723 return filtered; |
729 } | 724 } |
730 | 725 |
731 | 726 |
727 /** | |
728 * Get all outputs that the Artifact can do in this state (which includes | |
729 * all previous states). | |
730 * | |
731 * @return list of outputs | |
732 */ | |
732 public List<Output> getOutputs(Object context) { | 733 public List<Output> getOutputs(Object context) { |
733 List<String> stateIds = getPreviousStateIds(); | 734 List<String> stateIds = getPreviousStateIds(); |
734 List<Output> generated = new ArrayList<Output>(); | 735 List<Output> generated = new ArrayList<Output>(); |
735 | 736 |
736 for (String stateId: stateIds) { | 737 for (String stateId: stateIds) { |
742 | 743 |
743 return filterOutputs(generated); | 744 return filterOutputs(generated); |
744 } | 745 } |
745 | 746 |
746 | 747 |
748 /** | |
749 * Get output(s) for current state. | |
750 * @return list of outputs for current state. | |
751 */ | |
747 public List<Output> getCurrentOutputs(Object context) { | 752 public List<Output> getCurrentOutputs(Object context) { |
748 DefaultState cur = (DefaultState) getCurrentState(context); | 753 DefaultState cur = (DefaultState) getCurrentState(context); |
749 | 754 |
750 try { | 755 try { |
751 if (cur.validate(this)) { | 756 if (cur.validate(this)) { |
756 | 761 |
757 return new ArrayList<Output>(); | 762 return new ArrayList<Output>(); |
758 } | 763 } |
759 | 764 |
760 | 765 |
766 /** | |
767 * Get output(s) for a specific state. | |
768 * @param state State of interest | |
769 * @return list of output(s) for given state. | |
770 */ | |
761 protected List<Output> getOutputForState(DefaultState state) { | 771 protected List<Output> getOutputForState(DefaultState state) { |
762 List<Output> list = state.getOutputs(); | 772 List<Output> list = state.getOutputs(); |
763 if (list == null || list.size() == 0) { | 773 if (list == null || list.size() == 0) { |
764 logger.debug("-> No output modes for this state."); | 774 logger.debug("-> No output modes for this state."); |
765 return new ArrayList<Output>(); | 775 return new ArrayList<Output>(); |
766 } | 776 } |
767 | 777 |
768 List<Facet> fs = facets.get(state.getID()); | 778 if (facets == null || facets.size() == 0) { |
769 if (fs == null || fs.size() == 0) { | |
770 logger.debug("No facets found."); | 779 logger.debug("No facets found."); |
771 return new ArrayList<Output>(); | 780 return new ArrayList<Output>(); |
772 } | 781 } |
773 | 782 |
774 return generateOutputs(list, fs); | 783 return generateOutputs(list, facets); |
775 } | 784 } |
776 | 785 |
777 | 786 |
778 /** | 787 /** |
779 * Generate a list of outputs with facets from fs if type is found in list | 788 * Generate a list of outputs with facets from fs if type is found in list |
883 return compute(context, hash, current, type, generateFacets); | 892 return compute(context, hash, current, type, generateFacets); |
884 } | 893 } |
885 | 894 |
886 | 895 |
887 /** | 896 /** |
897 * Let current state compute and register facets. | |
898 * | |
888 * @param key key of state | 899 * @param key key of state |
889 * @param state state | 900 * @param state state |
890 * @param type Type of compute | 901 * @param type Type of compute |
891 * @param generateFacets Whether new facets shall be generated. | 902 * @param generateFacets Whether new facets shall be generated. |
892 */ | 903 */ |
938 return res; | 949 return res; |
939 } | 950 } |
940 finally { | 951 finally { |
941 if (generateFacets) { | 952 if (generateFacets) { |
942 if (fs.isEmpty()) { | 953 if (fs.isEmpty()) { |
943 facets.remove(stateID); | 954 facets.removeAll(fs); |
944 } | 955 } |
945 else { | 956 else { |
946 facets.put(stateID, fs); | 957 facets.addAll(fs); |
947 } | 958 } |
948 } | 959 } |
949 } | 960 } |
950 } | 961 } |
951 | 962 |