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.business.BusinessEntityExt;
22  import org.apache.juddi.datatype.response.BusinessDetailExt;
23  import org.apache.juddi.util.xml.XMLUtils;
24  import org.w3c.dom.Element;
25  
26  /***
27   * BusinessDetailExtHandler
28   *
29   * @author Steve Viens (sviens@apache.org)
30   */
31  public class BusinessDetailExtHandler extends AbstractHandler
32  {
33    public static final String TAG_NAME = "businessDetailExt";
34  
35    private HandlerMaker maker = null;
36  
37    protected BusinessDetailExtHandler(HandlerMaker maker)
38    {
39      this.maker = maker;
40    }
41  
42    public RegistryObject unmarshal(Element element)
43    {
44      BusinessDetailExt obj = new BusinessDetailExt();
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,BusinessEntityExtHandler.TAG_NAME);
69      for (int i=0; i<nodeList.size(); i++)
70      {
71        handler = maker.lookup(BusinessEntityExtHandler.TAG_NAME);
72        obj.addBusinessEntityExt((BusinessEntityExt)handler.unmarshal((Element)nodeList.elementAt(i)));
73      }
74  
75      return obj;
76    }
77  
78    public void marshal(RegistryObject object,Element parent)
79    {
80      BusinessDetailExt detail = (BusinessDetailExt)object;
81      String generic = detail.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 = detail.getOperator();
90      if (operator != null)
91        element.setAttribute("operator",operator);
92      else
93        element.setAttribute("operator","");
94  
95      boolean truncated = detail.isTruncated();
96      if (truncated)
97        element.setAttribute("truncated","true");
98  
99      Vector vector = detail.getBusinessEntityExtVector();
100     if ((vector!=null) && (vector.size() > 0))
101     {
102       handler = maker.lookup(BusinessEntityExtHandler.TAG_NAME);
103       for (int i=0; i < vector.size(); i++)
104         handler.marshal((BusinessEntityExt)vector.elementAt(i),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 }