KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.*;
17 import java.util.*;
18 import java.io.Serializable JavaDoc;
19
20 import oracle.net.TNSAddress.Description;
21
22 import org.compiere.util.DB;
23 import org.compiere.util.Env;
24 import org.compiere.util.CCache;
25 import org.compiere.util.NamePair;
26 import org.compiere.util.KeyNamePair;
27
28 /**
29  * Product Attribute Lookup Model (not Cached)
30  *
31  * @author Jorg Janke
32  * @version $Id: MPAttribute.java,v 1.1 2003/10/27 15:22:39 jjanke Exp $
33  */

34 public class MPAttribute extends Lookup
35     implements Serializable JavaDoc
36 {
37
38     /**
39      * Constructor
40      * @param ctx context
41      * @param WindowNo window no
42      */

43     public MPAttribute(Properties ctx, int WindowNo)
44     {
45         super();
46         m_ctx = ctx;
47         m_WindowNo = WindowNo;
48     } // MPAttribute
49

50     private int m_WindowNo;
51     private Properties m_ctx;
52
53     private PreparedStatement m_pstmt = null;
54
55     /**
56      * Get Display for Value (not cached)
57      * @param value Location_ID
58      * @return String Value
59      */

60     public String JavaDoc getDisplay (Object JavaDoc value)
61     {
62         if (value == null)
63             return "";
64         NamePair pp = get (value);
65         if (pp == null)
66             return "<" + value.toString() + ">";
67         return pp.getName();
68     } // getDisplay
69

70     /**
71      * The Lookup contains the key (not cached)
72      * @param key Location_ID
73      * @return true if key known
74      */

75     public boolean containsKey (Object JavaDoc key)
76     {
77         return get(key) != null;
78     } // containsKey
79

80     /**
81      * Get Object of Key Value
82      * @param value value
83      * @return Object or null
84      */

85     public NamePair get (Object JavaDoc value)
86     {
87         if (value == null)
88             return null;
89         int M_AttributeSetInstance_ID = 0;
90         if (value instanceof Integer JavaDoc)
91             M_AttributeSetInstance_ID = ((Integer JavaDoc)value).intValue();
92         else
93         {
94             try
95             {
96                 M_AttributeSetInstance_ID = Integer.parseInt(value.toString());
97             }
98             catch (Exception JavaDoc e)
99             {
100                 log.error("get - " + value, e);
101             }
102         }
103         if (M_AttributeSetInstance_ID == 0)
104             return null;
105         //
106
// Statement
107
if (m_pstmt == null)
108             m_pstmt = DB.prepareStatement("SELECT Description "
109                 + "FROM M_AttributeSetInstance "
110                 + "WHERE M_AttributeSetInstance_ID=?");
111         //
112
String JavaDoc Description = null;
113         try
114         {
115             m_pstmt.setInt(1, M_AttributeSetInstance_ID);
116             ResultSet rs = m_pstmt.executeQuery();
117             if (rs.next())
118                 Description = rs.getString(1); // Description
119
rs.close();
120         }
121         catch (Exception JavaDoc e)
122         {
123             log.error("get", e);
124         }
125         if (Description == null)
126             return null;
127         return new KeyNamePair (M_AttributeSetInstance_ID, Description);
128     } // get
129

130     /**
131      * Dispose
132      * @see org.compiere.model.Lookup#dispose()
133      */

134     public void dispose()
135     {
136         try
137         {
138             if (m_pstmt != null)
139                 m_pstmt.close();
140         }
141         catch (SQLException e)
142         {
143             log.error("dispose", e);
144         }
145         log.debug("dispose");
146         super.dispose();
147     } // dispose
148

149     /**
150      * Return data as sorted Array - not implemented
151      * @param mandatory mandatory
152      * @param onlyValidated only validated
153      * @param onlyActive only active
154      * @param temporary force load for temporary display
155      * @return null
156      */

157     public ArrayList getData (boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary)
158     {
159         log.error("getData - not implemented");
160         return null;
161     } // getArray
162

163     /**
164      * Get underlying fully qualified Table.Column Name.
165      * Used for VLookup.actionButton (Zoom)
166      * @return column name
167      */

168     public String JavaDoc getColumnName()
169     {
170         return "M_AttributeSetInstance_ID";
171     } // getColumnName
172

173 } // MPAttribute
174
Popular Tags