1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.handler;
17
18 import java.util.Vector;
19
20 import org.apache.juddi.datatype.KeyedReference;
21 import org.apache.juddi.datatype.RegistryObject;
22 import org.apache.juddi.datatype.response.AssertionStatusItem;
23 import org.apache.juddi.datatype.response.CompletionStatus;
24 import org.apache.juddi.datatype.response.KeysOwned;
25 import org.apache.juddi.util.xml.XMLUtils;
26 import org.w3c.dom.Element;
27
28 /***
29 * @author Steve Viens (sviens@apache.org)
30 */
31 public class AssertionStatusItemHandler extends AbstractHandler
32 {
33 public static final String TAG_NAME = "assertionStatusItem";
34 private static final String FROM_KEY_TAG_NAME = "fromKey";
35 private static final String TO_KEY_TAG_NAME = "toKey";
36
37 private HandlerMaker maker = null;
38
39 protected AssertionStatusItemHandler(HandlerMaker maker)
40 {
41 this.maker = maker;
42 }
43
44 public RegistryObject unmarshal(Element element)
45 {
46 AssertionStatusItem obj = new AssertionStatusItem();
47 Vector nodeList = null;
48 AbstractHandler handler = null;
49
50
51 obj.setCompletionStatus(element.getAttribute("completionStatus"));
52
53
54
55
56
57 nodeList = XMLUtils.getChildElementsByTagName(element,FROM_KEY_TAG_NAME);
58 if (nodeList.size() > 0)
59 {
60 Element keyElement = (Element)nodeList.elementAt(0);
61 obj.setFromKey(XMLUtils.getText(keyElement));
62 }
63
64 nodeList = XMLUtils.getChildElementsByTagName(element,TO_KEY_TAG_NAME);
65 if (nodeList.size() > 0)
66 {
67 Element keyElement = (Element)nodeList.elementAt(0);
68 obj.setToKey(XMLUtils.getText(keyElement));
69 }
70
71 nodeList = XMLUtils.getChildElementsByTagName(element,KeyedReferenceHandler.TAG_NAME);
72 if (nodeList.size() > 0)
73 {
74 handler = maker.lookup(KeyedReferenceHandler.TAG_NAME);
75 obj.setKeyedReference((KeyedReference)handler.unmarshal((Element)nodeList.elementAt(0)));
76 }
77
78 nodeList = XMLUtils.getChildElementsByTagName(element,KeysOwnedHandler.TAG_NAME);
79 if (nodeList.size() > 0)
80 {
81 handler = maker.lookup(KeysOwnedHandler.TAG_NAME);
82 obj.setKeysOwned((KeysOwned)handler.unmarshal((Element)nodeList.elementAt(0)));
83 }
84
85 return obj;
86 }
87
88 public void marshal(RegistryObject object,Element parent)
89 {
90 AssertionStatusItem item = (AssertionStatusItem)object;
91
92 String generic = getGeneric(null);
93 String namespace = getUDDINamespace(generic);
94 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
95 AbstractHandler handler = null;
96
97 CompletionStatus status = item.getCompletionStatus();
98 if ((status != null) && (status.getValue() != null))
99 element.setAttribute("completionStatus",status.getValue());
100 else
101 element.setAttribute("completionStatus","");
102
103 String fromKey = item.getFromKey();
104 if (fromKey != null)
105 {
106 Element keyElement = parent.getOwnerDocument().createElement(FROM_KEY_TAG_NAME);
107 keyElement.appendChild(parent.getOwnerDocument().createTextNode(fromKey));
108 element.appendChild(keyElement);
109 }
110
111 String toKey = item.getToKey();
112 if (toKey != null)
113 {
114 Element keyElement = parent.getOwnerDocument().createElement(TO_KEY_TAG_NAME);
115 keyElement.appendChild(parent.getOwnerDocument().createTextNode(toKey));
116 element.appendChild(keyElement);
117 }
118
119 KeyedReference keyedRef = item.getKeyedReference();
120 if (keyedRef != null)
121 {
122 handler = maker.lookup(KeyedReferenceHandler.TAG_NAME);
123 handler.marshal(keyedRef,element);
124 }
125
126 KeysOwned keysOwned = item.getKeysOwned();
127 if (keysOwned != null)
128 {
129 handler = maker.lookup(KeysOwnedHandler.TAG_NAME);
130 handler.marshal(keysOwned,element);
131 }
132
133 parent.appendChild(element);
134 }
135
136
137 /****************************************************************************/
138 /****************************** TEST DRIVER *********************************/
139 /****************************************************************************/
140
141
142 public static void main(String args[])
143 throws Exception
144 {
145 HandlerMaker maker = HandlerMaker.getInstance();
146 AbstractHandler handler = maker.lookup(AssertionStatusItemHandler.TAG_NAME);
147 Element parent = XMLUtils.newRootElement();
148 Element child = null;
149
150 KeysOwned keysOwned = new KeysOwned();
151 keysOwned.setToKey("dfddb58c-4853-4a71-865c-f84509017cc7");
152 keysOwned.setFromKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
153
154 AssertionStatusItem item = new AssertionStatusItem();
155 item.setCompletionStatus(new CompletionStatus(CompletionStatus.COMPLETE));
156 item.setFromKey("986d9a16-5d4d-46cf-9fac-6bb80a7091f6");
157 item.setToKey("dd45a24c-74fc-4e82-80c2-f99cdc76d681");
158 item.setKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","Subsidiary","1"));
159 item.setKeysOwned(keysOwned);
160
161 System.out.println();
162
163 RegistryObject regObject = item;
164 handler.marshal(regObject,parent);
165 child = (Element)parent.getFirstChild();
166 parent.removeChild(child);
167 XMLUtils.writeXML(child,System.out);
168
169 System.out.println();
170
171 regObject = handler.unmarshal(child);
172 handler.marshal(regObject,parent);
173 child = (Element)parent.getFirstChild();
174 parent.removeChild(child);
175 XMLUtils.writeXML(child,System.out);
176 }
177 }