KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > session > ServerBean


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.session;
15
16 import java.util.*;
17 import java.sql.*;
18 import javax.sql.*;
19
20 import java.rmi.RemoteException JavaDoc;
21 import javax.ejb.CreateException JavaDoc;
22 import javax.ejb.EJBException JavaDoc;
23 import javax.ejb.FinderException JavaDoc;
24 import javax.ejb.RemoveException JavaDoc;
25 import javax.ejb.SessionBean JavaDoc;
26 import javax.ejb.SessionContext JavaDoc;
27 import javax.naming.Context JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29 import javax.naming.NamingException JavaDoc;
30 import javax.rmi.PortableRemoteObject JavaDoc;
31
32 import org.apache.log4j.Logger;
33
34 import org.compiere.interfaces.*;
35
36 import org.compiere.Compiere;
37
38 import org.compiere.util.CompiereStatement;
39 import org.compiere.util.CompiereStatementVO;
40 import org.compiere.acct.AcctServer;
41 import org.compiere.model.MWindowVO;
42 import org.compiere.process.*;
43
44 /**
45  * Compiere Server Bean
46  *
47  * @ejb:bean name="compiere/Server"
48  * display-name="Compiere Server Session Bean"
49  * type="Stateless"
50  * transaction-type="Bean"
51  * jndi-name="ejb/compiere/Server"
52  *
53  * @ejb:ejb-ref ejb-name="compiere/Server"
54  * ref-name="compiere/Server"
55  *
56  * @author Jorg Janke
57  * @version $Id: ServerBean.java,v 1.12 2003/10/31 05:33:54 jjanke Exp $
58  */

59 public class ServerBean implements SessionBean JavaDoc
60 {
61     /** Context */
62     private SessionContext JavaDoc m_Context;
63     /** Logging */
64     private transient Logger log = Logger.getLogger(getClass());
65     //
66
private static int s_no = 0;
67     private int m_no = 0;
68     //
69
private int m_windowCount = 0;
70     private int m_postCount = 0;
71     private int m_processCount = 0;
72     private int m_stmt_rowSetCount = 0;
73     private int m_stmt_updateCount = 0;
74
75     /**
76      * Get and create Window Model Value Object
77      * @ejb:interface-method view-type="remote"
78      *
79      * @param ctx Environment Properties
80      * @param WindowNo number of this window
81      * @param AD_Window_ID the internal number of the window, if not 0, AD_Menu_ID is ignored
82      * @param AD_Menu_ID ine internal menu number, used when AD_Window_ID is 0
83      * @return initialized Window Model
84      * @throws RemoteException
85      */

86     public MWindowVO getWindowVO (Properties ctx, int WindowNo, int AD_Window_ID, int AD_Menu_ID)
87         throws RemoteException JavaDoc
88     {
89         log.info ("getWindowVO[" + m_no + "] Window=" + AD_Window_ID);
90     // log.debug (ctx);
91
MWindowVO vo = MWindowVO.create(ctx, WindowNo, AD_Window_ID, AD_Menu_ID);
92         m_windowCount++;
93         return vo;
94     } // getWindowVO
95

96
97     /**
98      * Post Immediate
99      * @ejb:interface-method view-type="remote"
100      *
101      * @param AD_Table_ID Table ID of Document
102      * @param AD_Client_ID Client ID of Document
103      * @param Record_ID Record ID of this document
104      * @param force force posting
105      * @return true, if success
106      * @throws RemoteException
107      */

108     public boolean postImmediate (int AD_Table_ID, int AD_Client_ID,
109         int Record_ID, boolean force)
110         throws RemoteException JavaDoc
111     {
112         log.info ("postImmediate[" + m_no + "] Table=" + AD_Table_ID + ", Record=" + Record_ID);
113         m_postCount++;
114         return AcctServer.postImmediate(AD_Table_ID, AD_Client_ID, Record_ID, force);
115     } // postImmediate
116

117     /*************************************************************************/
118
119     /**
120      * Get ResultSet
121      * @ejb:interface-method view-type="remote"
122      *
123      * @param info Result info
124      * @return RowSet
125      * @throws RemoteException
126      */

127     public RowSet stmt_getRowSet (CompiereStatementVO info) throws RemoteException JavaDoc
128     {
129     // log.debug("stmt_getRowSet[" + m_no + "]");
130
m_stmt_rowSetCount++;
131         CompiereStatement stmt = new CompiereStatement(info);
132         return stmt.remote_getRowSet();
133     } // stmt_getRowSet
134

135     /**
136      * Get ResultSet
137      * @ejb:interface-method view-type="remote"
138      *
139      * @param info Result info
140      * @return ResultSet or RowSet
141      * @throws RemoteException
142      */

143     public int stmt_executeUpdate (CompiereStatementVO info) throws RemoteException JavaDoc
144     {
145         log.debug("stmt_executeUpdate[" + m_no + "]");
146         m_stmt_updateCount++;
147         CompiereStatement stmt = new CompiereStatement(info);
148         return stmt.remote_executeUpdate();
149     } // stmt_executeUpdate
150

151     /*************************************************************************/
152
153     /**
154      * Process class on Server
155      * @ejb:interface-method view-type="remote"
156      *
157      * @param className class name
158      * @param ctx context
159      * @param AD_PInstance_ID instance
160      * @param Record_ID record
161      * @param Name Process Name
162      * @return true if success
163      * @throws RemoteException
164      */

165     public boolean process (String JavaDoc className, Properties ctx, String JavaDoc Name,
166         int AD_PInstance_ID, int Record_ID)
167         throws RemoteException JavaDoc
168     {
169         log.info ("process[" + m_no + "] " + AD_PInstance_ID);
170         m_processCount++;
171
172         return false;
173     } // process
174

175     /**
176      * Process Remote
177      * @ejb:interface-method view-type="remote"
178      *
179      * @param ctx Context
180      * @param pi Process Info
181      * @return resulting Process Info
182      * @throws RemoteException
183      */

184     public ProcessInfo process (Properties ctx, ProcessInfo pi) throws RemoteException JavaDoc
185     {
186         String JavaDoc className = pi.getClassName();
187         log.debug("process " + className + " - " + pi);
188         m_processCount++;
189         // Get Class
190
Class JavaDoc clazz = null;
191         try
192         {
193             clazz = Class.forName (className);
194         }
195         catch (ClassNotFoundException JavaDoc ex)
196         {
197             log.warn("process - " + className, ex);
198             pi.setSummary ("ClassNotFound", true);
199             return pi;
200         }
201         // Get Process
202
SvrProcess process = null;
203         try
204         {
205             process = (SvrProcess)clazz.newInstance ();
206         }
207         catch (Exception JavaDoc ex)
208         {
209             log.warn("process - Instance for " + className, ex);
210             pi.setSummary ("InstanceError", true);
211             return pi;
212         }
213         // Start Process
214
try
215         {
216             boolean ok = process.startProcess (ctx, pi);
217             pi = process.getProcessInfo();
218         }
219         catch (Exception JavaDoc ex1)
220         {
221             pi.setSummary ("ProcessError", true);
222             return pi;
223         }
224         return pi;
225     } // processData
226

227     /*************************************************************************/
228
229     /**
230      * Describes the instance and its content for debugging purpose
231      * @ejb:interface-method view-type="remote"
232      * @return Debugging information about the instance and its content
233      */

234     public String JavaDoc getStatus()
235     {
236         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("ServerBean[");
237         sb.append(m_no)
238             .append("-Window=").append(m_windowCount)
239             .append(",Post=").append(m_postCount)
240             .append(",Process=").append(m_processCount)
241             .append(",RowSet=").append(m_stmt_rowSetCount)
242             .append(",Update=").append(m_stmt_updateCount)
243             .append("]");
244         return sb.toString();
245     } // getStatus
246

247
248     /**
249      * String Representation
250      * @return info
251      */

252     public String JavaDoc toString()
253     {
254         return getStatus();
255     } // toString
256

257     /*************************************************************************/
258
259     /**
260      * Create the Session Bean
261      * @throws CreateException
262      * @ejb:create-method view-type="remote"
263      */

264     public void ejbCreate() throws CreateException JavaDoc
265     {
266         m_no = ++s_no;
267         log.info ("ejbCreate " + this);
268         try
269         {
270             org.compiere.Compiere.startupServer(new InitialContext JavaDoc());
271         }
272         catch (Exception JavaDoc ex)
273         {
274             log.error("ejbCreate", ex);
275         // throw new CreateException ();
276
}
277     } // ejbCreate
278

279
280     // -------------------------------------------------------------------------
281
// Framework Callbacks
282
// -------------------------------------------------------------------------
283

284     public void setSessionContext (SessionContext JavaDoc aContext) throws EJBException JavaDoc
285     {
286         m_Context = aContext;
287     }
288
289     public void ejbActivate() throws EJBException JavaDoc
290     {
291         if (log == null)
292             log = Logger.getLogger(getClass());
293         log.debug("ejbActivate " + this);
294     }
295
296     public void ejbPassivate() throws EJBException JavaDoc
297     {
298         log.debug("ejbPassivate " + this);
299     }
300
301     public void ejbRemove() throws EJBException JavaDoc
302     {
303         log.debug("ejbRemove " + this);
304     }
305
306 } // ServerBean
307
Popular Tags