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.Phone;
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 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 TAG_NAME = "phone";
32  
33    protected PhoneHandler(HandlerMaker maker)
34    {
35    }
36  
37    public RegistryObject unmarshal(Element element)
38    {
39      Phone obj = new Phone();
40  
41      // Attributes
42      String useType = element.getAttribute("useType");
43      if ((useType != null) && (useType.trim().length() > 0))
44        obj.setUseType(useType);
45  
46      // Text Node Value
47      obj.setValue(XMLUtils.getText(element));
48  
49      // Child Elements
50      // {none}
51  
52      return obj;
53    }
54  
55    public void marshal(RegistryObject object,Element parent)
56    {
57      Phone phone = (Phone)object;
58      String generic = getGeneric(null);
59      String namespace = getUDDINamespace(generic);
60      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
61  
62      String useType = phone.getUseType();
63      if ((useType != null) && (useType.trim().length() > 0))
64        element.setAttribute("useType",useType);
65  
66      String phoneValue = phone.getValue();
67      if (phoneValue != null)
68        element.appendChild(parent.getOwnerDocument().createTextNode(phoneValue));
69  
70      parent.appendChild(element);
71    }
72  }