This project has retired. For details please refer to its Attic page.
AsyncRegistration xref
View Javadoc
1   /*
2    * Copyright 2001-2010 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;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  import java.util.Properties;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.juddi.v3.client.config.UDDIClerk;
26  import org.apache.juddi.v3.client.mapping.wsdl.BPEL2UDDI;
27  import org.apache.juddi.v3.client.mapping.wsdl.WSDL2UDDI;
28  
29  public class AsyncRegistration implements Runnable {
30  
31  	private static Log log = LogFactory.getLog(AsyncRegistration.class);
32  	private UDDIClerk clerk;
33  	private URLLocalizer urlLocalizer;
34  	private Properties properties;
35  	private static Map<String,ServiceLocator> serviceLocators = new HashMap<String,ServiceLocator>();
36  	private RegistrationInfo registrationInfo;
37  	
38  	public AsyncRegistration(UDDIClerk clerk, URLLocalizer urlLocalizer, 
39  		Properties properties, RegistrationInfo registrationInfo) {
40  		super();
41  		this.clerk = clerk;
42  		this.urlLocalizer = urlLocalizer;
43  		this.properties = properties;
44  		this.registrationInfo = registrationInfo;
45  		
46  	}
47  
48  	public void run() {
49  		
50  		try {
51  			ServiceLocator serviceLocator = null;
52  			synchronized (serviceLocators) {
53  				if (!serviceLocators.containsKey(clerk.getName())) {
54  					serviceLocator = new ServiceLocator(clerk, urlLocalizer, properties);
55  					serviceLocators.put(clerk.getName(), serviceLocator);
56  				} else {
57  					serviceLocator = serviceLocators.get(clerk.getName());
58  				}
59  			}
60  			if (RegistrationType.WSDL.equals(registrationInfo.getRegistrationType())) {
61  				WSDL2UDDI wsdl2UDDI = new WSDL2UDDI(clerk, urlLocalizer, properties);
62  				wsdl2UDDI.registerBusinessService(registrationInfo.getServiceQName(), 
63  								   registrationInfo.getPortName(),
64  								   registrationInfo.getServiceUrl(),
65  								   registrationInfo.getWsdlDefinition()).getBusinessService();
66  				
67  			} else if (RegistrationType.BPEL.equals(registrationInfo.getRegistrationType())) {
68  				BPEL2UDDI bpel2UDDI = new BPEL2UDDI(clerk, urlLocalizer, properties);
69  				bpel2UDDI.register(registrationInfo.getServiceQName(), 
70  								   registrationInfo.getPortName(),
71  								   registrationInfo.getServiceUrl(),
72  								   registrationInfo.getWsdlDefinition());
73  			} else {
74  				log.error("Registration error, due to unsupported registration type of " + registrationInfo.getRegistrationType());
75  			}
76  		} catch (Exception e) {
77  			log.error("Not able to register " + registrationInfo.getRegistrationType() 
78  					+ " endpoint " + registrationInfo.getServiceQName()
79  					+ " to UDDI Registry. " + e.getMessage(),e);
80  		}
81  		
82  	}
83  
84  	public ServiceLocator getServiceLocator(String clerkName) {
85  		return serviceLocators.get(clerkName);
86  	}
87  }