KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > handler > AssertionStatusItemHandler


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.handler;
17
18 import java.util.Vector JavaDoc;
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 JavaDoc;
27
28 /**
29  * @author Steve Viens (sviens@apache.org)
30  */

31 public class AssertionStatusItemHandler extends AbstractHandler
32 {
33   public static final String JavaDoc TAG_NAME = "assertionStatusItem";
34   private static final String JavaDoc FROM_KEY_TAG_NAME = "fromKey";
35   private static final String JavaDoc 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 JavaDoc element)
45   {
46     AssertionStatusItem obj = new AssertionStatusItem();
47     Vector JavaDoc nodeList = null;
48     AbstractHandler handler = null;
49
50     // Attributes
51
obj.setCompletionStatus(element.getAttribute("completionStatus"));
52
53     // Text Node Value
54
// {none}
55

56     // Child Elements
57
nodeList = XMLUtils.getChildElementsByTagName(element,FROM_KEY_TAG_NAME);
58     if (nodeList.size() > 0)
59     {
60       Element JavaDoc keyElement = (Element JavaDoc)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 JavaDoc keyElement = (Element JavaDoc)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 JavaDoc)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 JavaDoc)nodeList.elementAt(0)));
83     }
84
85     return obj;
86   }
87
88   public void marshal(RegistryObject object,Element JavaDoc parent)
89   {
90     AssertionStatusItem item = (AssertionStatusItem)object;
91     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
92     AbstractHandler handler = null;
93
94     CompletionStatus status = item.getCompletionStatus();
95     if ((status != null) && (status.getValue() != null))
96       element.setAttribute("completionStatus",status.getValue());
97     else
98       element.setAttribute("completionStatus","");
99
100     String JavaDoc fromKey = item.getFromKey();
101     if (fromKey != null)
102     {
103       Element JavaDoc keyElement = parent.getOwnerDocument().createElement(FROM_KEY_TAG_NAME);
104       keyElement.appendChild(parent.getOwnerDocument().createTextNode(fromKey));
105       element.appendChild(keyElement);
106     }
107
108     String JavaDoc toKey = item.getToKey();
109     if (toKey != null)
110     {
111       Element JavaDoc keyElement = parent.getOwnerDocument().createElement(TO_KEY_TAG_NAME);
112       keyElement.appendChild(parent.getOwnerDocument().createTextNode(toKey));
113       element.appendChild(keyElement);
114     }
115
116     KeyedReference keyedRef = item.getKeyedReference();
117     if (keyedRef != null)
118     {
119       handler = maker.lookup(KeyedReferenceHandler.TAG_NAME);
120       handler.marshal(keyedRef,element);
121     }
122
123     KeysOwned keysOwned = item.getKeysOwned();
124     if (keysOwned != null)
125     {
126       handler = maker.lookup(KeysOwnedHandler.TAG_NAME);
127       handler.marshal(keysOwned,element);
128     }
129
130     parent.appendChild(element);
131   }
132
133
134   /***************************************************************************/
135   /***************************** TEST DRIVER *********************************/
136   /***************************************************************************/
137
138
139   public static void main(String JavaDoc args[])
140     throws Exception JavaDoc
141   {
142     HandlerMaker maker = HandlerMaker.getInstance();
143     AbstractHandler handler = maker.lookup(AssertionStatusItemHandler.TAG_NAME);
144     Element JavaDoc parent = XMLUtils.newRootElement();
145     Element JavaDoc child = null;
146
147     KeysOwned keysOwned = new KeysOwned();
148     keysOwned.setToKey("dfddb58c-4853-4a71-865c-f84509017cc7");
149     keysOwned.setFromKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
150
151     AssertionStatusItem item = new AssertionStatusItem();
152     item.setCompletionStatus(new CompletionStatus(CompletionStatus.COMPLETE));
153     item.setFromKey("986d9a16-5d4d-46cf-9fac-6bb80a7091f6");
154     item.setToKey("dd45a24c-74fc-4e82-80c2-f99cdc76d681");
155     item.setKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","Subsidiary","1"));
156     item.setKeysOwned(keysOwned);
157
158     System.out.println();
159
160     RegistryObject regObject = item;
161     handler.marshal(regObject,parent);
162     child = (Element JavaDoc)parent.getFirstChild();
163     parent.removeChild(child);
164     XMLUtils.writeXML(child,System.out);
165
166     System.out.println();
167
168     regObject = handler.unmarshal(child);
169     handler.marshal(regObject,parent);
170     child = (Element JavaDoc)parent.getFirstChild();
171     parent.removeChild(child);
172     XMLUtils.writeXML(child,System.out);
173   }
174 }
175
Popular Tags