KickJava   Java API By Example, From Geeks To Geeks.

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


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

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