KickJava   Java API By Example, From Geeks To Geeks.

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


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.KeyedReference;
21 import org.apache.juddi.datatype.RegistryObject;
22 import org.apache.juddi.datatype.assertion.PublisherAssertion;
23 import org.apache.juddi.util.xml.XMLUtils;
24 import org.w3c.dom.Element JavaDoc;
25
26 /**
27  * @author Steve Viens (sviens@apache.org)
28  * @author Anou Mana (anou_mana@users.sourceforge.net)
29  */

30 public class PublisherAssertionHandler extends AbstractHandler
31 {
32   public static final String JavaDoc TAG_NAME = "publisherAssertion";
33
34   private HandlerMaker maker = null;
35
36   protected PublisherAssertionHandler(HandlerMaker maker)
37   {
38     this.maker = maker;
39   }
40
41   public RegistryObject unmarshal(Element JavaDoc element)
42   {
43     PublisherAssertion obj = new PublisherAssertion();
44     Vector JavaDoc nodeList = null;
45     AbstractHandler handler = null;
46
47     // Child Elements
48
nodeList = XMLUtils.getChildElementsByTagName(element,"fromKey");
49     if (nodeList.size() > 0)
50     {
51       String JavaDoc fromKey = XMLUtils.getText((Element JavaDoc)nodeList.elementAt(0));
52       obj.setFromKey(fromKey);
53     }
54
55     nodeList = XMLUtils.getChildElementsByTagName(element,"toKey");
56     if (nodeList.size() > 0)
57     {
58       String JavaDoc toKey = XMLUtils.getText((Element JavaDoc)nodeList.elementAt(0));
59       obj.setToKey(toKey);
60     }
61
62     nodeList = XMLUtils.getChildElementsByTagName(element,KeyedReferenceHandler.TAG_NAME);
63     if (nodeList.size() > 0)
64     {
65       handler = maker.lookup(KeyedReferenceHandler.TAG_NAME);
66       obj.setKeyedReference((KeyedReference)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
67     }
68
69     return obj;
70   }
71
72   public void marshal(RegistryObject object,Element JavaDoc parent)
73   {
74     PublisherAssertion assertion = (PublisherAssertion)object;
75     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
76     AbstractHandler handler = null;
77
78     String JavaDoc fromKey = assertion.getFromKey();
79     if (fromKey != null)
80     {
81       Element JavaDoc fkElement = parent.getOwnerDocument().createElement("fromKey");
82       fkElement.appendChild(parent.getOwnerDocument().createTextNode(fromKey));
83       element.appendChild(fkElement);
84     }
85
86     String JavaDoc toKey = assertion.getToKey();
87     if (toKey != null)
88     {
89       Element JavaDoc tkElement = parent.getOwnerDocument().createElement("toKey");
90       tkElement.appendChild(parent.getOwnerDocument().createTextNode(toKey));
91       element.appendChild(tkElement);
92     }
93
94     KeyedReference keyedRef = assertion.getKeyedReference();
95     if (keyedRef != null)
96     {
97       handler = maker.lookup(KeyedReferenceHandler.TAG_NAME);
98       handler.marshal(keyedRef,element);
99     }
100
101     parent.appendChild(element);
102   }
103
104
105   /***************************************************************************/
106   /***************************** TEST DRIVER *********************************/
107   /***************************************************************************/
108
109
110   public static void main(String JavaDoc args[])
111     throws Exception JavaDoc
112   {
113     HandlerMaker maker = HandlerMaker.getInstance();
114     AbstractHandler handler = maker.lookup(PublisherAssertionHandler.TAG_NAME);
115     Element JavaDoc parent = XMLUtils.newRootElement();
116     Element JavaDoc child = null;
117
118     PublisherAssertion assertion = new PublisherAssertion();
119     assertion.setFromKey("b2f072e7-6013-4385-93b4-9c1c2ece1c8f");
120     assertion.setToKey("115be72d-0c04-4b5f-a729-79a522629c19");
121     assertion.setKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2"));
122
123     System.out.println();
124
125     RegistryObject regObject = assertion;
126     handler.marshal(regObject,parent);
127     child = (Element JavaDoc)parent.getFirstChild();
128     parent.removeChild(child);
129     XMLUtils.writeXML(child,System.out);
130
131     System.out.println();
132
133     regObject = handler.unmarshal(child);
134     handler.marshal(regObject,parent);
135     child = (Element JavaDoc)parent.getFirstChild();
136     parent.removeChild(child);
137     XMLUtils.writeXML(child,System.out);
138   }
139 }
Popular Tags