1 package org.apache.fulcrum.spring; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import org.springframework.beans.factory.FactoryBean; 23 import org.springframework.beans.factory.InitializingBean; 24 import org.apache.avalon.framework.service.ServiceManager; 25 26 /** 27 * A Spring factory bean to lookup Avalon service and get a hold on 28 * them as Spring bean. Such spring bean can than be injected as dependency 29 * into other beans. 30 * 31 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a> 32 */ 33 34 public class AvalonServiceFactoryBean implements FactoryBean, InitializingBean { 35 36 /** the Avalon ServiceManager */ 37 private ServiceManager serviceManager; 38 39 /** the name of the Avalon service to resolve */ 40 private String serviceName; 41 42 /** the resolved Avalon service */ 43 private Object service; 44 45 /** 46 * Resolve the service name to a service. 47 * 48 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() 49 */ 50 public void afterPropertiesSet() throws Exception 51 { 52 this.service = this.serviceManager.lookup(this.serviceName); 53 } 54 55 /** 56 * Set the Avalon ServiceManager to lookup the Avalon service. 57 * 58 * @param serviceManager the Avalon ServiceManager 59 */ 60 public void setServiceManager(ServiceManager serviceManager) 61 { 62 this.serviceManager = serviceManager; 63 } 64 65 /** 66 * Set the name of the Avalon service to be resolved by 67 * this Spring bean factory. 68 * 69 * @param serviceName the Avalon service name 70 */ 71 public void setServiceName(String serviceName) 72 { 73 this.serviceName = serviceName; 74 } 75 76 /** @see org.springframework.beans.factory.FactoryBean#getObject() */ 77 public Object getObject() throws Exception 78 { 79 return this.service; 80 } 81 82 /** @see org.springframework.beans.factory.FactoryBean#getObjectType() */ 83 public Class getObjectType() 84 { 85 return this.service.getClass(); 86 } 87 88 /** @see org.springframework.beans.factory.FactoryBean#isSingleton() */ 89 public boolean isSingleton() 90 { 91 return true; 92 } 93 }