KickJava   Java API By Example, From Geeks To Geeks.

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


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.IRegistry;
21 import org.apache.juddi.datatype.RegistryObject;
22 import org.apache.juddi.datatype.response.ServiceInfos;
23 import org.apache.juddi.datatype.response.ServiceList;
24 import org.apache.juddi.util.xml.XMLUtils;
25 import org.w3c.dom.Element JavaDoc;
26
27 /**
28  * "Knows about the creation and populating of ServiceList objects.
29  * Returns ServiceList."
30  *
31  * @author Steve Viens (sviens@apache.org)
32  */

33 public class ServiceListHandler extends AbstractHandler
34 {
35   public static final String JavaDoc TAG_NAME = "serviceList";
36
37   private HandlerMaker maker = null;
38
39   protected ServiceListHandler(HandlerMaker maker)
40   {
41     this.maker = maker;
42   }
43
44   public RegistryObject unmarshal(Element JavaDoc element)
45   {
46     ServiceList obj = new ServiceList();
47     Vector JavaDoc nodeList = null;
48     AbstractHandler handler = null;
49
50     // We could use the generic attribute value to
51
// determine which version of UDDI was used to
52
// format the request XML. - Steve
53

54     // Attributes
55
obj.setGeneric(element.getAttribute("generic"));
56     obj.setOperator(element.getAttribute("operator"));
57
58     // We can ignore the xmlns attribute since we
59
// can always determine it's value using the
60
// "generic" attribute. - Steve
61

62     String JavaDoc truncValue = element.getAttribute("truncated");
63     if (truncValue != null)
64       obj.setTruncated(truncValue.equalsIgnoreCase("true"));
65
66     // Text Node Value
67
// {none}
68

69     // Child Elements
70
nodeList = XMLUtils.getChildElementsByTagName(element,ServiceInfosHandler.TAG_NAME);
71     if (nodeList.size() > 0)
72     {
73       handler = maker.lookup(ServiceInfosHandler.TAG_NAME);
74       obj.setServiceInfos((ServiceInfos)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
75     }
76
77     return obj;
78   }
79
80   public void marshal(RegistryObject object,Element JavaDoc parent)
81   {
82     ServiceList list = (ServiceList)object;
83     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
84     AbstractHandler handler = null;
85
86     String JavaDoc generic = list.getGeneric();
87     if ((generic != null) && (generic.trim().length() > 0))
88     {
89       element.setAttribute("generic",generic);
90
91       if (generic.equals(IRegistry.UDDI_V1_GENERIC))
92         element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE);
93       else if (generic.equals(IRegistry.UDDI_V2_GENERIC))
94         element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE);
95       else if (generic.equals(IRegistry.UDDI_V3_GENERIC))
96         element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE);
97     }
98     else // Default to UDDI v2 values
99
{
100       element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC);
101       element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE);
102     }
103
104     String JavaDoc operator = list.getOperator();
105     if (operator != null)
106       element.setAttribute("operator",operator);
107     else
108       element.setAttribute("operator","");
109
110     boolean truncated = list.isTruncated();
111     if (truncated)
112       element.setAttribute("truncated","true");
113
114     ServiceInfos infos = list.getServiceInfos();
115     if (infos != null)
116     {
117       handler = maker.lookup(ServiceInfosHandler.TAG_NAME);
118       handler.marshal(infos,element);
119     }
120
121     parent.appendChild(element);
122   }
123
124
125   /***************************************************************************/
126   /***************************** TEST DRIVER *********************************/
127   /***************************************************************************/
128
129
130   public static void main(String JavaDoc args[])
131     throws Exception JavaDoc
132   {
133   }
134 }
Popular Tags