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 java.util.Vector;
19  
20  import org.apache.juddi.datatype.Name;
21  import org.apache.juddi.datatype.RegistryObject;
22  import org.apache.juddi.datatype.response.PublisherInfo;
23  import org.apache.juddi.util.xml.XMLUtils;
24  import org.w3c.dom.Element;
25  
26  /***
27   * ServiceInfoHandler
28   *
29   * @author Steve Viens (sviens@apache.org)
30   * @author Anou Mana (anou_mana@users.sourceforge.net)
31   */
32  public class PublisherInfoHandler extends AbstractHandler
33  {
34    public static final String TAG_NAME = "publisherInfo";
35  
36    private HandlerMaker maker = null;
37  
38    protected PublisherInfoHandler(HandlerMaker maker)
39    {
40      this.maker = maker;
41    }
42  
43    public RegistryObject unmarshal(Element element)
44    {
45      PublisherInfo obj = new PublisherInfo();
46      Vector nodeList = null;
47      AbstractHandler handler = null;
48  
49      // Attributes
50      obj.setPublisherID(element.getAttribute("publisherID"));
51  
52      // Text Node Value
53      // {none}
54  
55      // Child Elements
56      nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME);
57      if (nodeList.size() > 0)
58      {
59        handler = maker.lookup(NameHandler.TAG_NAME);
60        Name name = (Name )handler.unmarshal((Element)nodeList.elementAt(0));
61        if (name != null)
62          obj.setName(name);    
63      }
64  
65      return obj;
66    }
67  
68    public void marshal(RegistryObject object,Element parent)
69    {
70      PublisherInfo info = (PublisherInfo)object;
71      String generic = getGeneric(null);
72      String namespace = getUDDINamespace(generic);
73      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
74      AbstractHandler handler = null;
75  
76      String publisherID = info.getPublisherID();
77      if (publisherID != null)
78        element.setAttribute("publisherID",publisherID);
79  
80      Name name = info.getName();
81      if (name != null)
82      {
83        handler = maker.lookup(NameHandler.TAG_NAME);
84        handler.marshal(name,element);
85      }
86  
87      parent.appendChild(element);
88    }
89  
90  
91    /****************************************************************************/
92    /****************************** TEST DRIVER *********************************/
93    /****************************************************************************/
94  
95  
96    public static void main(String args[])
97      throws Exception
98    {
99    }
100 }