KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.juddi.datatype.RegistryObject;
19 import org.apache.juddi.datatype.response.CompletionStatus;
20 import org.apache.juddi.util.xml.XMLUtils;
21 import org.w3c.dom.Element JavaDoc;
22
23 /**
24  * @author Steve Viens (sviens@apache.org)
25  */

26 public class CompletionStatusHandler extends AbstractHandler
27 {
28   public static final String JavaDoc TAG_NAME = "completionStatus";
29
30   private HandlerMaker maker = null;
31
32   protected CompletionStatusHandler(HandlerMaker maker)
33   {
34     this.maker = maker;
35   }
36
37   public RegistryObject unmarshal(Element JavaDoc element)
38   {
39     CompletionStatus obj = new CompletionStatus();
40
41     // Attributes
42
// {none}
43

44     // Text Node Value
45
obj.setValue(XMLUtils.getText(element));
46
47     // Child Elements
48
// {none}
49

50     return obj;
51   }
52
53   public void marshal(RegistryObject object,Element JavaDoc parent)
54   {
55     CompletionStatus status = (CompletionStatus)object;
56     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
57
58     String JavaDoc statusValue = status.getValue();
59     if (statusValue != null)
60       element.appendChild(parent.getOwnerDocument().createTextNode(statusValue));
61
62     parent.appendChild(element);
63   }
64
65
66   /***************************************************************************/
67   /***************************** TEST DRIVER *********************************/
68   /***************************************************************************/
69
70
71   public static void main(String JavaDoc args[])
72     throws Exception JavaDoc
73   {
74     HandlerMaker maker = HandlerMaker.getInstance();
75     AbstractHandler handler = maker.lookup(CompletionStatusHandler.TAG_NAME);
76
77     Element JavaDoc parent = XMLUtils.newRootElement();
78     Element JavaDoc child = null;
79
80     CompletionStatus status = new CompletionStatus();
81     status.setValue(CompletionStatus.FROMKEY_INCOMPLETE);
82
83     System.out.println();
84
85     RegistryObject regObject = status;
86     handler.marshal(regObject,parent);
87     child = (Element JavaDoc)parent.getFirstChild();
88     parent.removeChild(child);
89     XMLUtils.writeXML(child,System.out);
90
91     System.out.println();
92
93     regObject = handler.unmarshal(child);
94     handler.marshal(regObject,parent);
95     child = (Element JavaDoc)parent.getFirstChild();
96     parent.removeChild(child);
97     XMLUtils.writeXML(child,System.out);
98   }
99 }
Popular Tags