KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > extras > spring > config > UMOManagerFactoryBean


1 /*
2  * $Id: UMOManagerFactoryBean.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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 java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.mule.MuleManager;
18 import org.mule.config.MuleConfiguration;
19 import org.mule.umo.UMOException;
20 import org.mule.umo.UMOInterceptorStack;
21 import org.mule.umo.endpoint.UMOEndpoint;
22 import org.mule.umo.lifecycle.InitialisationException;
23 import org.mule.umo.manager.UMOManager;
24 import org.mule.umo.manager.UMOTransactionManagerFactory;
25 import org.mule.umo.model.UMOModel;
26 import org.mule.umo.provider.UMOConnector;
27 import org.mule.umo.transformer.UMOTransformer;
28 import org.springframework.beans.factory.DisposableBean;
29 import org.springframework.beans.factory.FactoryBean;
30 import org.springframework.beans.factory.InitializingBean;
31
32 /**
33  * <code>UMOManagerFactoryBean</code> is a Spring FactoryBean used for creating a
34  * MuleManager from a Spring context. The context must explicitly wire the beans
35  * together. Users might want to try AutowireUMOManagerFactoryBean for a simpler and
36  * cleaner spring configuration.
37  *
38  * @see AutowireUMOManagerFactoryBean
39  */

40 public class UMOManagerFactoryBean implements FactoryBean, InitializingBean, DisposableBean
41 {
42     private final UMOManager manager;
43
44     public UMOManagerFactoryBean() throws Exception JavaDoc
45     {
46         this.manager = MuleManager.getInstance();
47     }
48
49     public Object JavaDoc getObject() throws Exception JavaDoc
50     {
51         return manager;
52     }
53
54     public Class JavaDoc getObjectType()
55     {
56         return UMOManager.class;
57     }
58
59     public boolean isSingleton()
60     {
61         return true;
62     }
63
64     public void setMessageEndpoints(Map JavaDoc endpoints) throws InitialisationException
65     {
66         for (Iterator JavaDoc iterator = endpoints.entrySet().iterator(); iterator.hasNext();)
67         {
68             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)iterator.next();
69             manager.registerEndpointIdentifier(entry.getKey().toString(), entry.getValue().toString());
70         }
71     }
72
73     public void setProperties(Map JavaDoc props)
74     {
75         for (Iterator JavaDoc iterator = props.entrySet().iterator(); iterator.hasNext();)
76         {
77             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)iterator.next();
78             manager.setProperty(entry.getKey(), entry.getValue());
79         }
80     }
81
82     public void setConfiguration(MuleConfiguration config)
83     {
84         MuleManager.setConfiguration(config);
85     }
86
87     public void setTransactionManagerFactory(UMOTransactionManagerFactory factory) throws Exception JavaDoc
88     {
89         manager.setTransactionManager(factory.create());
90     }
91
92     public void setConnectors(List JavaDoc connectors) throws UMOException
93     {
94         for (Iterator JavaDoc iterator = connectors.iterator(); iterator.hasNext();)
95         {
96             manager.registerConnector((UMOConnector)iterator.next());
97         }
98     }
99
100     public void setTransformers(List JavaDoc transformers) throws InitialisationException
101     {
102         for (Iterator JavaDoc iterator = transformers.iterator(); iterator.hasNext();)
103         {
104             manager.registerTransformer((UMOTransformer)iterator.next());
105         }
106     }
107
108     public void setProviders(List JavaDoc endpoints) throws InitialisationException
109     {
110         for (Iterator JavaDoc iterator = endpoints.iterator(); iterator.hasNext();)
111         {
112             manager.registerEndpoint((UMOEndpoint)iterator.next());
113         }
114     }
115
116     public void setInterceptorStacks(Map JavaDoc interceptors)
117     {
118         for (Iterator JavaDoc iterator = interceptors.entrySet().iterator(); iterator.hasNext();)
119         {
120             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)iterator.next();
121             manager.registerInterceptorStack(entry.getKey().toString(), (UMOInterceptorStack)entry.getValue());
122         }
123     }
124
125     public void setModel(UMOModel model) throws UMOException
126     {
127         manager.setModel(model);
128     }
129
130     public void afterPropertiesSet() throws Exception JavaDoc
131     {
132         manager.start();
133     }
134
135     public void destroy() throws Exception JavaDoc
136     {
137         manager.dispose();
138     }
139
140 }
141
Popular Tags