|
Spring Framework example source code file (MethodLocatingFactoryBean.java)
The Spring Framework MethodLocatingFactoryBean.java source code/* * Copyright 2002-2006 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.aop.config; import java.lang.reflect.Method; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.util.StringUtils; /** * {@link FactoryBean} implementation that locates a {@link Method} on a specified bean. * * @author Rob Harrop * @since 2.0 */ public class MethodLocatingFactoryBean implements FactoryBean, BeanFactoryAware { private String targetBeanName; private String methodName; private Method method; /** * Set the name of the bean to locate the {@link Method} on. * <p>This property is required. * @param targetBeanName the name of the bean to locate the {@link Method} on */ public void setTargetBeanName(String targetBeanName) { this.targetBeanName = targetBeanName; } /** * Set the name of the {@link Method} to locate. * <p>This property is required. * @param methodName the name of the {@link Method} to locate */ public void setMethodName(String methodName) { this.methodName = methodName; } public void setBeanFactory(BeanFactory beanFactory) { if (!StringUtils.hasText(this.targetBeanName)) { throw new IllegalArgumentException("Property 'targetBeanName' is required"); } if (!StringUtils.hasText(this.methodName)) { throw new IllegalArgumentException("Property 'methodName' is required"); } Class beanClass = beanFactory.getType(this.targetBeanName); if (beanClass == null) { throw new IllegalArgumentException("Can't determine type of bean with name '" + this.targetBeanName + "'"); } this.method = BeanUtils.resolveSignature(this.methodName, beanClass); if (this.method == null) { throw new IllegalArgumentException("Unable to locate method [" + this.methodName + "] on bean [" + this.targetBeanName + "]"); } } public Object getObject() throws Exception { return this.method; } public Class getObjectType() { return Method.class; } public boolean isSingleton() { return true; } } Other Spring Framework examples (source code examples)Here is a short list of links related to this Spring Framework MethodLocatingFactoryBean.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.