1 /*
2  * Copyright 2002-2007 the original author or authors.
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.springframework.aop.aspectj.annotation;
18 
19 import org.springframework.beans.factory.BeanFactory;
20 
21 /**
22  * AspectInstanceFactory backed by a BeanFactory-provided prototype,
23  * enforcing prototype semantics.
24  *
25  * <p>Note that this may instantiate multiple times, which probably won't give the
26  * semantics you expect. Use a {@link LazySingletonAspectInstanceFactoryDecorator}
27  * to wrap this to ensure only one new aspect comes back.
28  *
29  * @author Rod Johnson
30  * @author Juergen Hoeller
31  * @since 2.0
32  * @see org.springframework.beans.factory.BeanFactory
33  * @see LazySingletonAspectInstanceFactoryDecorator
34  */
35 public class PrototypeAspectInstanceFactory extends BeanFactoryAspectInstanceFactory {
36 
37 	/**
38 	 * Create a PrototypeAspectInstanceFactory. AspectJ will be called to
39 	 * introspect to create AJType metadata using the type returned for the
40 	 * given bean name from the BeanFactory.
41 	 * @param beanFactory the BeanFactory to obtain instance(s) from
42 	 * @param name the name of the bean
43 	 */
PrototypeAspectInstanceFactory(BeanFactory beanFactory, String name)44 	public PrototypeAspectInstanceFactory(BeanFactory beanFactory, String name) {
45 		super(beanFactory, name);
46 		if (!beanFactory.isPrototype(name)) {
47 			throw new IllegalArgumentException(
48 					"Cannot use PrototypeAspectInstanceFactory with bean named '" + name + "': not a prototype");
49 		}
50 	}
51 
52 }
53