Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ProtocolUtils.java @ 107:39d9391059bd
Added a ProtocolUtils class that provides functions that help creating the artifact protocol documents.
artifacts/trunk@1295 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 04 Feb 2011 16:52:39 +0000 |
parents | |
children | ab646e0f5569 |
comparison
equal
deleted
inserted
replaced
106:ece0fdb07975 | 107:39d9391059bd |
---|---|
1 /* | |
2 * Copyright (c) 2011 by Intevation GmbH | |
3 * | |
4 * This program is free software under the LGPL (>=v2.1) | |
5 * Read the file LGPL.txt coming with the software for details | |
6 * or visit http://www.gnu.org/licenses/ if it does not exist. | |
7 */ | |
8 package de.intevation.artifactdatabase; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 | |
12 import org.w3c.dom.Element; | |
13 import org.w3c.dom.Node; | |
14 | |
15 import de.intevation.artifacts.common.utils.XMLUtils; | |
16 | |
17 | |
18 /** | |
19 * This class provides methods that help creating the artifact protocol | |
20 * documents describe, feed, advance and out. | |
21 * | |
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
23 */ | |
24 public class ProtocolUtils { | |
25 | |
26 /** | |
27 * It should not be necessary to create instances of this class. | |
28 */ | |
29 private ProtocolUtils() {} | |
30 | |
31 | |
32 /** | |
33 * This method creates a node that might be used for the artifact protocol. | |
34 * | |
35 * @param creator The ElementCreator that is used to create the node. | |
36 * @param nodeName The node name. | |
37 * @param attrName The names of optional attributes. | |
38 * @param value The values for the optional attributes. | |
39 * | |
40 * @return the created node. | |
41 */ | |
42 public static Element createArtNode( | |
43 XMLUtils.ElementCreator creator, | |
44 String nodeName, String[] attrName, String[] value) | |
45 { | |
46 Element typeNode = creator.create(nodeName); | |
47 | |
48 if (attrName != null && value != null) { | |
49 for (int i = 0; i < attrName.length; i++) { | |
50 if (i < value.length) { | |
51 creator.addAttr(typeNode, attrName[i], value[i], true); | |
52 } | |
53 else { | |
54 break; | |
55 } | |
56 } | |
57 } | |
58 | |
59 return typeNode; | |
60 } | |
61 | |
62 | |
63 /** | |
64 * This method creates the root node for all artifact protocol documents. | |
65 * | |
66 * @param creator The ElementCreator used to create new elements. | |
67 * | |
68 * @return the root node for the artifact protocol document. | |
69 */ | |
70 public static Element createRootNode(XMLUtils.ElementCreator creator) { | |
71 return createArtNode(creator, "result", null, null); | |
72 } | |
73 | |
74 | |
75 /** | |
76 * This method appends the three necessary nodes <i>type</i>, <i>uuid</i> | |
77 * and <i>hash</i> of the describe document to <i>root</i> node. | |
78 * | |
79 * @param creator The ElementCreator that is used to create new nodes. | |
80 * @param root The root node of the describe document. | |
81 * @param uuid The UUID of the artifact. | |
82 * @param hash The hash if the artifact. | |
83 */ | |
84 public static void appendDescribeHeader( | |
85 XMLUtils.ElementCreator creator, Element root, String uuid, String hash) | |
86 { | |
87 root.appendChild(createArtNode( | |
88 creator, | |
89 "type", | |
90 new String[] {"name"}, | |
91 new String[] {"describe"})); | |
92 | |
93 root.appendChild(createArtNode( | |
94 creator, | |
95 "uuid", | |
96 new String[] {"value"}, | |
97 new String[] {uuid})); | |
98 | |
99 root.appendChild(createArtNode( | |
100 creator, | |
101 "hash", | |
102 new String[] {"value"}, | |
103 new String[] {hash})); | |
104 } | |
105 } | |
106 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |