KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > UserColumn


1 package jimm.datavision;
2 import jimm.datavision.source.DataSource;
3 import jimm.datavision.source.Table;
4 import jimm.datavision.source.sql.SQLQuery;
5 import jimm.util.XMLWriter;
6
7 /**
8  * A user column is an arbitrary expression inserted into the SQL query
9  * and retrieved as a column value. It may contain database
10  * column values, parameters, special values, strings, or
11  * numbers. It can't contain formulas because their values may be
12  * undefined when the query is run.
13  * <p>
14  * When used by a query, the following substitutions are made withing
15  * the <var>userString</var> of a user column:
16  * <ul>
17  * <li>{<i>table_name.column_name</i>} is replaced by the column name
18  * <i>table_name.column_name</i>.</li>
19  * <li> {%<i>special_value_name</i>} is replaced by a special value
20  * (report title, report run date, page number, or record number).</li>
21  * <li> {?<i>id_number</i>} is replaced by a parameter value (string,
22  * number, or date).</li>
23  * <ul>
24  *
25  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
26  */

27 public class UserColumn extends Expression implements Selectable {
28
29 public static final int MAX_DISPLAY_NAME_LENGTH = 16;
30
31 /**
32  * Constructor.
33  *
34  * @param id the unique identifier for the new user column; if
35  * <code>null</code>, generate a new id
36  * @param report the report containing this user column
37  * @param name the user column name
38  */

39 public UserColumn(Long JavaDoc id, Report report, String JavaDoc name) {
40     this(id, report, name, null);
41 }
42
43 /**
44  * Constructor. If <i>id</i> is <code>null</code>, generates a new id number.
45  * This number is one higher than any previously-seen id number. This does
46  * <em>not</em> guarantee that no later user column will be created manually
47  * with the same id number.
48  *
49  * @param id the unique identifier for the new user column; if
50  * <code>null</code>, generate a new id
51  * @param report the report containing this user column
52  * @param name the user column name
53  * @param evalString the string to evaulate at runtime.
54  */

55 public UserColumn(Long JavaDoc id, Report report, String JavaDoc name, String JavaDoc evalString) {
56     super(id == null ? report.generateNewUserColumnId() : id, report, name,
57       evalString, null);
58 }
59
60 public Object JavaDoc getValue(Report report) {
61     return report.columnValue(this);
62 }
63
64 public String JavaDoc fieldTypeString() { return "usercol"; }
65
66 public String JavaDoc getSelectString(SQLQuery query) {
67     String JavaDoc str = getExpression();
68     if (str == null)
69     return null;
70     return query.prepare(str);
71 }
72
73 public String JavaDoc getSortString(SQLQuery query) {
74     return getSelectString(query);
75 }
76
77 public Table getTable() { return null; }
78
79 public String JavaDoc getDisplayName() { return getName(); }
80
81 public String JavaDoc dragString() { return "usercol:" + getId(); }
82
83 public String JavaDoc designLabel() { return "{!" + getName() + "}"; }
84
85 public String JavaDoc formulaString() { return "{!" + getId() + "}"; }
86
87 public Selectable reloadInstance(DataSource dataSource) {
88     return this;
89 }
90
91 /**
92  * Returns this user column's SQL text as entered by the user.
93  */

94 public String JavaDoc toString() {
95     return getExpression();
96 }
97
98 public void writeXML(XMLWriter out) {
99     writeXML(out, "usercol");
100 }
101
102 }
103
Popular Tags