KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ve > luz > ica > jackass > daemon > proxy > ProxyServantFactory


1 /*
2  * Copyright (c) 2003 by The Jackass Team
3  * Licensed under the Open Software License version 2.0
4  */

5 package ve.luz.ica.jackass.daemon.proxy;
6
7 import java.lang.reflect.Constructor JavaDoc;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.apache.commons.pool.BasePoolableObjectFactory;
12
13 import org.omg.CORBA.CompletionStatus JavaDoc;
14 import org.omg.CORBA.INTERNAL JavaDoc;
15 import org.omg.CORBA.Object JavaDoc;
16 import org.omg.PortableServer.Servant JavaDoc;
17
18 /**
19  * Class required for proxy servant creation in the pool.
20  * @see org.apache.commons.pool.ObjectPool
21  * @author Nelson Arapé
22  */

23 public class ProxyServantFactory extends BasePoolableObjectFactory
24 {
25     private static final Log LOG = LogFactory.getLog(ProxyServantFactory.class);
26
27     private org.omg.CORBA.Object JavaDoc objectRef;
28     private Class JavaDoc proxyClass;
29
30     /**
31      * Constructor for ProxyServantFactory
32      * @param objectRef the reference to the real objects
33      * @param proxyClass the class of the proxies to be created
34      */

35     public ProxyServantFactory(Object JavaDoc objectRef, Class JavaDoc proxyClass)
36     {
37         this.objectRef = objectRef;
38         this.proxyClass = proxyClass;
39     }
40
41     /**
42      * Creates a proxy servant
43      * @return a proxy servant.
44      * @throws INTERNAL if a reflection error ocurrs
45      */

46     public java.lang.Object JavaDoc makeObject() throws Exception JavaDoc
47     {
48         // instantiate the proxy
49
try
50         {
51             Class JavaDoc[] params = {org.omg.CORBA.Object JavaDoc.class};
52             if (LOG.isDebugEnabled())
53             {
54                 LOG.debug("proxyClass " + proxyClass.getName());
55             }
56             Constructor JavaDoc constructor = proxyClass.getDeclaredConstructor(params);
57             Servant JavaDoc servant = (Servant JavaDoc) constructor.newInstance(new Object JavaDoc[] {objectRef});
58             return servant;
59         }
60         catch (Exception JavaDoc e)
61         {
62             String JavaDoc errorMsg = "Error while creating proxy servant ";
63
64             if (LOG.isErrorEnabled())
65             {
66                 errorMsg += " for class " + proxyClass;
67
68                 LOG.error(errorMsg, e);
69             }
70
71             throw new INTERNAL JavaDoc(errorMsg, 0, CompletionStatus.COMPLETED_NO);
72         }
73     }
74 }
Popular Tags