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.Description;
19  import org.apache.juddi.datatype.RegistryObject;
20  import org.apache.juddi.util.xml.XMLUtils;
21  import org.w3c.dom.Element;
22  
23  /***
24   * "Knows about the creation and populating of Description objects.
25   * Returns Description."
26   *
27   * @author Steve Viens (sviens@apache.org)
28   */
29  public class DescriptionHandler extends AbstractHandler
30  {
31    public static final String TAG_NAME = "description";
32  
33    protected DescriptionHandler(HandlerMaker maker)
34    {
35    }
36  
37    public RegistryObject unmarshal(Element element)
38    {   
39      // Attributes
40      String langCode = element.getAttribute("xml:lang");
41  
42      // Text Node Value
43      String descValue = XMLUtils.getText(element);
44  
45      // Child Elements
46      // {none}
47  
48      // Only create Description instance if descValue not null and not zero-length
49      Description obj = null;
50      if ((descValue != null) && (descValue.trim().length() > 0)) 
51        obj = new Description(descValue,langCode);
52      
53      return obj;
54    }
55  
56    public void marshal(RegistryObject object,Element parent)
57    {
58      Description descr = (Description)object;
59      String generic = getGeneric(null);
60      String namespace = getUDDINamespace(generic);
61      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
62  
63      String langCode = descr.getLanguageCode();
64      if ((langCode != null) && (langCode.trim().length() > 0))
65        element.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:lang",langCode);
66  
67      String descrValue = descr.getValue();
68      if (descrValue != null)
69        element.appendChild(parent.getOwnerDocument().createTextNode(descrValue));
70  
71      parent.appendChild(element);
72    }
73  
74  
75    /****************************************************************************/
76    /****************************** TEST DRIVER *********************************/
77    /****************************************************************************/
78  
79  
80    public static void main(String args[])
81      throws Exception
82    {
83    }
84  }