View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.core.resourceloader;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import javax.xml.namespace.QName;
23  
24  import org.kuali.rice.core.lifecycle.BaseLifecycle;
25  import org.kuali.rice.core.resourceloader.ServiceLocator;
26  
27  /**
28   * A simple {@link ServiceLocator} that allows users to put services into workflow's resource loading
29   * wihout creating their own {@link ServiceLocator}.
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public class SimpleServiceLocator extends BaseLifecycle implements ServiceLocator {
35  
36  	private Map<QName, Object> services = new HashMap<QName, Object>();
37  
38  	public String getContents(String indent, boolean servicePerLine) {
39  		String contents = indent + "SpringLoader " + this + " services =";
40  
41  		for (Map.Entry<QName, Object> serviceEntry : this.services.entrySet()) {
42  			if (servicePerLine) {
43  				contents += indent + "+++" + serviceEntry.getKey() + "=" + serviceEntry.getValue() + "\n";
44  			} else {
45  				contents += serviceEntry.getKey() + "=" + serviceEntry.getValue() + ", ";
46  			}
47  		}
48  
49  		return contents;
50  	}
51  
52  	public Object getService(QName qname) {
53  		return this.services.get(qname);
54  	}
55  
56  	public void addService(QName name, Object service) {
57  	    this.services.put(name, service);
58  	}
59  
60  	public void removeService(QName name) {
61  	    this.services.remove(name);
62  	}
63  }