KickJava   Java API By Example, From Geeks To Geeks.

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


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.IRegistry;
21 import org.apache.juddi.datatype.Description;
22 import org.apache.juddi.datatype.OverviewDoc;
23 import org.apache.juddi.datatype.RegistryObject;
24 import org.apache.juddi.datatype.binding.AccessPoint;
25 import org.apache.juddi.datatype.binding.BindingTemplate;
26 import org.apache.juddi.datatype.binding.HostingRedirector;
27 import org.apache.juddi.datatype.binding.InstanceDetails;
28 import org.apache.juddi.datatype.binding.TModelInstanceDetails;
29 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
30 import org.apache.juddi.datatype.response.BindingDetail;
31 import org.apache.juddi.util.xml.XMLUtils;
32 import org.w3c.dom.Element JavaDoc;
33
34 /**
35  * "Knows about the creation and populating of BindingDetail objects.
36  * Returns BindingDetail."
37  *
38  * @author Steve Viens (sviens@apache.org)
39  */

40 public class BindingDetailHandler extends AbstractHandler
41 {
42   public static final String JavaDoc TAG_NAME = "bindingDetail";
43
44   private HandlerMaker maker = null;
45
46   protected BindingDetailHandler(HandlerMaker maker)
47   {
48     this.maker = maker;
49   }
50
51   public RegistryObject unmarshal(Element JavaDoc element)
52   {
53     BindingDetail obj = new BindingDetail();
54     Vector JavaDoc nodeList = null;
55     AbstractHandler handler = null;
56
57     // We could use the generic attribute value to
58
// determine which version of UDDI was used to
59
// format the request XML. - Steve
60

61     // Attributes
62
obj.setGeneric(element.getAttribute("generic"));
63     obj.setOperator(element.getAttribute("operator"));
64
65     // We can ignore the xmlns attribute since we
66
// can always determine it's value using the
67
// "generic" attribute. - Steve
68

69     String JavaDoc truncValue = element.getAttribute("truncated");
70     if (truncValue != null)
71       obj.setTruncated(truncValue.equalsIgnoreCase("true"));
72
73     // Text Node Value
74
// {none}
75

76     // Child Elements
77
nodeList = XMLUtils.getChildElementsByTagName(element,BindingTemplateHandler.TAG_NAME);
78     for (int i=0; i<nodeList.size(); i++)
79     {
80       handler = maker.lookup(BindingTemplateHandler.TAG_NAME);
81       obj.addBindingTemplate((BindingTemplate)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i)));
82     }
83
84     return obj;
85   }
86
87   public void marshal(RegistryObject object,Element JavaDoc parent)
88   {
89     BindingDetail detail = (BindingDetail)object;
90     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
91     AbstractHandler handler = null;
92
93     String JavaDoc generic = detail.getGeneric();
94     if ((generic != null) && (generic.trim().length() > 0))
95     {
96       element.setAttribute("generic",generic);
97
98       if (generic.equals(IRegistry.UDDI_V1_GENERIC))
99         element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE);
100       else if (generic.equals(IRegistry.UDDI_V2_GENERIC))
101         element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE);
102       else if (generic.equals(IRegistry.UDDI_V3_GENERIC))
103         element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE);
104     }
105     else // Default to UDDI v2 values
106
{
107       element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC);
108       element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE);
109     }
110
111     String JavaDoc operator = detail.getOperator();
112     if (operator != null)
113       element.setAttribute("operator",operator);
114     else
115       element.setAttribute("operator","");
116
117     boolean truncated = detail.isTruncated();
118     if (truncated)
119       element.setAttribute("truncated","true");
120
121     Vector JavaDoc vector = detail.getBindingTemplateVector();
122     if ((vector!=null) && (vector.size() > 0))
123     {
124       handler = maker.lookup(BindingTemplateHandler.TAG_NAME);
125       for (int i=0; i < vector.size(); i++)
126         handler.marshal((BindingTemplate)vector.elementAt(i),element);
127     }
128
129     parent.appendChild(element);
130   }
131
132
133   /***************************************************************************/
134   /***************************** TEST DRIVER *********************************/
135   /***************************************************************************/
136
137
138   public static void main(String JavaDoc args[])
139     throws Exception JavaDoc
140   {
141     HandlerMaker maker = HandlerMaker.getInstance();
142     AbstractHandler handler = maker.lookup(BindingDetailHandler.TAG_NAME);
143     Element JavaDoc parent = XMLUtils.newRootElement();
144     Element JavaDoc child = null;
145
146     OverviewDoc overDoc = new OverviewDoc();
147     overDoc.setOverviewURL("http://www.sviens.com/service.html");
148     overDoc.addDescription(new Description("over-doc Descr"));
149     overDoc.addDescription(new Description("over-doc Descr Two","en"));
150
151     InstanceDetails instDetails = new InstanceDetails();
152     instDetails.addDescription(new Description("body-isa-wunder"));
153     instDetails.addDescription(new Description("sweetchild-o-mine","it"));
154     instDetails.setInstanceParms("inst-det parameters");
155     instDetails.setOverviewDoc(overDoc);
156
157     TModelInstanceInfo tModInstInfo = new TModelInstanceInfo();
158     tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9");
159     tModInstInfo.addDescription(new Description("tMod-Inst-Info"));
160     tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es"));
161     tModInstInfo.setInstanceDetails(instDetails);
162
163     TModelInstanceDetails tModInstDet = new TModelInstanceDetails();
164     tModInstDet.addTModelInstanceInfo(tModInstInfo);
165
166     BindingTemplate binding = new BindingTemplate();
167     binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a");
168     binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31");
169     binding.addDescription(new Description("whatever"));
170     binding.addDescription(new Description("whatever too","fr"));
171     binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0"));
172     binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl"));
173     binding.setTModelInstanceDetails(tModInstDet);
174
175     BindingDetail detail = new BindingDetail();
176     detail.setGeneric("2.0");
177     detail.setOperator("jUDDI.org");
178     detail.setTruncated(true);
179     detail.addBindingTemplate(binding);
180     detail.addBindingTemplate(binding);
181
182     System.out.println();
183
184     RegistryObject regObject = detail;
185     handler.marshal(regObject,parent);
186     child = (Element JavaDoc)parent.getFirstChild();
187     parent.removeChild(child);
188     XMLUtils.writeXML(child,System.out);
189
190     System.out.println();
191
192     regObject = handler.unmarshal(child);
193     handler.marshal(regObject,parent);
194     child = (Element JavaDoc)parent.getFirstChild();
195     parent.removeChild(child);
196     XMLUtils.writeXML(child,System.out);
197
198     System.out.println();
199   }
200 }
Popular Tags