Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java @ 1709:f643ea084213
Allow simple codepaths to have Facets initially being 'inactive' (wrt rendering).
flys-artifacts/trunk@2969 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 14 Oct 2011 08:52:44 +0000 |
parents | 12235a2ace21 |
children | b503d92dd709 |
comparison
equal
deleted
inserted
replaced
1708:e99b4bd32cd5 | 1709:f643ea084213 |
---|---|
8 | 8 |
9 import org.w3c.dom.Document; | 9 import org.w3c.dom.Document; |
10 import org.w3c.dom.Element; | 10 import org.w3c.dom.Element; |
11 import org.w3c.dom.Node; | 11 import org.w3c.dom.Node; |
12 | 12 |
13 import de.intevation.artifacts.ArtifactDatabase; | |
14 import de.intevation.artifacts.ArtifactDatabaseException; | |
13 import de.intevation.artifacts.ArtifactNamespaceContext; | 15 import de.intevation.artifacts.ArtifactNamespaceContext; |
14 | 16 |
15 import de.intevation.artifactdatabase.state.Facet; | 17 import de.intevation.artifactdatabase.state.Facet; |
16 import de.intevation.artifactdatabase.state.Output; | 18 import de.intevation.artifactdatabase.state.Output; |
17 | 19 |
18 import de.intevation.artifacts.common.utils.XMLUtils; | 20 import de.intevation.artifacts.common.utils.XMLUtils; |
19 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | 21 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; |
20 | 22 |
23 import de.intevation.flys.artifacts.FLYSArtifact; | |
21 import de.intevation.flys.artifacts.model.ManagedFacet; | 24 import de.intevation.flys.artifacts.model.ManagedFacet; |
22 | 25 |
23 /** | 26 /** |
24 * Create attribute- element of describe document of an ArtifactCollection. | 27 * Create attribute- element of describe document of an ArtifactCollection. |
25 * The attribute-element contains the merged output of all outputmodes and | 28 * The attribute-element contains the merged output of all outputmodes and |
26 * facets that are part of the collection. | 29 * facets that are part of the collection. |
27 */ | 30 */ |
28 public class AttributeWriter { | 31 public class AttributeWriter { |
29 | 32 |
33 /** ArtifactDatabase used to fetch Artifacts. */ | |
34 protected ArtifactDatabase db = null; | |
35 | |
30 protected Map<String, Output> oldAttr; | 36 protected Map<String, Output> oldAttr; |
37 | |
31 protected Map<String, Output> newAttr; | 38 protected Map<String, Output> newAttr; |
32 | 39 |
33 private static Logger logger = Logger.getLogger(AttributeWriter.class); | 40 private static Logger logger = Logger.getLogger(AttributeWriter.class); |
34 | 41 |
35 | 42 |
36 /** | 43 /** |
37 * Create a AttributeWriter. | 44 * Create a AttributeWriter. |
38 * Attributes not present in newAttr will not be included in the document. | 45 * Attributes not present in newAttr will not be included in the document. |
46 * @param db Database to fetch artifacts. | |
39 * @param oldAttr "Old" (possibly user-changed) outputs. | 47 * @param oldAttr "Old" (possibly user-changed) outputs. |
40 * @param newAttr "New" (eventually re-read in its original, unchagnged | 48 * @param newAttr "New" (eventually re-read in its original, unchagnged |
41 * form) outputs. | 49 * form) outputs. |
42 */ | 50 */ |
43 public AttributeWriter( | 51 public AttributeWriter( |
52 ArtifactDatabase db, | |
44 Map<String, Output> oldAttr, | 53 Map<String, Output> oldAttr, |
45 Map<String, Output> newAttr) | 54 Map<String, Output> newAttr) |
46 { | 55 { |
56 this.db = db; | |
47 this.oldAttr = oldAttr; | 57 this.oldAttr = oldAttr; |
48 this.newAttr = newAttr; | 58 this.newAttr = newAttr; |
49 } | 59 } |
50 | 60 |
51 | 61 |
107 | 117 |
108 if (b != null) { | 118 if (b != null) { |
109 facetsB = b.getFacets(); | 119 facetsB = b.getFacets(); |
110 } | 120 } |
111 | 121 |
112 writeFacets(doc, cr, output, facetsA, facetsB); | 122 |
123 try { | |
124 writeFacets(doc, cr, output, facetsA, facetsB); | |
125 } | |
126 catch (ArtifactDatabaseException ade) { | |
127 logger.error(ade, ade); | |
128 } | |
113 } | 129 } |
114 | 130 |
115 | 131 |
116 /** | 132 /** |
117 * @param doc Document to add facet nodes to | 133 * @param doc Document to add facet nodes to |
123 Document doc, | 139 Document doc, |
124 ElementCreator cr, | 140 ElementCreator cr, |
125 Element output, | 141 Element output, |
126 List<Facet> newFacets, | 142 List<Facet> newFacets, |
127 List<Facet> oldFacets) | 143 List<Facet> oldFacets) |
144 throws ArtifactDatabaseException | |
128 { | 145 { |
129 int num = newFacets.size(); | 146 int num = newFacets.size(); |
130 | 147 |
131 // Add all new Facets either in their old state or (if really | 148 // Add all new Facets either in their old state or (if really |
132 // new) as they are. | 149 // new) as they are. |
142 else { | 159 else { |
143 currentFacets.add(picked); | 160 currentFacets.add(picked); |
144 } | 161 } |
145 } | 162 } |
146 | 163 |
164 // With each genuinely new Facet, ask Artifact whether it comes to live | |
165 // in/activate. | |
166 for (ManagedFacet newMF: genuinelyNewFacets) { | |
167 FLYSArtifact flys = (FLYSArtifact) db.getRawArtifact(newMF.getArtifact()); | |
168 newMF.setActive(flys.getInitialFacetActivity( | |
169 newMF.getName(), | |
170 newMF.getIndex())); | |
171 } | |
172 | |
147 // For each genuinely new Facet check positional conflicts. | 173 // For each genuinely new Facet check positional conflicts. |
148 for (ManagedFacet newMF: genuinelyNewFacets) { | 174 for (ManagedFacet newMF: genuinelyNewFacets) { |
149 boolean conflicts = true; | 175 boolean conflicts = true; |
150 // Loop until all conflicts resolved. | 176 // Loop until all conflicts resolved. |
151 while (conflicts) { | 177 while (conflicts) { |
182 * @param oldFacets the old facets, new facet is compared against each of | 208 * @param oldFacets the old facets, new facet is compared against each of |
183 * these. | 209 * these. |
184 * @return facet if genuinely new, matching old facet otherwise. | 210 * @return facet if genuinely new, matching old facet otherwise. |
185 */ | 211 */ |
186 protected ManagedFacet pickFacet(ManagedFacet facet, | 212 protected ManagedFacet pickFacet(ManagedFacet facet, |
187 List<Facet> oldFacets) { | 213 List<Facet> oldFacets) |
214 { | |
188 if (oldFacets == null) { | 215 if (oldFacets == null) { |
189 logger.debug("No old facets to compare a new to found."); | 216 logger.debug("No old facets to compare a new to found."); |
190 return facet; | 217 return facet; |
191 } | 218 } |
192 | 219 |