KickJava   Java API By Example, From Geeks To Geeks.

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


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.IRegistry;
21 import org.apache.juddi.datatype.RegistryObject;
22 import org.apache.juddi.datatype.business.BusinessEntityExt;
23 import org.apache.juddi.datatype.response.BusinessDetailExt;
24 import org.apache.juddi.util.xml.XMLUtils;
25 import org.w3c.dom.Element JavaDoc;
26
27 /**
28  * BusinessDetailExtHandler
29  *
30  * @author Steve Viens (sviens@apache.org)
31  */

32 public class BusinessDetailExtHandler extends AbstractHandler
33 {
34   public static final String JavaDoc TAG_NAME = "businessDetailExt";
35
36   private HandlerMaker maker = null;
37
38   protected BusinessDetailExtHandler(HandlerMaker maker)
39   {
40     this.maker = maker;
41   }
42
43   public RegistryObject unmarshal(Element JavaDoc element)
44   {
45     BusinessDetailExt obj = new BusinessDetailExt();
46     Vector JavaDoc nodeList = null;
47     AbstractHandler handler = null;
48
49     // We could use the generic attribute value to
50
// determine which version of UDDI was used to
51
// format the request XML. - Steve
52

53     // Attributes
54
obj.setGeneric(element.getAttribute("generic"));
55     obj.setOperator(element.getAttribute("operator"));
56
57     // We can ignore the xmlns attribute since we
58
// can always determine it's value using the
59
// "generic" attribute. - Steve
60

61     String JavaDoc truncValue = element.getAttribute("truncated");
62     if (truncValue != null)
63       obj.setTruncated(truncValue.equalsIgnoreCase("true"));
64
65     // Text Node Value
66
// {none}
67

68     // Child Elements
69
nodeList = XMLUtils.getChildElementsByTagName(element,BusinessEntityExtHandler.TAG_NAME);
70     for (int i=0; i<nodeList.size(); i++)
71     {
72       handler = maker.lookup(BusinessEntityExtHandler.TAG_NAME);
73       obj.addBusinessEntityExt((BusinessEntityExt)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i)));
74     }
75
76     return obj;
77   }
78
79   public void marshal(RegistryObject object,Element JavaDoc parent)
80   {
81     BusinessDetailExt detail = (BusinessDetailExt)object;
82     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
83     AbstractHandler handler = null;
84
85     String JavaDoc generic = detail.getGeneric();
86     if ((generic != null) && (generic.trim().length() > 0))
87     {
88       element.setAttribute("generic",generic);
89
90       if (generic.equals(IRegistry.UDDI_V1_GENERIC))
91         element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE);
92       else if (generic.equals(IRegistry.UDDI_V2_GENERIC))
93         element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE);
94       else if (generic.equals(IRegistry.UDDI_V3_GENERIC))
95         element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE);
96     }
97     else // Default to UDDI v2 values
98
{
99       element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC);
100       element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE);
101     }
102
103     String JavaDoc operator = detail.getOperator();
104     if (operator != null)
105       element.setAttribute("operator",operator);
106     else
107       element.setAttribute("operator","");
108
109     boolean truncated = detail.isTruncated();
110     if (truncated)
111       element.setAttribute("truncated","true");
112
113     Vector JavaDoc vector = detail.getBusinessEntityExtVector();
114     if ((vector!=null) && (vector.size() > 0))
115     {
116       handler = maker.lookup(BusinessEntityExtHandler.TAG_NAME);
117       for (int i=0; i < vector.size(); i++)
118         handler.marshal((BusinessEntityExt)vector.elementAt(i),element);
119     }
120
121     parent.appendChild(element);
122   }
123
124
125   /***************************************************************************/
126   /***************************** TEST DRIVER *********************************/
127   /***************************************************************************/
128
129
130   public static void main(String JavaDoc args[])
131     throws Exception JavaDoc
132   {
133   }
134 }
Popular Tags