View Javadoc

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;
22  
23  /***
24   * @author Steve Viens (sviens@apache.org)
25   */
26  public class CompletionStatusHandler extends AbstractHandler
27  {
28    public static final String TAG_NAME = "completionStatus";
29  
30    protected CompletionStatusHandler(HandlerMaker maker)
31    {
32    }
33  
34    public RegistryObject unmarshal(Element element)
35    {
36      CompletionStatus obj = new CompletionStatus();
37  
38      // Attributes
39      // {none}
40  
41      // Text Node Value
42      obj.setValue(XMLUtils.getText(element));
43  
44      // Child Elements
45      // {none}
46  
47      return obj;
48    }
49  
50    public void marshal(RegistryObject object,Element parent)
51    {
52      CompletionStatus status = (CompletionStatus)object;
53      String generic = getGeneric(null);
54      String namespace = getUDDINamespace(generic);
55      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
56  
57      String statusValue = status.getValue();
58      if (statusValue != null)
59        element.appendChild(parent.getOwnerDocument().createTextNode(statusValue));
60  
61      parent.appendChild(element);
62    }
63  
64  
65    /****************************************************************************/
66    /****************************** TEST DRIVER *********************************/
67    /****************************************************************************/
68  
69  
70    public static void main(String args[])
71      throws Exception
72    {
73      HandlerMaker maker = HandlerMaker.getInstance();
74      AbstractHandler handler = maker.lookup(CompletionStatusHandler.TAG_NAME);
75  
76      Element parent = XMLUtils.newRootElement();
77      Element child = null;
78  
79      CompletionStatus status = new CompletionStatus();
80      status.setValue(CompletionStatus.FROMKEY_INCOMPLETE);
81  
82      System.out.println();
83  
84      RegistryObject regObject = status;
85      handler.marshal(regObject,parent);
86      child = (Element)parent.getFirstChild();
87      parent.removeChild(child);
88      XMLUtils.writeXML(child,System.out);
89  
90      System.out.println();
91  
92      regObject = handler.unmarshal(child);
93      handler.marshal(regObject,parent);
94      child = (Element)parent.getFirstChild();
95      parent.removeChild(child);
96      XMLUtils.writeXML(child,System.out);
97    }
98  }