View Javadoc

1   /*
2    * $Id: UMOManagerFactoryBean.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.extras.spring.config;
12  
13  import org.mule.MuleManager;
14  import org.mule.config.MuleConfiguration;
15  import org.mule.umo.UMOException;
16  import org.mule.umo.UMOInterceptorStack;
17  import org.mule.umo.endpoint.UMOEndpoint;
18  import org.mule.umo.lifecycle.InitialisationException;
19  import org.mule.umo.manager.UMOManager;
20  import org.mule.umo.manager.UMOTransactionManagerFactory;
21  import org.mule.umo.model.UMOModel;
22  import org.mule.umo.provider.UMOConnector;
23  import org.mule.umo.transformer.UMOTransformer;
24  
25  import java.util.Iterator;
26  import java.util.List;
27  import java.util.Map;
28  
29  import org.springframework.beans.factory.DisposableBean;
30  import org.springframework.beans.factory.FactoryBean;
31  import org.springframework.beans.factory.InitializingBean;
32  
33  /**
34   * <code>UMOManagerFactoryBean</code> is a Spring FactoryBean used for creating a
35   * MuleManager from a Spring context. The context must explicitly wire the beans
36   * together. Users might want to try AutowireUMOManagerFactoryBean for a simpler and
37   * cleaner spring configuration.
38   * 
39   * @see AutowireUMOManagerFactoryBean
40   * @deprecated use AutowireUMOManagerFactoryBean
41   */
42  public class UMOManagerFactoryBean implements FactoryBean, InitializingBean, DisposableBean
43  {
44      private final UMOManager manager;
45  
46      public UMOManagerFactoryBean() throws Exception
47      {
48          this.manager = MuleManager.getInstance();
49      }
50  
51      public Object getObject() throws Exception
52      {
53          return manager;
54      }
55  
56      public Class getObjectType()
57      {
58          return UMOManager.class;
59      }
60  
61      public boolean isSingleton()
62      {
63          return true;
64      }
65  
66      public void setMessageEndpoints(Map endpoints) throws InitialisationException
67      {
68          for (Iterator iterator = endpoints.entrySet().iterator(); iterator.hasNext();)
69          {
70              Map.Entry entry = (Map.Entry)iterator.next();
71              manager.registerEndpointIdentifier(entry.getKey().toString(), entry.getValue().toString());
72          }
73      }
74  
75      public void setProperties(Map props)
76      {
77          for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();)
78          {
79              Map.Entry entry = (Map.Entry)iterator.next();
80              manager.setProperty(entry.getKey(), entry.getValue());
81          }
82      }
83  
84      public void setConfiguration(MuleConfiguration config) throws UMOException
85      {
86          MuleManager.setConfiguration(config);
87      }
88  
89      public void setTransactionManagerFactory(UMOTransactionManagerFactory factory) throws Exception
90      {
91          manager.setTransactionManager(factory.create());
92      }
93  
94      public void setConnectors(List connectors) throws UMOException
95      {
96          for (Iterator iterator = connectors.iterator(); iterator.hasNext();)
97          {
98              manager.registerConnector((UMOConnector)iterator.next());
99          }
100     }
101 
102     public void setTransformers(List transformers) throws InitialisationException
103     {
104         for (Iterator iterator = transformers.iterator(); iterator.hasNext();)
105         {
106             manager.registerTransformer((UMOTransformer)iterator.next());
107         }
108     }
109 
110     public void setProviders(List endpoints) throws InitialisationException
111     {
112         for (Iterator iterator = endpoints.iterator(); iterator.hasNext();)
113         {
114             manager.registerEndpoint((UMOEndpoint)iterator.next());
115         }
116     }
117 
118     public void setInterceptorStacks(Map interceptors)
119     {
120         for (Iterator iterator = interceptors.entrySet().iterator(); iterator.hasNext();)
121         {
122             Map.Entry entry = (Map.Entry)iterator.next();
123             manager.registerInterceptorStack(entry.getKey().toString(), (UMOInterceptorStack)entry.getValue());
124         }
125     }
126 
127     public void setModel(UMOModel model) throws UMOException
128     {
129         manager.registerModel(model);
130     }
131 
132     public void afterPropertiesSet() throws Exception
133     {
134         manager.start();
135     }
136 
137     public void destroy() throws Exception
138     {
139         manager.dispose();
140     }
141 
142 }