View Javadoc

1   /*
2    * $Id: AbstractProxyFactory.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.config.pool;
12  
13  import org.mule.impl.MuleDescriptor;
14  import org.mule.impl.model.ComponentFactory;
15  import org.mule.impl.model.DefaultMuleProxy;
16  import org.mule.umo.UMOException;
17  import org.mule.umo.lifecycle.InitialisationException;
18  import org.mule.umo.model.UMOModel;
19  import org.mule.util.ObjectFactory;
20  import org.mule.util.ObjectPool;
21  
22  /**
23   * <code>AbstractProxyFactory</code> provides common behaviour for creating proxy
24   * objects.
25   */
26  
27  public abstract class AbstractProxyFactory implements ObjectFactory
28  {
29      /**
30       * The UMODescriptor used to create new components in the pool
31       */
32      protected MuleDescriptor descriptor;
33      protected UMOModel model;
34      protected ObjectPool pool;
35  
36      /**
37       * Creates a pool factory using the descriptor as the basis for creating its
38       * objects
39       * 
40       * @param descriptor the descriptor to use to construct a MuleProxy
41       * @see org.mule.umo.UMODescriptor
42       */
43      public AbstractProxyFactory(MuleDescriptor descriptor, UMOModel model)
44      {
45          this.descriptor = descriptor;
46          this.model = model;
47      }
48  
49      public Object create() throws UMOException
50      {
51          Object component = ComponentFactory.createComponent(descriptor);
52          afterComponentCreate(component);
53          return createProxy(component);
54      }
55  
56      protected Object createProxy(Object component) throws UMOException
57      {
58          return new DefaultMuleProxy(component, descriptor, model, pool);
59      }
60  
61      protected void afterComponentCreate(Object component) throws InitialisationException
62      {
63          // nothing to do
64      }
65  
66      public ObjectPool getPool()
67      {
68          return pool;
69      }
70  
71      public void setPool(ObjectPool pool)
72      {
73          this.pool = pool;
74      }
75  }