KickJava   Java API By Example, From Geeks To Geeks.

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


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.BindingTemplates;
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.util.xml.XMLUtils;
31 import org.w3c.dom.Element JavaDoc;
32
33 /**
34  * @author Steve Viens (sviens@apache.org)
35  */

36 public class BindingTemplatesHandler extends AbstractHandler
37 {
38   public static final String JavaDoc TAG_NAME = "bindingTemplates";
39
40   private HandlerMaker maker = null;
41
42   protected BindingTemplatesHandler(HandlerMaker maker)
43   {
44     this.maker = maker;
45   }
46
47   public RegistryObject unmarshal(Element JavaDoc element)
48   {
49     BindingTemplates obj = new BindingTemplates();
50     Vector JavaDoc nodeList = null;
51     AbstractHandler handler = null;
52
53     // Attributes
54
// {none}
55

56     // Text Node Value
57
// {none}
58

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