KickJava   Java API By Example, From Geeks To Geeks.

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


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.OverviewDoc;
22 import org.apache.juddi.datatype.RegistryObject;
23 import org.apache.juddi.datatype.binding.AccessPoint;
24 import org.apache.juddi.datatype.binding.BindingTemplate;
25 import org.apache.juddi.datatype.binding.HostingRedirector;
26 import org.apache.juddi.datatype.binding.InstanceDetails;
27 import org.apache.juddi.datatype.binding.TModelInstanceDetails;
28 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
29 import org.apache.juddi.datatype.request.AuthInfo;
30 import org.apache.juddi.datatype.request.SaveBinding;
31 import org.apache.juddi.util.xml.XMLUtils;
32 import org.w3c.dom.Element JavaDoc;
33
34 /**
35  * @author Steve Viens (sviens@apache.org)
36  */

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

62     // Child Elements
63
nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME);
64     if (nodeList.size() > 0)
65     {
66       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
67       obj.setAuthInfo((AuthInfo)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
68     }
69
70     nodeList = XMLUtils.getChildElementsByTagName(element,BindingTemplateHandler.TAG_NAME);
71     for (int i=0; i<nodeList.size(); i++)
72     {
73       handler = maker.lookup(BindingTemplateHandler.TAG_NAME);
74       obj.addBindingTemplate((BindingTemplate)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i)));
75     }
76
77     return obj;
78   }
79
80   public void marshal(RegistryObject object,Element JavaDoc parent)
81   {
82     SaveBinding request = (SaveBinding)object;
83     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
84     AbstractHandler handler = null;
85
86     String JavaDoc generic = request.getGeneric();
87     if (generic != null)
88       element.setAttribute("generic",generic);
89
90     AuthInfo authInfo = request.getAuthInfo();
91     if (authInfo != null)
92     {
93       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
94       handler.marshal(authInfo,element);
95     }
96
97     Vector JavaDoc bindingVector = request.getBindingTemplateVector();
98     if ((bindingVector!=null) && (bindingVector.size() > 0))
99     {
100       handler = maker.lookup(BindingTemplateHandler.TAG_NAME);
101       for (int i=0; i<bindingVector.size(); i++)
102         handler.marshal((BindingTemplate)bindingVector.elementAt(i),element);
103     }
104
105     parent.appendChild(element);
106   }
107
108
109   /***************************************************************************/
110   /***************************** TEST DRIVER *********************************/
111   /***************************************************************************/
112
113
114   public static void main(String JavaDoc args[])
115     throws Exception JavaDoc
116   {
117     HandlerMaker maker = HandlerMaker.getInstance();
118     AbstractHandler handler = maker.lookup(SaveBindingHandler.TAG_NAME);
119
120     Element JavaDoc parent = XMLUtils.newRootElement();
121     Element JavaDoc child = null;
122
123     AuthInfo authInfo = new AuthInfo();
124     authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726");
125
126     OverviewDoc overDoc = new OverviewDoc();
127     overDoc.setOverviewURL("http://www.sviens.com/service.html");
128     overDoc.addDescription(new Description("over-doc Descr"));
129     overDoc.addDescription(new Description("over-doc Descr Two","en"));
130
131     InstanceDetails instDetails = new InstanceDetails();
132     instDetails.addDescription(new Description("body-isa-wunder"));
133     instDetails.addDescription(new Description("sweetchild-o-mine","it"));
134     instDetails.setInstanceParms("inst-det parameters");
135     instDetails.setOverviewDoc(overDoc);
136
137     TModelInstanceInfo tModInstInfo = new TModelInstanceInfo();
138     tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9");
139     tModInstInfo.addDescription(new Description("tMod-Inst-Info"));
140     tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es"));
141     tModInstInfo.setInstanceDetails(instDetails);
142
143     TModelInstanceDetails tModInstDet = new TModelInstanceDetails();
144     tModInstDet.addTModelInstanceInfo(tModInstInfo);
145
146     BindingTemplate binding = new BindingTemplate();
147     binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a");
148     binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31");
149     binding.addDescription(new Description("whatever"));
150     binding.addDescription(new Description("whatever too","fr"));
151     binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0"));
152     binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl"));
153     binding.setTModelInstanceDetails(tModInstDet);
154
155     SaveBinding service = new SaveBinding();
156     service.setAuthInfo(authInfo);
157     service.addBindingTemplate(binding);
158     service.addBindingTemplate(binding);
159
160     System.out.println();
161
162     RegistryObject regObject = service;
163     handler.marshal(regObject,parent);
164     child = (Element JavaDoc)parent.getFirstChild();
165     parent.removeChild(child);
166     XMLUtils.writeXML(child,System.out);
167
168     System.out.println();
169
170     regObject = handler.unmarshal(child);
171     handler.marshal(regObject,parent);
172     child = (Element JavaDoc)parent.getFirstChild();
173     parent.removeChild(child);
174     XMLUtils.writeXML(child,System.out);
175
176     System.out.println();
177   }
178 }
Popular Tags