KickJava   Java API By Example, From Geeks To Geeks.

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


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.Name;
21 import org.apache.juddi.datatype.RegistryObject;
22 import org.apache.juddi.datatype.response.ServiceInfo;
23 import org.apache.juddi.util.xml.XMLUtils;
24 import org.w3c.dom.Element JavaDoc;
25
26 /**
27  * ServiceInfoHandler
28  *
29  * @author Steve Viens (sviens@apache.org)
30  * @author Anou Mana (anou_mana@users.sourceforge.net)
31  */

32 public class ServiceInfoHandler extends AbstractHandler
33 {
34   public static final String JavaDoc TAG_NAME = "serviceInfo";
35
36   private HandlerMaker maker = null;
37
38   protected ServiceInfoHandler(HandlerMaker maker)
39   {
40     this.maker = maker;
41   }
42
43   public RegistryObject unmarshal(Element JavaDoc element)
44   {
45     ServiceInfo obj = new ServiceInfo();
46     Vector JavaDoc nodeList = null;
47     AbstractHandler handler = null;
48
49     // Attributes
50
obj.setServiceKey(element.getAttribute("serviceKey"));
51     obj.setBusinessKey(element.getAttribute("businessKey"));
52
53     // Text Node Value
54
// {none}
55

56     // Child Elements
57
nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME);
58     for (int i=0; i<nodeList.size(); i++)
59     {
60       handler = maker.lookup(NameHandler.TAG_NAME);
61       Name name = (Name )handler.unmarshal((Element JavaDoc)nodeList.elementAt(i));
62       if (name != null)
63         obj.addName(name);
64     }
65
66     return obj;
67   }
68
69   public void marshal(RegistryObject object,Element JavaDoc parent)
70   {
71     ServiceInfo info = (ServiceInfo)object;
72     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
73     AbstractHandler handler = null;
74
75     // required attribute
76
String JavaDoc serviceKey = info.getServiceKey();
77     element.setAttribute("serviceKey",(serviceKey != null) ? serviceKey : "");
78
79     // required attribute
80
String JavaDoc businessKey = info.getBusinessKey();
81     element.setAttribute("businessKey",(businessKey != null) ? businessKey : "");
82
83     Vector JavaDoc vector = info.getNameVector();
84     if ((vector!=null) && (vector.size() > 0))
85     {
86       handler = maker.lookup(NameHandler.TAG_NAME);
87       for (int i=0; i < vector.size(); i++)
88         handler.marshal((Name)vector.elementAt(i),element);
89     }
90
91     parent.appendChild(element);
92   }
93
94
95   /***************************************************************************/
96   /***************************** TEST DRIVER *********************************/
97   /***************************************************************************/
98
99
100   public static void main(String JavaDoc args[])
101     throws Exception JavaDoc
102   {
103   }
104 }
Popular Tags