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 javax.xml.soap.SOAPElement;
21  //import javax.xml.soap.SOAPException;
22  
23  import org.apache.juddi.datatype.RegistryObject;
24  import org.apache.juddi.datatype.response.KeysOwned;
25  import org.apache.juddi.util.xml.XMLUtils;
26  import org.w3c.dom.Element;
27  
28  /***
29   * @author Steve Viens (sviens@apache.org)
30   */
31  public class KeysOwnedHandler extends AbstractHandler
32  {
33    public static final String TAG_NAME = "keysOwned";
34    private static final String FROM_KEY_TAG_NAME = "fromKey";
35    private static final String TO_KEY_TAG_NAME = "toKey";
36  
37    protected KeysOwnedHandler(HandlerMaker maker)
38    {
39    }
40  
41    public RegistryObject unmarshal(Element element)
42    {
43      KeysOwned obj = new KeysOwned();
44      Vector nodeList = null;
45  
46      // Attributes
47      // {none}
48  
49      // Text Node Value
50      // {none}
51  
52      // Child Elements
53      nodeList = XMLUtils.getChildElementsByTagName(element,FROM_KEY_TAG_NAME);
54      if (nodeList.size() > 0)
55      {
56        Element keyElement = (Element)nodeList.elementAt(0);
57        obj.setFromKey(XMLUtils.getText(keyElement));
58      }
59  
60      nodeList = XMLUtils.getChildElementsByTagName(element,TO_KEY_TAG_NAME);
61      if (nodeList.size() > 0)
62      {
63        Element keyElement = (Element)nodeList.elementAt(0);
64        obj.setToKey(XMLUtils.getText(keyElement));
65      }
66  
67      return obj;
68    }
69  
70    public void marshal(RegistryObject object,Element parent)
71    {
72      KeysOwned keysOwned = (KeysOwned)object;
73      String generic = getGeneric(null);
74      String namespace = getUDDINamespace(generic);
75      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
76  
77      String fromKey = keysOwned.getFromKey();
78      if ((fromKey != null) && (fromKey.length() > 0))
79      {
80        Element keyElement = parent.getOwnerDocument().createElement(FROM_KEY_TAG_NAME);
81        keyElement.appendChild(parent.getOwnerDocument().createTextNode(fromKey));
82        element.appendChild(keyElement);
83      }
84  
85      String toKey = keysOwned.getToKey();
86      if ((toKey != null) && (toKey.length() > 0))
87      {
88        Element keyElement = parent.getOwnerDocument().createElement(TO_KEY_TAG_NAME);
89        keyElement.appendChild(parent.getOwnerDocument().createTextNode(toKey));
90        element.appendChild(keyElement);
91      }
92  
93      parent.appendChild(element);
94    }
95  
96  /*  
97    public RegistryObject unmarshal(SOAPElement element)
98    {
99      return null;
100   }
101 
102   public void marshal(RegistryObject object,SOAPElement parent)
103     throws SOAPException
104   {
105   }
106 */
107 
108   /****************************************************************************/
109   /****************************** TEST DRIVER *********************************/
110   /****************************************************************************/
111 
112 
113   public static void main(String args[])
114     throws Exception
115   {
116   }
117 }