1 10 11 package org.mule.impl; 12 13 import java.beans.ExceptionListener ; 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import java.util.Map ; 19 20 import org.mule.MuleManager; 21 import org.mule.config.MuleConfiguration; 22 import org.mule.config.PoolingProfile; 23 import org.mule.config.QueueProfile; 24 import org.mule.config.ThreadingProfile; 25 import org.mule.impl.container.ContainerKeyPair; 26 import org.mule.impl.container.DescriptorContainerContext; 27 import org.mule.impl.container.DescriptorContainerKeyPair; 28 import org.mule.impl.container.MuleContainerContext; 29 import org.mule.impl.endpoint.MuleEndpoint; 30 import org.mule.routing.inbound.InboundMessageRouter; 31 import org.mule.routing.inbound.InboundPassThroughRouter; 32 import org.mule.routing.outbound.OutboundMessageRouter; 33 import org.mule.routing.outbound.OutboundPassThroughRouter; 34 import org.mule.umo.UMOException; 35 import org.mule.umo.UMOImmutableDescriptor; 36 import org.mule.umo.endpoint.UMOEndpoint; 37 import org.mule.umo.lifecycle.Initialisable; 38 import org.mule.umo.lifecycle.InitialisationException; 39 import org.mule.umo.manager.ContainerException; 40 import org.mule.umo.routing.UMOInboundMessageRouter; 41 import org.mule.umo.routing.UMOOutboundMessageRouter; 42 import org.mule.umo.routing.UMOOutboundRouter; 43 import org.mule.umo.routing.UMOResponseMessageRouter; 44 import org.mule.umo.transformer.UMOTransformer; 45 46 import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList; 47 48 55 56 public class ImmutableMuleDescriptor implements UMOImmutableDescriptor 57 { 58 61 public static final String INITIAL_STATE_STOPPED = "stopped"; 62 public static final String INITIAL_STATE_STARTED = "started"; 63 public static final String INITIAL_STATE_PAUSED = "paused"; 64 68 protected static final String MULE_PROPERTY_DOT_PROPERTIES = "org.mule.dotProperties"; 69 70 73 protected ExceptionListener exceptionListener = null; 74 75 80 protected Object implementationReference = null; 81 82 85 protected String name; 86 87 90 protected Map properties = new HashMap (); 91 92 95 protected String version = "1.0"; 96 97 100 protected List intecerptorList = new CopyOnWriteArrayList(); 101 102 protected UMOInboundMessageRouter inboundRouter = null; 103 104 protected UMOOutboundMessageRouter outboundRouter = null; 105 106 protected UMOResponseMessageRouter responseRouter = null; 107 108 114 protected UMOEndpoint inboundEndpoint; 115 116 122 protected UMOTransformer inboundTransformer = null; 123 124 130 protected UMOEndpoint outboundEndpoint; 131 132 138 protected UMOTransformer outboundTransformer = null; 139 140 146 protected UMOTransformer responseTransformer = null; 147 148 152 protected ThreadingProfile threadingProfile; 153 154 158 protected PoolingProfile poolingProfile; 159 160 163 protected QueueProfile queueProfile; 164 165 172 protected boolean containerManaged = true; 173 174 178 protected String initialState = INITIAL_STATE_STARTED; 179 180 183 protected boolean singleton = false; 184 185 protected List initialisationCallbacks = new ArrayList (); 186 187 protected String encoding = null; 188 189 194 protected String container = null; 195 196 202 public ImmutableMuleDescriptor(ImmutableMuleDescriptor descriptor) 203 { 204 inboundRouter = descriptor.getInboundRouter(); 205 outboundRouter = descriptor.getOutboundRouter(); 206 responseRouter = descriptor.getResponseRouter(); 207 inboundTransformer = descriptor.getInboundTransformer(); 208 outboundTransformer = descriptor.getOutboundTransformer(); 209 responseTransformer = descriptor.getResponseTransformer(); 210 implementationReference = descriptor.getImplementation(); 211 version = descriptor.getVersion(); 212 intecerptorList = descriptor.getInterceptors(); 213 properties = descriptor.getProperties(); 214 name = descriptor.getName(); 215 encoding = descriptor.getEncoding(); 216 217 threadingProfile = descriptor.getThreadingProfile(); 218 poolingProfile = descriptor.getPoolingProfile(); 219 queueProfile = descriptor.getQueueProfile(); 220 exceptionListener = descriptor.getExceptionListener(); 221 initialState = descriptor.getInitialState(); 222 singleton = descriptor.isSingleton(); 223 containerManaged = descriptor.isContainerManaged(); 224 } 225 226 230 protected ImmutableMuleDescriptor() 231 { 232 inboundRouter = new InboundMessageRouter(); 233 inboundRouter.addRouter(new InboundPassThroughRouter()); 234 } 235 236 public void initialise() throws InitialisationException 237 { 238 MuleConfiguration config = MuleManager.getConfiguration(); 239 if (threadingProfile == null) 240 { 241 threadingProfile = config.getComponentThreadingProfile(); 242 } 243 if (poolingProfile == null) 244 { 245 poolingProfile = config.getPoolingProfile(); 246 } 247 if (queueProfile == null) 248 { 249 queueProfile = config.getQueueProfile(); 250 } 251 252 if (exceptionListener == null) 253 { 254 exceptionListener = MuleManager.getInstance().getModel().getExceptionListener(); 255 } 256 else if (exceptionListener instanceof Initialisable) 257 { 258 ((Initialisable)exceptionListener).initialise(); 259 } 260 261 if (inboundEndpoint != null) 262 { 263 if (inboundTransformer != null) 264 { 265 inboundEndpoint.setTransformer(inboundTransformer); 266 } 267 ((MuleEndpoint)inboundEndpoint).initialise(); 268 if (inboundTransformer == null) 272 { 273 inboundTransformer = inboundEndpoint.getTransformer(); 274 } 275 } 276 277 if (outboundEndpoint != null) 278 { 279 if (outboundTransformer != null) 280 { 281 outboundEndpoint.setTransformer(outboundTransformer); 282 } 283 ((MuleEndpoint)outboundEndpoint).initialise(); 284 if (outboundTransformer == null) 288 { 289 outboundTransformer = outboundEndpoint.getTransformer(); 290 } 291 } 292 293 if (exceptionListener instanceof Initialisable) 294 { 295 ((Initialisable)exceptionListener).initialise(); 296 } 297 298 MuleEndpoint endpoint; 299 if (inboundRouter == null) 300 { 301 inboundRouter = new InboundMessageRouter(); 304 inboundRouter.addRouter(new InboundPassThroughRouter()); 305 } 306 else 307 { 308 if (inboundRouter.getCatchAllStrategy() != null 309 && inboundRouter.getCatchAllStrategy().getEndpoint() != null) 310 { 311 ((MuleEndpoint)inboundRouter.getCatchAllStrategy().getEndpoint()).initialise(); 312 } 313 for (Iterator iterator = inboundRouter.getEndpoints().iterator(); iterator.hasNext();) 314 { 315 endpoint = (MuleEndpoint)iterator.next(); 316 endpoint.initialise(); 317 } 318 } 319 320 if (responseRouter != null) 321 { 322 for (Iterator iterator = responseRouter.getEndpoints().iterator(); iterator.hasNext();) 323 { 324 endpoint = (MuleEndpoint)iterator.next(); 325 endpoint.initialise(); 326 } 327 } 328 329 if (outboundRouter == null) 330 { 331 outboundRouter = new OutboundMessageRouter(); 332 outboundRouter.addRouter(new OutboundPassThroughRouter(this)); 333 } 334 else 335 { 336 if (outboundRouter.getCatchAllStrategy() != null 337 && outboundRouter.getCatchAllStrategy().getEndpoint() != null) 338 { 339 ((MuleEndpoint)outboundRouter.getCatchAllStrategy().getEndpoint()).initialise(); 340 } 341 UMOOutboundRouter router = null; 342 for (Iterator iterator = outboundRouter.getRouters().iterator(); iterator.hasNext();) 343 { 344 router = (UMOOutboundRouter)iterator.next(); 345 for (Iterator iterator1 = router.getEndpoints().iterator(); iterator1.hasNext();) 346 { 347 endpoint = (MuleEndpoint)iterator1.next(); 348 endpoint.initialise(); 349 } 350 } 351 } 352 if (implementationReference instanceof String ) 354 { 355 if (DescriptorContainerContext.DESCRIPTOR_CONTAINER_NAME.equals(container)) 356 { 357 implementationReference = new DescriptorContainerKeyPair(name, implementationReference); 358 } 359 else 360 { 361 implementationReference = new ContainerKeyPair(container, implementationReference); 362 } 363 } 364 } 365 366 371 public ExceptionListener getExceptionListener() 372 { 373 return exceptionListener; 374 } 375 376 381 public UMOTransformer getInboundTransformer() 382 { 383 return inboundTransformer; 384 } 385 386 391 public String getName() 392 { 393 return name; 394 } 395 396 401 public UMOTransformer getOutboundTransformer() 402 { 403 return outboundTransformer; 404 } 405 406 411 public UMOTransformer getResponseTransformer() 412 { 413 return responseTransformer; 414 } 415 416 423 public Map getProperties() 424 { 425 return properties; 426 } 427 428 433 public String getVersion() 434 { 435 return version; 436 } 437 438 443 public List getInterceptors() 444 { 445 return intecerptorList; 446 } 447 448 public String getEncoding() 449 { 450 return encoding; 451 } 452 453 458 public String toString() 459 { 460 StringBuffer buffer = new StringBuffer (); 461 buffer.append("name=").append(name); 462 buffer.append(", outbound endpoint=").append(outboundEndpoint); 463 buffer.append(", send transformer=").append(outboundTransformer); 464 buffer.append(", inbound endpointUri=").append(inboundEndpoint); 465 buffer.append(", receive transformer=").append(inboundTransformer); 466 buffer.append(", encoding=").append(encoding); 467 return buffer.toString(); 468 } 469 470 475 public Object getImplementation() 476 { 477 return implementationReference; 478 } 479 480 public UMOInboundMessageRouter getInboundRouter() 481 { 482 return inboundRouter; 483 } 484 485 public UMOOutboundMessageRouter getOutboundRouter() 486 { 487 return outboundRouter; 488 } 489 490 494 public ThreadingProfile getThreadingProfile() 495 { 496 return threadingProfile; 497 } 498 499 public PoolingProfile getPoolingProfile() 500 { 501 return poolingProfile; 502 } 503 504 public QueueProfile getQueueProfile() 505 { 506 return queueProfile; 507 } 508 509 public boolean isContainerManaged() 510 { 511 return !MuleContainerContext.MULE_CONTAINER_NAME.equalsIgnoreCase(container); 512 } 513 514 public Class getImplementationClass() throws UMOException 515 { 516 Class implClass = null; 518 if (implementationReference instanceof String || implementationReference instanceof ContainerKeyPair) 519 { 520 Object object = MuleManager.getInstance().getContainerContext().getComponent( 521 implementationReference); 522 implClass = object.getClass(); 523 } 524 else 525 { 526 implClass = implementationReference.getClass(); 527 } 528 529 return implClass; 530 } 531 532 540 protected Class getImplementationForReference(String reference) throws ContainerException 541 { 542 Object object = MuleManager.getInstance().getContainerContext().getComponent(reference); 543 return object.getClass(); 544 } 545 546 public void fireInitialisationCallbacks(Object component) throws InitialisationException 547 { 548 InitialisationCallback callback; 549 for (Iterator iterator = initialisationCallbacks.iterator(); iterator.hasNext();) 550 { 551 callback = (InitialisationCallback)iterator.next(); 552 callback.initialise(component); 553 } 554 } 555 556 563 public UMOEndpoint getInboundEndpoint() 564 { 565 return inboundEndpoint; 566 } 567 568 575 public UMOEndpoint getOutboundEndpoint() 576 { 577 return outboundEndpoint; 578 } 579 580 public UMOResponseMessageRouter getResponseRouter() 581 { 582 return responseRouter; 583 } 584 585 public boolean isSingleton() 586 { 587 return singleton; 588 } 589 590 public String getInitialState() 591 { 592 return initialState; 593 } 594 595 603 public String getContainer() 604 { 605 return container; 606 } 607 } 608 | Popular Tags |