KickJava   Java API By Example, From Geeks To Geeks.

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


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 JavaDoc;
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 JavaDoc TAG_NAME = "name";
33
34   private HandlerMaker maker = null;
35
36   protected NameHandler(HandlerMaker maker)
37   {
38     this.maker = maker;
39   }
40
41   public RegistryObject unmarshal(Element JavaDoc element)
42   {
43     // Attributes
44
String JavaDoc langCode = element.getAttribute("xml:lang");
45
46     // Text Node Value
47
String JavaDoc nameValue = XMLUtils.getText(element);
48
49     // Child Elements
50
// {none}
51

52     // Only create Name instance if nameValue not null and not zero-length
53
Name obj = null;
54     if ((nameValue != null) && (nameValue.trim().length() > 0))
55       obj = new Name(nameValue,langCode);
56     
57     return obj;
58   }
59
60   public void marshal(RegistryObject object,Element JavaDoc parent)
61   {
62     Name name = (Name)object;
63     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
64
65     String JavaDoc langCode = name.getLanguageCode();
66     if ((langCode != null) && (langCode.trim().length() > 0))
67       element.setAttribute("xml:lang",langCode);
68
69     String JavaDoc nameValue = name.getValue();
70     if (nameValue != null)
71       element.appendChild(parent.getOwnerDocument().createTextNode(nameValue));
72
73     parent.appendChild(element);
74   }
75
76
77   /***************************************************************************/
78   /***************************** TEST DRIVER *********************************/
79   /***************************************************************************/
80
81
82   public static void main(String JavaDoc args[])
83     throws Exception JavaDoc
84   {
85   }
86 }
Popular Tags