KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc;
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 JavaDoc 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 JavaDoc element)
46   {
47     BusinessInfo obj = new BusinessInfo();
48     Vector JavaDoc 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 JavaDoc)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 JavaDoc)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 JavaDoc)nodeList.elementAt(0)));
81     }
82
83     return obj;
84   }
85
86   public void marshal(RegistryObject object,Element JavaDoc parent)
87   {
88     BusinessInfo info = (BusinessInfo)object;
89     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
90     AbstractHandler handler = null;
91
92     String JavaDoc businessKey = info.getBusinessKey();
93     if (businessKey != null)
94       element.setAttribute("businessKey",businessKey);
95
96     Vector JavaDoc nameVector = info.getNameVector();
97     if ((nameVector!=null) && (nameVector.size() > 0))
98     {
99       handler = maker.lookup(NameHandler.TAG_NAME);
100       for (int i=0; i < nameVector.size(); i++)
101         handler.marshal((org.apache.juddi.datatype.Name)nameVector.elementAt(i),element);
102     }
103
104     Vector JavaDoc descVector = info.getDescriptionVector();
105     if ((descVector!=null) && (descVector.size() > 0))
106     {
107       handler = maker.lookup(DescriptionHandler.TAG_NAME);
108       for (int i=0; i < descVector.size(); i++)
109         handler.marshal((Description)descVector.elementAt(i),element);
110     }
111
112     ServiceInfos infos = info.getServiceInfos();
113     if (infos != null)
114     {
115       handler = maker.lookup(ServiceInfosHandler.TAG_NAME);
116       handler.marshal(infos,element);
117     }
118
119     parent.appendChild(element);
120   }
121
122
123   /***************************************************************************/
124   /***************************** TEST DRIVER *********************************/
125   /***************************************************************************/
126
127
128   public static void main(String JavaDoc args[])
129     throws Exception JavaDoc
130   {
131   }
132 }
Popular Tags