01: /*
02: * $Id: MuleContextPostProcessor.java 10489 2008-01-23 17:53:38Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.config.spring;
12:
13: import org.mule.api.MuleContext;
14: import org.mule.api.context.MuleContextAware;
15:
16: import org.springframework.beans.BeansException;
17: import org.springframework.beans.factory.config.BeanPostProcessor;
18:
19: /**
20: * Responsible for passing in the MuleContext instance for all objects in the
21: * registry that want it. For an object to get an instance of the MuleContext
22: * it must implement MuleContextAware.
23: *
24: * @see MuleContextAware
25: * @see org.mule.api.MuleContext
26: */
27: public class MuleContextPostProcessor implements BeanPostProcessor {
28:
29: private MuleContext muleContext;
30:
31: public MuleContextPostProcessor(MuleContext muleContext) {
32: this .muleContext = muleContext;
33: }
34:
35: public Object postProcessBeforeInitialization(Object bean,
36: String beanName) throws BeansException {
37: if (bean instanceof MuleContextAware) {
38: if (muleContext == null) {
39: return bean;
40: }
41:
42: ((MuleContextAware) bean).setMuleContext(muleContext);
43: }
44: return bean;
45: }
46:
47: public Object postProcessAfterInitialization(Object bean,
48: String beanName) throws BeansException {
49: return bean;
50: }
51:
52: }
|