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