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.CategoryBag;
21  import org.apache.juddi.datatype.Description;
22  import org.apache.juddi.datatype.KeyedReference;
23  import org.apache.juddi.datatype.Name;
24  import org.apache.juddi.datatype.OverviewDoc;
25  import org.apache.juddi.datatype.RegistryObject;
26  import org.apache.juddi.datatype.binding.AccessPoint;
27  import org.apache.juddi.datatype.binding.BindingTemplate;
28  import org.apache.juddi.datatype.binding.BindingTemplates;
29  import org.apache.juddi.datatype.binding.HostingRedirector;
30  import org.apache.juddi.datatype.binding.InstanceDetails;
31  import org.apache.juddi.datatype.binding.TModelInstanceDetails;
32  import org.apache.juddi.datatype.binding.TModelInstanceInfo;
33  import org.apache.juddi.datatype.service.BusinessService;
34  import org.apache.juddi.datatype.service.BusinessServices;
35  import org.apache.juddi.util.xml.XMLUtils;
36  import org.w3c.dom.Element;
37  
38  /***
39   * "Knows about the creation and populating of BusinessServices objects.
40   * Returns BusinessServices."
41   *
42   * @author Steve Viens (sviens@apache.org)
43   */
44  public class BusinessServicesHandler extends AbstractHandler
45  {
46    public static final String TAG_NAME = "businessServices";
47  
48    private HandlerMaker maker = null;
49  
50    protected BusinessServicesHandler(HandlerMaker maker)
51    {
52      this.maker = maker;
53    }
54  
55    public RegistryObject unmarshal(Element element)
56    {
57      BusinessServices obj = new BusinessServices();
58      Vector nodeList = null;
59      AbstractHandler handler = null;
60  
61      // Attributes
62      // {none}
63  
64      // Text Node Value
65      // {none}
66  
67      // Child Elements
68      nodeList = XMLUtils.getChildElementsByTagName(element,BusinessServiceHandler.TAG_NAME);
69      for (int i=0; i<nodeList.size(); i++)
70      {
71        handler = maker.lookup(BusinessServiceHandler.TAG_NAME);
72        obj.addBusinessService((BusinessService)handler.unmarshal((Element)nodeList.elementAt(i)));
73      }
74  
75      return obj;
76    }
77  
78    public void marshal(RegistryObject object,Element parent)
79    {
80      BusinessServices services = (BusinessServices)object;
81      String generic = getGeneric(null);
82      String namespace = getUDDINamespace(generic);
83      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
84      AbstractHandler handler = null;
85  
86      Vector serviceVector = services.getBusinessServiceVector();
87      if ((serviceVector!=null) && (serviceVector.size() > 0))
88      {
89        handler = maker.lookup(BusinessServiceHandler.TAG_NAME);
90        for (int i=0; i < serviceVector.size(); i++)
91          handler.marshal((BusinessService)serviceVector.elementAt(i),element);
92      }
93  
94      parent.appendChild(element);
95    }
96  
97  
98    /****************************************************************************/
99    /****************************** TEST DRIVER *********************************/
100   /****************************************************************************/
101 
102 
103   public static void main(String args[])
104     throws Exception
105   {
106     HandlerMaker maker = HandlerMaker.getInstance();
107     AbstractHandler handler = maker.lookup(BusinessServicesHandler.TAG_NAME);
108     Element parent = XMLUtils.newRootElement();
109     Element child = null;
110 
111     OverviewDoc overDoc = new OverviewDoc();
112     overDoc.setOverviewURL("http://www.sviens.com/service.html");
113     overDoc.addDescription(new Description("over-doc Descr"));
114     overDoc.addDescription(new Description("over-doc Descr Two","en"));
115 
116     InstanceDetails instDetails = new InstanceDetails();
117     instDetails.addDescription(new Description("body-isa-wunder"));
118     instDetails.addDescription(new Description("sweetchild-o-mine","it"));
119     instDetails.setInstanceParms("inst-det parameters");
120     instDetails.setOverviewDoc(overDoc);
121 
122     TModelInstanceInfo tModInstInfo = new TModelInstanceInfo();
123     tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9");
124     tModInstInfo.addDescription(new Description("tMod-Inst-Info"));
125     tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es"));
126     tModInstInfo.setInstanceDetails(instDetails);
127 
128     TModelInstanceDetails tModInstDet = new TModelInstanceDetails();
129     tModInstDet.addTModelInstanceInfo(tModInstInfo);
130 
131     BindingTemplate binding =  new BindingTemplate();
132     binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a");
133     binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31");
134     binding.addDescription(new Description("whatever"));
135     binding.addDescription(new Description("whatever too","fr"));
136     binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0"));
137     binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl"));
138     binding.setTModelInstanceDetails(tModInstDet);
139 
140     BindingTemplates bindings = new BindingTemplates();
141     bindings.addBindingTemplate(binding);
142 
143     CategoryBag catBag = new CategoryBag();
144     catBag.addKeyedReference(new KeyedReference("keyName","keyValue"));
145     catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","keyName2","keyValue2"));
146 
147     BusinessService service = new BusinessService();
148     service.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
149     service.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77");
150     service.setBindingTemplates(bindings);
151     service.setCategoryBag(catBag);
152     service.addName(new Name("serviceNm"));
153     service.addName(new Name("serviceNm2","en"));
154     service.addDescription(new Description("service whatever"));
155     service.addDescription(new Description("service whatever too","it"));
156 
157     BusinessServices services = new BusinessServices();
158     services.addBusinessService(service);
159     services.addBusinessService(service);
160 
161     System.out.println();
162 
163     RegistryObject regObject = services;
164     handler.marshal(regObject,parent);
165     child = (Element)parent.getFirstChild();
166     parent.removeChild(child);
167     XMLUtils.writeXML(child,System.out);
168 
169     System.out.println();
170 
171     regObject = handler.unmarshal(child);
172     handler.marshal(regObject,parent);
173     child = (Element)parent.getFirstChild();
174     parent.removeChild(child);
175     XMLUtils.writeXML(child,System.out);
176 
177     System.out.println();
178   }
179 }