KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

54     // Child Elements
55
nodeList = XMLUtils.getChildElementsByTagName(element,PublisherIDHandler.TAG_NAME);
56     for (int i=0; i<nodeList.size(); i++)
57     {
58       handler = maker.lookup(PublisherIDHandler.TAG_NAME);
59       obj.addPublisherID((PublisherID)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i)));
60     }
61
62     return obj;
63   }
64
65   public void marshal(RegistryObject object,Element JavaDoc parent)
66   {
67     GetPublisherDetail request = (GetPublisherDetail)object;
68     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
69     AbstractHandler handler = null;
70
71     String JavaDoc generic = request.getGeneric();
72     if (generic != null)
73       element.setAttribute("generic",generic);
74
75     Vector JavaDoc idVector = request.getPublisherIDVector();
76     if ((idVector!=null) && (idVector.size() > 0))
77     {
78       handler = maker.lookup(PublisherIDHandler.TAG_NAME);
79       for (int i=0; i<idVector.size(); i++)
80         handler.marshal(new PublisherID((String JavaDoc)idVector.elementAt(i)),element);
81     }
82
83     parent.appendChild(element);
84   }
85
86
87   /***************************************************************************/
88   /***************************** TEST DRIVER *********************************/
89   /***************************************************************************/
90
91
92   public static void main(String JavaDoc args[])
93     throws Exception JavaDoc
94   {
95     HandlerMaker maker = HandlerMaker.getInstance();
96     AbstractHandler handler = maker.lookup(GetPublisherDetailHandler.TAG_NAME);
97
98     Element JavaDoc parent = XMLUtils.newRootElement();
99     Element JavaDoc child = null;
100
101     GetPublisherDetail service = new GetPublisherDetail();
102     service.addPublisherID("sviens");
103     service.addPublisherID(new PublisherID("jdoe"));
104
105     System.out.println();
106
107     RegistryObject regObject = service;
108     handler.marshal(regObject,parent);
109     child = (Element JavaDoc)parent.getFirstChild();
110     parent.removeChild(child);
111     XMLUtils.writeXML(child,System.out);
112
113     System.out.println();
114
115     regObject = handler.unmarshal(child);
116     handler.marshal(regObject,parent);
117     child = (Element JavaDoc)parent.getFirstChild();
118     parent.removeChild(child);
119     XMLUtils.writeXML(child,System.out);
120   }
121 }
Popular Tags