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.ServiceInfos;
22  import org.apache.juddi.datatype.response.ServiceList;
23  import org.apache.juddi.util.xml.XMLUtils;
24  import org.w3c.dom.Element;
25  
26  /***
27   * "Knows about the creation and populating of ServiceList objects.
28   * Returns ServiceList."
29   *
30   * @author Steve Viens (sviens@apache.org)
31   */
32  public class ServiceListHandler extends AbstractHandler
33  {
34    public static final String TAG_NAME = "serviceList";
35  
36    private HandlerMaker maker = null;
37  
38    protected ServiceListHandler(HandlerMaker maker)
39    {
40      this.maker = maker;
41    }
42  
43    public RegistryObject unmarshal(Element element)
44    {
45      ServiceList obj = new ServiceList();
46      Vector 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 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,ServiceInfosHandler.TAG_NAME);
70      if (nodeList.size() > 0)
71      {
72        handler = maker.lookup(ServiceInfosHandler.TAG_NAME);
73        obj.setServiceInfos((ServiceInfos)handler.unmarshal((Element)nodeList.elementAt(0)));
74      }
75  
76      return obj;
77    }
78  
79    public void marshal(RegistryObject object,Element parent)
80    {
81      ServiceList list = (ServiceList)object;
82      String generic = list.getGeneric();
83      generic = getGeneric(generic);
84      String namespace = getUDDINamespace(generic);
85      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
86      AbstractHandler handler = null;
87  
88      element.setAttribute("generic",generic);
89  
90      String operator = list.getOperator();
91      if (operator != null)
92        element.setAttribute("operator",operator);
93      else
94        element.setAttribute("operator","");
95  
96      boolean truncated = list.isTruncated();
97      if (truncated)
98        element.setAttribute("truncated","true");
99  
100     ServiceInfos infos = list.getServiceInfos();
101     if (infos != null)
102     {
103       handler = maker.lookup(ServiceInfosHandler.TAG_NAME);
104       handler.marshal(infos,element);
105     }
106 
107     parent.appendChild(element);
108   }
109 
110 
111   /****************************************************************************/
112   /****************************** TEST DRIVER *********************************/
113   /****************************************************************************/
114 
115 
116   public static void main(String args[])
117     throws Exception
118   {
119   }
120 }