KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ve > luz > ica > jackass > instantiator > StatelessServantFactory


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.instantiator;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.apache.commons.pool.BasePoolableObjectFactory;
10 import org.omg.CORBA.CompletionStatus JavaDoc;
11 import org.omg.CORBA.INTERNAL JavaDoc;
12
13 import ve.luz.ica.jackass.component.ApplicationContext;
14 import ve.luz.ica.jackass.component.StatelessContext;
15 import ve.luz.ica.jackass.component.StatelessHook;
16
17 /**
18  * StatelessServantFactory creates servants of for stateless objects.
19  * @author Carlos Arévalo, Nelson Arapé
20  */

21 public class StatelessServantFactory extends BasePoolableObjectFactory
22 {
23     private static final Log LOG = LogFactory.getLog(StatelessServantFactory.class);
24
25     private static final int ERR_MINOR_CODE = 0;
26
27     private ApplicationContext appContext;
28     private StatelessContext compContext;
29     private Class JavaDoc servantClass;
30
31     /**
32      * StatelessServantFactory constructor
33      * @param appContext the application context to be passed to the created servants
34      * @param compContext the component context to be passed to the created servants
35      * @param servantClass the class that will be used to instantiate the servants
36      */

37     public StatelessServantFactory(ApplicationContext appContext, StatelessContext compContext, Class JavaDoc servantClass)
38     {
39         this.appContext = appContext;
40         this.compContext = compContext;
41         this.servantClass = servantClass;
42     }
43
44
45     /**
46      * Creates a new Servant for the corresponding oid passed as argument
47      * @return the just created servant
48      * @throws Exception if there is an error when creating the servant
49      * @see org.apache.commons.pool.KeyedPoolableObjectFactory#makeObject(java.lang.Object)
50      */

51     public Object JavaDoc makeObject() throws Exception JavaDoc
52     {
53         try
54         {
55             if (LOG.isDebugEnabled()) LOG.debug("Creating object for class " + servantClass);
56             StatelessHook hook = (StatelessHook) servantClass.newInstance();
57             hook.jackassSetContexts(appContext, compContext);
58             hook.jackassCreate();
59
60             if (LOG.isDebugEnabled()) LOG.debug("Object created ");
61
62             return hook;
63         }
64         catch (Exception JavaDoc e)
65         {
66             String JavaDoc errorMsg = "Error while creating proxy servant";
67
68             if (LOG.isErrorEnabled())
69             {
70                 errorMsg += " for class " + servantClass;
71                 LOG.error(errorMsg, e);
72             }
73
74             throw new INTERNAL JavaDoc(errorMsg, ERR_MINOR_CODE, CompletionStatus.COMPLETED_NO);
75         }
76     }
77 }
78
Popular Tags