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.Description;
21  import org.apache.juddi.datatype.Name;
22  import org.apache.juddi.datatype.RegistryObject;
23  import org.apache.juddi.datatype.response.BusinessInfo;
24  import org.apache.juddi.datatype.response.ServiceInfos;
25  import org.apache.juddi.util.xml.XMLUtils;
26  import org.w3c.dom.Element;
27  
28  /***
29   * BusinessInfoHandler
30   *
31   * @author Steve Viens (sviens@apache.org)
32   * @author Anou Mana (anou_mana@users.sourceforge.net)
33   */
34  public class BusinessInfoHandler extends AbstractHandler
35  {
36    public static final String TAG_NAME = "businessInfo";
37  
38    private HandlerMaker maker = null;
39  
40    protected BusinessInfoHandler(HandlerMaker maker)
41    {
42      this.maker = maker;
43    }
44  
45    public RegistryObject unmarshal(Element element)
46    {
47      BusinessInfo obj = new BusinessInfo();
48      Vector nodeList = null;
49      AbstractHandler handler = null;
50  
51      // Attributes
52      obj.setBusinessKey(element.getAttribute("businessKey"));
53  
54      // Text Node Value
55      // {none}
56  
57      // Child Elements
58      nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME);
59      for (int i=0; i<nodeList.size(); i++)
60      {
61        handler = maker.lookup(NameHandler.TAG_NAME);
62        Name name = (Name )handler.unmarshal((Element)nodeList.elementAt(i));
63        if (name != null)
64          obj.addName(name);
65      }
66  
67      nodeList = XMLUtils.getChildElementsByTagName(element,DescriptionHandler.TAG_NAME);
68      for (int i=0; i<nodeList.size(); i++)
69      {
70        handler = maker.lookup(DescriptionHandler.TAG_NAME);
71        Description descr = (Description)handler.unmarshal((Element)nodeList.elementAt(i));
72        if (descr != null)
73          obj.addDescription(descr);
74      }
75  
76      nodeList = XMLUtils.getChildElementsByTagName(element,ServiceInfosHandler.TAG_NAME);
77      if (nodeList.size() > 0)
78      {
79        handler = maker.lookup(ServiceInfosHandler.TAG_NAME);
80        obj.setServiceInfos((ServiceInfos)handler.unmarshal((Element)nodeList.elementAt(0)));
81      }
82  
83      return obj;
84    }
85  
86    public void marshal(RegistryObject object,Element parent)
87    {
88      BusinessInfo info = (BusinessInfo)object;
89      String generic = getGeneric(null);
90      String namespace = getUDDINamespace(generic);
91      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
92      AbstractHandler handler = null;
93  
94      String businessKey = info.getBusinessKey();
95      if (businessKey != null)
96        element.setAttribute("businessKey",businessKey);
97  
98      Vector nameVector = info.getNameVector();
99      if ((nameVector!=null) && (nameVector.size() > 0))
100     {
101       handler = maker.lookup(NameHandler.TAG_NAME);
102       for (int i=0; i < nameVector.size(); i++)
103         handler.marshal((org.apache.juddi.datatype.Name)nameVector.elementAt(i),element);
104     }
105 
106     Vector descVector = info.getDescriptionVector();
107     if ((descVector!=null) && (descVector.size() > 0))
108     {
109       handler = maker.lookup(DescriptionHandler.TAG_NAME);
110       for (int i=0; i < descVector.size(); i++)
111         handler.marshal((Description)descVector.elementAt(i),element);
112     }
113 
114     ServiceInfos infos = info.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 args[])
131     throws Exception
132   {
133   }
134 }