KickJava   Java API By Example, From Geeks To Geeks.

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


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.RegistryObject;
21 import org.apache.juddi.datatype.request.AuthInfo;
22 import org.apache.juddi.datatype.request.GetAssertionStatusReport;
23 import org.apache.juddi.datatype.response.CompletionStatus;
24 import org.apache.juddi.util.xml.XMLUtils;
25 import org.w3c.dom.Element JavaDoc;
26
27 /**
28  * @author Steve Viens (sviens@apache.org)
29  */

30 public class GetAssertionStatusReportHandler extends AbstractHandler
31 {
32   public static final String JavaDoc TAG_NAME = "get_assertionStatusReport";
33
34   private HandlerMaker maker = null;
35
36   protected GetAssertionStatusReportHandler(HandlerMaker maker)
37   {
38     this.maker = maker;
39   }
40
41   public RegistryObject unmarshal(Element JavaDoc element)
42   {
43     GetAssertionStatusReport obj = new GetAssertionStatusReport();
44     Vector JavaDoc nodeList = null;
45     AbstractHandler handler = null;
46
47     // Attributes
48
String JavaDoc generic = element.getAttribute("generic");
49     if ((generic != null && (generic.trim().length() > 0)))
50       obj.setGeneric(generic);
51
52     // Text Node Value
53
// {none}
54

55     // Child Elements
56
nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME);
57     if (nodeList.size() > 0)
58     {
59       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
60       obj.setAuthInfo((AuthInfo)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
61     }
62
63     nodeList = XMLUtils.getChildElementsByTagName(element,CompletionStatusHandler.TAG_NAME);
64     if (nodeList.size() > 0)
65     {
66       handler = maker.lookup(CompletionStatusHandler.TAG_NAME);
67       obj.setCompletionStatus((CompletionStatus)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
68     }
69
70     return obj;
71   }
72
73   public void marshal(RegistryObject object,Element JavaDoc parent)
74   {
75     GetAssertionStatusReport request = (GetAssertionStatusReport)object;
76     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
77     AbstractHandler handler = null;
78
79     String JavaDoc generic = request.getGeneric();
80     if (generic != null)
81       element.setAttribute("generic",generic);
82
83     AuthInfo authInfo = request.getAuthInfo();
84     if (authInfo != null)
85     {
86       handler = maker.lookup(AuthInfoHandler.TAG_NAME);
87       handler.marshal(authInfo,element);
88     }
89
90     String JavaDoc status = request.getCompletionStatus();
91     if (status != null)
92     {
93       handler = maker.lookup(CompletionStatusHandler.TAG_NAME);
94       handler.marshal(new CompletionStatus(status),element);
95     }
96
97     parent.appendChild(element);
98   }
99
100
101   /***************************************************************************/
102   /***************************** TEST DRIVER *********************************/
103   /***************************************************************************/
104
105
106   public static void main(String JavaDoc args[])
107     throws Exception JavaDoc
108   {
109     HandlerMaker maker = HandlerMaker.getInstance();
110     AbstractHandler handler = maker.lookup(GetAssertionStatusReportHandler.TAG_NAME);
111
112     Element JavaDoc parent = XMLUtils.newRootElement();
113     Element JavaDoc child = null;
114
115     AuthInfo authInfo = new AuthInfo();
116     authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726");
117
118     GetAssertionStatusReport service = new GetAssertionStatusReport();
119     service.setAuthInfo(authInfo);
120     service.setCompletionStatus(CompletionStatus.COMPLETE);
121
122     System.out.println();
123
124     RegistryObject regObject = service;
125     handler.marshal(regObject,parent);
126     child = (Element JavaDoc)parent.getFirstChild();
127     parent.removeChild(child);
128     XMLUtils.writeXML(child,System.out);
129
130     System.out.println();
131
132     regObject = handler.unmarshal(child);
133     handler.marshal(regObject,parent);
134     child = (Element JavaDoc)parent.getFirstChild();
135     parent.removeChild(child);
136     XMLUtils.writeXML(child,System.out);
137   }
138 }
Popular Tags