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.RegistryObject;
22  import org.apache.juddi.datatype.binding.InstanceDetails;
23  import org.apache.juddi.datatype.binding.TModelInstanceInfo;
24  import org.apache.juddi.util.xml.XMLUtils;
25  import org.w3c.dom.Element;
26  
27  /***
28   * @author Steve Viens (sviens@apache.org)
29   * @author Anou Mana (anou_mana@users.sourceforge.net)
30   */
31  public class TModelInstanceInfoHandler extends AbstractHandler
32  {
33    public static final String TAG_NAME = "tModelInstanceInfo";
34  
35    private HandlerMaker maker = null;
36  
37    protected TModelInstanceInfoHandler(HandlerMaker maker)
38    {
39      this.maker = maker;
40    }
41  
42    public RegistryObject unmarshal(Element element)
43    {
44      TModelInstanceInfo obj = new TModelInstanceInfo();
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,DescriptionHandler.TAG_NAME);
56      for (int i=0; i<nodeList.size(); i++)
57      {
58        handler = maker.lookup(DescriptionHandler.TAG_NAME);
59        Description descr = (Description)handler.unmarshal((Element)nodeList.elementAt(i));
60        if (descr != null)
61          obj.addDescription(descr);
62      }
63  
64      nodeList = XMLUtils.getChildElementsByTagName(element,InstanceDetailsHandler.TAG_NAME);
65      for (int i=0; i<nodeList.size(); i++)
66      {
67        handler = maker.lookup(InstanceDetailsHandler.TAG_NAME);
68        obj.setInstanceDetails((InstanceDetails)handler.unmarshal((Element)nodeList.elementAt(i)));
69      }
70  
71      return obj;
72    }
73  
74    public void marshal(RegistryObject object,Element parent)
75    {
76      TModelInstanceInfo tModInstInfo = (TModelInstanceInfo)object;
77      String generic = getGeneric(null);
78      String namespace = getUDDINamespace(generic);
79      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
80      AbstractHandler handler = null;
81  
82      String tModelKey = tModInstInfo.getTModelKey();
83      if (tModelKey != null)
84        element.setAttribute("tModelKey",tModelKey);
85  
86    Vector descrVector = tModInstInfo.getDescriptionVector();
87    if ((descrVector!=null) && (descrVector.size() > 0))
88    {
89      handler = maker.lookup(DescriptionHandler.TAG_NAME);
90      for (int i=0; i < descrVector.size(); i++)
91      handler.marshal((Description)descrVector.elementAt(i),element);
92    }
93  
94     InstanceDetails instDet = tModInstInfo.getInstanceDetails();
95      if (instDet != null)
96      {
97        handler = maker.lookup(InstanceDetailsHandler.TAG_NAME);
98        handler.marshal(instDet,element);
99      }
100 
101     parent.appendChild(element);
102   }
103 
104 
105   /****************************************************************************/
106   /****************************** TEST DRIVER *********************************/
107   /****************************************************************************/
108 
109 
110   public static void main(String args[])
111     throws Exception
112   {
113   }
114 }