View Javadoc

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;
19  
20  import org.apache.juddi.datatype.RegistryObject;
21  import org.apache.juddi.datatype.response.BusinessInfos;
22  import org.apache.juddi.datatype.response.BusinessList;
23  import org.apache.juddi.util.xml.XMLUtils;
24  import org.w3c.dom.Element;
25  
26  /***
27   * BusinessListHandler
28   *
29   * @author Steve Viens (sviens@apache.org)
30   */
31  public class BusinessListHandler extends AbstractHandler
32  {
33    public static final String TAG_NAME = "businessList";
34  
35    private HandlerMaker maker = null;
36  
37    protected BusinessListHandler(HandlerMaker maker)
38    {
39      this.maker = maker;
40    }
41  
42    public RegistryObject unmarshal(Element element)
43    {
44      BusinessList obj = new BusinessList();
45      Vector nodeList = null;
46      AbstractHandler handler = null;
47  
48      // We could use the generic attribute value to
49      // determine which version of UDDI was used to
50      // format the request XML. - Steve
51  
52      // Attributes
53      obj.setGeneric(element.getAttribute("generic"));
54      obj.setOperator(element.getAttribute("operator"));
55  
56      // We can ignore the xmlns attribute since we
57      // can always determine it's value using the
58      // "generic" attribute. - Steve
59  
60      String truncValue = element.getAttribute("truncated");
61      if (truncValue != null)
62        obj.setTruncated(truncValue.equalsIgnoreCase("true"));
63  
64      // Text Node Value
65      // {none}
66  
67      // Child Elements
68      nodeList = XMLUtils.getChildElementsByTagName(element,BusinessInfosHandler.TAG_NAME);
69      if (nodeList.size() > 0)
70      {
71        handler = maker.lookup(BusinessInfosHandler.TAG_NAME);
72        obj.setBusinessInfos((BusinessInfos)handler.unmarshal((Element)nodeList.elementAt(0)));
73      }
74  
75      return obj;
76    }
77  
78    public void marshal(RegistryObject object,Element parent)
79    {
80      BusinessList list = (BusinessList)object;
81      String generic = list.getGeneric();
82      generic = getGeneric(generic);
83      String namespace = getUDDINamespace(generic);
84      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
85      AbstractHandler handler = null;
86  
87      element.setAttribute("generic",generic);
88  
89      String operator = list.getOperator();
90      if (operator != null)
91        element.setAttribute("operator",operator);
92      else
93        element.setAttribute("operator","");
94  
95      boolean truncated = list.isTruncated();
96      if (truncated)
97        element.setAttribute("truncated","true");
98  
99      BusinessInfos infos = list.getBusinessInfos();
100     if (infos != null)
101     {
102       handler = maker.lookup(BusinessInfosHandler.TAG_NAME);
103       handler.marshal(infos,element);
104     }
105 
106     parent.appendChild(element);
107   }
108 
109 
110   /****************************************************************************/
111   /****************************** TEST DRIVER *********************************/
112   /****************************************************************************/
113 
114 
115   public static void main(String args[])
116     throws Exception
117   {
118   }
119 }