KickJava   Java API By Example, From Geeks To Geeks.

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


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-2001 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.sql.*;
17 import java.util.*;
18
19 import org.compiere.util.*;
20 import java.io.*;
21
22 /**
23  * Account Schema Element Object
24  *
25  * @author Jorg Janke
26  * @version $Id: AcctSchemaElement.java,v 1.11 2003/07/28 03:57:55 jjanke Exp $
27  */

28 public final class AcctSchemaElement implements Serializable
29 {
30     /**
31      * Constructor
32      * @param id C_AcctSchema_Element_ID
33      * @param seqNo Sequence
34      * @param name Name
35      * @param segmentType Type
36      * @param C_Element_ID C_Element_ID
37      * @param defaultValue default
38      * @param mandatory mandatory
39      * @param balanced balanced
40      */

41     private AcctSchemaElement (int id, int seqNo, String JavaDoc name, String JavaDoc segmentType,
42         int C_Element_ID, int defaultValue, boolean mandatory, boolean balanced)
43     {
44         m_ID = id;
45         m_seqNo = seqNo;
46         m_name = name;
47         m_segmentType = segmentType;
48         m_C_Element_ID = C_Element_ID;
49         m_defaultValue = defaultValue;
50         m_mandatory = mandatory;
51         m_balanced = balanced;
52     } // AcctSchemaElement
53

54     private int m_ID;
55     private int m_seqNo;
56     private String JavaDoc m_name;
57     private String JavaDoc m_segmentType;
58     private int m_C_Element_ID;
59     private int m_defaultValue;
60     private boolean m_mandatory;
61     private boolean m_balanced;
62     private boolean m_active;
63
64     /** Segment */
65     public final static String JavaDoc SEGMENT_Org = "OO";
66     /** Segment */
67     public final static String JavaDoc SEGMENT_Account = "AC";
68     /** Segment */
69     public final static String JavaDoc SEGMENT_BPartner = "BP";
70     /** Segment */
71     public final static String JavaDoc SEGMENT_Product = "PR";
72     /** Segment */
73     public final static String JavaDoc SEGMENT_Activity = "AY";
74     /** Segment */
75     public final static String JavaDoc SEGMENT_LocationFrom= "LF";
76     /** Segment */
77     public final static String JavaDoc SEGMENT_LocationTo = "LT";
78     /** Segment */
79     public final static String JavaDoc SEGMENT_Campaign = "MC";
80     /** Segment */
81     public final static String JavaDoc SEGMENT_OrgTrx = "OT";
82     /** Segment */
83     public final static String JavaDoc SEGMENT_Project = "PJ";
84     /** Segment */
85     public final static String JavaDoc SEGMENT_SalesRegion = "SR";
86     /** Segment */
87     public final static String JavaDoc SEGMENT_User1 = "U1";
88     /** Segment */
89     public final static String JavaDoc SEGMENT_User2 = "U2";
90
91     /**
92      * Factory: Return ArrayList of Account Schema Elements
93      * @param C_AcctSchema_ID C_AcctSchema_ID
94      * @return ArrayList with Elements
95      */

96     public static ArrayList getAcctSchemaElementList (int C_AcctSchema_ID)
97     {
98         Log.trace(Log.l3_Util, "AcctSchamaElement.getAcctSchemaElementList - " + C_AcctSchema_ID);
99         ArrayList list = new ArrayList();
100         //
101
String JavaDoc sql = "SELECT C_AcctSchema_Element_ID,SeqNo,Name,ElementType," // 1..4
102
+ "C_Element_ID,IsMandatory,IsBalanced, " // 5..7
103
+ "Org_ID,C_ElementValue_ID,C_BPartner_ID,M_Product_ID," // 8..11
104
+ "C_Activity_ID,C_Location_ID,C_Campaign_ID," // 12..14
105
+ "C_Project_ID,C_SalesRegion_ID " // 15..16
106
+ "FROM C_AcctSchema_Element "
107             + "WHERE C_AcctSchema_ID=? AND IsActive='Y' ORDER BY SeqNo";
108
109         try
110         {
111             PreparedStatement pstmt = DB.prepareStatement(sql);
112             pstmt.setInt(1, C_AcctSchema_ID);
113             ResultSet rs = pstmt.executeQuery();
114             while (rs.next())
115             {
116                 int id = rs.getInt(1);
117                 int seqNo = rs.getInt(2);
118                 String JavaDoc name = rs.getString(3);
119                 String JavaDoc segmentType = rs.getString(4);
120                 int C_Element_ID = rs.getInt(5);
121                 boolean mandatory = rs.getString(6).equals("Y");
122                 boolean balanced = rs.getString(7).equals("Y");
123                 //
124
int defaultValue = 0;
125                 if (segmentType.equals(SEGMENT_Org))
126                     defaultValue = rs.getInt(8); // Org_ID
127
else if (segmentType.equals(SEGMENT_Account))
128                     defaultValue = rs.getInt(9); // C_ElementValue_ID
129
else if (segmentType.equals(SEGMENT_BPartner))
130                     defaultValue = rs.getInt(10);
131                 else if (segmentType.equals(SEGMENT_Product))
132                     defaultValue = rs.getInt(11);
133                 else if (segmentType.equals(SEGMENT_Activity))
134                     defaultValue = rs.getInt(12);
135                 else if (segmentType.equals(SEGMENT_LocationFrom))
136                     defaultValue = rs.getInt(13); // C_Location_ID
137
else if (segmentType.equals(SEGMENT_LocationTo))
138                     defaultValue = rs.getInt(13); // C_Location_ID
139
else if (segmentType.equals(SEGMENT_Campaign))
140                     defaultValue = rs.getInt(14);
141                 else if (segmentType.equals(SEGMENT_OrgTrx))
142                     defaultValue = rs.getInt(8); // Org_ID
143
else if (segmentType.equals(SEGMENT_Project))
144                     defaultValue = rs.getInt(15);
145                 else if (segmentType.equals(SEGMENT_SalesRegion))
146                     defaultValue = rs.getInt(16);
147                 else if (segmentType.equals(SEGMENT_User1))
148                     defaultValue = rs.getInt(9); // C_ElementValue_ID
149
else if (segmentType.equals(SEGMENT_User2))
150                     defaultValue = rs.getInt(9); // C_ElementValue_ID
151
//
152
Log.trace(Log.l6_Database, seqNo + " " + name + " " + segmentType + "=" + defaultValue);
153                 if (mandatory && defaultValue == 0)
154                     Log.error("AcctSchameElement.getAcctSchemaElementList - No default value for " + name);
155                 //
156
AcctSchemaElement e = new AcctSchemaElement(id, seqNo, name, segmentType,
157                     C_Element_ID, defaultValue, mandatory, balanced);
158                 list.add(e);
159             }
160             rs.close();
161             pstmt.close();
162         }
163         catch (SQLException e)
164         {
165             Log.error ("AcctSchemaElement.getAcctSchemaElementList", e);
166         }
167         return list;
168     } // getAcctSchemaElementList
169

170     /*************************************************************************/
171
172     /**
173      * Get Display Name
174      * @return name
175      */

176     public String JavaDoc getName()
177     {
178         return m_name;
179     } // getName
180

181     /**
182      * Get Segment Type
183      * @return segment type
184      */

185     public String JavaDoc getSegmentType()
186     {
187         return m_segmentType;
188     } // getSegmentType
189

190     /**
191      * Is Segment Type
192      * @param st gegmant type
193      * @return segment type
194      */

195     public boolean isSegmentType (String JavaDoc st)
196     {
197         return m_segmentType.equals(st);
198     } // isSegmentType
199

200     /**
201      * Get ColumnName
202      * @return column name
203      */

204     public String JavaDoc getColumnName()
205     {
206         return getColumnName(m_segmentType);
207     } // getColumnName
208

209     /**
210      * Get Column Name of segment type
211      * @param segmentType segment type
212      * @return column name
213      */

214     public static String JavaDoc getColumnName(String JavaDoc segmentType)
215     {
216         if (segmentType.equals(SEGMENT_Org))
217             return "AD_Org_ID";
218         else if (segmentType.equals(SEGMENT_Account))
219             return "Account_ID";
220         else if (segmentType.equals(SEGMENT_BPartner))
221             return "C_BPartner_ID";
222         else if (segmentType.equals(SEGMENT_Product))
223             return "M_Product_ID";
224         else if (segmentType.equals(SEGMENT_Activity))
225             return "C_Activity_ID";
226         else if (segmentType.equals(SEGMENT_LocationFrom))
227             return "C_LocFrom_ID";
228         else if (segmentType.equals(SEGMENT_LocationTo))
229             return "C_LocTo_ID";
230         else if (segmentType.equals(SEGMENT_Campaign))
231             return "C_Campaign_ID";
232         else if (segmentType.equals(SEGMENT_OrgTrx))
233             return "AD_OrgTrx_ID";
234         else if (segmentType.equals(SEGMENT_Project))
235             return "C_Project_ID";
236         else if (segmentType.equals(SEGMENT_SalesRegion))
237             return "C_SalesRegion_ID";
238         else if (segmentType.equals(SEGMENT_User1))
239             return "User1_ID";
240         else if (segmentType.equals(SEGMENT_User2))
241             return "User2_ID";
242         //
243
return "";
244     } // getColumnName
245

246     /**
247      * Get Value Query for Segment Type
248      * @param segmentType segment type
249      * @return query "SELECT Value,Name FROM Table WHERE ID="
250      */

251     public static String JavaDoc getValueQuery (String JavaDoc segmentType)
252     {
253         if (segmentType.equals(SEGMENT_Org))
254             return "SELECT Value,Name FROM AD_Org WHERE AD_Org_ID=";
255         else if (segmentType.equals(SEGMENT_Account))
256             return "SELECT Value,Name FROM C_ElementValue WHERE C_ElementValue_ID=";
257         else if (segmentType.equals(SEGMENT_BPartner))
258             return "SELECT Value,Name FROM C_BPartner WHERE C_BPartner_ID=";
259         else if (segmentType.equals(SEGMENT_Product))
260             return "SELECT Value,Name FROM M_Product WHERE M_Product_ID=";
261         else if (segmentType.equals(SEGMENT_Activity))
262             return "SELECT Value,Name FROM C_Activity WHERE C_Activity_ID=";
263         else if (segmentType.equals(SEGMENT_LocationFrom))
264             return "SELECT City,Address1 FROM C_Location WHERE C_Location_ID=";
265         else if (segmentType.equals(SEGMENT_LocationTo))
266             return "SELECT City,Address1 FROM C_Location WHERE C_Location_ID=";
267         else if (segmentType.equals(SEGMENT_Campaign))
268             return "SELECT Value,Name FROM C_Campaign WHERE C_Campaign_ID=";
269         else if (segmentType.equals(SEGMENT_OrgTrx))
270             return "SELECT Value,Name FROM AD_Org WHERE AD_Org_ID=";
271         else if (segmentType.equals(SEGMENT_Project))
272             return "SELECT Value,Name FROM C_Project WHERE C_Project_ID=";
273         else if (segmentType.equals(SEGMENT_SalesRegion))
274             return "SELECT Value,Name FROM C_SalesRegion WHERE C_SalesRegion_ID";
275         else if (segmentType.equals(SEGMENT_User1))
276             return "SELECT Value,Name FROM C_ElementValue WHERE C_ElementValue_ID=";
277         else if (segmentType.equals(SEGMENT_User2))
278             return "SELECT Value,Name FROM C_ElementValue WHERE C_ElementValue_ID=";
279         //
280
return "";
281     } // getColumnName
282

283
284     /**
285      * Get ID
286      * @return ID
287      */

288     public int getID()
289     {
290         return m_ID;
291     }
292     public int getC_Element_ID()
293     {
294         return m_C_Element_ID;
295     }
296     public int getDefaultValue()
297     {
298         return m_defaultValue;
299     }
300     public boolean isMandatory()
301     {
302         return m_mandatory;
303     }
304     public boolean isBalanced()
305     {
306         return m_balanced;
307     }
308     public int getSeqNo()
309     {
310         return m_seqNo;
311     }
312
313
314     /**
315      * String representation
316      * @return info
317      */

318     public String JavaDoc toString()
319     {
320         return "AcctSchemaElement[" + m_name + " (" + m_segmentType + ") Pos=" + m_seqNo + "]";
321     } // toString
322

323 } // AcctSchemaElement
324
Popular Tags