KickJava   Java API By Example, From Geeks To Geeks.

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


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.BusinessInfos;
23 import org.apache.juddi.datatype.response.BusinessList;
24 import org.apache.juddi.util.xml.XMLUtils;
25 import org.w3c.dom.Element JavaDoc;
26
27 /**
28  * BusinessListHandler
29  *
30  * @author Steve Viens (sviens@apache.org)
31  */

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

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

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

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