KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > handler > TModelInstanceInfoHandler


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 JavaDoc;
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 JavaDoc;
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 JavaDoc 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 JavaDoc element)
43   {
44     TModelInstanceInfo obj = new TModelInstanceInfo();
45     Vector JavaDoc 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 JavaDoc)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 JavaDoc)nodeList.elementAt(i)));
69     }
70
71     return obj;
72   }
73
74   public void marshal(RegistryObject object,Element JavaDoc parent)
75   {
76     TModelInstanceInfo tModInstInfo = (TModelInstanceInfo)object;
77     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
78     AbstractHandler handler = null;
79
80     String JavaDoc tModelKey = tModInstInfo.getTModelKey();
81     if (tModelKey != null)
82       element.setAttribute("tModelKey",tModelKey);
83
84   Vector JavaDoc descrVector = tModInstInfo.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    InstanceDetails instDet = tModInstInfo.getInstanceDetails();
93     if (instDet != null)
94     {
95       handler = maker.lookup(InstanceDetailsHandler.TAG_NAME);
96       handler.marshal(instDet,element);
97     }
98
99     parent.appendChild(element);
100   }
101
102
103   /***************************************************************************/
104   /***************************** TEST DRIVER *********************************/
105   /***************************************************************************/
106
107
108   public static void main(String JavaDoc args[])
109     throws Exception JavaDoc
110   {
111   }
112 }
Popular Tags