Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java @ 1785:661dfad9910a
Use compatibility matrix when creating collections output.
flys-artifacts/trunk@3107 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 28 Oct 2011 10:04:22 +0000 |
parents | b503d92dd709 |
children | d5d2bffb26ca |
comparison
equal
deleted
inserted
replaced
1784:0fe3c4849baa | 1785:661dfad9910a |
---|---|
35 | 35 |
36 protected Map<String, Output> oldAttr; | 36 protected Map<String, Output> oldAttr; |
37 | 37 |
38 protected Map<String, Output> newAttr; | 38 protected Map<String, Output> newAttr; |
39 | 39 |
40 /** List of already seen facets. */ | |
41 protected List<Facet> oldFacets; | |
42 | |
43 /** List of "new" facets. */ | |
44 protected List<Facet> newFacets; | |
45 | |
46 /** | |
47 * "Compatibility matrix", mapws list of facet names to output names. | |
48 * Any facet that is not found in the list for a specific output will | |
49 * not be added to the resulting document. | |
50 */ | |
51 protected Map<String, List<String>> compatibilities; | |
52 | |
40 private static Logger logger = Logger.getLogger(AttributeWriter.class); | 53 private static Logger logger = Logger.getLogger(AttributeWriter.class); |
41 | 54 |
42 | 55 |
43 /** | 56 /** |
44 * Create a AttributeWriter. | 57 * Create a AttributeWriter. |
49 * form) outputs. | 62 * form) outputs. |
50 */ | 63 */ |
51 public AttributeWriter( | 64 public AttributeWriter( |
52 ArtifactDatabase db, | 65 ArtifactDatabase db, |
53 Map<String, Output> oldAttr, | 66 Map<String, Output> oldAttr, |
54 Map<String, Output> newAttr) | 67 List<Facet> oldFacets, |
55 { | 68 Map<String, Output> newAttr, |
56 this.db = db; | 69 List<Facet> newFacets, |
57 this.oldAttr = oldAttr; | 70 Map<String, List<String>> matrix) |
58 this.newAttr = newAttr; | 71 { |
72 this.db = db; | |
73 this.oldAttr = oldAttr; | |
74 this.newAttr = newAttr; | |
75 this.oldFacets = oldFacets; | |
76 this.newFacets = newFacets; | |
77 this.compatibilities = matrix; | |
59 } | 78 } |
60 | 79 |
61 | 80 |
62 /** | 81 /** |
63 * Create document by merging outputs given in | 82 * Create document by merging outputs given in |
83 | 102 |
84 attribute.appendChild(outs); | 103 attribute.appendChild(outs); |
85 doc.appendChild(attribute); | 104 doc.appendChild(attribute); |
86 | 105 |
87 for (String outName: newAttr.keySet()) { | 106 for (String outName: newAttr.keySet()) { |
88 | |
89 Output a = newAttr.get(outName); | 107 Output a = newAttr.get(outName); |
90 Output b = oldAttr.get(outName); | 108 Output b = oldAttr.get(outName); |
91 | 109 |
92 writeOutput(doc, outs, cr, a, b); | 110 writeOutput(doc, outs, cr, a.getName(), newFacets, oldFacets); |
93 } | 111 } |
94 | 112 |
95 return doc; | 113 return doc; |
96 } | 114 } |
97 | 115 |
98 | 116 |
99 /** | 117 /** |
100 * @param doc Document to add output nodes to | 118 * @param doc Document to add output nodes to |
101 * @param outs Node in Document to add output nodes to | 119 * @param outs Node in Document to add output nodes to |
102 * @param a the new output | 120 * @param cr ElementCreator in use to modify doc/outs |
103 * @param b the old output | 121 * @param outputName the "new" outputs name |
122 * @param newOutFacets Facets of the new outputs | |
123 * @param oldOutFacets Facets of the old outputs (can be null) | |
104 */ | 124 */ |
105 protected void writeOutput( | 125 protected void writeOutput( |
106 Document doc, | 126 Document doc, |
107 Node outs, | 127 Node outs, |
108 ElementCreator cr, | 128 ElementCreator cr, |
109 Output a, /* new output */ | 129 String outputName, |
110 Output b) /* old output */ | 130 List<Facet> newOutFacets, |
131 List<Facet> oldOutFacets) | |
111 { | 132 { |
112 Element output = cr.create("output"); | 133 Element output = cr.create("output"); |
113 cr.addAttr(output, "name", a.getName()); | 134 cr.addAttr(output, "name", outputName); |
114 | 135 |
115 outs.appendChild(output); | 136 outs.appendChild(output); |
116 | 137 |
117 List<Facet> facetsA = a.getFacets(); | 138 List<String> compatibleFacets = this.compatibilities.get(outputName); |
118 List<Facet> facetsB = null; | |
119 | |
120 if (b != null) { | |
121 facetsB = b.getFacets(); | |
122 } | |
123 | |
124 | |
125 try { | 139 try { |
126 writeFacets(doc, cr, output, facetsA, facetsB); | 140 writeFacets(doc, cr, output, newOutFacets, oldOutFacets, compatibleFacets); |
127 } | 141 } |
128 catch (ArtifactDatabaseException ade) { | 142 catch (ArtifactDatabaseException ade) { |
129 logger.error(ade, ade); | 143 logger.error(ade, ade); |
130 } | 144 } |
131 } | 145 } |
132 | 146 |
133 | 147 |
134 /** | 148 /** |
135 * @param doc Document to add facet nodes to | 149 * @param doc Document to add facet nodes to |
150 * @param cr ElementCreator to use with output/doc | |
136 * @param output Node in Document to add facet nodes to | 151 * @param output Node in Document to add facet nodes to |
137 * @param a the new facets | 152 * @param newFacets the new facets |
138 * @param b the old facets | 153 * @param oldFacets the old facets |
154 * @param compatibleFacets List of facets to accept | |
139 */ | 155 */ |
140 protected void writeFacets( | 156 protected void writeFacets( |
141 Document doc, | 157 Document doc, |
142 ElementCreator cr, | 158 ElementCreator cr, |
143 Element output, | 159 Element output, |
144 List<Facet> newFacets, | 160 List<Facet> newFacets, |
145 List<Facet> oldFacets) | 161 List<Facet> oldFacets, |
162 List<String> compatibleFacets) | |
146 throws ArtifactDatabaseException | 163 throws ArtifactDatabaseException |
147 { | 164 { |
148 int num = newFacets.size(); | 165 int num = newFacets.size(); |
149 | 166 |
150 // Add all new Facets either in their old state or (if really | 167 // Add all new Facets either in their old state or (if really |
151 // new) as they are. | 168 // new) as they are. |
152 List<ManagedFacet> currentFacets = new ArrayList<ManagedFacet>(); | 169 List<ManagedFacet> currentFacets = new ArrayList<ManagedFacet>(); |
153 List<ManagedFacet> genuinelyNewFacets = new ArrayList<ManagedFacet>(); | 170 List<ManagedFacet> genuinelyNewFacets = new ArrayList<ManagedFacet>(); |
171 | |
154 for (int i = 0; i < num; i++) { | 172 for (int i = 0; i < num; i++) { |
155 ManagedFacet facet = (ManagedFacet) newFacets.get(i); | 173 ManagedFacet facet = (ManagedFacet) newFacets.get(i); |
174 if (!compatibleFacets.contains(facet.getName())) { | |
175 //logger.debug("Have incompatible facet, skip: " + facet.getName()); | |
176 continue; | |
177 } | |
178 //else logger.debug("Have compatible facet: " + facet.getName()); | |
156 | 179 |
157 ManagedFacet picked = pickFacet(facet, oldFacets); | 180 ManagedFacet picked = pickFacet(facet, oldFacets); |
181 | |
158 if (facet.equals(picked)) { | 182 if (facet.equals(picked)) { |
159 genuinelyNewFacets.add(picked); | 183 genuinelyNewFacets.add(picked); |
160 } | 184 } |
161 else { | 185 else { |
162 currentFacets.add(picked); | 186 currentFacets.add(picked); |