View Javadoc

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;
19  
20  import org.apache.juddi.datatype.KeyedReference;
21  import org.apache.juddi.datatype.RegistryObject;
22  import org.apache.juddi.datatype.response.AssertionStatusItem;
23  import org.apache.juddi.datatype.response.AssertionStatusReport;
24  import org.apache.juddi.datatype.response.CompletionStatus;
25  import org.apache.juddi.datatype.response.KeysOwned;
26  import org.apache.juddi.util.xml.XMLUtils;
27  import org.w3c.dom.Element;
28  
29  /***
30   * @author Steve Viens (sviens@apache.org)
31   */
32  public class AssertionStatusReportHandler extends AbstractHandler
33  {
34    public static final String TAG_NAME = "assertionStatusReport";
35  
36    private HandlerMaker maker = null;
37  
38    protected AssertionStatusReportHandler(HandlerMaker maker)
39    {
40      this.maker = maker;
41    }
42  
43    public RegistryObject unmarshal(Element element)
44    {
45      AssertionStatusReport obj = new AssertionStatusReport();
46      Vector nodeList = null;
47      AbstractHandler handler = null;
48  
49      // We could use the generic attribute value to
50      // determine which version of UDDI was used to
51      // format the request XML. - Steve
52  
53      // Attributes
54      obj.setGeneric(element.getAttribute("generic"));
55      obj.setOperator(element.getAttribute("operator"));
56  
57      // We can ignore the xmlns attribute since we
58      // can always determine it's value using the
59      // "generic" attribute. - Steve
60  
61      // Text Node Value
62      // {none}
63  
64      // Child Elements
65      nodeList = XMLUtils.getChildElementsByTagName(element,AssertionStatusItemHandler.TAG_NAME);
66      for (int i=0; i<nodeList.size(); i++)
67      {
68        handler = maker.lookup(AssertionStatusItemHandler.TAG_NAME);
69        obj.addAssertionStatusItem((AssertionStatusItem)handler.unmarshal((Element)nodeList.elementAt(i)));
70      }
71  
72      return obj;
73    }
74  
75    public void marshal(RegistryObject object,Element parent)
76    {
77      AssertionStatusReport report = (AssertionStatusReport)object;
78      String generic = report.getGeneric();
79      generic = getGeneric(generic);
80      String namespace = getUDDINamespace(generic);
81      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
82      AbstractHandler handler = null;
83  
84      element.setAttribute("generic",generic);
85      
86      String operator = report.getOperator();
87      if (operator != null)
88        element.setAttribute("operator",operator);
89      else
90        element.setAttribute("operator","");
91      
92      Vector vector = report.getAssertionStatusItemVector();
93      if ((vector!=null) && (vector.size() > 0))
94      {
95        handler = maker.lookup(AssertionStatusItemHandler.TAG_NAME);
96        for (int i=0; i<vector.size(); i++)
97          handler.marshal((AssertionStatusItem)vector.elementAt(i),element);
98      }
99  
100     parent.appendChild(element);
101   }
102 
103 
104   /****************************************************************************/
105   /****************************** TEST DRIVER *********************************/
106   /****************************************************************************/
107 
108 
109   public static void main(String args[])
110     throws Exception
111   {
112     HandlerMaker maker = HandlerMaker.getInstance();
113     AbstractHandler handler = maker.lookup(AssertionStatusReportHandler.TAG_NAME);
114     Element parent = XMLUtils.newRootElement();
115     Element child = null;
116 
117     KeysOwned keysOwned = new KeysOwned();
118     keysOwned.setFromKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
119     keysOwned.setToKey("dfddb58c-4853-4a71-865c-f84509017cc7");
120 
121     AssertionStatusItem item = new AssertionStatusItem();
122     item.setFromKey("986d9a16-5d4d-46cf-9fac-6bb80a7091f6");
123     item.setToKey("dd45a24c-74fc-4e82-80c2-f99cdc76d681");
124     item.setKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","Subsidiary","1"));
125     item.setCompletionStatus(new CompletionStatus(CompletionStatus.COMPLETE));
126     item.setKeysOwned(keysOwned);
127 
128     AssertionStatusReport report = new AssertionStatusReport();
129     report.setGeneric("2.0");
130     report.setOperator("jUDDI.org");
131     report.addAssertionStatusItem(item);
132     report.addAssertionStatusItem(item);
133 
134     System.out.println();
135 
136     RegistryObject regObject = report;
137     handler.marshal(regObject,parent);
138     child = (Element)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)parent.getFirstChild();
147     parent.removeChild(child);
148     XMLUtils.writeXML(child,System.out);
149   }
150 }