KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > framework > ProxyConfig


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.framework;
18
19 import java.io.Serializable JavaDoc;
20
21 import org.springframework.util.Assert;
22
23 /**
24  * Convenience superclass for configuration used in creating proxies,
25  * to ensure that all proxy creators have consistent properties.
26  *
27  * @author Rod Johnson
28  * @author Juergen Hoeller
29  * @see AdvisedSupport
30  */

31 public class ProxyConfig implements Serializable JavaDoc {
32
33     /** use serialVersionUID from Spring 1.2 for interoperability */
34     private static final long serialVersionUID = -8409359707199703185L;
35
36
37     private boolean proxyTargetClass = false;
38
39     private boolean optimize = false;
40
41     boolean opaque = false;
42
43     boolean exposeProxy = false;
44
45     private boolean frozen = false;
46
47
48     /**
49      * Set whether to proxy the target class directly, instead of just proxying
50      * specific interfaces. Default is "false".
51      * <p>Set this to "true" to force proxying for the TargetSource's exposed
52      * target class. If that target class is an interface, a JDK proxy will be
53      * created for the given interface. If that target class is any other class,
54      * a CGLIB proxy will be created for the given class.
55      * <p>Note: Depending on the configuration of the concrete proxy factory,
56      * the proxy-target-class behavior will also be applied if no interfaces
57      * have been specified (and no interface autodetection is activated).
58      * @see org.springframework.aop.TargetSource#getTargetClass()
59      */

60     public void setProxyTargetClass(boolean proxyTargetClass) {
61         this.proxyTargetClass = proxyTargetClass;
62     }
63
64     /**
65      * Return whether to proxy the target class directly as well as any interfaces.
66      */

67     public boolean isProxyTargetClass() {
68         return this.proxyTargetClass;
69     }
70
71     /**
72      * Set whether proxies should perform aggressive optimizations.
73      * The exact meaning of "aggressive optimizations" will differ
74      * between proxies, but there is usually some tradeoff.
75      * Default is "false".
76      * <p>For example, optimization will usually mean that advice changes won't
77      * take effect after a proxy has been created. For this reason, optimization
78      * is disabled by default. An optimize value of "true" may be ignored
79      * if other settings preclude optimization: for example, if "exposeProxy"
80      * is set to "true" and that's not compatible with the optimization.
81      */

82     public void setOptimize(boolean optimize) {
83         this.optimize = optimize;
84     }
85
86     /**
87      * Return whether proxies should perform aggressive optimizations.
88      */

89     public boolean isOptimize() {
90         return this.optimize;
91     }
92
93     /**
94      * Set whether proxies created by this configuration should be prevented
95      * from being cast to {@link Advised} to query proxy status.
96      * <p>Default is "false", meaning that any AOP proxy can be cast to
97      * {@link Advised}.
98      */

99     public void setOpaque(boolean opaque) {
100         this.opaque = opaque;
101     }
102
103     /**
104      * Return whether proxies created by this configuration should be
105      * prevented from being cast to {@link Advised}.
106      */

107     public boolean isOpaque() {
108         return this.opaque;
109     }
110
111     /**
112      * Set whether the proxy should be exposed by the AOP framework as a
113      * ThreadLocal for retrieval via the AopContext class. This is useful
114      * if an advised object needs to call another advised method on itself.
115      * (If it uses <code>this</code>, the invocation will not be advised).
116      * <p>Default is "false", for optimal performance.
117      */

118     public void setExposeProxy(boolean exposeProxy) {
119         this.exposeProxy = exposeProxy;
120     }
121     
122     /**
123      * Return whether the AOP proxy will expose the AOP proxy for
124      * each invocation.
125      */

126     public boolean isExposeProxy() {
127         return this.exposeProxy;
128     }
129
130     /**
131      * Set whether this config should be frozen.
132      * <p>When a config is frozen, no advice changes can be made. This is
133      * useful for optimization, and useful when we don't want callers to
134      * be able to manipulate configuration after casting to Advised.
135      */

136     public void setFrozen(boolean frozen) {
137         this.frozen = frozen;
138     }
139
140     /**
141      * Return whether the config is frozen, and no advice changes can be made.
142      */

143     public boolean isFrozen() {
144         return this.frozen;
145     }
146
147
148     /**
149      * Copy configuration from the other config object.
150      * @param other object to copy configuration from
151      */

152     public void copyFrom(ProxyConfig other) {
153         Assert.notNull(other, "Other ProxyConfig object must not be null");
154         this.proxyTargetClass = other.proxyTargetClass;
155         this.optimize = other.optimize;
156         this.exposeProxy = other.exposeProxy;
157         this.frozen = other.frozen;
158         this.opaque = other.opaque;
159     }
160
161     public String JavaDoc toString() {
162         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
163         sb.append("proxyTargetClass=").append(this.proxyTargetClass).append("; ");
164         sb.append("optimize=").append(this.optimize).append("; ");
165         sb.append("opaque=").append(this.opaque).append("; ");
166         sb.append("exposeProxy=").append(this.exposeProxy).append("; ");
167         sb.append("frozen=").append(this.frozen);
168         return sb.toString();
169     }
170
171 }
172
Popular Tags