01: package org.mule.config.spring;
02:
03: import org.mule.api.MuleContext;
04: import org.mule.api.config.ConfigurationException;
05: import org.mule.api.config.MuleConfiguration;
06: import org.mule.api.context.MuleContextAware;
07: import org.mule.config.DefaultMuleConfiguration;
08: import org.mule.config.i18n.MessageFactory;
09:
10: import org.apache.commons.logging.Log;
11: import org.apache.commons.logging.LogFactory;
12: import org.springframework.beans.factory.SmartFactoryBean;
13:
14: /**
15: * This class is a "SmartFactoryBean" which allows a few XML attributes to be set on the
16: * otherwise read-only MuleConfiguration. It looks up the MuleConfiguration from the
17: * MuleContext and does some class-casting to be able to modify it. Note that this will
18: * only work if the MuleContext has not yet been started, otherwise the modifications
19: * will be ignored (and warnings logged).
20: */
21: public class MuleConfigurationConfigurator implements MuleContextAware,
22: SmartFactoryBean {
23: private MuleContext muleContext;
24:
25: // We instantiate DefaultMuleConfiguration to make sure we get the default values for
26: // any properties not set by the user.
27: private DefaultMuleConfiguration config = new DefaultMuleConfiguration();
28:
29: protected transient Log logger = LogFactory
30: .getLog(MuleConfigurationConfigurator.class);
31:
32: public void setMuleContext(MuleContext context) {
33: this .muleContext = context;
34: }
35:
36: public boolean isEagerInit() {
37: return true;
38: }
39:
40: public boolean isPrototype() {
41: return false;
42: }
43:
44: public Object getObject() throws Exception {
45: MuleConfiguration configuration = muleContext
46: .getConfiguration();
47: if (configuration instanceof DefaultMuleConfiguration) {
48: ((DefaultMuleConfiguration) configuration)
49: .setDefaultSynchronousEndpoints(config
50: .isDefaultSynchronousEndpoints());
51: ((DefaultMuleConfiguration) configuration)
52: .setDefaultSynchronousEventTimeout(config
53: .getDefaultSynchronousEventTimeout());
54: ((DefaultMuleConfiguration) configuration)
55: .setDefaultRemoteSync(config.isDefaultRemoteSync());
56: ((DefaultMuleConfiguration) configuration)
57: .setDefaultTransactionTimeout(config
58: .getDefaultTransactionTimeout());
59: return configuration;
60: } else {
61: throw new ConfigurationException(
62: MessageFactory
63: .createStaticMessage("Unable to set properties on read-only MuleConfiguration: "
64: + configuration.getClass()));
65: }
66: }
67:
68: public Class getObjectType() {
69: return MuleConfiguration.class;
70: }
71:
72: public boolean isSingleton() {
73: return true;
74: }
75:
76: public void setDefaultSynchronousEndpoints(boolean synchronous) {
77: config.setDefaultSynchronousEndpoints(synchronous);
78: }
79:
80: public void setDefaultSynchronousEventTimeout(
81: int synchronousEventTimeout) {
82: config
83: .setDefaultSynchronousEventTimeout(synchronousEventTimeout);
84: }
85:
86: public void setDefaultRemoteSync(boolean remoteSync) {
87: config.setDefaultRemoteSync(remoteSync);
88: }
89:
90: public void setDefaultTransactionTimeout(
91: int defaultTransactionTimeout) {
92: config.setDefaultTransactionTimeout(defaultTransactionTimeout);
93: }
94: }
|