KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > pool > CommonsPoolProxyFactory


1 /*
2  * $Id: CommonsPoolProxyFactory.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.config.pool;
12
13 import org.apache.commons.beanutils.BeanUtils;
14 import org.apache.commons.pool.PoolableObjectFactory;
15 import org.mule.config.i18n.Message;
16 import org.mule.config.i18n.Messages;
17 import org.mule.impl.MuleDescriptor;
18 import org.mule.umo.lifecycle.InitialisationException;
19
20 /**
21  * <code>CommonsPoolProxyFactory</code> is used to create MuleProxies for use in a
22  * proxy pool. This is a jakarta commons-pool implementation.
23  *
24  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
25  * @version $Revision: 3798 $
26  */

27 public class CommonsPoolProxyFactory extends AbstractProxyFactory implements PoolableObjectFactory
28 {
29     /**
30      * Creates a pool factory using the descriptor as the basis for creating its
31      * objects
32      *
33      * @param descriptor the descriptor to use to construct a MuleProxy
34      * @see MuleDescriptor
35      */

36     public CommonsPoolProxyFactory(MuleDescriptor descriptor)
37     {
38         super(descriptor);
39     }
40
41     /*
42      * (non-Javadoc)
43      *
44      * @see org.apache.commons.pool.PoolableObjectFactory#activateObject(java.lang.Object)
45      */

46     public void activateObject(Object JavaDoc arg0) throws Exception JavaDoc
47     {
48         // nothing to do
49
}
50
51     /*
52      * (non-Javadoc)
53      *
54      * @see org.apache.commons.pool.PoolableObjectFactory#destroyObject(java.lang.Object)
55      */

56     public void destroyObject(Object JavaDoc object) throws Exception JavaDoc
57     {
58         pool.onRemove(object);
59     }
60
61     /*
62      * (non-Javadoc)
63      *
64      * @see org.apache.commons.pool.PoolableObjectFactory#makeObject()
65      */

66     public Object JavaDoc makeObject() throws Exception JavaDoc
67     {
68         Object JavaDoc object = create();
69         pool.onAdd(object);
70         return object;
71     }
72
73     /*
74      * (non-Javadoc)
75      *
76      * @see org.apache.commons.pool.PoolableObjectFactory#passivateObject(java.lang.Object)
77      */

78     public void passivateObject(Object JavaDoc arg0) throws Exception JavaDoc
79     {
80         // nothing to do
81
}
82
83     /*
84      * (non-Javadoc)
85      *
86      * @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object)
87      */

88     public boolean validateObject(Object JavaDoc arg0)
89     {
90         return true;
91     }
92
93     protected void afterComponentCreate(Object JavaDoc component) throws InitialisationException
94     {
95         try
96         {
97             BeanUtils.populate(component, descriptor.getProperties());
98         }
99         catch (Exception JavaDoc e)
100         {
101             throw new InitialisationException(new Message(Messages.FAILED_TO_SET_PROPERTIES_ON_X,
102                 "Component '" + descriptor.getName() + "'"), e, descriptor);
103         }
104     }
105
106 }
107
Popular Tags