KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.juddi.datatype.KeyedReference;
19 import org.apache.juddi.datatype.RegistryObject;
20 import org.apache.juddi.util.xml.XMLUtils;
21 import org.w3c.dom.Element JavaDoc;
22
23 /**
24  * "Knows about the creation and populating of KeyedReference objects.
25  * Returns KeyedReference."
26  *
27  * @author Steve Viens (sviens@apache.org)
28  */

29 public class KeyedReferenceHandler extends AbstractHandler
30 {
31   public static final String JavaDoc TAG_NAME = "keyedReference";
32
33   private HandlerMaker maker = null;
34
35   protected KeyedReferenceHandler(HandlerMaker maker)
36   {
37     this.maker = maker;
38   }
39
40   public RegistryObject unmarshal(Element JavaDoc element)
41   {
42     KeyedReference obj = new KeyedReference();
43
44     // Attributes
45
obj.setTModelKey(element.getAttribute("tModelKey"));
46     obj.setKeyName(element.getAttribute("keyName"));
47     obj.setKeyValue(element.getAttribute("keyValue"));
48
49     // Text Node Value
50
// {none}
51

52     // Child Elements
53
// {none}
54

55     return obj;
56   }
57
58   public void marshal(RegistryObject object,Element JavaDoc parent)
59   {
60     KeyedReference keyedRef = (KeyedReference)object;
61     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
62
63     String JavaDoc tModelKey = keyedRef.getTModelKey();
64     if (tModelKey != null)
65       element.setAttribute("tModelKey",tModelKey);
66
67     String JavaDoc keyName = keyedRef.getKeyName();
68     if (keyName != null)
69       element.setAttribute("keyName",keyName);
70
71     String JavaDoc keyValue = keyedRef.getKeyValue();
72     if (keyValue != null)
73       element.setAttribute("keyValue",keyValue);
74
75     parent.appendChild(element);
76   }
77
78
79   /***************************************************************************/
80   /***************************** TEST DRIVER *********************************/
81   /***************************************************************************/
82
83
84   public static void main(String JavaDoc args[])
85     throws Exception JavaDoc
86   {
87     HandlerMaker maker = HandlerMaker.getInstance();
88   AbstractHandler handler = maker.lookup(KeyedReferenceHandler.TAG_NAME);
89
90     Element JavaDoc parent = XMLUtils.newRootElement();
91     Element JavaDoc child = null;
92
93     KeyedReference keyedRef = new KeyedReference();
94     keyedRef.setTModelKey("uuid:3860b975-9e0c-4cec-bad6-87dfe00e3864");
95     keyedRef.setKeyName("idBagKeyName2");
96     keyedRef.setKeyValue("idBagKeyValue2");
97
98     System.out.println();
99
100     RegistryObject regObject = keyedRef;
101     handler.marshal(regObject,parent);
102     child = (Element JavaDoc)parent.getFirstChild();
103     parent.removeChild(child);
104     XMLUtils.writeXML(child,System.out);
105
106     System.out.println();
107
108     regObject = handler.unmarshal(child);
109     handler.marshal(regObject,parent);
110     child = (Element JavaDoc)parent.getFirstChild();
111     parent.removeChild(child);
112     XMLUtils.writeXML(child,System.out);
113   }
114 }
Popular Tags