KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MSession


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-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.model;
15
16 import java.net.*;
17 import java.sql.*;
18 import java.util.*;
19
20 import org.compiere.util.*;
21
22 /**
23  * Session Model.
24  * Maintained in AMenu.
25  *
26  * @author Jorg Janke
27  * @version $Id: MSession.java,v 1.1 2003/10/21 05:35:21 jjanke Exp $
28  */

29 public class MSession extends X_AD_Session
30 {
31     /**
32      * Get/set default session
33      * @param ctx
34      * @return session
35      */

36     public static MSession getDefault (Properties ctx)
37     {
38         if (s_session == null)
39         {
40             s_session = new MSession (ctx);
41             s_session.save();
42         }
43         return s_session;
44     } // get
45

46     /**
47      * Get default session
48      * @return session
49      */

50     public static MSession getDefault ()
51     {
52         return s_session;
53     } // get
54

55     
56     /** Session */
57     private static MSession s_session = null;
58     
59     /*************************************************************************/
60     
61     /**
62      * Standard Constructor
63      * @param ctx context
64      * @param AD_Session_ID id
65      */

66     public MSession (Properties ctx, int AD_Session_ID)
67     {
68         super(ctx, AD_Session_ID);
69         if (AD_Session_ID == 0)
70         {
71             setProcessed (false);
72         }
73     } // MSession
74

75     /**
76      * Load Costructor
77      * @param ctx context
78      * @param rs result set
79      */

80     public MSession(Properties ctx, ResultSet rs)
81     {
82         super(ctx, rs);
83     } // MSession
84

85     /**
86      * New Constructor
87      * @param ctx context
88      * @param AD_Session_ID id
89      */

90     public MSession (Properties ctx, String JavaDoc Remote_Addr, String JavaDoc Remote_Host, String JavaDoc WebSession)
91     {
92         this (ctx, 0);
93         if (Remote_Addr != null)
94             setRemote_Addr(Remote_Addr);
95         if (Remote_Host != null)
96             setRemote_Host(Remote_Host);
97         if (WebSession != null)
98             setWebSession(WebSession);
99     } // MSession
100

101     /**
102      * New Constructor
103      * @param ctx context
104      */

105     public MSession (Properties ctx)
106     {
107         this (ctx, 0);
108         try
109         {
110             InetAddress lh = InetAddress.getLocalHost();
111             setRemote_Addr(lh.getHostAddress());
112             setRemote_Host(lh.getHostName());
113         }
114         catch (UnknownHostException e)
115         {
116             log.error("MSession - No Local Host", e);
117         }
118     } // MSession
119

120     /**
121      * String Representation
122      * @return info
123      */

124     public String JavaDoc toString()
125     {
126         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("MSession[")
127             .append(getAD_Session_ID())
128             .append(",AD_User_ID=").append(getCreatedBy())
129             .append(",").append(getCreated())
130             .append(",Remote=").append(getRemote_Addr());
131         String JavaDoc s = getRemote_Host();
132         if (s != null && s.length() > 0)
133             sb.append(",").append(s);
134         sb.append("]");
135         return sb.toString();
136     } // toString
137

138     /**
139      * Session Logout
140      */

141     public void logout()
142     {
143         setProcessed(true);
144         save();
145         log.info("logout - " + TimeUtil.formatElapsed(getCreated(), getUpdated()));
146     } // logout
147

148
149     /**
150      * Create Change Log only if table is logged
151      * @param AD_Table_ID table
152      * @param AD_Column_ID column
153      * @param Record_ID record
154      * @param OldValue old
155      * @param NewValue new
156      * @return saved change log or null
157      */

158     public MChangeLog changeLog (int AD_Table_ID, int AD_Column_ID, int Record_ID,
159         String JavaDoc OldValue, String JavaDoc NewValue)
160     {
161         if (!MChangeLog.isLogged(AD_Table_ID))
162             return null;
163         //
164
MChangeLog cl = new MChangeLog(getCtx(), getAD_Session_ID(),
165             AD_Table_ID, AD_Column_ID, Record_ID, OldValue, NewValue);
166         cl.save();
167         return cl;
168     } // changeLog
169

170 } // MSession
171

172
Popular Tags