KickJava   Java API By Example, From Geeks To Geeks.

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


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 Smart 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.util.*;
17
18 import org.compiere.util.*;
19
20 /**
21  * Client Model
22  *
23  * @author Jorg Janke
24  * @version $Id: MClient.java,v 1.1 2003/10/21 05:35:20 jjanke Exp $
25  */

26 public class MClient extends X_AD_Client implements CacheInterface
27 {
28     /**
29      * Load Constructor
30      * @param ctx context
31      * @param AD_Client_ID id
32      */

33     public MClient(Properties ctx, int AD_Client_ID)
34     {
35         super (ctx, AD_Client_ID);
36         CacheMgt.get().register(this);
37     } // MClient
38

39     /**
40      * Simplified Constructor
41      * @param ctx context
42      */

43     public MClient(Properties ctx)
44     {
45         this (ctx, Env.getContextAsInt(ctx, "#AD_Client_ID"));
46     } // MClient
47

48     /** Client Info */
49     private MClientInfo m_info = null;
50
51     /**
52      * Get SMTP Host
53      * @return SMTP or loaclhost
54      */

55     public String JavaDoc getSMTPHost()
56     {
57         String JavaDoc s = super.getSMTPHost();
58         if (s == null)
59             s = "localhost";
60         return s;
61     } // getSMTPHost
62

63     /**
64      * Reset Cache & reload this
65      * @return no of cache
66      */

67     public int reset()
68     {
69         load();
70         int no = 1;
71         if (s_client == null)
72             no++;
73         s_client = null;
74         return no;
75     } // reset
76

77     /**
78      * Get Client Info
79      * @return Client Info
80      */

81     public MClientInfo getMClientInfo()
82     {
83         if (m_info == null)
84             m_info = MClientInfo.get (getCtx(), getAD_Client_ID());
85         return m_info;
86     } // getMClientInfo
87

88     /**
89      * String Representation
90      * @return info
91      */

92     public String JavaDoc toString()
93     {
94         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ("MClient[")
95             .append(getID()).append("-").append(getValue())
96             .append("]");
97         return sb.toString();
98     } // toString
99

100     /**
101      * Get Default Accounting Currency
102      * @return currency or 0
103      */

104     public int getC_Currency_ID()
105     {
106         if (m_info == null)
107             getMClientInfo();
108         if (m_info != null)
109             return m_info.getC_Currency_ID();
110         return 0;
111     } // getC_Currency_ID
112

113
114     /*************************************************************************/
115
116     /** Cached Client */
117     private static MClient s_client = null;
118
119     /**
120      * Get client
121      * @param ctx context
122      * @param AD_Client_ID id
123      * @return client
124      */

125     public static MClient get (Properties ctx, int AD_Client_ID)
126     {
127         MClient client = new MClient (ctx, AD_Client_ID);
128         if (s_client == null
129             || (s_client != null && s_client.getAD_Client_ID() == AD_Client_ID))
130             s_client = client;
131         return client;
132     } // get
133

134     /**
135      * Get optionally cached client
136      * @param ctx context
137      * @return client
138      */

139     public static MClient get (Properties ctx)
140     {
141         int AD_Client_ID = Env.getContextAsInt(ctx, "#AD_Client_ID");
142         if (s_client == null)
143             s_client = new MClient (ctx, AD_Client_ID);
144         if (s_client.getAD_Client_ID() == AD_Client_ID)
145             return s_client;
146         return new MClient (ctx, AD_Client_ID);
147     } // get
148

149 } // MClient
150
Popular Tags