View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.rice.ksb.messaging.config;
17  
18  import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
19  import org.kuali.rice.ksb.messaging.ServiceDefinition;
20  import org.kuali.rice.ksb.service.KSBServiceLocator;
21  
22  
23  /**
24   * Registers {@link ServiceDefinition} objects 
25   * configured as a service (typically a Spring bean) dynamically with the 
26   * service registry.
27   *  
28   *  
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   *
31   */
32  public class ServiceBasedServiceDefinitionRegisterer {
33  	
34  	private String serviceName;
35  	
36  	public ServiceBasedServiceDefinitionRegisterer(String serviceName) {
37  		this.setServiceName(serviceName);
38  	}
39  
40  	/**
41  	 * Goes to the {@link GlobalResourceLoader} to find the ServiceDefinition using the name
42  	 * passed in.  Validates the Definition and registers it with the registry.
43  	 * 
44  	 * @param serviceName
45  	 * @param forceRegistryRefresh
46  	 */
47  	public void registerServiceDefinition(boolean forceRegistryRefresh) {
48  		ServiceDefinition serviceDef = (ServiceDefinition)GlobalResourceLoader.getService(this.getServiceName());
49  		serviceDef.validate();
50  		KSBServiceLocator.getServiceDeployer().registerService(serviceDef, forceRegistryRefresh);
51  	}
52  	
53  	public void unregisterServiceDefinition() {
54  		ServiceDefinition serviceDef = (ServiceDefinition)GlobalResourceLoader.getService(this.getServiceName());
55  		KSBServiceLocator.getServiceDeployer().removeRemoteServiceFromRegistry(serviceDef.getServiceName());
56  	}
57  
58  	public String getServiceName() {
59  		return this.serviceName;
60  	}
61  
62  	public void setServiceName(String serviceName) {
63  		this.serviceName = serviceName;
64  	}
65  }