KickJava   Java API By Example, From Geeks To Geeks.

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


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.Phone;
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 Phone objects.
25  * Returns Phone."
26  *
27  * @author Steve Viens (sviens@apache.org)
28  */

29 public class PhoneHandler extends AbstractHandler
30 {
31   public static final String JavaDoc TAG_NAME = "phone";
32
33   private HandlerMaker maker = null;
34
35   protected PhoneHandler(HandlerMaker maker)
36   {
37     this.maker = maker;
38   }
39
40   public RegistryObject unmarshal(Element JavaDoc element)
41   {
42     Phone obj = new Phone();
43
44     // Attributes
45
String JavaDoc useType = element.getAttribute("useType");
46     if ((useType != null) && (useType.trim().length() > 0))
47       obj.setUseType(useType);
48
49     // Text Node Value
50
obj.setValue(XMLUtils.getText(element));
51
52     // Child Elements
53
// {none}
54

55     return obj;
56   }
57
58   public void marshal(RegistryObject object,Element JavaDoc parent)
59   {
60     Phone phone = (Phone)object;
61     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
62
63     String JavaDoc useType = phone.getUseType();
64     if ((useType != null) && (useType.trim().length() > 0))
65       element.setAttribute("useType",useType);
66
67     String JavaDoc phoneValue = phone.getValue();
68     if (phoneValue != null)
69       element.appendChild(parent.getOwnerDocument().createTextNode(phoneValue));
70
71     parent.appendChild(element);
72   }
73 }
Popular Tags