001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.aop.framework;
018:
019: import java.io.Serializable;
020:
021: import org.springframework.util.Assert;
022:
023: /**
024: * Convenience superclass for configuration used in creating proxies,
025: * to ensure that all proxy creators have consistent properties.
026: *
027: * @author Rod Johnson
028: * @author Juergen Hoeller
029: * @see AdvisedSupport
030: */
031: public class ProxyConfig implements Serializable {
032:
033: /** use serialVersionUID from Spring 1.2 for interoperability */
034: private static final long serialVersionUID = -8409359707199703185L;
035:
036: private boolean proxyTargetClass = false;
037:
038: private boolean optimize = false;
039:
040: boolean opaque = false;
041:
042: boolean exposeProxy = false;
043:
044: private boolean frozen = false;
045:
046: /**
047: * Set whether to proxy the target class directly, instead of just proxying
048: * specific interfaces. Default is "false".
049: * <p>Set this to "true" to force proxying for the TargetSource's exposed
050: * target class. If that target class is an interface, a JDK proxy will be
051: * created for the given interface. If that target class is any other class,
052: * a CGLIB proxy will be created for the given class.
053: * <p>Note: Depending on the configuration of the concrete proxy factory,
054: * the proxy-target-class behavior will also be applied if no interfaces
055: * have been specified (and no interface autodetection is activated).
056: * @see org.springframework.aop.TargetSource#getTargetClass()
057: */
058: public void setProxyTargetClass(boolean proxyTargetClass) {
059: this .proxyTargetClass = proxyTargetClass;
060: }
061:
062: /**
063: * Return whether to proxy the target class directly as well as any interfaces.
064: */
065: public boolean isProxyTargetClass() {
066: return this .proxyTargetClass;
067: }
068:
069: /**
070: * Set whether proxies should perform aggressive optimizations.
071: * The exact meaning of "aggressive optimizations" will differ
072: * between proxies, but there is usually some tradeoff.
073: * Default is "false".
074: * <p>For example, optimization will usually mean that advice changes won't
075: * take effect after a proxy has been created. For this reason, optimization
076: * is disabled by default. An optimize value of "true" may be ignored
077: * if other settings preclude optimization: for example, if "exposeProxy"
078: * is set to "true" and that's not compatible with the optimization.
079: */
080: public void setOptimize(boolean optimize) {
081: this .optimize = optimize;
082: }
083:
084: /**
085: * Return whether proxies should perform aggressive optimizations.
086: */
087: public boolean isOptimize() {
088: return this .optimize;
089: }
090:
091: /**
092: * Set whether proxies created by this configuration should be prevented
093: * from being cast to {@link Advised} to query proxy status.
094: * <p>Default is "false", meaning that any AOP proxy can be cast to
095: * {@link Advised}.
096: */
097: public void setOpaque(boolean opaque) {
098: this .opaque = opaque;
099: }
100:
101: /**
102: * Return whether proxies created by this configuration should be
103: * prevented from being cast to {@link Advised}.
104: */
105: public boolean isOpaque() {
106: return this .opaque;
107: }
108:
109: /**
110: * Set whether the proxy should be exposed by the AOP framework as a
111: * ThreadLocal for retrieval via the AopContext class. This is useful
112: * if an advised object needs to call another advised method on itself.
113: * (If it uses <code>this</code>, the invocation will not be advised).
114: * <p>Default is "false", for optimal performance.
115: */
116: public void setExposeProxy(boolean exposeProxy) {
117: this .exposeProxy = exposeProxy;
118: }
119:
120: /**
121: * Return whether the AOP proxy will expose the AOP proxy for
122: * each invocation.
123: */
124: public boolean isExposeProxy() {
125: return this .exposeProxy;
126: }
127:
128: /**
129: * Set whether this config should be frozen.
130: * <p>When a config is frozen, no advice changes can be made. This is
131: * useful for optimization, and useful when we don't want callers to
132: * be able to manipulate configuration after casting to Advised.
133: */
134: public void setFrozen(boolean frozen) {
135: this .frozen = frozen;
136: }
137:
138: /**
139: * Return whether the config is frozen, and no advice changes can be made.
140: */
141: public boolean isFrozen() {
142: return this .frozen;
143: }
144:
145: /**
146: * Copy configuration from the other config object.
147: * @param other object to copy configuration from
148: */
149: public void copyFrom(ProxyConfig other) {
150: Assert.notNull(other,
151: "Other ProxyConfig object must not be null");
152: this .proxyTargetClass = other.proxyTargetClass;
153: this .optimize = other.optimize;
154: this .exposeProxy = other.exposeProxy;
155: this .frozen = other.frozen;
156: this .opaque = other.opaque;
157: }
158:
159: public String toString() {
160: StringBuffer sb = new StringBuffer();
161: sb.append("proxyTargetClass=").append(this .proxyTargetClass)
162: .append("; ");
163: sb.append("optimize=").append(this .optimize).append("; ");
164: sb.append("opaque=").append(this .opaque).append("; ");
165: sb.append("exposeProxy=").append(this .exposeProxy).append("; ");
166: sb.append("frozen=").append(this.frozen);
167: return sb.toString();
168: }
169:
170: }
|