KickJava   Java API By Example, From Geeks To Geeks.

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


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.OverviewDoc;
22 import org.apache.juddi.datatype.RegistryObject;
23 import org.apache.juddi.datatype.binding.InstanceDetails;
24 import org.apache.juddi.datatype.binding.InstanceParms;
25 import org.apache.juddi.util.xml.XMLUtils;
26 import org.w3c.dom.Element JavaDoc;
27
28 /**
29  * "Knows about the creation and populating of InstanceDetails objects.
30  * Returns InstanceDetails."
31  *
32  * @author Steve Viens (sviens@apache.org)
33  */

34 public class InstanceDetailsHandler extends AbstractHandler
35 {
36   public static final String JavaDoc TAG_NAME = "instanceDetails";
37
38   private HandlerMaker maker = null;
39
40   protected InstanceDetailsHandler(HandlerMaker maker)
41   {
42     this.maker = maker;
43   }
44
45   public RegistryObject unmarshal(Element JavaDoc element)
46   {
47     InstanceDetails obj = new InstanceDetails();
48     Vector JavaDoc nodeList = null;
49     AbstractHandler handler = null;
50
51     // Attributes
52
// {none}
53

54     // Text Node Value
55
// {none}
56

57     // Child Elements
58
nodeList = XMLUtils.getChildElementsByTagName(element,DescriptionHandler.TAG_NAME);
59     for (int i=0; i<nodeList.size(); i++)
60     {
61       handler = maker.lookup(DescriptionHandler.TAG_NAME);
62       Description descr = (Description)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i));
63       if (descr != null)
64         obj.addDescription(descr);
65     }
66
67     nodeList = XMLUtils.getChildElementsByTagName(element,OverviewDocHandler.TAG_NAME);
68     if (nodeList.size() > 0)
69     {
70       handler = maker.lookup(OverviewDocHandler.TAG_NAME);
71       obj.setOverviewDoc((OverviewDoc)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
72     }
73
74     nodeList = XMLUtils.getChildElementsByTagName(element,InstanceParmsHandler.TAG_NAME);
75     if (nodeList.size() > 0)
76     {
77       handler = maker.lookup(InstanceParmsHandler.TAG_NAME);
78       obj.setInstanceParms((InstanceParms)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
79     }
80
81     return obj;
82   }
83
84   public void marshal(RegistryObject object,Element JavaDoc parent)
85   {
86     InstanceDetails instDet = (InstanceDetails)object;
87     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
88     AbstractHandler handler = null;
89
90   Vector JavaDoc descrVector = instDet.getDescriptionVector();
91   if ((descrVector!=null) && (descrVector.size() > 0))
92   {
93     handler = maker.lookup(DescriptionHandler.TAG_NAME);
94     for (int i=0; i < descrVector.size(); i++)
95     handler.marshal((Description)descrVector.elementAt(i),element);
96   }
97
98     OverviewDoc overDoc = instDet.getOverviewDoc();
99     if (overDoc != null)
100     {
101       handler = maker.lookup(OverviewDocHandler.TAG_NAME);
102       handler.marshal(overDoc,element);
103     }
104
105   InstanceParms instanceParms = instDet.getInstanceParms();
106   if (instanceParms != null)
107   {
108     handler = maker.lookup(InstanceParmsHandler.TAG_NAME);
109     handler.marshal(instanceParms,element);
110   }
111
112     parent.appendChild(element);
113   }
114
115
116   /***************************************************************************/
117   /***************************** TEST DRIVER *********************************/
118   /***************************************************************************/
119
120
121   public static void main(String JavaDoc args[])
122     throws Exception JavaDoc
123   {
124   }
125 }
Popular Tags