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.Description;
21  import org.apache.juddi.datatype.OverviewDoc;
22  import org.apache.juddi.datatype.OverviewURL;
23  import org.apache.juddi.datatype.RegistryObject;
24  import org.apache.juddi.util.xml.XMLUtils;
25  import org.w3c.dom.Element;
26  
27  /***
28   * "Knows about the creation and populating of OverviewDoc objects.
29   * Returns OverviewDoc."
30   *
31   * @author Steve Viens (sviens@apache.org)
32   */
33  public class OverviewDocHandler extends AbstractHandler
34  {
35    public static final String TAG_NAME = "overviewDoc";
36  
37    private HandlerMaker maker = null;
38  
39    protected OverviewDocHandler(HandlerMaker maker)
40    {
41      this.maker = maker;
42    }
43  
44    public RegistryObject unmarshal(Element element)
45    {
46      OverviewDoc obj = new OverviewDoc();
47      Vector nodeList = null;
48      AbstractHandler handler = null;
49  
50      // Attributes
51      // {none}
52  
53      // Text Node Value
54      // {none}
55  
56      // Child Elements
57      nodeList = XMLUtils.getChildElementsByTagName(element,DescriptionHandler.TAG_NAME);
58      for (int i=0; i<nodeList.size(); i++)
59      {
60        handler = maker.lookup(DescriptionHandler.TAG_NAME);
61        Description descr = (Description)handler.unmarshal((Element)nodeList.elementAt(i));
62        if (descr != null)
63          obj.addDescription(descr);
64      }
65  
66      nodeList = XMLUtils.getChildElementsByTagName(element,OverviewURLHandler.TAG_NAME);
67      if (nodeList.size() > 0)
68      {
69        handler = maker.lookup(OverviewURLHandler.TAG_NAME);
70        obj.setOverviewURL((OverviewURL)handler.unmarshal((Element)nodeList.elementAt(0)));
71      }
72  
73      return obj;
74    }
75  
76    public void marshal(RegistryObject object,Element parent)
77    {
78      OverviewDoc overDoc = (OverviewDoc)object;
79      String generic = getGeneric(null);
80      String namespace = getUDDINamespace(generic);
81      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
82      AbstractHandler handler = null;
83  
84      Vector descrVector = overDoc.getDescriptionVector();
85      if ((descrVector!=null) && (descrVector.size() > 0))
86      {
87        handler = maker.lookup(DescriptionHandler.TAG_NAME);
88        for (int i=0; i < descrVector.size(); i++)
89          handler.marshal((Description)descrVector.elementAt(i),element);
90      }
91  
92      OverviewURL overURL = overDoc.getOverviewURL();
93      if (overURL != null)
94      {
95        handler = maker.lookup(OverviewURLHandler.TAG_NAME);
96        handler.marshal(overURL,element);
97      }
98  
99      parent.appendChild(element);
100   }
101 
102 
103   /****************************************************************************/
104   /****************************** TEST DRIVER *********************************/
105   /****************************************************************************/
106 
107 
108   public static void main(String args[])
109     throws Exception
110   {
111   }
112 }