KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > soap > xfire > XFireClientPoolFactory


1 /*
2  * $Id: XFireClientPoolFactory.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.providers.soap.xfire;
12
13 import java.util.List JavaDoc;
14
15 import org.apache.commons.pool.BasePoolableObjectFactory;
16 import org.codehaus.xfire.XFire;
17 import org.codehaus.xfire.handler.Handler;
18 import org.codehaus.xfire.transport.Transport;
19 import org.codehaus.xfire.client.Client;
20 import org.codehaus.xfire.service.Service;
21 import org.mule.config.MuleProperties;
22 import org.mule.umo.endpoint.UMOEndpointURI;
23 import org.mule.umo.endpoint.UMOImmutableEndpoint;
24 import org.mule.providers.soap.xfire.transport.MuleUniversalTransport;
25
26 public class XFireClientPoolFactory extends BasePoolableObjectFactory
27 {
28
29     protected UMOEndpointURI uri;
30     protected Service service;
31     protected XFire xfire;
32     protected XFireConnector connector;
33
34     public XFireClientPoolFactory(UMOImmutableEndpoint endpoint, Service service, XFire xfire)
35     {
36         super();
37         uri = endpoint.getEndpointURI();
38         connector = (XFireConnector)endpoint.getConnector();
39         this.service = service;
40         this.xfire = xfire;
41     }
42
43     public Object JavaDoc makeObject() throws Exception JavaDoc
44     {
45         Class JavaDoc transportClazz;
46         if(connector.getClientTransport() == null)
47             transportClazz = MuleUniversalTransport.class;
48         else
49             transportClazz = Class.forName(connector.getClientTransport());
50         
51         Transport transport = (Transport)transportClazz.getConstructor(null).newInstance(null);
52         Client client = new Client(transport, service, uri.toString());
53         client.setXFire(xfire);
54         client.setEndpointUri(uri.toString());
55         client.addInHandler(new MuleHeadersInHandler());
56         client.addOutHandler(new MuleHeadersOutHandler());
57
58         List JavaDoc inList = connector.getClientInHandlers();
59         if(inList != null)
60         {
61             for(int i = 0; i < inList.size(); i++)
62             {
63                 Class JavaDoc clazz = Class.forName(inList.get(i).toString());
64                 Handler handler = (Handler)clazz.getConstructor(null).newInstance(null);
65                 client.addInHandler(handler);
66             }
67         }
68         
69         List JavaDoc outList = connector.getClientOutHandlers();
70         if(outList != null)
71         {
72             for(int i = 0; i < outList.size(); i++)
73             {
74                 Class JavaDoc clazz = Class.forName(outList.get(i).toString());
75                 Handler handler = (Handler)clazz.getConstructor(null).newInstance(null);
76                 client.addOutHandler(handler);
77             }
78         }
79         return client;
80     }
81
82     public void passivateObject(Object JavaDoc obj) throws Exception JavaDoc
83     {
84         ((Client)obj).removeProperty(MuleProperties.MULE_EVENT_PROPERTY);
85         super.passivateObject(obj);
86     }
87
88 }
89
Popular Tags