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