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 org.apache.juddi.datatype.RegistryObject;
19  import org.apache.juddi.datatype.binding.InstanceParms;
20  import org.apache.juddi.util.xml.XMLUtils;
21  import org.w3c.dom.Element;
22  
23  /***
24   * "Knows about the creation and populating of InstanceParms objects.
25   * Returns InstanceParms."
26   *
27   * @author Steve Viens (sviens@apache.org)
28   */
29  public class InstanceParmsHandler extends AbstractHandler
30  {
31    public static final String TAG_NAME = "instanceParms";
32  
33    protected InstanceParmsHandler(HandlerMaker maker)
34    {
35    }
36  
37    public RegistryObject unmarshal(Element element)
38    {
39      InstanceParms obj = new InstanceParms();
40  
41      // Attributes
42      // {none}
43  
44      // Text Node Value
45      obj.setText(XMLUtils.getText(element));
46  
47      // Child Elements
48      // {nonoe}
49  
50      return obj;
51    }
52  
53    public void marshal(RegistryObject object,Element parent)
54    {
55      InstanceParms parms = (InstanceParms)object;
56      String generic = getGeneric(null);
57      String namespace = getUDDINamespace(generic);
58      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
59  
60      String parmsValue = parms.getValue();
61      if (parmsValue != null)
62        element.appendChild(parent.getOwnerDocument().createTextNode(parmsValue));
63  
64      parent.appendChild(element);
65    }
66  
67  
68    /****************************************************************************/
69    /****************************** TEST DRIVER *********************************/
70    /****************************************************************************/
71  
72  
73    public static void main(String args[])
74      throws Exception
75    {
76      HandlerMaker maker = HandlerMaker.getInstance();
77    AbstractHandler handler = maker.lookup(InstanceParmsHandler.TAG_NAME);
78      Element parent = XMLUtils.newRootElement();
79      Element child = null;
80  
81      InstanceParms instParms = new InstanceParms();
82      instParms.setText("iParms-whatever");
83  
84      System.out.println();
85  
86      RegistryObject regObject = instParms;
87      handler.marshal(regObject,parent);
88      child = (Element)parent.getFirstChild();
89      parent.removeChild(child);
90      XMLUtils.writeXML(child,System.out);
91  
92      System.out.println();
93  
94      regObject = handler.unmarshal(child);
95      handler.marshal(regObject,parent);
96      child = (Element)parent.getFirstChild();
97      parent.removeChild(child);
98      XMLUtils.writeXML(child,System.out);
99    }
100 }