This project has retired. For details please refer to its Attic page.
BPEL2UDDI xref
View Javadoc
1   /*
2    * Copyright 2001-2011 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   */
17  package org.apache.juddi.v3.client.mapping.wsdl;
18  
19  import org.apache.juddi.v3.client.mapping.Common2UDDI;
20  import java.net.MalformedURLException;
21  import java.net.URL;
22  import java.rmi.RemoteException;
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.Map;
26  import java.util.Properties;
27  import java.util.Set;
28  
29  import javax.wsdl.Binding;
30  import javax.wsdl.Definition;
31  import javax.wsdl.Port;
32  import javax.wsdl.PortType;
33  import javax.wsdl.Service;
34  import javax.wsdl.WSDLException;
35  import javax.xml.namespace.QName;
36  
37  import org.apache.commons.configuration.ConfigurationException;
38  import org.apache.commons.logging.Log;
39  import org.apache.commons.logging.LogFactory;
40  import org.apache.juddi.api_v3.AccessPointType;
41  import org.apache.juddi.jaxb.PrintUDDI;
42  import org.apache.juddi.v3.annotations.AnnotationProcessor;
43  import org.apache.juddi.v3.client.config.Property;
44  import org.apache.juddi.v3.client.config.UDDIClerk;
45  import org.apache.juddi.v3.client.config.UDDIKeyConvention;
46  import org.apache.juddi.v3.client.mapping.URLLocalizer;
47  import org.apache.juddi.v3.client.transport.TransportException;
48  import org.uddi.api_v3.AccessPoint;
49  import org.uddi.api_v3.BindingTemplate;
50  import org.uddi.api_v3.BusinessService;
51  import org.uddi.api_v3.CategoryBag;
52  import org.uddi.api_v3.FindBinding;
53  import org.uddi.api_v3.FindTModel;
54  import org.uddi.api_v3.GetTModelDetail;
55  import org.uddi.api_v3.InstanceDetails;
56  import org.uddi.api_v3.KeyedReference;
57  import org.uddi.api_v3.Name;
58  import org.uddi.api_v3.OverviewDoc;
59  import org.uddi.api_v3.OverviewURL;
60  import org.uddi.api_v3.TModel;
61  import org.uddi.api_v3.TModelBag;
62  import org.uddi.api_v3.TModelDetail;
63  import org.uddi.api_v3.TModelInfo;
64  import org.uddi.api_v3.TModelInstanceDetails;
65  import org.uddi.api_v3.TModelInstanceInfo;
66  import org.uddi.api_v3.TModelList;
67  import org.w3c.dom.Element;
68  
69  
70  /**
71   * BPEL4WS abstract processes describe the observable behavior of Web services. They 
72   * complement abstract WSDL interfaces (port types and operations) and the UDDI model 
73   * by defining dependencies between service operations in the context of a message 
74   * exchange. The technical note 'uddi-spec-tc-tn-bpel' describes the relationships 
75   * between the three models and suggests how BPEL4WS abstract processes can be used 
76   * in a UDDI Registry. This class implements the registrations suggestions as put 
77   * forward in the technote.
78   * 
79   * * @author Kurt T Stam <kurt.stam@apache.org>
80   *
81   */
82  public class BPEL2UDDI extends AnnotationProcessor {
83  	
84  	private Log log = LogFactory.getLog(this.getClass());
85  	
86  	private String keyDomainURI;
87  	private UDDIClerk clerk;
88  	private String lang;
89  	private URLLocalizer urlLocalizer;
90  	private String businessKey;
91  	private Properties properties = new Properties();
92  
93  	private WSDL2UDDI wsdl2UDDI;
94  	
95  	public BPEL2UDDI(UDDIClerk clerk, URLLocalizer urlLocalizer, Properties properties) throws ConfigurationException {
96  		super();
97  		
98  		this.clerk = clerk;
99  		this.urlLocalizer = urlLocalizer;
100 		this.properties = properties;
101 		
102 		//Obtaining values from the properties
103 		this.keyDomainURI = "uddi:" + properties.getProperty("keyDomain") + ":";
104 		this.businessKey = UDDIKeyConvention.getBusinessKey(properties);
105 		this.lang = properties.getProperty(Property.LANG,Property.DEFAULT_LANG);
106 		
107 		this.wsdl2UDDI = new WSDL2UDDI(clerk, urlLocalizer, properties);
108 	}
109 	
110 	public String getKeyDomainURI() {
111 		return keyDomainURI;
112 	}
113 
114 	public void setKeyDomainURI(String keyDomainURI) {
115 		this.keyDomainURI = keyDomainURI;
116 	}
117 	
118 	public UDDIClerk getClerk() {
119 		return clerk;
120 	}
121 
122 	public void setClerk(UDDIClerk clerk) {
123 		this.clerk = clerk;
124 	}
125 	
126 	public String getLang() {
127 		return lang;
128 	}
129 
130 	public void setLang(String lang) {
131 		this.lang = lang;
132 	}
133 	
134 	public URLLocalizer getUrlLocalizer() {
135 		return urlLocalizer;
136 	}
137 
138 	public void setUrlLocalizer(URLLocalizer urlLocalizer) {
139 		this.urlLocalizer = urlLocalizer;
140 	}
141 
142 	/**
143 	 * 1. Register PortType tModels
144 	 * 2. Register WSDL BPEL4WS Process
145 	 * 3. Register WSDL Port
146 	 * 4. Register Process Service
147 	 * 5. Register Binding
148 	 * 
149 	 * @param serviceName - QName of the service
150 	 * @param portName - portName of the service
151 	 * @param serviceUrl - URL at which the service can be invoked
152 	 * @param wsdlDefinition - WSDL Definition of the Web Service
153          * @return a binding template
154 	 * @throws WSDLException 
155 	 * @throws MalformedURLException 
156 	 * @throws TransportException 
157 	 * @throws ConfigurationException 
158 	 * @throws RemoteException 
159 	 */
160 	@SuppressWarnings("unchecked")
161 	public BindingTemplate register(QName serviceName, String portName, URL serviceUrl, Definition wsdlDefinition) 
162 		throws WSDLException, MalformedURLException, RemoteException, ConfigurationException, TransportException 
163 	{
164 		String targetNamespace = wsdlDefinition.getTargetNamespace();
165 		String genericWSDLURL  = wsdlDefinition.getDocumentBaseURI();   //TODO maybe point to repository version
166 		String bpelOverviewURL = "http://localhost:8080/bpel-console/"; //TODO maybe point to bpel in console
167 		
168 		String serviceKey = UDDIKeyConvention.getServiceKey(properties, serviceName.getLocalPart());
169 		BusinessService service = lookupService(serviceKey);
170 		if (service==null) {
171 			List<TModel> tModels = new ArrayList<TModel>();
172 			// Create the PortType tModels
173 			Map<QName,PortType> portTypes = (Map<QName,PortType>) wsdlDefinition.getAllPortTypes();
174 			tModels.addAll(createWSDLPortTypeTModels(genericWSDLURL, portTypes));
175 			// Create the Binding tModels
176 			Map<QName,Binding> bindings = (Map<QName,Binding>) wsdlDefinition.getAllBindings();
177 			tModels.addAll(createWSDLBindingTModels(genericWSDLURL, bindings));
178 			// Create the BPEL4WS tModel
179 			TModel bpel4WSTModel = createBPEL4WSProcessTModel(serviceName, targetNamespace, portTypes, bpelOverviewURL);
180 		    tModels.add(bpel4WSTModel);
181 		    // Register these tModels
182 		    for (TModel tModel : tModels) {
183 				clerk.register(tModel);
184 			}
185 		    // BPEL Service
186 		    service = createBusinessService(serviceName, wsdlDefinition);
187 		    // Register this BPEL Service
188 		    clerk.register(service);
189 		}
190 		//Add the BindingTemplate to this Service
191 		BindingTemplate binding = createBPELBinding(serviceName, portName, serviceUrl, wsdlDefinition);
192 		// Register BindingTemplate
193 		clerk.register(binding);
194 		return binding;
195 	}
196 	
197 	public String unRegister(QName serviceName, String portName, URL serviceUrl) throws RemoteException, ConfigurationException, TransportException {
198 		
199 		String serviceKey = UDDIKeyConvention.getServiceKey(properties, serviceName.getLocalPart());
200 		BusinessService service = lookupService(serviceKey);
201 		boolean isRemoveServiceIfNoTemplates = true; 
202 		String bindingKey = UDDIKeyConvention.getBindingKey(properties, serviceName, portName, serviceUrl);
203 		//check if this bindingKey is in the service's binding templates
204 		for (BindingTemplate bindingTemplate : service.getBindingTemplates().getBindingTemplate()) {
205 			if (bindingKey.equals(bindingTemplate.getBindingKey())) {
206 				clerk.unRegisterBinding(bindingKey);
207 				//if this is the last binding for this service, and 
208 				if (service.getBindingTemplates().getBindingTemplate().size()==1 && isRemoveServiceIfNoTemplates) {
209 					clerk.unRegisterService(serviceKey);
210 					
211 					FindTModel findTmodelForProcessName = createFindTModelForProcessName(serviceName);
212 					TModelList tModelList = clerk.findTModel(findTmodelForProcessName);
213 					if (tModelList!=null && tModelList.getTModelInfos()!=null && tModelList.getTModelInfos().getTModelInfo()!=null) {
214 						TModelInfo tModelInfo = tModelList.getTModelInfos().getTModelInfo().get(0);
215 						String bpel4WSTModelKey = tModelInfo.getTModelKey();
216 						clerk.unRegisterTModel(bpel4WSTModelKey);
217 						// now use this key to find the portType TModels
218 						GetTModelDetail findAllPortTypesForProcess = createFindAllPortTypesForProcess_1(bpel4WSTModelKey);
219 						TModelDetail tModelDetail = clerk.getTModelDetail(findAllPortTypesForProcess);
220 						if (tModelDetail!=null) {
221 							List<TModel> tModelPortTypeList = tModelDetail.getTModel();
222 							if (tModelPortTypeList!=null && tModelPortTypeList.size()>0) {
223 								TModel bpel4WSTModel = tModelPortTypeList.get(0);
224 								CategoryBag categoryBag = bpel4WSTModel.getCategoryBag();
225 								if (categoryBag!=null && categoryBag.getKeyedReference()!=null) {
226 									List<KeyedReference> portTypeTModelKeys = new ArrayList<KeyedReference>();
227 									KeyedReference namespaceRef = null;
228 									for (KeyedReference keyedReference : categoryBag.getKeyedReference()) {
229 										if ("uddi:uddi.org:wsdl:porttypereference".equals(keyedReference.getTModelKey()) ) {
230 											portTypeTModelKeys.add(keyedReference);
231 										}
232 										if ("uddi:uddi.org:xml:namespace".equals(keyedReference.getTModelKey()) ) {
233 											namespaceRef = keyedReference;
234 										}
235 									}
236 									String namespace = null;
237 									if (namespaceRef!=null) namespace = namespaceRef.getKeyValue();
238 									//find the bindingTModel
239 									for (KeyedReference keyedReference : portTypeTModelKeys) {
240 										FindTModel findBindingTModel = WSDL2UDDI.createFindBindingTModelForPortType(keyedReference.getKeyValue(), namespace);
241 										TModelList bindingTmodels = clerk.findTModel(findBindingTModel);
242 										if (bindingTmodels!=null && bindingTmodels.getTModelInfos()!=null && bindingTmodels.getTModelInfos().getTModelInfo()!=null) {
243 											for (TModelInfo bindingTModelInfo : bindingTmodels.getTModelInfos().getTModelInfo()) {
244 												//delete the Binding TModel
245 												clerk.unRegisterTModel(bindingTModelInfo.getTModelKey());
246 											}
247 										}
248 										//delete the PortType TModel
249 										clerk.unRegisterTModel(keyedReference.getKeyValue());	
250 									}
251  								}
252 							}
253 						}
254 					}
255 				}
256 				break;
257 			}
258 		}
259 		return service.getServiceKey();	
260 	}
261 	/**
262 	 * Perform a lookup by serviceKey, and will return null if not found.
263 	 * @param serviceKey
264 	 * @return a business service
265 	 * @throws RemoteException
266 	 * @throws ConfigurationException
267 	 * @throws TransportException
268 	 */
269 	public BusinessService lookupService(String serviceKey) throws RemoteException, ConfigurationException, TransportException {
270 		
271 		//Checking if this serviceKey already exist
272 		BusinessService service = clerk.getServiceDetail(serviceKey);
273 		return service;
274 	}
275 	/**
276 	 * Registers the Service into UDDI.
277 	 * 
278 	 * @param serviceName
279 	 * @param wsdlDefinition
280 	 * @return a business service
281 	 */
282 	public BusinessService createBusinessService(QName serviceName, Definition wsdlDefinition) {
283 		
284 		log.debug("Constructing Service UDDI Information for " + serviceName);
285 		BusinessService service = new BusinessService();
286 		// BusinessKey
287 		service.setBusinessKey(businessKey);
288 		// ServiceKey
289 		service.setServiceKey(UDDIKeyConvention.getServiceKey(properties, serviceName.getLocalPart()));
290 		// Description
291 		String serviceDescription = properties.getProperty(Property.SERVICE_DESCRIPTION, Property.DEFAULT_SERVICE_DESCRIPTION);
292 		if (wsdlDefinition.getService(serviceName) !=null) {
293 			// Override with the service description from the WSDL if present
294 			Element docElement = wsdlDefinition.getService(serviceName).getDocumentationElement();
295 			if (docElement!=null && docElement.getTextContent()!=null) {
296 				serviceDescription = docElement.getTextContent();
297 			}
298 		}
299 		
300 		service.getDescription().addAll(Common2UDDI.mapDescription(serviceDescription, lang));
301 		// Service name
302 		Name sName = new Name();
303 		sName.setLang(lang);
304 		sName.setValue(serviceName.getLocalPart());
305 		service.getName().add(sName);
306 		
307 		//customization to add KeyedReferences into the categoryBag of the service
308 		if (properties.containsKey(Property.SERVICE_CATEGORY_BAG)) {
309 			String serviceCategoryBag = properties.getProperty(Property.SERVICE_CATEGORY_BAG);
310 			log.debug("Adding KeyedReferences '" +  serviceCategoryBag + "' to service " + serviceName.getLocalPart());
311 			CategoryBag categoryBag = parseCategoryBag(serviceCategoryBag);
312 	        service.setCategoryBag(categoryBag);
313 		}
314 		
315 		return service;
316 	}
317 	
318 	public Set<TModel> createWSDLPortTypeTModels(String wsdlURL, Map<QName,PortType> portTypes) throws WSDLException 
319 	{
320 		return wsdl2UDDI.createWSDLPortTypeTModels(wsdlURL, portTypes);
321 	}
322 	
323 	public Set<TModel> createWSDLBindingTModels(String wsdlURL, Map<QName,Binding> bindings) throws WSDLException 
324 	{
325 		return wsdl2UDDI.createWSDLBindingTModels(wsdlURL, bindings);
326 	}
327 	
328 	/**
329 	 * BPEL4WS abstract processes are published as separate UDDI tModels. They are named with the BPEL4WS process 
330 	 * name. They are categorized as BPEL4WS process definitions, using a category system defined in this 
331 	 * technical note. Their overviewDoc references an external BPEL4WS document that contains the process definition.
332 	 * All WSDL portTypes that are used in the BPEL4WS process definition (via the referenced BPEL4WS partnerLinkTypes) 
333 	 * are published as portType tModels according to [WSDL2UDDI]. The process tModel references all such WSDL portType
334 	 * tModels, using the WSDL portType Reference tModel defined in [WSDL2UDDI]. Note that it is a characteristic 
335 	 * of the BPEL4WS process that it defines a conversation based on WSDL portTypes. Thus, the relationship 
336 	 * between process tModel and portType tModel is to be published by the process tModel publisher, not by 
337 	 * the portType tModel publisher, which may be a different person.
338 	 * 
339 	 * In the current implementation it is all registered by the same publisher. 
340 	 * 
341 	 * @param serviceName
342 	 * @param targetNamespace
343 	 * @param portTypes
344 	 * @param bpelOverviewURL
345 	 * @return tmodels
346 	 */
347     public TModel createBPEL4WSProcessTModel(QName serviceName, String targetNamespace, Map<QName,PortType> portTypes, String bpelOverviewURL) {
348     	TModel tModel = new TModel();
349     	// Set the Key
350     	tModel.setTModelKey(keyDomainURI + serviceName.getLocalPart() + "Process");
351     	// Set the Name
352     	Name name = new Name();
353     	name.setLang("en");
354     	name.setValue(serviceName.getLocalPart());
355     	tModel.setName(name);
356     	// Set the OverviewURL
357     	OverviewURL overviewURL = new OverviewURL();
358     	overviewURL.setValue("http://localhost:8080/bpel-console/"); //should point to the bpel of this process, maybe in guvnor
359     	OverviewDoc overviewDoc = new OverviewDoc();
360     	overviewDoc.setOverviewURL(overviewURL);
361     	tModel.getOverviewDoc().add(overviewDoc);
362     	// Set the categoryBag
363     	CategoryBag categoryBag = new CategoryBag();
364     	
365     	if (targetNamespace!=null) {
366     		KeyedReference namespaceReference = WSDL2UDDI.newKeyedReference(
367     			"uddi:uddi.org:xml:namespace", "uddi-org:xml:namespace", targetNamespace);
368     		categoryBag.getKeyedReference().add(namespaceReference);
369     	}
370     	KeyedReference typesReference = WSDL2UDDI.newKeyedReference(
371     			"uddi:uddi.org:bpel:types", "uddi-org:bpel:types", "process");
372     	categoryBag.getKeyedReference().add(typesReference);
373     	for (QName qName : portTypes.keySet()) {
374     		String portTypeKey = keyDomainURI + qName.getLocalPart();
375 	    	KeyedReference portTypeReference = WSDL2UDDI.newKeyedReference(
376 	    			"uddi:uddi.org:wsdl:porttypereference", "uddi-org:wsdl:portTypeReference", portTypeKey);
377 	    	categoryBag.getKeyedReference().add(portTypeReference);
378     	}
379     	
380     	tModel.setCategoryBag(categoryBag);
381     	
382     	if (log.isDebugEnabled()) {
383     		log.debug(new PrintUDDI<TModel>().print(tModel));
384     	}
385     	
386     	return tModel;
387     }
388     
389     public BindingTemplate createBPELBinding(QName serviceName, String portName, URL serviceUrl, Definition wsdlDefinition) {
390 		
391     	BindingTemplate bindingTemplate = new BindingTemplate();
392 		// Set BusinessService Key
393 		bindingTemplate.setServiceKey(UDDIKeyConvention.getServiceKey(properties, serviceName.getLocalPart()));
394 		// Set Binding Key
395 		String bindingKey = UDDIKeyConvention.getBindingKey(properties, serviceName, portName, serviceUrl);
396 		bindingTemplate.setBindingKey(bindingKey);
397 		// Set AccessPoint
398 		AccessPoint accessPoint = new AccessPoint();
399 		accessPoint.setUseType(AccessPointType.END_POINT.toString());
400 		accessPoint.setValue(urlLocalizer.rewrite(serviceUrl));
401 		bindingTemplate.setAccessPoint(accessPoint);
402 		
403 		Service service =  wsdlDefinition.getService(serviceName);
404 		
405 		if (service!=null) {
406 			TModelInstanceDetails tModelInstanceDetails = new TModelInstanceDetails();
407 			
408 			Port port = service.getPort(portName);
409 			if (port!=null) {
410 				Binding binding = port.getBinding();
411 				// Set the Binding Description
412 				String bindingDescription = properties.getProperty(Property.BINDING_DESCRIPTION, Property.DEFAULT_BINDING_DESCRIPTION);
413 				// Override with the service description from the WSDL if present
414 				Element docElement = binding.getDocumentationElement();
415 				if (docElement!=null && docElement.getTextContent()!=null) {
416 					bindingDescription = docElement.getTextContent();
417 				}
418 				
419 				bindingTemplate.getDescription().addAll(Common2UDDI.mapDescription(bindingDescription, lang));
420 				
421 				// reference wsdl:binding tModel
422 				TModelInstanceInfo tModelInstanceInfoBinding = new TModelInstanceInfo();
423 				tModelInstanceInfoBinding.setTModelKey(keyDomainURI + binding.getQName().getLocalPart());
424 				InstanceDetails instanceDetails = new InstanceDetails();
425 				instanceDetails.setInstanceParms(portName);  
426 				tModelInstanceInfoBinding.setInstanceDetails(instanceDetails);
427 				
428 				tModelInstanceInfoBinding.getDescription().addAll(Common2UDDI.mapDescription("The wsdl:binding that this wsdl:port implements. " + bindingDescription +
429 						" The instanceParms specifies the port local name.", lang));
430 				tModelInstanceDetails.getTModelInstanceInfo().add(tModelInstanceInfoBinding);
431 				
432 				// reference wsdl:portType tModel
433 				PortType portType = binding.getPortType();
434 				TModelInstanceInfo tModelInstanceInfoPortType = new TModelInstanceInfo();
435 				tModelInstanceInfoPortType.setTModelKey(keyDomainURI + portType.getQName().getLocalPart());
436 				String portTypeDescription = "";
437 				docElement = portType.getDocumentationElement();
438 				if (docElement!=null && docElement.getTextContent()!=null) {
439 					portTypeDescription = docElement.getTextContent();
440 				}
441 				
442 				tModelInstanceInfoPortType.getDescription().addAll(Common2UDDI.mapDescription("The wsdl:portType that this wsdl:port implements." + portTypeDescription, lang));
443 				tModelInstanceDetails.getTModelInstanceInfo().add(tModelInstanceInfoPortType);
444 				
445 				//reference bpel:process tModel
446 				TModelInstanceInfo tModelInstanceInfoBPEL = new TModelInstanceInfo();
447 				tModelInstanceInfoBPEL.setTModelKey(keyDomainURI + service.getQName().getLocalPart() + "Process");
448 				
449 				// Description
450 				String serviceDescription = properties.getProperty(Property.SERVICE_DESCRIPTION, Property.DEFAULT_SERVICE_DESCRIPTION);
451 				// Override with the service description from the WSDL if present
452 				docElement = wsdlDefinition.getService(serviceName).getDocumentationElement();
453 				if (docElement!=null && docElement.getTextContent()!=null) {
454 					serviceDescription = docElement.getTextContent();
455 				}
456 				
457 				tModelInstanceInfoBPEL.getDescription().addAll(Common2UDDI.mapDescription("The bpel:process this wsdl:port supports." + serviceDescription, lang));
458 				tModelInstanceDetails.getTModelInstanceInfo().add(tModelInstanceInfoBPEL);
459 				
460 				bindingTemplate.setTModelInstanceDetails(tModelInstanceDetails);
461 			} else {
462 				log.error("Could not find Port with portName: " + portName);
463 			}
464 		} else {
465 			log.error("Could not find Service with serviceName: " + serviceName.getLocalPart());
466 		}
467 		
468 		if (log.isDebugEnabled()) {
469     		log.debug(new PrintUDDI<BindingTemplate>().print(bindingTemplate));
470     	}
471 		
472 		return bindingTemplate;
473 	}
474     
475     /** Finds and returns ALL the tModels related to the process, so that i.e. they
476      * can be removed on undeployment of the service.
477      * 
478      * @param serviceName
479      * @return a tModel if found
480      */
481     public FindTModel createFindTModelForProcessName (QName serviceName) {
482     	
483     	FindTModel findTModel = new FindTModel();
484     	Name name = new Name();
485     	//name.setLang(lang);
486     	name.setValue(serviceName.getLocalPart());
487     	findTModel.setName(name);
488     	CategoryBag categoryBag = new CategoryBag();
489     	
490     	String namespace = serviceName.getNamespaceURI();
491     	if (namespace!=null && namespace.length()!=0) {
492     		KeyedReference namespaceReference = WSDL2UDDI.newKeyedReference(
493     			"uddi:uddi.org:xml:namespace", "uddi-org:xml:namespace", namespace);
494     		categoryBag.getKeyedReference().add(namespaceReference);
495     	}
496     	KeyedReference typesReference = WSDL2UDDI.newKeyedReference(
497     			"uddi:uddi.org:bpel:types", "uddi-org:bpel:types", "process");
498     	categoryBag.getKeyedReference().add(typesReference);
499     	findTModel.setCategoryBag(categoryBag);
500     	
501     	if (log.isDebugEnabled()) {
502     		log.debug(new PrintUDDI<FindTModel>().print(findTModel));
503     	}
504     	return findTModel;
505     }
506     /**
507      * Find all processes that use the given portType.
508      * 
509      * @param portTypeKey
510      * @return tmodel info
511      */
512     public FindTModel createFindProcessesForPortTypes(String portTypeKey) {
513     	FindTModel findTModel = new FindTModel();
514     	CategoryBag categoryBag = new CategoryBag();
515     	
516     	KeyedReference typesReference = WSDL2UDDI.newKeyedReference(
517     			"uddi:uddi.org:bpel:types", "uddi-org:bpel:types", "process");
518     	categoryBag.getKeyedReference().add(typesReference);
519     	
520     	KeyedReference portTypeReference = WSDL2UDDI.newKeyedReference(
521     			"uddi:uddi.org:wsdl:porttypereference", "uddi-org:wsdl:portTypeReference", portTypeKey);
522     	categoryBag.getKeyedReference().add(portTypeReference);
523     	
524     	findTModel.setCategoryBag(categoryBag);
525     	
526     	return findTModel;
527     }
528     /**
529      * Find all portTypes used in the given process. This should return the 
530      * tModel registration for the process tModel. The tModelKeys for the 
531      * portTypes used in the process can be obtained from the process tModels 
532      * categoryBag, and passed into the second call.
533      * 
534      * @param processKey
535      * @return GetTModelDetail
536      */
537     public GetTModelDetail createFindAllPortTypesForProcess_1(String processKey) {
538     	GetTModelDetail getTModelDetail = new GetTModelDetail();
539     	getTModelDetail.getTModelKey().add(processKey);
540     	return getTModelDetail;
541     }
542     /**
543      * Once retrieved, the second call is made to get the tModel registrations 
544      * for the portTypes with the keys found in the first step.
545      * 
546      * @param portTypeTModelKeys - List of portType tModels found in the first step.
547      * @return GetTModelDetail
548      */
549     public GetTModelDetail createFindAllPortTypesForProcess_2(List<String> portTypeTModelKeys) {
550     	GetTModelDetail getTModelDetail = new GetTModelDetail();
551     	for (String tModelKey : portTypeTModelKeys) {
552     		getTModelDetail.getTModelKey().add(tModelKey);
553     	}
554     	return getTModelDetail;
555     }
556     /**
557      * Find all implementations of the given process.
558      * @param processKey
559      * @return FindBinding
560      */
561     public FindBinding createFindImplementationsForProcess(String processKey) {
562     	FindBinding findBinding = new FindBinding();
563     	TModelBag tModelBag = new TModelBag();
564     	tModelBag.getTModelKey().add(processKey);
565     	return findBinding;
566     }
567 	
568 }