KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > scope > DefaultScopedObject


1 /*
2  * Copyright 2002-2006 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.scope;
18
19 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
20 import org.springframework.util.Assert;
21
22 /**
23  * Default implementation of the {@link ScopedObject} interface.
24  *
25  * <p>Simply delegates the calls to the underlying
26  * {@link ConfigurableBeanFactory bean factory}
27  * ({@link ConfigurableBeanFactory#getBean(String)}/
28  * {@link ConfigurableBeanFactory#destroyScopedBean(String)}).
29  *
30  * @author Juergen Hoeller
31  * @since 2.0
32  * @see org.springframework.beans.factory.BeanFactory#getBean
33  * @see org.springframework.beans.factory.config.ConfigurableBeanFactory#destroyScopedBean
34  */

35 public class DefaultScopedObject implements ScopedObject {
36
37     private final ConfigurableBeanFactory beanFactory;
38
39     private final String JavaDoc targetBeanName;
40
41
42     /**
43      * Creates a new instance of the {@link DefaultScopedObject} class.
44      * @param beanFactory the {@link ConfigurableBeanFactory} that holds the scoped target object
45      * @param targetBeanName the name of the target bean
46      * @throws IllegalArgumentException if either of the parameters is <code>null</code>; or
47      * if the <code>targetBeanName</code> consists wholly of whitespace
48      */

49     public DefaultScopedObject(ConfigurableBeanFactory beanFactory, String JavaDoc targetBeanName) {
50         Assert.notNull(beanFactory, "BeanFactory must not be null");
51         Assert.hasText(targetBeanName, "'targetBeanName' must not be empty");
52         this.beanFactory = beanFactory;
53         this.targetBeanName = targetBeanName;
54     }
55
56
57     public Object JavaDoc getTargetObject() {
58         return this.beanFactory.getBean(this.targetBeanName);
59     }
60
61     public void removeFromScope() {
62         this.beanFactory.destroyScopedBean(this.targetBeanName);
63     }
64
65 }
66
Popular Tags