1 10 11 package org.mule.config.builders; 12 13 import org.apache.commons.beanutils.ConvertUtils; 14 import org.apache.commons.digester.AbstractObjectCreationFactory; 15 import org.apache.commons.digester.Digester; 16 import org.apache.commons.digester.ObjectCreateRule; 17 import org.apache.commons.digester.Rule; 18 import org.apache.commons.digester.SetNextRule; 19 import org.apache.commons.digester.SetPropertiesRule; 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 import org.mule.MuleManager; 23 import org.mule.config.ConfigurationBuilder; 24 import org.mule.config.ConfigurationException; 25 import org.mule.config.MuleConfiguration; 26 import org.mule.config.MuleDtdResolver; 27 import org.mule.config.MuleProperties; 28 import org.mule.config.PoolingProfile; 29 import org.mule.config.QueueProfile; 30 import org.mule.config.ReaderResource; 31 import org.mule.config.ThreadingProfile; 32 import org.mule.config.converters.ConnectorConverter; 33 import org.mule.config.converters.EndpointConverter; 34 import org.mule.config.converters.EndpointURIConverter; 35 import org.mule.config.converters.TransactionFactoryConverter; 36 import org.mule.config.converters.TransformerConverter; 37 import org.mule.config.i18n.Message; 38 import org.mule.config.i18n.Messages; 39 import org.mule.config.pool.CommonsPoolFactory; 40 import org.mule.impl.DefaultLifecycleAdapter; 41 import org.mule.impl.MuleDescriptor; 42 import org.mule.impl.MuleTransactionConfig; 43 import org.mule.impl.endpoint.MuleEndpoint; 44 import org.mule.impl.model.ModelFactory; 45 import org.mule.impl.security.MuleSecurityManager; 46 import org.mule.interceptors.InterceptorStack; 47 import org.mule.model.DynamicEntryPointResolver; 48 import org.mule.providers.AbstractConnector; 49 import org.mule.providers.ConnectionStrategy; 50 import org.mule.routing.LoggingCatchAllStrategy; 51 import org.mule.routing.inbound.InboundMessageRouter; 52 import org.mule.routing.outbound.OutboundMessageRouter; 53 import org.mule.routing.response.ResponseMessageRouter; 54 import org.mule.transaction.constraints.BatchConstraint; 55 import org.mule.umo.UMODescriptor; 56 import org.mule.umo.UMOEncryptionStrategy; 57 import org.mule.umo.UMOInterceptor; 58 import org.mule.umo.UMOInterceptorStack; 59 import org.mule.umo.UMOTransactionFactory; 60 import org.mule.umo.endpoint.UMOEndpoint; 61 import org.mule.umo.endpoint.UMOEndpointURI; 62 import org.mule.umo.lifecycle.InitialisationException; 63 import org.mule.umo.manager.ContainerException; 64 import org.mule.umo.manager.UMOAgent; 65 import org.mule.umo.manager.UMOContainerContext; 66 import org.mule.umo.manager.UMOManager; 67 import org.mule.umo.manager.UMOTransactionManagerFactory; 68 import org.mule.umo.model.UMOModel; 69 import org.mule.umo.provider.UMOConnector; 70 import org.mule.umo.routing.UMOInboundMessageRouter; 71 import org.mule.umo.routing.UMOOutboundMessageRouter; 72 import org.mule.umo.routing.UMOOutboundRouter; 73 import org.mule.umo.routing.UMOResponseMessageRouter; 74 import org.mule.umo.security.UMOEndpointSecurityFilter; 75 import org.mule.umo.security.UMOSecurityManager; 76 import org.mule.umo.security.UMOSecurityProvider; 77 import org.mule.umo.transformer.UMOTransformer; 78 import org.mule.util.ClassUtils; 79 import org.mule.util.PropertiesUtils; 80 import org.mule.util.StringUtils; 81 import org.mule.util.queue.EventFilePersistenceStrategy; 82 import org.xml.sax.Attributes ; 83 84 import java.beans.ExceptionListener ; 85 import java.io.InputStream ; 86 import java.io.InputStreamReader ; 87 import java.util.ArrayList ; 88 import java.util.HashMap ; 89 import java.util.Iterator ; 90 import java.util.List ; 91 import java.util.Map ; 92 import java.util.Properties ; 93 94 99 public class MuleXmlConfigurationBuilder extends AbstractDigesterConfiguration 100 implements ConfigurationBuilder 101 { 102 105 protected static Log logger = LogFactory.getLog(MuleXmlConfigurationBuilder.class); 106 107 public static final String DEFAULT_ENTRY_POINT_RESOLVER = DynamicEntryPointResolver.class.getName(); 108 public static final String DEFAULT_LIFECYCLE_ADAPTER = DefaultLifecycleAdapter.class.getName(); 109 public static final String DEFAULT_ENDPOINT = MuleEndpoint.class.getName(); 110 public static final String DEFAULT_TRANSACTION_CONFIG = MuleTransactionConfig.class.getName(); 111 public static final String DEFAULT_DESCRIPTOR = MuleDescriptor.class.getName(); 112 public static final String DEFAULT_SECURITY_MANAGER = MuleSecurityManager.class.getName(); 113 public static final String DEFAULT_OUTBOUND_MESSAGE_ROUTER = OutboundMessageRouter.class.getName(); 114 public static final String DEFAULT_INBOUND_MESSAGE_ROUTER = InboundMessageRouter.class.getName(); 115 public static final String DEFAULT_RESPONSE_MESSAGE_ROUTER = ResponseMessageRouter.class.getName(); 116 public static final String DEFAULT_CATCH_ALL_STRATEGY = LoggingCatchAllStrategy.class.getName(); 117 public static final String DEFAULT_POOL_FACTORY = CommonsPoolFactory.class.getName(); 118 public static final String THREADING_PROFILE = ThreadingProfile.class.getName(); 119 public static final String POOLING_PROFILE = PoolingProfile.class.getName(); 120 public static final String QUEUE_PROFILE = QueueProfile.class.getName(); 121 122 public static final String PERSISTENCE_STRATEGY_INTERFACE = EventFilePersistenceStrategy.class.getName(); 123 public static final String INBOUND_MESSAGE_ROUTER_INTERFACE = UMOInboundMessageRouter.class.getName(); 124 public static final String RESPONSE_MESSAGE_ROUTER_INTERFACE = UMOResponseMessageRouter.class.getName(); 125 public static final String OUTBOUND_MESSAGE_ROUTER_INTERFACE = UMOOutboundMessageRouter.class.getName(); 126 public static final String TRANSFORMER_INTERFACE = UMOTransformer.class.getName(); 127 public static final String TRANSACTION_MANAGER_FACTORY_INTERFACE = UMOTransactionManagerFactory.class.getName(); 128 public static final String SECURITY_PROVIDER_INTERFACE = UMOSecurityProvider.class.getName(); 129 public static final String ENCRYPTION_STRATEGY_INTERFACE = UMOEncryptionStrategy.class.getName(); 130 public static final String ENDPOINT_SECURITY_FILTER_INTERFACE = UMOEndpointSecurityFilter.class.getName(); 131 public static final String AGENT_INTERFACE = UMOAgent.class.getName(); 132 public static final String TRANSACTION_FACTORY_INTERFACE = UMOTransactionFactory.class.getName(); 133 public static final String TRANSACTION_CONSTRAINT_INTERFACE = BatchConstraint.class.getName(); 134 public static final String CONNECTOR_INTERFACE = UMOConnector.class.getName(); 135 public static final String INTERCEPTOR_INTERFACE = UMOInterceptor.class.getName(); 136 public static final String ROUTER_INTERFACE = UMOOutboundRouter.class.getName(); 137 public static final String EXCEPTION_STRATEGY_INTERFACE = ExceptionListener .class.getName(); 138 public static final String CONNECTION_STRATEGY_INTERFACE = ConnectionStrategy.class.getName(); 139 140 protected UMOManager manager; 141 142 private List transformerReferences = new ArrayList (); 143 private List endpointReferences = new ArrayList (); 144 145 public MuleXmlConfigurationBuilder() throws ConfigurationException 146 { 147 super(System.getProperty(MuleProperties.XML_VALIDATE_SYSTEM_PROPERTY, "true") 148 .equalsIgnoreCase("true"), System.getProperty(MuleProperties.XML_DTD_SYSTEM_PROPERTY, 149 MuleDtdResolver.DEFAULT_MULE_DTD)); 150 151 ConvertUtils.register(new EndpointConverter(), UMOEndpoint.class); 152 ConvertUtils.register(new TransformerConverter(), UMOTransformer.class); 153 ConvertUtils.register(new ConnectorConverter(), UMOConnector.class); 154 ConvertUtils.register(new TransactionFactoryConverter(), UMOTransactionFactory.class); 155 ConvertUtils.register(new EndpointURIConverter(), UMOEndpointURI.class); 156 157 String path = getRootName(); 158 addManagerRules(digester, path); 159 addServerPropertiesRules(path + "/environment-properties", "addProperties", 0); 160 addContainerContextRules(path + "/container-context", "setContainerContext", 0); 161 162 addMuleConfigurationRules(digester, path); 163 addTransformerRules(digester, path); 164 addSecurityManagerRules(digester, path); 165 addTransactionManagerRules(digester, path); 166 addGlobalEndpointRules(digester, path); 167 addEndpointIdentifierRules(digester, path); 168 addInterceptorStackRules(digester, path); 169 addConnectorRules(digester, path); 170 addAgentRules(digester, path); 171 172 addModelRules(digester, path); 173 addMuleDescriptorRules(digester, path); 175 } 176 177 public String getRootName() 178 { 179 return "mule-configuration"; 180 } 181 182 public UMOManager configure(String configResources) throws ConfigurationException 183 { 184 return configure(configResources, null); 185 } 186 187 public UMOManager configure(String configResources, String startupPropertiesFile) 188 throws ConfigurationException 189 { 190 try 191 { 192 String [] resources = StringUtils.splitAndTrim(configResources, ","); 193 MuleManager.getConfiguration().setConfigResources(resources); 194 ReaderResource[] readers = new ReaderResource[resources.length]; 195 for (int i = 0; i < resources.length; i++) 196 { 197 InputStream is = loadConfig(resources[i].trim()); 198 readers[i] = new ReaderResource(resources[i].trim(), 199 new InputStreamReader (is, configEncoding)); 200 } 201 202 if (startupPropertiesFile != null) 204 { 205 return configure(readers, PropertiesUtils.loadProperties(startupPropertiesFile, getClass())); 206 } 207 else 208 return configure(readers, null); 209 210 } 211 catch (Exception e) 212 { 213 throw new ConfigurationException(e); 214 } 215 } 216 217 221 public UMOManager configure(ReaderResource[] configResources) throws ConfigurationException 222 { 223 return configure(configResources, null); 224 } 225 226 public UMOManager configure(ReaderResource[] configResources, Properties startupProperties) 227 throws ConfigurationException 228 { 229 if (startupProperties != null) 230 { 231 ((MuleManager)MuleManager.getInstance()).addProperties(startupProperties); 232 } 233 manager = (MuleManager)process(configResources); 234 if (manager == null) 235 { 236 throw new ConfigurationException(new Message(Messages.FAILED_TO_CREATE_MANAGER_INSTANCE_X, 237 "Are you using a correct configuration builder?")); 238 } 239 try 240 { 241 setContainerProperties(); 242 setTransformers(); 243 setGlobalEndpoints(); 244 if (System.getProperty(MuleProperties.MULE_START_AFTER_CONFIG_SYSTEM_PROPERTY, "true") 245 .equalsIgnoreCase("true")) 246 { 247 manager.start(); 248 } 249 } 250 catch (Exception e) 251 { 252 throw new ConfigurationException(new Message(Messages.X_FAILED_TO_INITIALISE, "MuleManager"), e); 253 } 254 return manager; 255 } 256 257 262 public boolean isConfigured() 263 { 264 return manager != null; 265 } 266 267 protected void setContainerProperties() throws ContainerException 268 { 269 UMOContainerContext ctx = manager.getContainerContext(); 270 try 271 { 272 for (Iterator iterator = containerReferences.iterator(); iterator.hasNext();) 273 { 274 ContainerReference reference = (ContainerReference)iterator.next(); 275 reference.resolveReference(ctx); 276 } 277 } 278 finally 279 { 280 containerReferences.clear(); 281 } 282 } 283 284 protected void setTransformers() throws InitialisationException 285 { 286 try 287 { 288 for (Iterator iterator = transformerReferences.iterator(); iterator.hasNext();) 289 { 290 TransformerReference reference = (TransformerReference)iterator.next(); 291 reference.resolveTransformer(); 292 } 293 } 294 finally 295 { 296 transformerReferences.clear(); 297 } 298 } 299 300 protected void setGlobalEndpoints() throws InitialisationException 301 { 302 UMOManager manager = MuleManager.getInstance(); 307 308 Map endpoints = new HashMap (manager.getEndpoints()); 311 for (Iterator iterator = endpoints.values().iterator(); iterator.hasNext();) 312 { 313 UMOEndpoint ep = (UMOEndpoint)iterator.next(); 314 ep.initialise(); 315 manager.unregisterEndpoint(ep.getName()); 316 manager.registerEndpoint(ep); 317 } 318 319 try 320 { 321 for (Iterator iterator = endpointReferences.iterator(); iterator.hasNext();) 322 { 323 EndpointReference reference = (EndpointReference)iterator.next(); 324 reference.resolveEndpoint(); 325 } 326 } 327 finally 328 { 329 endpointReferences.clear(); 330 } 331 } 332 333 protected void addManagerRules(Digester digester, String path) 334 { 335 digester.addFactoryCreate(path, new AbstractObjectCreationFactory() 336 { 337 public Object createObject(Attributes attributes) throws Exception 338 { 339 manager = MuleManager.getInstance(); 340 return manager; 341 } 342 }); 343 digester.addSetProperties(path); 344 } 345 346 protected void addMuleConfigurationRules(Digester digester, String path) 347 { 348 digester.addSetProperties(path); 349 path += "/mule-environment-properties"; 351 digester.addObjectCreate(path, MuleConfiguration.class); 352 addSetPropertiesRule(path, digester); 353 354 addPoolingProfileRules(digester, path); 356 357 addQueueProfileRules(digester, path); 359 360 digester.addObjectCreate(path + "/threading-profile", THREADING_PROFILE); 362 SetPropertiesRule threadingRule = new SetPropertiesRule(); 363 threadingRule.addAlias("poolExhaustedAction", "poolExhaustedActionString"); 364 digester.addRule(path + "/threading-profile", threadingRule); 365 digester.addRule(path + "/threading-profile", new Rule() 366 { 367 private String id; 368 369 public void begin(String s, String s1, Attributes attributes) throws Exception 370 { 371 id = attributes.getValue("id"); 372 } 373 374 public void end(String s, String s1) throws Exception 375 { 376 ThreadingProfile tp = (ThreadingProfile)digester.peek(); 377 MuleConfiguration cfg = (MuleConfiguration)digester.peek(1); 378 379 if ("default".equals(id)) 380 { 381 cfg.setDefaultThreadingProfile(tp); 382 cfg.setMessageDispatcherThreadingProfile(tp); 383 cfg.setMessageReceiverThreadingProfile(tp); 384 cfg.setComponentThreadingProfile(tp); 385 } 386 else if ("messageReceiver".equals(id) || "receiver".equals(id)) 387 { 388 cfg.setMessageReceiverThreadingProfile(tp); 389 } 390 else if ("messageDispatcher".equals(id) || "dispatcher".equals(id)) 391 { 392 cfg.setMessageDispatcherThreadingProfile(tp); 393 } 394 else if ("component".equals(id)) 395 { 396 cfg.setComponentThreadingProfile(tp); 397 } 398 } 399 }); 400 401 digester.addObjectCreate(path + "/persistence-strategy", PERSISTENCE_STRATEGY_INTERFACE, "className"); 403 addMulePropertiesRule(path + "/persistence-strategy", digester); 404 digester.addSetNext(path + "/persistence-strategy", "setPersistenceStrategy"); 405 406 digester.addObjectCreate(path + "/connection-strategy", CONNECTION_STRATEGY_INTERFACE, "className"); 408 addMulePropertiesRule(path + "/connection-strategy", digester); 409 digester.addRule(path + "/connection-strategy", new SetNextRule("setConnectionStrategy") 412 { 413 public void end(String s, String s1) throws Exception 414 { 415 super.end(s, s1); 416 } 417 }); 418 419 digester.addRule(path, new Rule() 420 { 421 public void end(String s, String s1) throws Exception 422 { 423 MuleManager.setConfiguration((MuleConfiguration)digester.peek()); 424 } 425 }); 426 } 427 428 protected void addSecurityManagerRules(Digester digester, String path) throws ConfigurationException 429 { 430 path += "/security-manager"; 432 addObjectCreateOrGetFromContainer(path, DEFAULT_SECURITY_MANAGER, "className", "ref", false); 433 434 digester.addObjectCreate(path + "/security-provider", SECURITY_PROVIDER_INTERFACE, "className"); 436 addSetPropertiesRule(path + "/security-provider", digester); 437 addMulePropertiesRule(path + "/security-provider", digester); 438 digester.addSetNext(path + "/security-provider", "addProvider"); 439 440 digester.addObjectCreate(path + "/encryption-strategy", ENCRYPTION_STRATEGY_INTERFACE, "className"); 442 addSetPropertiesRule(path + "/encryption-strategy", digester); 443 addMulePropertiesRule(path + "/encryption-strategy", digester); 444 digester.addRule(path + "/encryption-strategy", new Rule() 445 { 446 private String name; 447 448 public void begin(String endpointName, String endpointName1, Attributes attributes) 449 throws Exception 450 { 451 name = attributes.getValue("name"); 452 } 453 454 public void end(String endpointName, String endpointName1) throws Exception 455 { 456 UMOEncryptionStrategy s = (UMOEncryptionStrategy)digester.peek(); 457 ((UMOSecurityManager)digester.peek(1)).addEncryptionStrategy(name, s); 458 } 459 }); 460 digester.addSetNext(path, "setSecurityManager"); 461 462 } 463 464 protected void addTransformerRules(Digester digester, String path) throws ConfigurationException 465 { 466 path += "/transformers/transformer"; 468 addObjectCreateOrGetFromContainer(path, TRANSFORMER_INTERFACE, "className", "ref", true); 469 470 addSetPropertiesRule(path, digester); 471 472 addMulePropertiesRule(path, digester); 473 digester.addSetRoot(path, "registerTransformer"); 474 } 475 476 protected void addGlobalEndpointRules(Digester digester, String path) throws ConfigurationException 477 { 478 path += "/global-endpoints"; 480 addEndpointRules(digester, path, "registerEndpoint"); 481 } 482 483 protected void addEndpointIdentifierRules(Digester digester, String path) throws ConfigurationException 484 { 485 path += "/endpoint-identifiers/endpoint-identifier"; 487 digester.addRule(path, new Rule() 488 { 489 private PlaceholderProcessor processor = new PlaceholderProcessor(); 490 491 public void begin(String s, String s1, Attributes attributes) throws Exception 492 { 493 attributes = processor.processAttributes(attributes, s1); 494 String name = attributes.getValue("name"); 495 String value = attributes.getValue("value"); 496 ((UMOManager)digester.getRoot()).registerEndpointIdentifier(name, value); 497 } 498 }); 499 } 500 501 protected void addTransactionManagerRules(Digester digester, String path) throws ConfigurationException 502 { 503 path += "/transaction-manager"; 505 addObjectCreateOrGetFromContainer(path, TRANSACTION_MANAGER_FACTORY_INTERFACE, "factory", "ref", true); 506 addMulePropertiesRule(path, digester); 507 508 digester.addSetRoot(path, "setTransactionManager"); 509 digester.addRule(path, new Rule() 510 { 511 public void end(String s, String s1) throws Exception 512 { 513 UMOTransactionManagerFactory txFactory = (UMOTransactionManagerFactory)digester.pop(); 514 digester.push(txFactory.create()); 515 } 516 }); 517 } 518 519 protected void addAgentRules(Digester digester, String path) throws ConfigurationException 520 { 521 path += "/agents/agent"; 523 addObjectCreateOrGetFromContainer(path, AGENT_INTERFACE, "className", "ref", true); 524 addSetPropertiesRule(path, digester); 525 526 addMulePropertiesRule(path, digester); 527 528 digester.addSetRoot(path, "registerAgent"); 529 } 530 531 protected void addConnectorRules(Digester digester, String path) throws ConfigurationException 532 { 533 path += "/connector"; 535 addObjectCreateOrGetFromContainer(path, CONNECTOR_INTERFACE, "className", "ref", true); 536 537 addSetPropertiesRule(path, digester); 538 539 addMulePropertiesRule(path, digester); 540 541 digester.addRule(path + "/threading-profile", new Rule() 542 { 543 private String id; 544 545 public void begin(String s, String s1, Attributes attributes) throws Exception 546 { 547 MuleConfiguration cfg = MuleManager.getConfiguration(); 549 id = attributes.getValue("id"); 550 if ("default".equals(id)) 551 { 552 digester.push(cfg.getDefaultThreadingProfile()); 553 } 554 else if ("receiver".equals(id)) 555 { 556 digester.push(cfg.getMessageReceiverThreadingProfile()); 557 } 558 else if ("dispatcher".equals(id)) 559 { 560 digester.push(cfg.getMessageDispatcherThreadingProfile()); 561 } 562 563 } 564 565 public void end(String s, String s1) throws Exception 566 { 567 ThreadingProfile tp = (ThreadingProfile)digester.pop(); 568 AbstractConnector cnn = (AbstractConnector)digester.peek(); 569 570 if ("default".equals(id)) 571 { 572 cnn.setReceiverThreadingProfile(tp); 573 cnn.setDispatcherThreadingProfile(tp); 574 } 575 else if ("receiver".equals(id)) 576 { 577 cnn.setReceiverThreadingProfile(tp); 578 } 579 else if ("dispatcher".equals(id)) 580 { 581 cnn.setDispatcherThreadingProfile(tp); 582 } 583 } 584 }); 585 586 SetPropertiesRule threadingRule = new SetPropertiesRule(); 587 threadingRule.addAlias("setPoolExhaustedAction", "setPoolExhaustedActionString"); 588 digester.addRule(path + "/threading-profile", threadingRule); 589 590 digester.addObjectCreate(path + "/connection-strategy", CONNECTION_STRATEGY_INTERFACE, "className"); 592 addMulePropertiesRule(path + "/connection-strategy", digester); 593 digester.addSetNext(path + "/connection-strategy", "setConnectionStrategy"); 594 595 addExceptionStrategyRules(digester, path); 596 597 digester.addSetRoot(path, "registerConnector"); 599 } 600 601 protected void addInterceptorStackRules(Digester digester, String path) throws ConfigurationException 602 { 603 path += "/interceptor-stack"; 605 digester.addRule(path + "/interceptor", new ObjectCreateRule(INTERCEPTOR_INTERFACE, "className") 606 { 607 public void end(String s, String s1) throws Exception 608 { 609 610 } 611 }); 612 613 digester.addRule(path, new Rule() 614 { 615 public void begin(String s, String s1, Attributes attributes) throws Exception 616 { 617 digester.push(attributes.getValue("name")); 618 } 619 620 public void end(String s, String s1) throws Exception 621 { 622 List list = new ArrayList (); 623 Object obj = digester.peek(); 624 while (obj instanceof UMOInterceptor) 625 { 626 list.add(0, digester.pop()); 627 obj = digester.peek(); 628 } 629 InterceptorStack stack = new InterceptorStack(); 630 stack.setInterceptors(list); 631 manager.registerInterceptorStack(digester.pop().toString(), stack); 632 } 633 }); 634 635 addMulePropertiesRule(path + "/interceptor", digester); 636 } 637 638 protected void addModelRules(Digester digester, String path) throws ConfigurationException 639 { 640 path += "/model"; 642 643 digester.addRule(path, new Rule() 644 { 645 public void begin(String string, String string1, Attributes attributes) throws Exception 646 { 647 UMOModel model = manager.getModel(); 648 if (MuleManager.DEFAULT_MODEL_NAME.equals(model.getName())) 651 { 652 model = null; 653 } 654 if (model == null) 655 { 656 String modelType = attributes.getValue("type"); 657 if (modelType == null) 658 { 659 modelType = MuleManager.getConfiguration().getModelType(); 660 } 661 if (modelType.equalsIgnoreCase("custom")) 662 { 663 String className = attributes.getValue("className"); 664 if (className == null) 665 { 666 throw new IllegalArgumentException ( 667 "Cannot use 'custom' model type without setting the 'className' for the model"); 668 } 669 else 670 { 671 model = (UMOModel)ClassUtils.instanciateClass(className, ClassUtils.NO_ARGS, 672 getClass()); 673 } 674 } 675 else 676 { 677 model = ModelFactory.createModel(modelType); 678 } 679 } 680 digester.push(model); 681 } 682 }); 683 684 addSetPropertiesRule(path, digester); 685 686 digester.addSetRoot(path, "setModel"); 687 688 digester.addObjectCreate(path + "/entry-point-resolver", DEFAULT_ENTRY_POINT_RESOLVER, "className"); 690 addSetPropertiesRule(path + "/entry-point-resolver", digester); 691 692 digester.addSetNext(path + "/entry-point-resolver", "setEntryPointResolver"); 693 694 digester.addObjectCreate(path + "/component-lifecycle-adapter-factory", DEFAULT_LIFECYCLE_ADAPTER, 696 "className"); 697 addSetPropertiesRule(path, digester); 698 digester.addSetNext(path + "/component-lifecycle-adapter-factory", "setLifecycleAdapterFactory"); 699 700 addPoolingProfileRules(digester, path); 702 703 addExceptionStrategyRules(digester, path); 705 706 addMuleDescriptorRules(digester, path); 708 } 709 710 protected void addMuleDescriptorRules(Digester digester, String path) throws ConfigurationException 711 { 712 path += "/mule-descriptor"; 714 addObjectCreateOrGetFromContainer(path, DEFAULT_DESCRIPTOR, "className", "ref", "container", false); 715 716 addSetPropertiesRule(path, digester); 717 718 addMessageRouterRules(digester, path, "inbound"); 720 addMessageRouterRules(digester, path, "outbound"); 721 addMessageRouterRules(digester, path, "response"); 722 723 addThreadingProfileRules(digester, path, "component"); 725 726 addPoolingProfileRules(digester, path); 728 729 addQueueProfileRules(digester, path); 731 732 digester.addRule(path + "/interceptor", new Rule() 734 { 735 public void begin(String string, String string1, Attributes attributes) throws Exception 736 { 737 String value = attributes.getValue("name"); 738 if (value == null) 739 { 740 value = attributes.getValue("className"); 741 } 742 UMOManager man = (UMOManager)digester.getRoot(); 743 UMOInterceptorStack interceptorStack = man.lookupInterceptorStack(value); 744 MuleDescriptor temp = (MuleDescriptor)digester.peek(); 745 if (interceptorStack != null) 746 { 747 temp.addInterceptor(interceptorStack); 748 } 749 else 750 { 751 Class clazz = digester.getClassLoader().loadClass(value); 754 Object instance = clazz.newInstance(); 755 temp.addInterceptor((UMOInterceptor)instance); 756 digester.push(instance); 757 } 758 } 759 760 public void end(String s, String s1) throws Exception 761 { 762 if (digester.peek() instanceof UMOInterceptor) 763 { 764 digester.pop(); 765 } 766 } 767 }); 768 769 addMulePropertiesRule(path + "/interceptor", digester); 770 771 addExceptionStrategyRules(digester, path); 773 774 addMulePropertiesRule(path, digester, "setProperties"); 775 digester.addSetNext(path + "/properties", "setProperties"); 776 777 digester.addRule(path, new Rule() 779 { 780 public void end(String s, String s1) throws Exception 781 { 782 UMODescriptor descriptor = (UMODescriptor)digester.peek(); 783 Object obj = digester.peek(1); 784 final UMOModel model; 785 if (obj instanceof UMOManager) 786 { 787 model = ((UMOManager)obj).getModel(); 788 } 789 else 790 { 791 model = (UMOModel)obj; 792 } 793 model.registerComponent(descriptor); 794 } 795 }); 796 } 797 798 protected void addThreadingProfileRules(Digester digester, String path, final String type) 799 { 800 digester.addRule(path + "/threading-profile", new Rule() 802 { 803 public void begin(String s, String s1, Attributes attributes) throws Exception 804 { 805 MuleConfiguration cfg = MuleManager.getConfiguration(); 807 if ("component".equals(type)) 808 { 809 digester.push(cfg.getComponentThreadingProfile()); 810 } 811 else if ("messageReceiver".equals(type)) 812 { 813 digester.push(cfg.getComponentThreadingProfile()); 814 } 815 else if ("messageDispatcher".equals(type)) 816 { 817 digester.push(cfg.getComponentThreadingProfile()); 818 } 819 else 820 { 821 digester.push(cfg.getDefaultThreadingProfile()); 822 } 823 } 824 825 public void end(String s, String s1) throws Exception 826 { 827 digester.pop(); 828 } 829 }); 830 SetPropertiesRule threadingRule = new SetPropertiesRule(); 832 threadingRule.addAlias("setPoolExhaustedAction", "setPoolExhaustedActionString"); 833 digester.addRule(path + "/threading-profile", threadingRule); 834 digester.addSetNext(path + "/threading-profile", "setThreadingProfile"); 835 } 836 837 protected void addPoolingProfileRules(Digester digester, String path) 838 { 839 digester.addRule(path + "/pooling-profile", new Rule() 841 { 842 public void begin(String s, String s1, Attributes attributes) throws Exception 843 { 844 MuleConfiguration cfg = MuleManager.getConfiguration(); 846 digester.push(cfg.getPoolingProfile()); 847 } 848 849 public void end(String s, String s1) throws Exception 850 { 851 digester.pop(); 852 } 853 }); 854 855 SetPropertiesRule rule = new SetPropertiesRule(); 856 rule.addAlias("exhaustedAction", "exhaustedActionString"); 857 rule.addAlias("initialisationPolicy", "initialisationPolicyString"); 858 digester.addRule(path + "/pooling-profile", rule); 859 digester.addSetNext(path + "/pooling-profile", "setPoolingProfile"); 860 } 861 862 protected void addQueueProfileRules(Digester digester, String path) 863 { 864 digester.addObjectCreate(path + "/queue-profile", QUEUE_PROFILE); 865 addSetPropertiesRule(path + "/queue-profile", digester); 866 digester.addSetNext(path + "/queue-profile", "setQueueProfile"); 867 } 868 869 protected void addMessageRouterRules(Digester digester, String path, String type) 870 throws ConfigurationException 871 { 872 String defaultRouter; 873 String setMethod; 874 if ("inbound".equals(type)) 875 { 876 defaultRouter = DEFAULT_INBOUND_MESSAGE_ROUTER; 877 setMethod = "setInboundRouter"; 878 path += "/inbound-router"; 879 addEndpointRules(digester, path, "addEndpoint"); 881 addGlobalReferenceEndpointRules(digester, path, "addEndpoint"); 882 } 883 else if ("response".equals(type)) 884 { 885 defaultRouter = DEFAULT_RESPONSE_MESSAGE_ROUTER; 886 setMethod = "setResponseRouter"; 887 path += "/response-router"; 888 addEndpointRules(digester, path, "addEndpoint"); 891 addGlobalReferenceEndpointRules(digester, path, "addEndpoint"); 892 } 893 else 894 { 895 defaultRouter = DEFAULT_OUTBOUND_MESSAGE_ROUTER; 896 setMethod = "setOutboundRouter"; 897 path += "/outbound-router"; 898 } 899 digester.addObjectCreate(path, defaultRouter, "className"); 900 addSetPropertiesRule(path, digester); 901 902 digester.addObjectCreate(path + "/catch-all-strategy", DEFAULT_CATCH_ALL_STRATEGY, "className"); 904 addSetPropertiesRule(path + "/catch-all-strategy", digester); 905 906 addEndpointRules(digester, path + "/catch-all-strategy", "setEndpoint"); 908 addGlobalReferenceEndpointRules(digester, path + "/catch-all-strategy", "setEndpoint"); 909 910 addMulePropertiesRule(path + "/catch-all-strategy", digester); 911 digester.addSetNext(path + "/catch-all-strategy", "setCatchAllStrategy"); 912 913 addRouterRules(digester, path, type); 915 916 digester.addSetNext(path, setMethod); 918 } 919 920 protected void addRouterRules(Digester digester, String path, final String type) 921 throws ConfigurationException 922 { 923 path += "/router"; 924 if ("inbound".equals(type)) 925 { 926 digester.addObjectCreate(path, INBOUND_MESSAGE_ROUTER_INTERFACE, "className"); 927 } 928 else if ("response".equals(type)) 929 { 930 digester.addObjectCreate(path, RESPONSE_MESSAGE_ROUTER_INTERFACE, "className"); 931 } 932 else 933 { 934 digester.addObjectCreate(path, OUTBOUND_MESSAGE_ROUTER_INTERFACE, "className"); 935 } 936 937 addSetPropertiesRule(path, digester, new String []{"enableCorrelation", "propertyExtractor"}, 938 new String []{"enableCorrelationAsString", "propertyExtractorAsString"}); 939 addMulePropertiesRule(path, digester); 940 if ("outbound".equals(type)) 941 { 942 addEndpointRules(digester, path, "addEndpoint"); 943 addReplyToRules(digester, path); 944 addGlobalReferenceEndpointRules(digester, path, "addEndpoint"); 945 addTransactionConfigRules(path, digester); 946 } 947 addFilterRules(digester, path); 948 949 digester.addSetNext(path, "addRouter"); 951 } 952 953 protected void addReplyToRules(Digester digester, String path) throws ConfigurationException 954 { 955 path += "/reply-to"; 957 digester.addRule(path, new Rule() 958 { 959 public void begin(String s, String s1, Attributes attributes) throws Exception 960 { 961 String replyTo = attributes.getValue("address"); 962 ((UMOOutboundRouter)digester.peek()).setReplyTo(replyTo); 963 } 964 }); 965 } 966 967 protected void addEndpointRules(Digester digester, String path, String method) 968 throws ConfigurationException 969 { 970 path += "/endpoint"; 972 addObjectCreateOrGetFromContainer(path, DEFAULT_ENDPOINT, "className", "ref", false); 973 addCommonEndpointRules(digester, path, method); 974 } 975 976 protected void addGlobalReferenceEndpointRules(Digester digester, String path, final String method) 977 throws ConfigurationException 978 { 979 path += "/global-endpoint"; 981 digester.addRule(path, new Rule() 982 { 983 public void begin(String s, String s1, Attributes attributes) throws Exception 984 { 985 String name = attributes.getValue("name"); 986 String address = attributes.getValue("address"); 987 String trans = attributes.getValue("transformers"); 988 String responseTrans = attributes.getValue("responseTransformers"); 989 String createConnector = attributes.getValue("createConnector"); 990 EndpointReference ref = new EndpointReference(method, name, address, trans, responseTrans, 991 createConnector, digester.peek()); 992 digester.push(ref); 995 } 996 997 public void end(String endpointName, String endpointName1) throws Exception 998 { 999 endpointReferences.add(digester.pop()); 1000 } 1001 }); 1002 addCommonEndpointRules(digester, path, null); 1003 } 1004 1005 protected void addCommonEndpointRules(Digester digester, String path, String method) 1006 throws ConfigurationException 1007 { 1008 addSetPropertiesRule(path, digester, new String []{"address", "transformers", "responseTransformers", 1009 "createConnector"}, new String []{"endpointURI", "transformer", "responseTransformer", 1010 "createConnectorAsString"}); 1011 addMulePropertiesRule(path, digester, "setProperties"); 1013 addTransactionConfigRules(path, digester); 1014 1015 addFilterRules(digester, path); 1016 if (method != null) 1017 { 1018 digester.addSetNext(path, method); 1019 } 1020 1021 digester.addObjectCreate(path + "/security-filter", ENDPOINT_SECURITY_FILTER_INTERFACE, "className"); 1023 1024 addMulePropertiesRule(path + "/security-filter", digester); 1025 digester.addSetNext(path + "/security-filter", "setSecurityFilter"); 1026 } 1027 1028 protected void addTransactionConfigRules(String path, Digester digester) 1029 { 1030 digester.addObjectCreate(path + "/transaction", DEFAULT_TRANSACTION_CONFIG); 1031 addSetPropertiesRule(path + "/transaction", digester, new String []{"action"}, 1032 new String []{"actionAsString"}); 1033 1034 digester.addObjectCreate(path + "/transaction/constraint", TRANSACTION_CONSTRAINT_INTERFACE, 1035 "className"); 1036 addSetPropertiesRule(path + "/transaction/constraint", digester); 1037 1038 digester.addSetNext(path + "/transaction/constraint", "setConstraint"); 1039 digester.addSetNext(path + "/transaction", "setTransactionConfig"); 1040 } 1041 1042 protected void addExceptionStrategyRules(Digester digester, String path) throws ConfigurationException 1043 { 1044 path += "/exception-strategy"; 1045 digester.addObjectCreate(path, EXCEPTION_STRATEGY_INTERFACE, "className"); 1046 addMulePropertiesRule(path, digester); 1047 1048 addEndpointRules(digester, path, "addEndpoint"); 1050 addGlobalReferenceEndpointRules(digester, path, "addEndpoint"); 1051 digester.addSetNext(path, "setExceptionListener"); 1052 } 1053 1054 protected void addSetPropertiesRule(String path, Digester digester, String [] s1, String [] s2) 1055 { 1056 digester.addRule(path, new ExtendedMuleSetPropertiesRule(s1, s2)); 1057 } 1058 1059 protected void addSetPropertiesRule(String path, Digester digester) 1060 { 1061 digester.addRule(path, new ExtendedMuleSetPropertiesRule()); 1062 } 1063 1064 private void addTransformerReference(String propName, String transName, Object object) 1065 { 1066 transformerReferences.add(new TransformerReference(propName, transName, object)); 1067 } 1068 1069 private void addEndpointReference(String propName, String endpointName, Object object) 1070 { 1071 endpointReferences.add(new EndpointReference(propName, endpointName, null, null, null, null, object)); 1072 } 1073 1074 1081 public class ExtendedMuleSetPropertiesRule extends MuleSetPropertiesRule 1082 { 1083 public ExtendedMuleSetPropertiesRule() 1084 { 1085 super(); 1086 } 1087 1088 public ExtendedMuleSetPropertiesRule(PlaceholderProcessor processor) 1089 { 1090 super(processor); 1091 } 1092 1093 public ExtendedMuleSetPropertiesRule(String [] strings, String [] strings1) 1094 { 1095 super(strings, strings1); 1096 } 1097 1098 public ExtendedMuleSetPropertiesRule(String [] strings, 1099 String [] strings1, 1100 PlaceholderProcessor processor) 1101 { 1102 super(strings, strings1, processor); 1103 } 1104 1105 public void begin(String s1, String s2, Attributes attributes) throws Exception 1106 { 1107 attributes = processor.processAttributes(attributes, s2); 1108 String transformerNames = attributes.getValue("transformer"); 1111 if (transformerNames != null) 1112 { 1113 addTransformerReference("transformer", transformerNames, digester.peek()); 1114 } 1115 transformerNames = attributes.getValue("transformers"); 1116 if (transformerNames != null) 1117 { 1118 addTransformerReference("transformer", transformerNames, digester.peek()); 1119 } 1120 1121 transformerNames = attributes.getValue("responseTransformers"); 1122 if (transformerNames != null) 1123 { 1124 addTransformerReference("responseTransformer", transformerNames, digester.peek()); 1125 } 1126 1127 1133 transformerNames = attributes.getValue("inboundTransformer"); 1134 if (transformerNames != null) 1135 { 1136 addTransformerReference("inboundTransformer", transformerNames, digester.peek()); 1137 } 1138 1139 transformerNames = attributes.getValue("outboundTransformer"); 1140 if (transformerNames != null) 1141 { 1142 addTransformerReference("outboundTransformer", transformerNames, digester.peek()); 1143 } 1144 1145 transformerNames = attributes.getValue("responseTransformer"); 1146 if (transformerNames != null) 1147 { 1148 addTransformerReference("responseTransformer", transformerNames, digester.peek()); 1149 } 1150 1151 String endpoint = attributes.getValue("inboundEndpoint"); 1155 if (endpoint != null) 1156 { 1157 Object o = manager.getEndpoints().get(endpoint); 1158 if (o != null) 1159 { 1160 addEndpointReference("setInboundEndpoint", endpoint, digester.peek()); 1161 } 1162 } 1163 1164 endpoint = attributes.getValue("outboundEndpoint"); 1165 if (endpoint != null) 1166 { 1167 Object o = manager.getEndpoints().get(endpoint); 1168 if (o != null) 1169 { 1170 addEndpointReference("setOutboundEndpoint", endpoint, digester.peek()); 1171 } 1172 } 1173 super.begin(attributes); 1174 } 1175 } 1176 1177 protected void addObjectCreateOrGetFromContainer(final String path, 1178 String defaultImpl, 1179 final String classAttrib, 1180 final String refAttrib, 1181 final boolean classRefRequired) 1182 { 1183 digester.addRule(path, new ObjectGetOrCreateRule(defaultImpl, classAttrib, refAttrib, classAttrib, 1184 classRefRequired, "getContainerContext")); 1185 } 1186 1187 protected void addObjectCreateOrGetFromContainer(final String path, 1188 String defaultImpl, 1189 final String classAttrib, 1190 final String refAttrib, 1191 final String containerAttrib, 1192 final boolean classRefRequired) 1193 { 1194 digester.addRule(path, new ObjectGetOrCreateRule(defaultImpl, classAttrib, refAttrib, 1195 containerAttrib, classAttrib, classRefRequired, "getContainerContext")); 1196 } 1197} 1198 | Popular Tags |