Coverage Report - org.mule.config.builders.MuleXmlConfigurationBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleXmlConfigurationBuilder
0%
0/361
0%
0/58
2.029
MuleXmlConfigurationBuilder$1
0%
0/3
N/A
2.029
MuleXmlConfigurationBuilder$10
0%
0/12
0%
0/2
2.029
MuleXmlConfigurationBuilder$11
0%
0/22
0%
0/12
2.029
MuleXmlConfigurationBuilder$12
0%
0/17
0%
0/6
2.029
MuleXmlConfigurationBuilder$13
0%
0/7
N/A
2.029
MuleXmlConfigurationBuilder$14
0%
0/12
0%
0/6
2.029
MuleXmlConfigurationBuilder$15
0%
0/6
N/A
2.029
MuleXmlConfigurationBuilder$16
0%
0/4
N/A
2.029
MuleXmlConfigurationBuilder$17
0%
0/11
N/A
2.029
MuleXmlConfigurationBuilder$2
0%
0/17
0%
0/12
2.029
MuleXmlConfigurationBuilder$3
0%
0/3
N/A
2.029
MuleXmlConfigurationBuilder$4
0%
0/3
N/A
2.029
MuleXmlConfigurationBuilder$5
0%
0/6
N/A
2.029
MuleXmlConfigurationBuilder$6
0%
0/7
N/A
2.029
MuleXmlConfigurationBuilder$7
0%
0/4
N/A
2.029
MuleXmlConfigurationBuilder$8
0%
0/20
0%
0/12
2.029
MuleXmlConfigurationBuilder$9
0%
0/2
N/A
2.029
MuleXmlConfigurationBuilder$ExtendedMuleSetPropertiesRule
0%
0/43
0%
0/20
2.029
 
 1  
 /*
 2  
  * $Id: MuleXmlConfigurationBuilder.java 9540 2007-11-01 14:14:52Z akuzmin $
 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.config.builders;
 12  
 
 13  
 import org.mule.MuleManager;
 14  
 import org.mule.config.ConfigurationBuilder;
 15  
 import org.mule.config.ConfigurationException;
 16  
 import org.mule.config.MuleConfiguration;
 17  
 import org.mule.config.MuleDtdResolver;
 18  
 import org.mule.config.MuleProperties;
 19  
 import org.mule.config.PoolingProfile;
 20  
 import org.mule.config.QueueProfile;
 21  
 import org.mule.config.ReaderResource;
 22  
 import org.mule.config.ThreadingProfile;
 23  
 import org.mule.config.converters.ConnectorConverter;
 24  
 import org.mule.config.converters.EndpointConverter;
 25  
 import org.mule.config.converters.EndpointURIConverter;
 26  
 import org.mule.config.converters.TransactionFactoryConverter;
 27  
 import org.mule.config.converters.TransformerConverter;
 28  
 import org.mule.config.i18n.CoreMessages;
 29  
 import org.mule.config.pool.CommonsPoolFactory;
 30  
 import org.mule.impl.DefaultLifecycleAdapter;
 31  
 import org.mule.impl.MuleDescriptor;
 32  
 import org.mule.impl.MuleTransactionConfig;
 33  
 import org.mule.impl.endpoint.MuleEndpoint;
 34  
 import org.mule.impl.model.ModelFactory;
 35  
 import org.mule.impl.model.resolvers.DynamicEntryPointResolver;
 36  
 import org.mule.impl.security.MuleSecurityManager;
 37  
 import org.mule.interceptors.InterceptorStack;
 38  
 import org.mule.providers.AbstractConnector;
 39  
 import org.mule.providers.ConnectionStrategy;
 40  
 import org.mule.providers.service.TransportFactory;
 41  
 import org.mule.providers.service.TransportFactoryException;
 42  
 import org.mule.routing.LoggingCatchAllStrategy;
 43  
 import org.mule.routing.inbound.InboundRouterCollection;
 44  
 import org.mule.routing.nested.NestedRouter;
 45  
 import org.mule.routing.nested.NestedRouterCollection;
 46  
 import org.mule.routing.outbound.OutboundRouterCollection;
 47  
 import org.mule.routing.response.ResponseRouterCollection;
 48  
 import org.mule.transaction.constraints.BatchConstraint;
 49  
 import org.mule.umo.UMODescriptor;
 50  
 import org.mule.umo.UMOEncryptionStrategy;
 51  
 import org.mule.umo.UMOInterceptor;
 52  
 import org.mule.umo.UMOInterceptorStack;
 53  
 import org.mule.umo.UMOTransactionFactory;
 54  
 import org.mule.umo.endpoint.UMOEndpoint;
 55  
 import org.mule.umo.endpoint.UMOEndpointURI;
 56  
 import org.mule.umo.lifecycle.InitialisationException;
 57  
 import org.mule.umo.manager.ContainerException;
 58  
 import org.mule.umo.manager.UMOAgent;
 59  
 import org.mule.umo.manager.UMOContainerContext;
 60  
 import org.mule.umo.manager.UMOManager;
 61  
 import org.mule.umo.manager.UMOTransactionManagerFactory;
 62  
 import org.mule.umo.model.UMOModel;
 63  
 import org.mule.umo.provider.UMOConnector;
 64  
 import org.mule.umo.routing.UMOInboundRouterCollection;
 65  
 import org.mule.umo.routing.UMONestedRouterCollection;
 66  
 import org.mule.umo.routing.UMOOutboundRouter;
 67  
 import org.mule.umo.routing.UMOOutboundRouterCollection;
 68  
 import org.mule.umo.routing.UMOResponseRouterCollection;
 69  
 import org.mule.umo.security.UMOEndpointSecurityFilter;
 70  
 import org.mule.umo.security.UMOSecurityManager;
 71  
 import org.mule.umo.security.UMOSecurityProvider;
 72  
 import org.mule.umo.transformer.UMOTransformer;
 73  
 import org.mule.util.ArrayUtils;
 74  
 import org.mule.util.ClassUtils;
 75  
 import org.mule.util.IOUtils;
 76  
 import org.mule.util.PropertiesUtils;
 77  
 import org.mule.util.StringUtils;
 78  
 import org.mule.util.queue.EventFilePersistenceStrategy;
 79  
 
 80  
 import java.beans.ExceptionListener;
 81  
 import java.io.IOException;
 82  
 import java.io.InputStream;
 83  
 import java.io.InputStreamReader;
 84  
 import java.util.ArrayList;
 85  
 import java.util.HashMap;
 86  
 import java.util.Iterator;
 87  
 import java.util.List;
 88  
 import java.util.Map;
 89  
 import java.util.Properties;
 90  
 
 91  
 import org.apache.commons.beanutils.ConvertUtils;
 92  
 import org.apache.commons.digester.AbstractObjectCreationFactory;
 93  
 import org.apache.commons.digester.Digester;
 94  
 import org.apache.commons.digester.ObjectCreateRule;
 95  
 import org.apache.commons.digester.Rule;
 96  
 import org.apache.commons.digester.SetNextRule;
 97  
 import org.apache.commons.digester.SetPropertiesRule;
 98  
 import org.xml.sax.Attributes;
 99  
 
 100  
 /**
 101  
  * <code>MuleXmlConfigurationBuilder</code> is a configuration parser that builds a
 102  
  * MuleManager instance based on a mule xml configration file defined in the
 103  
  * mule-configuration.dtd.
 104  
  */
 105  0
 public class MuleXmlConfigurationBuilder extends AbstractDigesterConfiguration
 106  
     implements ConfigurationBuilder
 107  
 {
 108  0
     public static final String DEFAULT_ENTRY_POINT_RESOLVER = DynamicEntryPointResolver.class.getName();
 109  0
     public static final String DEFAULT_LIFECYCLE_ADAPTER = DefaultLifecycleAdapter.class.getName();
 110  0
     public static final String DEFAULT_ENDPOINT = MuleEndpoint.class.getName();
 111  0
     public static final String DEFAULT_TRANSACTION_CONFIG = MuleTransactionConfig.class.getName();
 112  0
     public static final String DEFAULT_DESCRIPTOR = MuleDescriptor.class.getName();
 113  0
     public static final String DEFAULT_SECURITY_MANAGER = MuleSecurityManager.class.getName();
 114  0
     public static final String DEFAULT_OUTBOUND_ROUTER_COLLECTION = OutboundRouterCollection.class.getName();
 115  0
     public static final String DEFAULT_INBOUND_ROUTER_COLLECTION = InboundRouterCollection.class.getName();
 116  0
     public static final String DEFAULT_NESTED_ROUTER_COLLECTION = NestedRouterCollection.class.getName();
 117  0
     public static final String DEFAULT_RESPONSE_ROUTER_COLLECTION = ResponseRouterCollection.class.getName();
 118  0
     public static final String DEFAULT_NESTED_ROUTER = NestedRouter.class.getName();
 119  0
     public static final String DEFAULT_CATCH_ALL_STRATEGY = LoggingCatchAllStrategy.class.getName();
 120  0
     public static final String DEFAULT_POOL_FACTORY = CommonsPoolFactory.class.getName();
 121  0
     public static final String THREADING_PROFILE = ThreadingProfile.class.getName();
 122  0
     public static final String POOLING_PROFILE = PoolingProfile.class.getName();
 123  0
     public static final String QUEUE_PROFILE = QueueProfile.class.getName();
 124  
 
 125  0
     public static final String PERSISTENCE_STRATEGY_INTERFACE = EventFilePersistenceStrategy.class.getName();
 126  0
     public static final String INBOUND_MESSAGE_ROUTER_INTERFACE = UMOInboundRouterCollection.class.getName();
 127  0
     public static final String NESTED_MESSAGE_ROUTER_INTERFACE = UMONestedRouterCollection.class.getName();
 128  0
     public static final String RESPONSE_MESSAGE_ROUTER_INTERFACE = UMOResponseRouterCollection.class.getName();
 129  0
     public static final String OUTBOUND_MESSAGE_ROUTER_INTERFACE = UMOOutboundRouterCollection.class.getName();
 130  0
     public static final String TRANSFORMER_INTERFACE = UMOTransformer.class.getName();
 131  0
     public static final String TRANSACTION_MANAGER_FACTORY_INTERFACE = UMOTransactionManagerFactory.class.getName();
 132  0
     public static final String SECURITY_PROVIDER_INTERFACE = UMOSecurityProvider.class.getName();
 133  0
     public static final String ENCRYPTION_STRATEGY_INTERFACE = UMOEncryptionStrategy.class.getName();
 134  0
     public static final String ENDPOINT_SECURITY_FILTER_INTERFACE = UMOEndpointSecurityFilter.class.getName();
 135  0
     public static final String AGENT_INTERFACE = UMOAgent.class.getName();
 136  0
     public static final String TRANSACTION_FACTORY_INTERFACE = UMOTransactionFactory.class.getName();
 137  0
     public static final String TRANSACTION_CONSTRAINT_INTERFACE = BatchConstraint.class.getName();
 138  0
     public static final String CONNECTOR_INTERFACE = UMOConnector.class.getName();
 139  0
     public static final String INTERCEPTOR_INTERFACE = UMOInterceptor.class.getName();
 140  0
     public static final String ROUTER_INTERFACE = UMOOutboundRouter.class.getName();
 141  0
     public static final String EXCEPTION_STRATEGY_INTERFACE = ExceptionListener.class.getName();
 142  0
     public static final String CONNECTION_STRATEGY_INTERFACE = ConnectionStrategy.class.getName();
 143  
 
 144  
     protected UMOManager manager;
 145  
 
 146  0
     private final List transformerReferences = new ArrayList();
 147  0
     private final List endpointReferences = new ArrayList();
 148  
 
 149  
     public MuleXmlConfigurationBuilder() throws ConfigurationException
 150  
     {
 151  0
         super(System.getProperty(MuleProperties.XML_VALIDATE_SYSTEM_PROPERTY, "true")
 152  
             .equalsIgnoreCase("true"), System.getProperty(MuleProperties.XML_DTD_SYSTEM_PROPERTY,
 153  
             MuleDtdResolver.DEFAULT_MULE_DTD));
 154  
 
 155  0
         ConvertUtils.register(new EndpointConverter(), UMOEndpoint.class);
 156  0
         ConvertUtils.register(new TransformerConverter(), UMOTransformer.class);
 157  0
         ConvertUtils.register(new ConnectorConverter(), UMOConnector.class);
 158  0
         ConvertUtils.register(new TransactionFactoryConverter(), UMOTransactionFactory.class);
 159  0
         ConvertUtils.register(new EndpointURIConverter(), UMOEndpointURI.class);
 160  
 
 161  0
         String path = getRootName();
 162  0
         addManagerRules(digester, path);
 163  0
         addServerPropertiesRules(path + "/environment-properties", "addProperties", 0);
 164  0
         addContainerContextRules(path + "/container-context", "setContainerContext", 0);
 165  
 
 166  0
         addMuleConfigurationRules(digester, path);
 167  0
         addTransformerRules(digester, path);
 168  0
         addSecurityManagerRules(digester, path);
 169  0
         addTransactionManagerRules(digester, path);
 170  0
         addGlobalEndpointRules(digester, path);
 171  0
         addEndpointIdentifierRules(digester, path);
 172  0
         addInterceptorStackRules(digester, path);
 173  0
         addConnectorRules(digester, path);
 174  0
         addAgentRules(digester, path);
 175  
 
 176  0
         addModelRules(digester, path);
 177  
         // These rules allow for individual component configurations
 178  
         //RM* this is no longer required since Mule supports Multiple models and can inherit existing models.
 179  
         // This means that every mule-descriptor should be wrapped with a model element if its a stand alone
 180  
         //component config
 181  
         //addMuleDescriptorRules(digester, path);
 182  0
     }
 183  
 
 184  
     public String getRootName()
 185  
     {
 186  0
         return "mule-configuration";
 187  
     }
 188  
 
 189  
     public UMOManager configure(String configResources) throws ConfigurationException
 190  
     {
 191  0
         return configure(configResources, null);
 192  
     }
 193  
 
 194  
     public UMOManager configure(String configResources, String startupPropertiesFile)
 195  
         throws ConfigurationException
 196  
     {
 197  
         try
 198  
         {
 199  0
             String[] resources = StringUtils.splitAndTrim(configResources, ",");
 200  0
             if (logger.isDebugEnabled())
 201  
             {
 202  0
                 logger.debug("There is/are " + resources.length + " configuration resource(s): " + ArrayUtils.toString(resources));
 203  
             }
 204  0
             MuleManager.getConfiguration().setConfigResources(resources);
 205  0
             ReaderResource[] readers = new ReaderResource[resources.length];
 206  
             String resource; 
 207  0
             for (int i = 0; i < resources.length; i++)
 208  
             {
 209  0
                 resource = resources[i];
 210  0
                 readers[i] = new ReaderResource(resource, 
 211  
                                             new InputStreamReader(loadResource(resource), configEncoding));
 212  
             }
 213  
 
 214  
             // Load startup properties if any.
 215  0
             if (startupPropertiesFile != null)
 216  
             {
 217  0
                 return configure(readers, PropertiesUtils.loadProperties(startupPropertiesFile, getClass()));
 218  
             }
 219  
             else
 220  
             {
 221  0
                 return configure(readers, null);
 222  
             }
 223  
 
 224  
         }
 225  0
         catch (Exception e)
 226  
         {
 227  0
             throw new ConfigurationException(e);
 228  
         }
 229  
     }
 230  
 
 231  
     /**
 232  
      * Override this method to provide alternative ways of loading a resource.
 233  
      */
 234  
     protected InputStream loadResource(String configResource) throws ConfigurationException
 235  
     {
 236  
         try
 237  
         {
 238  0
             InputStream input = IOUtils.getResourceAsStream(configResource, getClass());
 239  0
             if (input == null)
 240  
             {
 241  0
                 throw new ConfigurationException(CoreMessages.cannotLoadFromClasspath(configResource));
 242  
             }
 243  0
             return input;
 244  
         }
 245  0
         catch (IOException e)
 246  
         {
 247  0
             throw new ConfigurationException(CoreMessages.cannotLoadFromClasspath(configResource), e);
 248  
         }
 249  
     }
 250  
     
 251  
     /**
 252  
      * @deprecated Please use configure(ReaderResource[] configResources, Properties
 253  
      *             startupProperties) instead.
 254  
      */
 255  
     public UMOManager configure(ReaderResource[] configResources) throws ConfigurationException
 256  
     {
 257  0
         return configure(configResources, null);
 258  
     }
 259  
 
 260  
     public UMOManager configure(ReaderResource[] configResources, Properties startupProperties)
 261  
         throws ConfigurationException
 262  
     {
 263  0
         if (startupProperties != null)
 264  
         {
 265  0
             ((MuleManager)MuleManager.getInstance()).addProperties(startupProperties);
 266  
         }
 267  
         // Parse the config files with the Digester.
 268  0
         manager = (MuleManager)process(configResources);
 269  0
         if (manager == null)
 270  
         {
 271  0
             throw new ConfigurationException(
 272  
                 CoreMessages.failedToCreateManagerInstance("Are you using a correct configuration builder?"));
 273  
         }
 274  
         try
 275  
         {
 276  0
             setContainerProperties();
 277  0
             setTransformers();
 278  0
             setGlobalEndpoints();
 279  0
             if (System.getProperty(MuleProperties.MULE_START_AFTER_CONFIG_SYSTEM_PROPERTY, "true")
 280  
                 .equalsIgnoreCase("true"))
 281  
             {
 282  0
                 manager.start();
 283  
             }
 284  
         }
 285  0
         catch (Exception e)
 286  
         {
 287  0
             throw new ConfigurationException(CoreMessages.objectFailedToInitialise("MuleManager"), e);
 288  0
         }
 289  0
         return manager;
 290  
     }
 291  
 
 292  
     /**
 293  
      * Indicate whether this ConfigurationBulder has been configured yet
 294  
      *
 295  
      * @return <code>true</code> if this ConfigurationBulder has been configured
 296  
      */
 297  
     public boolean isConfigured()
 298  
     {
 299  0
         return manager != null;
 300  
     }
 301  
 
 302  
     protected void setContainerProperties() throws ContainerException
 303  
     {
 304  0
         UMOContainerContext ctx = manager.getContainerContext();
 305  
         try
 306  
         {
 307  0
             for (Iterator iterator = containerReferences.iterator(); iterator.hasNext();)
 308  
             {
 309  0
                 ContainerReference reference = (ContainerReference)iterator.next();
 310  0
                 reference.resolveReference(ctx);
 311  0
             }
 312  
         }
 313  
         finally
 314  
         {
 315  0
             containerReferences.clear();
 316  0
         }
 317  0
     }
 318  
 
 319  
     protected void setTransformers() throws InitialisationException
 320  
     {
 321  
         try
 322  
         {
 323  0
             for (Iterator iterator = transformerReferences.iterator(); iterator.hasNext();)
 324  
             {
 325  0
                 TransformerReference reference = (TransformerReference)iterator.next();
 326  0
                 reference.resolveTransformer();
 327  0
             }
 328  
         }
 329  
         finally
 330  
         {
 331  0
             transformerReferences.clear();
 332  0
         }
 333  0
     }
 334  
 
 335  
     protected void setGlobalEndpoints() throws InitialisationException
 336  
     {
 337  
         // because Mule Xml allows developers to overload global endpoints
 338  
         // we need a way to initialise Global endpoints after the Xml has
 339  
         // been processed but before the MuleManager is initialised. So we do
 340  
         // it here.
 341  0
         UMOManager manager = MuleManager.getInstance();
 342  
 
 343  
         // we need to take a copy of the endpoints since we're going to modify them
 344  
         // while iterating
 345  0
         Map endpoints = new HashMap(manager.getEndpoints());
 346  0
         for (Iterator iterator = endpoints.values().iterator(); iterator.hasNext();)
 347  
         {
 348  0
             UMOEndpoint ep = (UMOEndpoint)iterator.next();
 349  
             try
 350  
             {
 351  0
                 if (ep.getConnector() == null)
 352  
                 {
 353  0
                     UMOConnector connector = TransportFactory.getOrCreateConnectorByProtocol(ep);
 354  0
                     if (connector == null)
 355  
                     {
 356  0
                         throw new InitialisationException(
 357  
                                 CoreMessages.failedToCreateConnectorFromUri(ep.getEndpointURI()), this);
 358  
 
 359  
                     }
 360  0
                     ep.setConnector(connector);
 361  
                 }
 362  
             }
 363  0
             catch (TransportFactoryException e)
 364  
             {
 365  0
                 throw new InitialisationException(
 366  
                         CoreMessages.failedToCreateConnectorFromUri(ep.getEndpointURI()), e, this);
 367  0
             }
 368  
 
 369  0
             manager.unregisterEndpoint(ep.getName());
 370  0
             manager.registerEndpoint(ep);
 371  0
         }
 372  
 
 373  
         try
 374  
         {
 375  0
             for (Iterator iterator = endpointReferences.iterator(); iterator.hasNext();)
 376  
             {
 377  0
                 EndpointReference reference = (EndpointReference)iterator.next();
 378  0
                 reference.resolveEndpoint();
 379  0
             }
 380  
         }
 381  
         finally
 382  
         {
 383  0
             endpointReferences.clear();
 384  0
         }
 385  0
     }
 386  
 
 387  
     protected void addManagerRules(Digester digester, String path)
 388  
     {
 389  0
         digester.addFactoryCreate(path, new AbstractObjectCreationFactory()
 390  
         {
 391  0
             public Object createObject(Attributes attributes) throws Exception
 392  
             {
 393  0
                 manager = MuleManager.getInstance();
 394  0
                 return manager;
 395  
             }
 396  
         });
 397  0
         digester.addSetProperties(path);
 398  0
     }
 399  
 
 400  
     protected void addMuleConfigurationRules(Digester digester, String path)
 401  
     {
 402  0
         digester.addSetProperties(path);
 403  
         // Create mule system properties and defaults
 404  0
         path += "/mule-environment-properties";
 405  0
         digester.addObjectCreate(path, MuleConfiguration.class);
 406  0
         addSetPropertiesRule(path, digester);
 407  
 
 408  
         // Add pooling profile rules
 409  0
         addPoolingProfileRules(digester, path);
 410  
 
 411  
         // Add Queue Profile rules
 412  0
         addQueueProfileRules(digester, path);
 413  
 
 414  
         // set threading profile
 415  0
         digester.addObjectCreate(path + "/threading-profile", THREADING_PROFILE);
 416  0
         SetPropertiesRule threadingRule = new SetPropertiesRule();
 417  0
         threadingRule.addAlias("poolExhaustedAction", "poolExhaustedActionString");
 418  0
         digester.addRule(path + "/threading-profile", threadingRule);
 419  0
         digester.addRule(path + "/threading-profile", new Rule()
 420  
         {
 421  
             private String id;
 422  
 
 423  
             public void begin(String s, String s1, Attributes attributes) throws Exception
 424  
             {
 425  0
                 id = attributes.getValue("id");
 426  0
             }
 427  
 
 428  0
             public void end(String s, String s1) throws Exception
 429  
             {
 430  0
                 ThreadingProfile tp = (ThreadingProfile)digester.peek();
 431  0
                 MuleConfiguration cfg = (MuleConfiguration)digester.peek(1);
 432  
 
 433  0
                 if ("default".equals(id))
 434  
                 {
 435  0
                     cfg.setDefaultThreadingProfile(tp);
 436  0
                     cfg.setMessageDispatcherThreadingProfile(tp);
 437  0
                     cfg.setMessageReceiverThreadingProfile(tp);
 438  0
                     cfg.setComponentThreadingProfile(tp);
 439  
                 }
 440  0
                 else if ("messageReceiver".equals(id) || "receiver".equals(id))
 441  
                 {
 442  0
                     cfg.setMessageReceiverThreadingProfile(tp);
 443  
                 }
 444  0
                 else if ("messageDispatcher".equals(id) || "dispatcher".equals(id))
 445  
                 {
 446  0
                     cfg.setMessageDispatcherThreadingProfile(tp);
 447  
                 }
 448  0
                 else if ("component".equals(id))
 449  
                 {
 450  0
                     cfg.setComponentThreadingProfile(tp);
 451  
                 }
 452  0
             }
 453  
         });
 454  
 
 455  
         // add persistence strategy
 456  0
         digester.addObjectCreate(path + "/persistence-strategy", PERSISTENCE_STRATEGY_INTERFACE, "className");
 457  0
         addMulePropertiesRule(path + "/persistence-strategy", digester);
 458  0
         digester.addSetNext(path + "/persistence-strategy", "setPersistenceStrategy");
 459  
 
 460  
         // Connection strategy
 461  0
         digester.addObjectCreate(path + "/connection-strategy", CONNECTION_STRATEGY_INTERFACE, "className");
 462  0
         addMulePropertiesRule(path + "/connection-strategy", digester);
 463  
         // digester.addSetNext(path + "/connection-strategy",
 464  
         // "setConnectionStrategy");
 465  0
         digester.addRule(path + "/connection-strategy", new SetNextRule("setConnectionStrategy")
 466  
         {
 467  0
             public void end(String s, String s1) throws Exception
 468  
             {
 469  0
                 super.end(s, s1);
 470  0
             }
 471  
         });
 472  
 
 473  0
         digester.addRule(path, new Rule()
 474  
         {
 475  0
             public void end(String s, String s1) throws Exception
 476  
             {
 477  0
                 MuleManager.setConfiguration((MuleConfiguration)digester.peek());
 478  0
             }
 479  
         });
 480  0
     }
 481  
 
 482  
     protected void addSecurityManagerRules(Digester digester, String path) throws ConfigurationException
 483  
     {
 484  
         // Create container Context
 485  0
         path += "/security-manager";
 486  0
         addObjectCreateOrGetFromContainer(path, DEFAULT_SECURITY_MANAGER, "className", "ref", false);
 487  
 
 488  
         // Add propviders
 489  0
         digester.addObjectCreate(path + "/security-provider", SECURITY_PROVIDER_INTERFACE, "className");
 490  0
         addSetPropertiesRule(path + "/security-provider", digester);
 491  0
         addMulePropertiesRule(path + "/security-provider", digester);
 492  0
         digester.addSetNext(path + "/security-provider", "addProvider");
 493  
 
 494  
         // Add encryption strategies
 495  0
         digester.addObjectCreate(path + "/encryption-strategy", ENCRYPTION_STRATEGY_INTERFACE, "className");
 496  0
         addSetPropertiesRule(path + "/encryption-strategy", digester);
 497  0
         addMulePropertiesRule(path + "/encryption-strategy", digester);
 498  0
         digester.addRule(path + "/encryption-strategy", new Rule()
 499  
         {
 500  
             private String name;
 501  
 
 502  
             public void begin(String endpointName, String endpointName1, Attributes attributes)
 503  
                 throws Exception
 504  
             {
 505  0
                 name = attributes.getValue("name");
 506  0
             }
 507  
 
 508  0
             public void end(String endpointName, String endpointName1) throws Exception
 509  
             {
 510  0
                 UMOEncryptionStrategy s = (UMOEncryptionStrategy)digester.peek();
 511  0
                 ((UMOSecurityManager)digester.peek(1)).addEncryptionStrategy(name, s);
 512  0
             }
 513  
         });
 514  0
         digester.addSetNext(path, "setSecurityManager");
 515  
 
 516  0
     }
 517  
 
 518  
     protected void addTransformerRules(Digester digester, String path) throws ConfigurationException
 519  
     {
 520  
         // Create Transformers
 521  0
         path += "/transformers/transformer";
 522  0
         addObjectCreateOrGetFromContainer(path, TRANSFORMER_INTERFACE, "className", "ref", true);
 523  
 
 524  0
         addSetPropertiesRule(path, digester);
 525  
 
 526  0
         addMulePropertiesRule(path, digester);
 527  0
         digester.addSetRoot(path, "registerTransformer");
 528  0
     }
 529  
 
 530  
     protected void addGlobalEndpointRules(Digester digester, String path) throws ConfigurationException
 531  
     {
 532  
         // Create global message endpoints
 533  0
         path += "/global-endpoints";
 534  0
         addEndpointRules(digester, path, "registerEndpoint");
 535  0
     }
 536  
 
 537  
     protected void addEndpointIdentifierRules(Digester digester, String path) throws ConfigurationException
 538  
     {
 539  
         // Create and reqister endpoints
 540  0
         path += "/endpoint-identifiers/endpoint-identifier";
 541  0
         digester.addRule(path, new Rule()
 542  
         {
 543  0
             private PlaceholderProcessor processor = new PlaceholderProcessor();
 544  
 
 545  0
             public void begin(String s, String s1, Attributes attributes) throws Exception
 546  
             {
 547  0
                 attributes = processor.processAttributes(attributes, s1);
 548  0
                 String name = attributes.getValue("name");
 549  0
                 String value = attributes.getValue("value");
 550  0
                 ((UMOManager)digester.getRoot()).registerEndpointIdentifier(name, value);
 551  0
             }
 552  
         });
 553  0
     }
 554  
 
 555  
     protected void addTransactionManagerRules(Digester digester, String path) throws ConfigurationException
 556  
     {
 557  
         // Create transactionManager
 558  0
         path += "/transaction-manager";
 559  0
         addObjectCreateOrGetFromContainer(path, TRANSACTION_MANAGER_FACTORY_INTERFACE, "factory", "ref", true);
 560  0
         addMulePropertiesRule(path, digester);
 561  
 
 562  0
         digester.addSetRoot(path, "setTransactionManager");
 563  0
         digester.addRule(path, new Rule()
 564  
         {
 565  0
             public void end(String s, String s1) throws Exception
 566  
             {
 567  0
                 UMOTransactionManagerFactory txFactory = (UMOTransactionManagerFactory)digester.pop();
 568  0
                 digester.push(txFactory.create());
 569  0
             }
 570  
         });
 571  0
     }
 572  
 
 573  
     protected void addAgentRules(Digester digester, String path) throws ConfigurationException
 574  
     {
 575  
         // Create Agents
 576  0
         path += "/agents/agent";
 577  0
         addObjectCreateOrGetFromContainer(path, AGENT_INTERFACE, "className", "ref", true);
 578  0
         addSetPropertiesRule(path, digester);
 579  
 
 580  0
         addMulePropertiesRule(path, digester);
 581  
 
 582  0
         digester.addSetRoot(path, "registerAgent");
 583  0
     }
 584  
 
 585  
     protected void addConnectorRules(Digester digester, String path) throws ConfigurationException
 586  
     {
 587  
         // Create connectors
 588  0
         path += "/connector";
 589  0
         addObjectCreateOrGetFromContainer(path, CONNECTOR_INTERFACE, "className", "ref", true);
 590  
 
 591  0
         addSetPropertiesRule(path, digester);
 592  
 
 593  0
         addMulePropertiesRule(path, digester);
 594  
 
 595  0
         digester.addRule(path + "/threading-profile", new Rule()
 596  
         {
 597  
             private String id;
 598  
 
 599  
             public void begin(String s, String s1, Attributes attributes) throws Exception
 600  
             {
 601  
                 // use the global tp as a template
 602  0
                 MuleConfiguration cfg = MuleManager.getConfiguration();
 603  0
                 id = attributes.getValue("id");
 604  0
                 if ("default".equals(id))
 605  
                 {
 606  0
                     digester.push(cfg.getDefaultThreadingProfile());
 607  
                 }
 608  0
                 else if ("receiver".equals(id))
 609  
                 {
 610  0
                     digester.push(cfg.getMessageReceiverThreadingProfile());
 611  
                 }
 612  0
                 else if ("dispatcher".equals(id))
 613  
                 {
 614  0
                     digester.push(cfg.getMessageDispatcherThreadingProfile());
 615  
                 }
 616  
 
 617  0
             }
 618  
 
 619  0
             public void end(String s, String s1) throws Exception
 620  
             {
 621  0
                 ThreadingProfile tp = (ThreadingProfile)digester.pop();
 622  0
                 AbstractConnector cnn = (AbstractConnector)digester.peek();
 623  
 
 624  0
                 if ("default".equals(id))
 625  
                 {
 626  0
                     cnn.setReceiverThreadingProfile(tp);
 627  0
                     cnn.setDispatcherThreadingProfile(tp);
 628  
                 }
 629  0
                 else if ("receiver".equals(id))
 630  
                 {
 631  0
                     cnn.setReceiverThreadingProfile(tp);
 632  
                 }
 633  0
                 else if ("dispatcher".equals(id))
 634  
                 {
 635  0
                     cnn.setDispatcherThreadingProfile(tp);
 636  
                 }
 637  0
             }
 638  
         });
 639  
 
 640  0
         SetPropertiesRule threadingRule = new SetPropertiesRule();
 641  0
         threadingRule.addAlias("poolExhaustedAction", "poolExhaustedActionString");
 642  0
         digester.addRule(path + "/threading-profile", threadingRule);
 643  
 
 644  
         // Connection strategy
 645  0
         digester.addObjectCreate(path + "/connection-strategy", CONNECTION_STRATEGY_INTERFACE, "className");
 646  0
         addMulePropertiesRule(path + "/connection-strategy", digester);
 647  0
         digester.addSetNext(path + "/connection-strategy", "setConnectionStrategy");
 648  
 
 649  0
         addExceptionStrategyRules(digester, path);
 650  
 
 651  
         // register conntector
 652  0
         digester.addSetRoot(path, "registerConnector");
 653  0
     }
 654  
 
 655  
     protected void addInterceptorStackRules(Digester digester, String path) throws ConfigurationException
 656  
     {
 657  
         // Create Inteceptor stacks
 658  0
         path += "/interceptor-stack";
 659  0
         digester.addRule(path + "/interceptor", new ObjectCreateRule(INTERCEPTOR_INTERFACE, "className")
 660  
         {
 661  0
             public void end(String s, String s1) throws Exception
 662  
             {
 663  
                 /* do not pop the result */
 664  0
             }
 665  
         });
 666  
 
 667  0
         digester.addRule(path, new Rule()
 668  
         {
 669  
             public void begin(String s, String s1, Attributes attributes) throws Exception
 670  
             {
 671  0
                 digester.push(attributes.getValue("name"));
 672  0
             }
 673  
 
 674  0
             public void end(String s, String s1) throws Exception
 675  
             {
 676  0
                 List list = new ArrayList();
 677  0
                 Object obj = digester.peek();
 678  0
                 while (obj instanceof UMOInterceptor)
 679  
                 {
 680  0
                     list.add(0, digester.pop());
 681  0
                     obj = digester.peek();
 682  
                 }
 683  0
                 InterceptorStack stack = new InterceptorStack();
 684  0
                 stack.setInterceptors(list);
 685  0
                 manager.registerInterceptorStack(digester.pop().toString(), stack);
 686  0
             }
 687  
         });
 688  
 
 689  0
         addMulePropertiesRule(path + "/interceptor", digester);
 690  0
     }
 691  
 
 692  
     protected void addModelRules(Digester digester, String path) throws ConfigurationException
 693  
     {
 694  
         // Create Model
 695  0
         path += "/model";
 696  
 
 697  0
         digester.addRule(path, new Rule()
 698  
         {
 699  0
             public void begin(String string, String string1, Attributes attributes) throws Exception
 700  
             {
 701  
                 UMOModel model;
 702  0
                 String modelType = attributes.getValue("type");
 703  0
                 String modelName = attributes.getValue("name");
 704  0
                 if (modelType == null)
 705  
                 {
 706  0
                     modelType = MuleManager.getConfiguration().getModelType();
 707  
                 }
 708  0
                 if (modelType.equalsIgnoreCase("custom"))
 709  
                 {
 710  0
                     String className = attributes.getValue("className");
 711  0
                     if (className == null)
 712  
                     {
 713  0
                         throw new IllegalArgumentException(
 714  
                             "Cannot use 'custom' model type without setting the 'className' for the model");
 715  
                     }
 716  
                     else
 717  
                     {
 718  0
                         model = (UMOModel)ClassUtils.instanciateClass(className, ClassUtils.NO_ARGS,
 719  
                             getClass());
 720  
                     }
 721  0
                 }
 722  0
                 else if (modelType.equalsIgnoreCase("inherited"))
 723  
                 {
 724  0
                     Map models = MuleManager.getInstance().getModels();
 725  0
                     if(models.size()==0)
 726  
                     {
 727  0
                         throw new IllegalArgumentException("When using model inheritance there must be one model registered with Mule");
 728  
                     }
 729  0
                     model = (UMOModel)models.get(modelName);
 730  0
                     if(model == null)
 731  
                     {
 732  0
                         throw new IllegalArgumentException("Cannot inherit from model '" + modelName + "'. No such model registered");
 733  
                     }
 734  0
                 }
 735  
                 else
 736  
                 {
 737  0
                     model = ModelFactory.createModel(modelType);
 738  
                 }
 739  
 
 740  0
                 digester.push(model);
 741  0
             }
 742  
         });
 743  
 
 744  0
         addSetPropertiesRule(path, digester);
 745  
 
 746  0
         digester.addSetRoot(path, "registerModel");
 747  
 
 748  
         // Create endpointUri resolver
 749  0
         digester.addObjectCreate(path + "/entry-point-resolver", DEFAULT_ENTRY_POINT_RESOLVER, "className");
 750  0
         addSetPropertiesRule(path + "/entry-point-resolver", digester);
 751  
 
 752  0
         digester.addSetNext(path + "/entry-point-resolver", "setEntryPointResolver");
 753  
 
 754  
         // Create lifecycle adapter
 755  0
         digester.addObjectCreate(path + "/component-lifecycle-adapter-factory", DEFAULT_LIFECYCLE_ADAPTER,
 756  
             "className");
 757  0
         addSetPropertiesRule(path, digester);
 758  0
         digester.addSetNext(path + "/component-lifecycle-adapter-factory", "setLifecycleAdapterFactory");
 759  
 
 760  
         // Pool factory
 761  0
         addPoolingProfileRules(digester, path);
 762  
 
 763  
         // Exception strategy
 764  0
         addExceptionStrategyRules(digester, path);
 765  
 
 766  
         // Add Components
 767  0
         addMuleDescriptorRules(digester, path);
 768  0
     }
 769  
 
 770  
     protected void addMuleDescriptorRules(Digester digester, String path) throws ConfigurationException
 771  
     {
 772  
         // Create Mule UMOs
 773  0
         path += "/mule-descriptor";
 774  0
         addObjectCreateOrGetFromContainer(path, DEFAULT_DESCRIPTOR, "className", "ref", "container", false);
 775  
 
 776  0
         addSetPropertiesRule(path, digester);
 777  
 
 778  
         // Create Message Routers
 779  0
         addMessageRouterRules(digester, path, "inbound");
 780  0
         addMessageRouterRules(digester, path, "outbound");
 781  0
         addMessageRouterRules(digester, path, "nested");
 782  0
         addMessageRouterRules(digester, path, "response");
 783  
 
 784  
         // Add threading profile rules
 785  0
         addThreadingProfileRules(digester, path, "component");
 786  
 
 787  
         // Add pooling profile rules
 788  0
         addPoolingProfileRules(digester, path);
 789  
 
 790  
         // queue profile rules
 791  0
         addQueueProfileRules(digester, path);
 792  
 
 793  
         // Create interceptors
 794  0
         digester.addRule(path + "/interceptor", new Rule()
 795  
         {
 796  
             public void begin(String string, String string1, Attributes attributes) throws Exception
 797  
             {
 798  0
                 String value = attributes.getValue("name");
 799  0
                 if (value == null)
 800  
                 {
 801  0
                     value = attributes.getValue("className");
 802  
                 }
 803  0
                 UMOManager man = (UMOManager)digester.getRoot();
 804  0
                 UMOInterceptorStack interceptorStack = man.lookupInterceptorStack(value);
 805  0
                 MuleDescriptor temp = (MuleDescriptor)digester.peek();
 806  0
                 if (interceptorStack != null)
 807  
                 {
 808  0
                     temp.addInterceptor(interceptorStack);
 809  
                 }
 810  
                 else
 811  
                 {
 812  
                     // Instantiate the new object and push it on the context
 813  
                     // stack
 814  0
                     Class clazz = digester.getClassLoader().loadClass(value);
 815  0
                     Object instance = clazz.newInstance();
 816  0
                     temp.addInterceptor((UMOInterceptor)instance);
 817  0
                     digester.push(instance);
 818  
                 }
 819  0
             }
 820  
 
 821  0
             public void end(String s, String s1) throws Exception
 822  
             {
 823  0
                 if (digester.peek() instanceof UMOInterceptor)
 824  
                 {
 825  0
                     digester.pop();
 826  
                 }
 827  0
             }
 828  
         });
 829  
 
 830  0
         addMulePropertiesRule(path + "/interceptor", digester);
 831  
 
 832  
         // Set exception strategy
 833  0
         addExceptionStrategyRules(digester, path);
 834  
 
 835  0
         addMulePropertiesRule(path, digester, "setProperties");
 836  0
         digester.addSetNext(path + "/properties", "setProperties");
 837  
 
 838  
         // register the component
 839  0
         digester.addRule(path, new Rule()
 840  
         {
 841  0
             public void end(String s, String s1) throws Exception
 842  
             {
 843  0
                 UMODescriptor descriptor = (UMODescriptor)digester.peek();
 844  0
                 Object obj = digester.peek(1);
 845  0
                 final UMOModel model = (UMOModel)obj;
 846  0
                 descriptor.setModelName(model.getName());
 847  0
                 model.registerComponent(descriptor);
 848  0
             }
 849  
         });
 850  0
     }
 851  
 
 852  
     protected void addThreadingProfileRules(Digester digester, String path, final String type)
 853  
     {
 854  
         // set threading profile
 855  0
         digester.addRule(path + "/threading-profile", new Rule()
 856  
         {
 857  
             public void begin(String s, String s1, Attributes attributes) throws Exception
 858  
             {
 859  
                 // use the default as a template
 860  0
                 MuleConfiguration cfg = MuleManager.getConfiguration();
 861  0
                 if ("component".equals(type))
 862  
                 {
 863  0
                     digester.push(cfg.getComponentThreadingProfile());
 864  
                 }
 865  0
                 else if ("messageReceiver".equals(type))
 866  
                 {
 867  0
                     digester.push(cfg.getComponentThreadingProfile());
 868  
                 }
 869  0
                 else if ("messageDispatcher".equals(type))
 870  
                 {
 871  0
                     digester.push(cfg.getComponentThreadingProfile());
 872  
                 }
 873  
                 else
 874  
                 {
 875  0
                     digester.push(cfg.getDefaultThreadingProfile());
 876  
                 }
 877  0
             }
 878  
 
 879  0
             public void end(String s, String s1) throws Exception
 880  
             {
 881  0
                 digester.pop();
 882  0
             }
 883  
         });
 884  
         // set threading profile
 885  0
         SetPropertiesRule threadingRule = new SetPropertiesRule();
 886  0
         threadingRule.addAlias("poolExhaustedAction", "poolExhaustedActionString");
 887  0
         digester.addRule(path + "/threading-profile", threadingRule);
 888  0
         digester.addSetNext(path + "/threading-profile", "setThreadingProfile");
 889  0
     }
 890  
 
 891  
     protected void addPoolingProfileRules(Digester digester, String path)
 892  
     {
 893  
         // set pooling profile
 894  0
         digester.addRule(path + "/pooling-profile", new Rule()
 895  
         {
 896  
             public void begin(String s, String s1, Attributes attributes) throws Exception
 897  
             {
 898  
                 // use the default as a template
 899  0
                 MuleConfiguration cfg = MuleManager.getConfiguration();
 900  0
                 digester.push(cfg.getPoolingProfile());
 901  0
             }
 902  
 
 903  0
             public void end(String s, String s1) throws Exception
 904  
             {
 905  0
                 digester.pop();
 906  0
             }
 907  
         });
 908  
 
 909  0
         SetPropertiesRule rule = new SetPropertiesRule();
 910  0
         rule.addAlias("exhaustedAction", "exhaustedActionString");
 911  0
         rule.addAlias("initialisationPolicy", "initialisationPolicyString");
 912  0
         digester.addRule(path + "/pooling-profile", rule);
 913  0
         digester.addSetNext(path + "/pooling-profile", "setPoolingProfile");
 914  0
     }
 915  
 
 916  
     protected void addQueueProfileRules(Digester digester, String path)
 917  
     {
 918  0
         digester.addObjectCreate(path + "/queue-profile", QUEUE_PROFILE);
 919  0
         addSetPropertiesRule(path + "/queue-profile", digester);
 920  0
         digester.addSetNext(path + "/queue-profile", "setQueueProfile");
 921  0
     }
 922  
 
 923  
     protected void addMessageRouterRules(Digester digester, String path, String type)
 924  
         throws ConfigurationException
 925  
     {
 926  
         String defaultRouter;
 927  
         String setMethod;
 928  0
         if ("inbound".equals(type))
 929  
         {
 930  0
             defaultRouter = DEFAULT_INBOUND_ROUTER_COLLECTION;
 931  0
             setMethod = "setInboundRouter";
 932  0
             path += "/inbound-router";
 933  
             // Add endpoints for multiple inbound endpoints
 934  0
             addEndpointRules(digester, path, "addEndpoint");
 935  0
             addGlobalReferenceEndpointRules(digester, path, "addEndpoint");
 936  
         }
 937  0
         else if ("response".equals(type))
 938  
         {
 939  0
             defaultRouter = DEFAULT_RESPONSE_ROUTER_COLLECTION;
 940  0
             setMethod = "setResponseRouter";
 941  0
             path += "/response-router";
 942  
             // Add endpoints for multiple response endpoints i.e. replyTo
 943  
             // addresses
 944  0
             addEndpointRules(digester, path, "addEndpoint");
 945  0
             addGlobalReferenceEndpointRules(digester, path, "addEndpoint");
 946  
         }
 947  0
         else if ("nested".equals(type)) {
 948  0
                         defaultRouter = DEFAULT_NESTED_ROUTER_COLLECTION;
 949  0
                         setMethod = "setNestedRouter";
 950  0
                         path += "/nested-router";
 951  
 
 952  
             }
 953  
         else
 954  
         {
 955  0
             defaultRouter = DEFAULT_OUTBOUND_ROUTER_COLLECTION;
 956  0
             setMethod = "setOutboundRouter";
 957  0
             path += "/outbound-router";
 958  
         }
 959  0
         digester.addObjectCreate(path, defaultRouter, "className");
 960  0
         addSetPropertiesRule(path, digester);
 961  
 
 962  
         // Add Catch All strategy
 963  0
         digester.addObjectCreate(path + "/catch-all-strategy", DEFAULT_CATCH_ALL_STRATEGY, "className");
 964  0
         addSetPropertiesRule(path + "/catch-all-strategy", digester);
 965  
 
 966  
         // Add endpointUri for catch-all strategy
 967  0
         addEndpointRules(digester, path + "/catch-all-strategy", "setEndpoint");
 968  0
         addGlobalReferenceEndpointRules(digester, path + "/catch-all-strategy", "setEndpoint");
 969  
 
 970  0
         addMulePropertiesRule(path + "/catch-all-strategy", digester);
 971  0
         digester.addSetNext(path + "/catch-all-strategy", "setCatchAllStrategy");
 972  
 
 973  
         // Add router rules
 974  0
         addRouterRules(digester, path, type);
 975  
 
 976  
         // add the router to the descriptor
 977  0
         digester.addSetNext(path, setMethod);
 978  0
     }
 979  
 
 980  
     protected void addRouterRules(Digester digester, String path, final String type)
 981  
         throws ConfigurationException
 982  
     {
 983  0
         if("nested".equals(type))
 984  
         {
 985  0
             path += "/binding";
 986  0
             digester.addObjectCreate(path, DEFAULT_NESTED_ROUTER);
 987  
 
 988  
 
 989  0
         } else if ("inbound".equals(type))
 990  
         {
 991  0
             path += "/router";
 992  0
             digester.addObjectCreate(path, INBOUND_MESSAGE_ROUTER_INTERFACE, "className");
 993  
         }
 994  0
         else if ("response".equals(type))
 995  
         {
 996  0
             path += "/router";
 997  0
             digester.addObjectCreate(path, RESPONSE_MESSAGE_ROUTER_INTERFACE, "className");
 998  
         }
 999  
         else
 1000  
         {
 1001  0
             path += "/router";
 1002  0
             digester.addObjectCreate(path, OUTBOUND_MESSAGE_ROUTER_INTERFACE, "className");
 1003  
         }
 1004  
 
 1005  0
         addSetPropertiesRule(path, digester, new String[]{"enableCorrelation", "propertyExtractor"},
 1006  
             new String[]{"enableCorrelationAsString", "propertyExtractorAsString"});
 1007  0
         addMulePropertiesRule(path, digester);
 1008  0
         if ("outbound".equals(type))
 1009  
         {
 1010  0
             addEndpointRules(digester, path, "addEndpoint");
 1011  0
             addReplyToRules(digester, path);
 1012  0
             addGlobalReferenceEndpointRules(digester, path, "addEndpoint");
 1013  0
             addTransactionConfigRules(path, digester);
 1014  
         }
 1015  0
         else if("nested".equals(type))
 1016  
         {
 1017  
             //Right now only one endpoint can be set on a nested Router so call
 1018  
             //setEndpoint not addEndpoint
 1019  0
             addEndpointRules(digester, path, "setEndpoint");
 1020  0
                         addGlobalReferenceEndpointRules(digester, path, "setEndpoint");
 1021  
         }
 1022  0
         addFilterRules(digester, path);
 1023  
 
 1024  
         // Set the router on the to the message router
 1025  0
         digester.addSetNext(path, "addRouter");
 1026  0
     }
 1027  
 
 1028  
     protected void addReplyToRules(Digester digester, String path) throws ConfigurationException
 1029  
     {
 1030  
         // Set message endpoint
 1031  0
         path += "/reply-to";
 1032  0
         digester.addRule(path, new Rule()
 1033  
         {
 1034  0
             public void begin(String s, String s1, Attributes attributes) throws Exception
 1035  
             {
 1036  0
                 String replyTo = attributes.getValue("address");
 1037  0
                 ((UMOOutboundRouter)digester.peek()).setReplyTo(replyTo);
 1038  0
             }
 1039  
         });
 1040  0
     }
 1041  
 
 1042  
     protected void addEndpointRules(Digester digester, String path, String method)
 1043  
         throws ConfigurationException
 1044  
     {
 1045  
         // Set message endpoint
 1046  0
         path += "/endpoint";
 1047  0
         addObjectCreateOrGetFromContainer(path, DEFAULT_ENDPOINT, "className", "ref", false);
 1048  0
         addCommonEndpointRules(digester, path, method);
 1049  0
     }
 1050  
 
 1051  
     protected void addGlobalReferenceEndpointRules(Digester digester, String path, final String method)
 1052  
         throws ConfigurationException
 1053  
     {
 1054  
         // Set message endpoint
 1055  0
         path += "/global-endpoint";
 1056  0
         digester.addRule(path, new Rule()
 1057  
         {
 1058  
             public void begin(String s, String s1, Attributes attributes) throws Exception
 1059  
             {
 1060  0
                 String name = attributes.getValue("name");
 1061  0
                 String address = attributes.getValue("address");
 1062  0
                 String trans = attributes.getValue("transformers");
 1063  0
                 String responseTrans = attributes.getValue("responseTransformers");
 1064  0
                 String createConnector = attributes.getValue("createConnector");
 1065  0
                 EndpointReference ref = new EndpointReference(method, name, address, trans, responseTrans,
 1066  
                     createConnector, digester.peek());
 1067  
                 // TODO encoding
 1068  
                 // String encoding = attributes.getValue("encoding");
 1069  0
                 digester.push(ref);
 1070  0
             }
 1071  
 
 1072  0
             public void end(String endpointName, String endpointName1) throws Exception
 1073  
             {
 1074  0
                 endpointReferences.add(digester.pop());
 1075  0
             }
 1076  
         });
 1077  0
         addCommonEndpointRules(digester, path, null);
 1078  0
     }
 1079  
 
 1080  
     protected void addCommonEndpointRules(Digester digester, String path, String method)
 1081  
         throws ConfigurationException
 1082  
     {
 1083  0
         addSetPropertiesRule(path, digester, new String[]{"address", "transformers", "responseTransformers",
 1084  
             "createConnector"}, new String[]{"endpointURI", "transformer", "responseTransformer",
 1085  
             "createConnectorAsString"});
 1086  
         // todo test
 1087  0
         addMulePropertiesRule(path, digester, "setProperties");
 1088  0
         addTransactionConfigRules(path, digester);
 1089  
 
 1090  0
         addFilterRules(digester, path);
 1091  0
         if (method != null)
 1092  
         {
 1093  0
             digester.addSetNext(path, method);
 1094  
         }
 1095  
 
 1096  
         // Add security filter rules
 1097  0
         digester.addObjectCreate(path + "/security-filter", ENDPOINT_SECURITY_FILTER_INTERFACE, "className");
 1098  
 
 1099  0
         addMulePropertiesRule(path + "/security-filter", digester);
 1100  0
         digester.addSetNext(path + "/security-filter", "setSecurityFilter");
 1101  0
     }
 1102  
 
 1103  
     protected void addTransactionConfigRules(String path, Digester digester)
 1104  
     {
 1105  0
         digester.addObjectCreate(path + "/transaction", DEFAULT_TRANSACTION_CONFIG);
 1106  0
         addSetPropertiesRule(path + "/transaction", digester, new String[]{"action"},
 1107  
             new String[]{"actionAsString"});
 1108  
 
 1109  0
         digester.addObjectCreate(path + "/transaction/factory", TRANSACTION_FACTORY_INTERFACE, "className");
 1110  0
         addMulePropertiesRule(path + "/transaction/factory", digester);
 1111  0
         digester.addSetNext(path + "/transaction/factory", "setFactory");
 1112  
 
 1113  0
         digester.addObjectCreate(path + "/transaction/constraint", TRANSACTION_CONSTRAINT_INTERFACE, "className");
 1114  0
         addSetPropertiesRule(path + "/transaction/constraint", digester);
 1115  
 
 1116  0
         digester.addSetNext(path + "/transaction/constraint", "setConstraint");
 1117  0
         digester.addSetNext(path + "/transaction", "setTransactionConfig");
 1118  0
     }
 1119  
 
 1120  
     protected void addExceptionStrategyRules(Digester digester, String path) throws ConfigurationException
 1121  
     {
 1122  0
         path += "/exception-strategy";
 1123  0
         digester.addObjectCreate(path, EXCEPTION_STRATEGY_INTERFACE, "className");
 1124  0
         addMulePropertiesRule(path, digester);
 1125  
 
 1126  
         // Add endpoint rules
 1127  0
         addEndpointRules(digester, path, "addEndpoint");
 1128  0
         addGlobalReferenceEndpointRules(digester, path, "addEndpoint");
 1129  0
         digester.addSetNext(path, "setExceptionListener");
 1130  0
     }
 1131  
 
 1132  
     protected void addSetPropertiesRule(String path, Digester digester, String[] s1, String[] s2)
 1133  
     {
 1134  0
         digester.addRule(path, new ExtendedMuleSetPropertiesRule(s1, s2));
 1135  0
     }
 1136  
 
 1137  
     protected void addSetPropertiesRule(String path, Digester digester)
 1138  
     {
 1139  0
         digester.addRule(path, new ExtendedMuleSetPropertiesRule());
 1140  0
     }
 1141  
 
 1142  
     private void addTransformerReference(String propName, String transName, Object object)
 1143  
     {
 1144  0
         transformerReferences.add(new TransformerReference(propName, transName, object));
 1145  0
     }
 1146  
 
 1147  
     private void addEndpointReference(String propName, String endpointName, Object object)
 1148  
     {
 1149  0
         endpointReferences.add(new EndpointReference(propName, endpointName, null, null, null, null, object));
 1150  0
     }
 1151  
 
 1152  
     /**
 1153  
      * this rule serves 2 functions - 1. Allows for late binding of certain types of
 1154  
      * object, namely Transformers and endpoints that need to be set on objects once
 1155  
      * the Manager configuration has been processed 2. Allows for template parameters
 1156  
      * to be parse on the configuration file in the form of ${param-name}. These will
 1157  
      * get resolved against properties set in the mule-properites element
 1158  
      */
 1159  
     public class ExtendedMuleSetPropertiesRule extends MuleSetPropertiesRule
 1160  
     {
 1161  
         public ExtendedMuleSetPropertiesRule()
 1162  0
         {
 1163  0
             super();
 1164  0
         }
 1165  
 
 1166  
         public ExtendedMuleSetPropertiesRule(PlaceholderProcessor processor)
 1167  0
         {
 1168  0
             super(processor);
 1169  0
         }
 1170  
 
 1171  
         public ExtendedMuleSetPropertiesRule(String[] strings, String[] strings1)
 1172  0
         {
 1173  0
             super(strings, strings1);
 1174  0
         }
 1175  
 
 1176  
         public ExtendedMuleSetPropertiesRule(String[] strings,
 1177  
                                              String[] strings1,
 1178  
                                              PlaceholderProcessor processor)
 1179  0
         {
 1180  0
             super(strings, strings1, processor);
 1181  0
         }
 1182  
 
 1183  
         public void begin(String s1, String s2, Attributes attributes) throws Exception
 1184  
         {
 1185  0
             attributes = processor.processAttributes(attributes, s2);
 1186  
             // Add transformer references that will be bound to their objects
 1187  
             // once all configuration has bean read
 1188  0
             String transformerNames = attributes.getValue("transformer");
 1189  0
             if (transformerNames != null)
 1190  
             {
 1191  0
                 addTransformerReference("transformer", transformerNames, digester.peek());
 1192  
             }
 1193  0
             transformerNames = attributes.getValue("transformers");
 1194  0
             if (transformerNames != null)
 1195  
             {
 1196  0
                 addTransformerReference("transformer", transformerNames, digester.peek());
 1197  
             }
 1198  
 
 1199  0
             transformerNames = attributes.getValue("responseTransformers");
 1200  0
             if (transformerNames != null)
 1201  
             {
 1202  0
                 addTransformerReference("responseTransformer", transformerNames, digester.peek());
 1203  
             }
 1204  
 
 1205  
             // transformerNames = attributes.getValue("responseTransformer");
 1206  
             // if (transformerNames != null) {
 1207  
             // addTransformerReference("responseTransformer", transformerNames,
 1208  
             // digester.peek());
 1209  
             // }
 1210  
 
 1211  0
             transformerNames = attributes.getValue("inboundTransformer");
 1212  0
             if (transformerNames != null)
 1213  
             {
 1214  0
                 addTransformerReference("inboundTransformer", transformerNames, digester.peek());
 1215  
             }
 1216  
 
 1217  0
             transformerNames = attributes.getValue("outboundTransformer");
 1218  0
             if (transformerNames != null)
 1219  
             {
 1220  0
                 addTransformerReference("outboundTransformer", transformerNames, digester.peek());
 1221  
             }
 1222  
 
 1223  0
             transformerNames = attributes.getValue("responseTransformer");
 1224  0
             if (transformerNames != null)
 1225  
             {
 1226  0
                 addTransformerReference("responseTransformer", transformerNames, digester.peek());
 1227  
             }
 1228  
 
 1229  
             // Special case handling of global endpoint refs on the
 1230  
             // inboundEndpoint/
 1231  
             // outboundendpoint attributes of the descriptor
 1232  0
             String endpoint = attributes.getValue("inboundEndpoint");
 1233  0
             if (endpoint != null)
 1234  
             {
 1235  0
                 Object o = manager.getEndpoints().get(endpoint);
 1236  0
                 if (o != null)
 1237  
                 {
 1238  0
                     addEndpointReference("setInboundEndpoint", endpoint, digester.peek());
 1239  
                 }
 1240  
             }
 1241  
 
 1242  0
             endpoint = attributes.getValue("outboundEndpoint");
 1243  0
             if (endpoint != null)
 1244  
             {
 1245  0
                 Object o = manager.getEndpoints().get(endpoint);
 1246  0
                 if (o != null)
 1247  
                 {
 1248  0
                     addEndpointReference("setOutboundEndpoint", endpoint, digester.peek());
 1249  
                 }
 1250  
             }
 1251  0
             super.begin(attributes);
 1252  0
         }
 1253  
     }
 1254  
 
 1255  
     protected void addObjectCreateOrGetFromContainer(final String path,
 1256  
                                                      String defaultImpl,
 1257  
                                                      final String classAttrib,
 1258  
                                                      final String refAttrib,
 1259  
                                                      final boolean classRefRequired)
 1260  
     {
 1261  0
         digester.addRule(path, new ObjectGetOrCreateRule(defaultImpl, classAttrib, refAttrib, classAttrib,
 1262  
             classRefRequired, "getContainerContext"));
 1263  0
     }
 1264  
 
 1265  
     protected void addObjectCreateOrGetFromContainer(final String path,
 1266  
                                                      String defaultImpl,
 1267  
                                                      final String classAttrib,
 1268  
                                                      final String refAttrib,
 1269  
                                                      final String containerAttrib,
 1270  
                                                      final boolean classRefRequired)
 1271  
     {
 1272  0
         digester.addRule(path, new ObjectGetOrCreateRule(defaultImpl, classAttrib, refAttrib,
 1273  
             containerAttrib, classAttrib, classRefRequired, "getContainerContext"));
 1274  0
     }
 1275  
 }