KickJava   Java API By Example, From Geeks To Geeks.

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


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.KeyedReference;
22 import org.apache.juddi.datatype.RegistryObject;
23 import org.apache.juddi.datatype.response.AssertionStatusItem;
24 import org.apache.juddi.datatype.response.AssertionStatusReport;
25 import org.apache.juddi.datatype.response.CompletionStatus;
26 import org.apache.juddi.datatype.response.KeysOwned;
27 import org.apache.juddi.util.xml.XMLUtils;
28 import org.w3c.dom.Element JavaDoc;
29
30 /**
31  * @author Steve Viens (sviens@apache.org)
32  */

33 public class AssertionStatusReportHandler extends AbstractHandler
34 {
35   public static final String JavaDoc TAG_NAME = "assertionStatusReport";
36
37   private HandlerMaker maker = null;
38
39   protected AssertionStatusReportHandler(HandlerMaker maker)
40   {
41     this.maker = maker;
42   }
43
44   public RegistryObject unmarshal(Element JavaDoc element)
45   {
46     AssertionStatusReport obj = new AssertionStatusReport();
47     Vector JavaDoc nodeList = null;
48     AbstractHandler handler = null;
49
50     // We could use the generic attribute value to
51
// determine which version of UDDI was used to
52
// format the request XML. - Steve
53

54     // Attributes
55
obj.setGeneric(element.getAttribute("generic"));
56     obj.setOperator(element.getAttribute("operator"));
57
58     // We can ignore the xmlns attribute since we
59
// can always determine it's value using the
60
// "generic" attribute. - Steve
61

62     // Text Node Value
63
// {none}
64

65     // Child Elements
66
nodeList = XMLUtils.getChildElementsByTagName(element,AssertionStatusItemHandler.TAG_NAME);
67     for (int i=0; i<nodeList.size(); i++)
68     {
69       handler = maker.lookup(AssertionStatusItemHandler.TAG_NAME);
70       obj.addAssertionStatusItem((AssertionStatusItem)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i)));
71     }
72
73     return obj;
74   }
75
76   public void marshal(RegistryObject object,Element JavaDoc parent)
77   {
78     AssertionStatusReport report = (AssertionStatusReport)object;
79     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
80     AbstractHandler handler = null;
81
82     String JavaDoc generic = report.getGeneric();
83     if ((generic != null) && (generic.trim().length() > 0))
84     {
85       element.setAttribute("generic",generic);
86
87       if (generic.equals(IRegistry.UDDI_V1_GENERIC))
88         element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE);
89       else if (generic.equals(IRegistry.UDDI_V2_GENERIC))
90         element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE);
91       else if (generic.equals(IRegistry.UDDI_V3_GENERIC))
92         element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE);
93     }
94     else // Default to UDDI v2 values
95
{
96       element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC);
97       element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE);
98     }
99     
100     String JavaDoc operator = report.getOperator();
101     if (operator != null)
102       element.setAttribute("operator",operator);
103     else
104       element.setAttribute("operator","");
105     
106     Vector JavaDoc vector = report.getAssertionStatusItemVector();
107     if ((vector!=null) && (vector.size() > 0))
108     {
109       handler = maker.lookup(AssertionStatusItemHandler.TAG_NAME);
110       for (int i=0; i<vector.size(); i++)
111         handler.marshal((AssertionStatusItem)vector.elementAt(i),element);
112     }
113
114     parent.appendChild(element);
115   }
116
117
118   /***************************************************************************/
119   /***************************** TEST DRIVER *********************************/
120   /***************************************************************************/
121
122
123   public static void main(String JavaDoc args[])
124     throws Exception JavaDoc
125   {
126     HandlerMaker maker = HandlerMaker.getInstance();
127     AbstractHandler handler = maker.lookup(AssertionStatusReportHandler.TAG_NAME);
128     Element JavaDoc parent = XMLUtils.newRootElement();
129     Element JavaDoc child = null;
130
131     KeysOwned keysOwned = new KeysOwned();
132     keysOwned.setFromKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
133     keysOwned.setToKey("dfddb58c-4853-4a71-865c-f84509017cc7");
134
135     AssertionStatusItem item = new AssertionStatusItem();
136     item.setFromKey("986d9a16-5d4d-46cf-9fac-6bb80a7091f6");
137     item.setToKey("dd45a24c-74fc-4e82-80c2-f99cdc76d681");
138     item.setKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","Subsidiary","1"));
139     item.setCompletionStatus(new CompletionStatus(CompletionStatus.COMPLETE));
140     item.setKeysOwned(keysOwned);
141
142     AssertionStatusReport report = new AssertionStatusReport();
143     report.setGeneric("2.0");
144     report.setOperator("jUDDI.org");
145     report.addAssertionStatusItem(item);
146     report.addAssertionStatusItem(item);
147
148     System.out.println();
149
150     RegistryObject regObject = report;
151     handler.marshal(regObject,parent);
152     child = (Element JavaDoc)parent.getFirstChild();
153     parent.removeChild(child);
154     XMLUtils.writeXML(child,System.out);
155
156     System.out.println();
157
158     regObject = handler.unmarshal(child);
159     handler.marshal(regObject,parent);
160     child = (Element JavaDoc)parent.getFirstChild();
161     parent.removeChild(child);
162     XMLUtils.writeXML(child,System.out);
163   }
164 }
Popular Tags