KickJava   Java API By Example, From Geeks To Geeks.

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


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

28 public class GetRegistryInfoHandler extends AbstractHandler
29 {
30   public static final String JavaDoc TAG_NAME = "get_registryInfo";
31
32   private HandlerMaker maker = null;
33
34   protected GetRegistryInfoHandler(HandlerMaker maker)
35   {
36     this.maker = maker;
37   }
38
39   public RegistryObject unmarshal(Element JavaDoc element)
40   {
41     GetRegistryInfo obj = new GetRegistryInfo();
42     Vector JavaDoc nodeList = null;
43     AbstractHandler handler = null;
44
45     // Attributes
46
String JavaDoc generic = element.getAttribute("generic");
47     if ((generic != null && (generic.trim().length() > 0)))
48       obj.setGeneric(generic);
49
50     // Text Node Value
51
// {none}
52

53     // Child Elements
54
// {none}
55

56     return obj;
57   }
58
59   public void marshal(RegistryObject object,Element JavaDoc parent)
60   {
61     GetRegistryInfo request = (GetRegistryInfo)object;
62     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
63     AbstractHandler handler = null;
64
65     String JavaDoc generic = request.getGeneric();
66     if (generic != null)
67       element.setAttribute("generic",generic);
68
69     parent.appendChild(element);
70   }
71
72
73   /***************************************************************************/
74   /***************************** TEST DRIVER *********************************/
75   /***************************************************************************/
76
77
78   public static void main(String JavaDoc args[])
79     throws Exception JavaDoc
80   {
81     HandlerMaker maker = HandlerMaker.getInstance();
82     AbstractHandler handler = maker.lookup(GetRegistryInfoHandler.TAG_NAME);
83
84     Element JavaDoc parent = XMLUtils.newRootElement();
85     Element JavaDoc child = null;
86
87     GetRegistryInfo service = new GetRegistryInfo();
88     System.out.println();
89
90     RegistryObject regObject = service;
91     handler.marshal(regObject,parent);
92     child = (Element JavaDoc)parent.getFirstChild();
93     parent.removeChild(child);
94     XMLUtils.writeXML(child,System.out);
95
96     System.out.println();
97
98     regObject = handler.unmarshal(child);
99     handler.marshal(regObject,parent);
100     child = (Element JavaDoc)parent.getFirstChild();
101     parent.removeChild(child);
102     XMLUtils.writeXML(child,System.out);
103   }
104 }
Popular Tags