KickJava   Java API By Example, From Geeks To Geeks.

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


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.CategoryBag;
21 import org.apache.juddi.datatype.Description;
22 import org.apache.juddi.datatype.IdentifierBag;
23 import org.apache.juddi.datatype.KeyedReference;
24 import org.apache.juddi.datatype.OverviewDoc;
25 import org.apache.juddi.datatype.RegistryObject;
26 import org.apache.juddi.datatype.UploadRegister;
27 import org.apache.juddi.datatype.request.AuthInfo;
28 import org.apache.juddi.datatype.request.SaveTModel;
29 import org.apache.juddi.datatype.tmodel.TModel;
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 SaveTModelHandler extends AbstractHandler
37 {
38   public static final String JavaDoc TAG_NAME = "save_tModel";
39
40   private HandlerMaker maker = null;
41
42   protected SaveTModelHandler(HandlerMaker maker)
43   {
44     this.maker = maker;
45   }
46
47   public RegistryObject unmarshal(Element JavaDoc element)
48   {
49     SaveTModel obj = new SaveTModel();
50     Vector JavaDoc nodeList = null;
51     AbstractHandler handler = null;
52
53     // Attributes
54
String JavaDoc generic = element.getAttribute("generic");
55     if ((generic != null && (generic.trim().length() > 0)))
56       obj.setGeneric(generic);
57
58     // Text Node Value
59
// {none}
60

61     // Child Elements
62
nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME);
63     if (nodeList.size() > 0)
64     {
65       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
66       obj.setAuthInfo((AuthInfo)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
67     }
68
69     nodeList = XMLUtils.getChildElementsByTagName(element,TModelHandler.TAG_NAME);
70     for (int i=0; i<nodeList.size(); i++)
71     {
72       handler = maker.lookup(TModelHandler.TAG_NAME);
73       obj.addTModel((TModel)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i)));
74     }
75
76     nodeList = XMLUtils.getChildElementsByTagName(element,UploadRegisterHandler.TAG_NAME);
77     for (int i=0; i<nodeList.size(); i++)
78     {
79       handler = maker.lookup(UploadRegisterHandler.TAG_NAME);
80       obj.addUploadRegister((UploadRegister)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i)));
81     }
82
83     return obj;
84   }
85
86   public void marshal(RegistryObject object,Element JavaDoc parent)
87   {
88     SaveTModel request = (SaveTModel)object;
89     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
90     AbstractHandler handler = null;
91
92     String JavaDoc generic = request.getGeneric();
93     if (generic != null)
94       element.setAttribute("generic",generic);
95
96     AuthInfo authInfo = request.getAuthInfo();
97     if (authInfo != null)
98     {
99       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
100       handler.marshal(authInfo,element);
101     }
102
103     Vector JavaDoc tModelVector = request.getTModelVector();
104     if ((tModelVector!=null) && (tModelVector.size() > 0))
105     {
106       handler = maker.lookup(TModelHandler.TAG_NAME);
107       for (int i=0; i<tModelVector.size(); i++)
108         handler.marshal((TModel)tModelVector.elementAt(i),element);
109     }
110
111     Vector JavaDoc urVector = request.getUploadRegisterVector();
112     if ((urVector!=null) && (urVector.size() > 0))
113     {
114       handler = maker.lookup(UploadRegisterHandler.TAG_NAME);
115       for (int i=0; i<urVector.size(); i++)
116         handler.marshal((UploadRegister)urVector.elementAt(i),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     HandlerMaker maker = HandlerMaker.getInstance();
132     AbstractHandler handler = maker.lookup(SaveTModelHandler.TAG_NAME);
133
134     Element JavaDoc parent = XMLUtils.newRootElement();
135     Element JavaDoc child = null;
136
137     AuthInfo authInfo = new AuthInfo();
138     authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726");
139
140     OverviewDoc overDoc = new OverviewDoc();
141     overDoc.setOverviewURL("http://www.sviens.com/service.html");
142     overDoc.addDescription(new Description("over-doc Descr"));
143     overDoc.addDescription(new Description("over-doc Descr Two","en"));
144
145     CategoryBag catBag = new CategoryBag();
146     catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue"));
147     catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2"));
148
149     IdentifierBag idBag = new IdentifierBag();
150     idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue"));
151     idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2"));
152
153     TModel tModel = new TModel();
154     tModel.setTModelKey("uuid:269855db-62eb-4862-8e5a-1b06f2753038");
155     tModel.setOperator("jUDDI");
156     tModel.setAuthorizedName("Steve Viens");
157     tModel.setName("jUDDI TModel");
158     tModel.addDescription(new Description("tModel whatever"));
159     tModel.addDescription(new Description("tModel whatever too","fr"));
160     tModel.setCategoryBag(catBag);
161     tModel.setIdentifierBag(idBag);
162     tModel.setOverviewDoc(overDoc);
163
164     SaveTModel request = new SaveTModel();
165     request.setAuthInfo(authInfo);
166     request.addTModel(tModel);
167     request.addTModel(tModel);
168     request.addUploadRegister(new UploadRegister("http://www.juddi.org/businessEntity.xml"));
169     request.addUploadRegister(new UploadRegister("http://www.sourceforge.net/businessService.xml"));
170     request.addUploadRegister(new UploadRegister("http://www.uddi.org/bindingTemplate.xml"));
171
172     System.out.println();
173
174     RegistryObject regObject = request;
175     handler.marshal(regObject,parent);
176     child = (Element JavaDoc)parent.getFirstChild();
177     parent.removeChild(child);
178     XMLUtils.writeXML(child,System.out);
179
180     System.out.println();
181
182     regObject = handler.unmarshal(child);
183     handler.marshal(regObject,parent);
184     child = (Element JavaDoc)parent.getFirstChild();
185     parent.removeChild(child);
186     XMLUtils.writeXML(child,System.out);
187   }
188 }
Popular Tags