Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java @ 51:a2923d63f530
Introduced a data structure DataList to manage to list of Data objects of a single state.
flys-client/trunk@1505 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 17 Mar 2011 16:44:51 +0000 |
parents | b6b89ff1adee |
children | 1d0be51ab93b |
comparison
equal
deleted
inserted
replaced
50:827eb4e06ebf | 51:a2923d63f530 |
---|---|
12 import de.intevation.artifacts.common.ArtifactNamespaceContext; | 12 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
13 import de.intevation.artifacts.common.utils.ClientProtocolUtils; | 13 import de.intevation.artifacts.common.utils.ClientProtocolUtils; |
14 import de.intevation.artifacts.common.utils.XMLUtils; | 14 import de.intevation.artifacts.common.utils.XMLUtils; |
15 | 15 |
16 import de.intevation.flys.client.shared.model.ArtifactDescription; | 16 import de.intevation.flys.client.shared.model.ArtifactDescription; |
17 import de.intevation.flys.client.shared.model.Data; | |
18 import de.intevation.flys.client.shared.model.DataItem; | 17 import de.intevation.flys.client.shared.model.DataItem; |
18 import de.intevation.flys.client.shared.model.DataList; | |
19 import de.intevation.flys.client.shared.model.DefaultArtifactDescription; | |
19 import de.intevation.flys.client.shared.model.DefaultData; | 20 import de.intevation.flys.client.shared.model.DefaultData; |
20 import de.intevation.flys.client.shared.model.DefaultDataItem; | 21 import de.intevation.flys.client.shared.model.DefaultDataItem; |
21 import de.intevation.flys.client.shared.model.DefaultArtifactDescription; | |
22 | 22 |
23 | 23 |
24 /** | 24 /** |
25 * This factory class helps creating an {@link ArtifactDescription} based on the | 25 * This factory class helps creating an {@link ArtifactDescription} based on the |
26 * DESCRIBE document of an artifact returned by the artifact server. Use the | 26 * DESCRIBE document of an artifact returned by the artifact server. Use the |
35 | 35 |
36 public static final String XPATH_UIPROVIDER = "@art:uiprovider"; | 36 public static final String XPATH_UIPROVIDER = "@art:uiprovider"; |
37 | 37 |
38 public static final String XPATH_REACHABLE_STATE = "art:state"; | 38 public static final String XPATH_REACHABLE_STATE = "art:state"; |
39 | 39 |
40 public static final String XPATH_STATIC_STATE_NODE = "art:state"; | |
41 | |
40 public static final String XPATH_STATIC_DATA_NODE = "art:data"; | 42 public static final String XPATH_STATIC_DATA_NODE = "art:data"; |
41 | 43 |
42 public static final String XPATH_STATIC_ITEM_NODE = "art:item"; | 44 public static final String XPATH_STATIC_ITEM_NODE = "art:item"; |
43 | 45 |
44 /** | 46 /** |
62 XPATH_STATE_NAME, | 64 XPATH_STATE_NAME, |
63 XPathConstants.STRING, | 65 XPathConstants.STRING, |
64 ArtifactNamespaceContext.INSTANCE); | 66 ArtifactNamespaceContext.INSTANCE); |
65 System.out.println("Current state name: " + state); | 67 System.out.println("Current state name: " + state); |
66 | 68 |
67 Data currentData = extractCurrentData(dynamicNode); | 69 DataList currentData = extractCurrentData(dynamicNode, state); |
68 Data[] old = extractOldData(staticNode); | 70 DataList[] old = extractOldData(staticNode); |
69 String[] states = extractReachableStates(reachable); | 71 String[] states = extractReachableStates(reachable); |
70 | 72 |
71 return new DefaultArtifactDescription(old, currentData, state, states); | 73 return new DefaultArtifactDescription(old, currentData, state, states); |
72 } | 74 } |
73 | 75 |
75 /** | 77 /** |
76 * This method extracts the data that the user is able to enter in the | 78 * This method extracts the data that the user is able to enter in the |
77 * current state of the artifact. | 79 * current state of the artifact. |
78 * | 80 * |
79 * @param dynamicNode The dynamic node of the DESCRIBE document. | 81 * @param dynamicNode The dynamic node of the DESCRIBE document. |
82 * @param state The name of the current state. | |
80 * | 83 * |
81 * @return A {@link Data} object that represents the data which might be | 84 * @return A {@link Data} object that represents the data which might be |
82 * entered by the user in the current state or null, if no data might be | 85 * entered by the user in the current state or null, if no data might be |
83 * entered. | 86 * entered. |
84 */ | 87 */ |
85 protected static Data extractCurrentData(Node dynamicNode) { | 88 protected static DataList extractCurrentData(Node dynamicNode, String state) { |
86 System.out.println("ArtifactDescriptionFactory - extractCurrentData()"); | 89 System.out.println("ArtifactDescriptionFactory - extractCurrentData()"); |
87 | 90 |
88 Node data = ClientProtocolUtils.getSelectNode(dynamicNode); | 91 NodeList data = ClientProtocolUtils.getSelectNode(dynamicNode); |
89 NodeList choices = ClientProtocolUtils.getItemNodes(data); | 92 String uiProvider = extractUIProvider(dynamicNode); |
90 String label = ClientProtocolUtils.getLabel(data); | 93 |
91 String name = XMLUtils.xpathString( | 94 if (data == null || data.getLength() == 0) { |
92 data, "@art:name", ArtifactNamespaceContext.INSTANCE); | 95 return null; |
93 | 96 } |
94 DataItem[] dataItems = extractCurrentDataItems(choices); | 97 |
95 String uiProvider = extractUIProvider(data); | 98 int dataNum = data.getLength(); |
96 | 99 DataList list = new DataList(state, dataNum, uiProvider); |
97 return new DefaultData(name, label, null, dataItems, uiProvider); | 100 |
101 for (int i = 0; i < dataNum; i++) { | |
102 Node d = data.item(i); | |
103 | |
104 NodeList choices = ClientProtocolUtils.getItemNodes(d); | |
105 String label = ClientProtocolUtils.getLabel(d); | |
106 String name = XMLUtils.xpathString( | |
107 d, "@art:name", ArtifactNamespaceContext.INSTANCE); | |
108 | |
109 DataItem[] dataItems = extractCurrentDataItems(choices); | |
110 | |
111 list.add(new DefaultData(name, label, null, dataItems)); | |
112 } | |
113 | |
114 return list; | |
98 } | 115 } |
99 | 116 |
100 | 117 |
101 /** | 118 /** |
102 * This method extract the {@link DataItem}s of the DESCRIBE document. | 119 * This method extract the {@link DataItem}s of the DESCRIBE document. |
134 * This method extracts the data objects from the data node of the static ui | 151 * This method extracts the data objects from the data node of the static ui |
135 * part of the DESCRIBE document. | 152 * part of the DESCRIBE document. |
136 * | 153 * |
137 * @param staticNode The static ui node of the DESCRIBE. | 154 * @param staticNode The static ui node of the DESCRIBE. |
138 * | 155 * |
139 * @return the Data objects. | 156 * @return the DataList objects. |
140 */ | 157 */ |
141 protected static Data[] extractOldData(Node staticNode) { | 158 protected static DataList[] extractOldData(Node staticNode) { |
142 System.out.println("ArtifactDescriptionFactory - extractOldData()"); | 159 System.out.println("ArtifactDescriptionFactory - extractOldData()"); |
143 | 160 |
144 NodeList dataNodes = (NodeList) XMLUtils.xpath( | 161 NodeList stateNodes = (NodeList) XMLUtils.xpath( |
145 staticNode, | 162 staticNode, |
146 XPATH_STATIC_DATA_NODE, | 163 XPATH_STATIC_STATE_NODE, |
147 XPathConstants.NODESET, | 164 XPathConstants.NODESET, |
148 ArtifactNamespaceContext.INSTANCE); | 165 ArtifactNamespaceContext.INSTANCE); |
149 | 166 |
150 if (dataNodes == null || dataNodes.getLength() == 0) { | 167 if (stateNodes == null || stateNodes.getLength() == 0) { |
151 System.out.println("No old items found."); | 168 System.out.println("No old items found."); |
152 return null; | 169 return null; |
153 } | 170 } |
154 | 171 |
155 int count = dataNodes.getLength(); | 172 int count = stateNodes.getLength(); |
156 | 173 DataList[] data = new DataList[count]; |
157 Data[] data = new Data[count]; | |
158 | 174 |
159 for (int i = 0; i < count; i++) { | 175 for (int i = 0; i < count; i++) { |
160 Node tmp = dataNodes.item(i); | 176 Node tmp = stateNodes.item(i); |
161 | 177 |
162 String name = XMLUtils.xpathString( | 178 String name = XMLUtils.xpathString( |
163 tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); | 179 tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); |
164 String type = XMLUtils.xpathString( | 180 |
165 tmp, "@art:type", ArtifactNamespaceContext.INSTANCE); | 181 NodeList dataNodes = (NodeList) XMLUtils.xpath( |
166 | 182 tmp, |
167 DataItem[] items = extractOldDataItems(tmp); | 183 XPATH_STATIC_DATA_NODE, |
168 | 184 XPathConstants.NODESET, |
169 data[i] = new DefaultData(name, name, type, items, null); | 185 ArtifactNamespaceContext.INSTANCE); |
186 | |
187 if (dataNodes == null || dataNodes.getLength() == 0) { | |
188 continue; | |
189 } | |
190 | |
191 int size = dataNodes.getLength(); | |
192 DataList list = new DataList(name, size); | |
193 | |
194 for (int j = 0; j < size; j++) { | |
195 Node dataNode = dataNodes.item(j); | |
196 | |
197 String dName = XMLUtils.xpathString( | |
198 dataNode, "@art:name", ArtifactNamespaceContext.INSTANCE); | |
199 String dType = XMLUtils.xpathString( | |
200 dataNode, "@art:type", ArtifactNamespaceContext.INSTANCE); | |
201 | |
202 DataItem[] items = extractOldDataItems(dataNode); | |
203 | |
204 list.add(new DefaultData(dName, dName, dType, items)); | |
205 | |
206 data[i] = list; | |
207 } | |
170 } | 208 } |
171 | 209 |
172 return data; | 210 return data; |
173 } | 211 } |
174 | 212 |
216 * | 254 * |
217 * @param data The data node. | 255 * @param data The data node. |
218 * | 256 * |
219 * @return the UIProvider that is specified in the data node. | 257 * @return the UIProvider that is specified in the data node. |
220 */ | 258 */ |
221 protected static String extractUIProvider(Node data) { | 259 protected static String extractUIProvider(Node ui) { |
222 return (String) XMLUtils.xpath( | 260 return (String) XMLUtils.xpath( |
223 data, | 261 ui, |
224 XPATH_UIPROVIDER, | 262 XPATH_UIPROVIDER, |
225 XPathConstants.STRING, | 263 XPathConstants.STRING, |
226 ArtifactNamespaceContext.INSTANCE); | 264 ArtifactNamespaceContext.INSTANCE); |
227 } | 265 } |
228 | 266 |