KickJava   Java API By Example, From Geeks To Geeks.

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


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.BusinessKey;
21 import org.apache.juddi.datatype.RegistryObject;
22 import org.apache.juddi.datatype.request.AuthInfo;
23 import org.apache.juddi.datatype.request.DeleteBusiness;
24 import org.apache.juddi.util.xml.XMLUtils;
25 import org.w3c.dom.Element JavaDoc;
26
27 /**
28  * DeleteBusinessHandler
29  *
30  * "Knows about the creation and populating of DeleteBusiness objects.
31  * Returns DeleteBusiness."
32  *
33  * @author Steve Viens (sviens@apache.org)
34  */

35 public class DeleteBusinessHandler extends AbstractHandler
36 {
37   public static final String JavaDoc TAG_NAME = "delete_business";
38
39   private HandlerMaker maker = null;
40
41   protected DeleteBusinessHandler(HandlerMaker maker)
42   {
43     this.maker = maker;
44   }
45
46   public RegistryObject unmarshal(Element JavaDoc element)
47   {
48     DeleteBusiness obj = new DeleteBusiness();
49     Vector JavaDoc nodeList = null;
50     AbstractHandler handler = null;
51
52     // Attributes
53
String JavaDoc generic = element.getAttribute("generic");
54     if ((generic != null && (generic.trim().length() > 0)))
55       obj.setGeneric(generic);
56
57     // Text Node Value
58
// {none}
59

60     // Child Elements
61
nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME);
62     if (nodeList.size() > 0)
63     {
64       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
65       obj.setAuthInfo((AuthInfo)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
66     }
67
68     nodeList = XMLUtils.getChildElementsByTagName(element,BusinessKeyHandler.TAG_NAME);
69     for (int i=0; i<nodeList.size(); i++)
70     {
71       handler = maker.lookup(BusinessKeyHandler.TAG_NAME);
72       obj.addBusinessKey((BusinessKey)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i)));
73     }
74
75     return obj;
76   }
77
78   public void marshal(RegistryObject object,Element JavaDoc parent)
79   {
80     DeleteBusiness request = (DeleteBusiness)object;
81     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
82     AbstractHandler handler = null;
83
84     String JavaDoc generic = request.getGeneric();
85     if (generic != null)
86       element.setAttribute("generic",generic);
87
88     AuthInfo authInfo = request.getAuthInfo();
89     if (authInfo != null)
90     {
91       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
92       handler.marshal(authInfo,element);
93     }
94
95     Vector JavaDoc keyVector = request.getBusinessKeyVector();
96     if ((keyVector!=null) && (keyVector.size() > 0))
97     {
98       handler = maker.lookup(BusinessKeyHandler.TAG_NAME);
99       for (int i=0; i<keyVector.size(); i++)
100         handler.marshal(new BusinessKey((String JavaDoc)keyVector.elementAt(i)),element);
101     }
102
103     parent.appendChild(element);
104   }
105
106
107   /***************************************************************************/
108   /***************************** TEST DRIVER *********************************/
109   /***************************************************************************/
110
111
112   public static void main(String JavaDoc args[])
113     throws Exception JavaDoc
114   {
115     HandlerMaker maker = HandlerMaker.getInstance();
116     AbstractHandler handler = maker.lookup(DeleteBusinessHandler.TAG_NAME);
117
118     Element JavaDoc parent = XMLUtils.newRootElement();
119     Element JavaDoc child = null;
120
121     AuthInfo authInfo = new AuthInfo();
122     authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726");
123
124     DeleteBusiness service = new DeleteBusiness();
125     service.setAuthInfo(authInfo);
126     service.addBusinessKey("1bd50f65-9671-41ae-8d13-b3b5a5afcda0");
127     service.addBusinessKey(new BusinessKey("1fbe67e6-f8b5-4743-a23f-9c13e4273d9f"));
128
129     System.out.println();
130
131     RegistryObject regObject = service;
132     handler.marshal(regObject,parent);
133     child = (Element JavaDoc)parent.getFirstChild();
134     parent.removeChild(child);
135     XMLUtils.writeXML(child,System.out);
136
137     System.out.println();
138
139     regObject = handler.unmarshal(child);
140     handler.marshal(regObject,parent);
141     child = (Element JavaDoc)parent.getFirstChild();
142     parent.removeChild(child);
143     XMLUtils.writeXML(child,System.out);
144   }
145 }
Popular Tags