1 /***
2 *
3 */
4 package ar.com.epere4.java2excel.parser.impl;
5
6 import ognl.OgnlException;
7
8 /***
9 * Implementation of {@link ar.com.epere4.java2excel.parser.PropertyDtd} that
10 * returns a constant value with
11 * {@link ar.com.epere4.java2excel.parser.PropertyDtd#
12 * evaluateExpression(Object)}.
13 * <p>
14 * Instances of this class are intended to be used to display values that
15 * has to be all the same but are not present as a property in the collection.
16 * Objects like this must be added manualy by you using the method
17 * {@link ar.com.epere4.java2excel.parser.BodyDtd#addProperty(PropertyDtd)}.
18 * <p>
19 * The result of using this is a column with all values equals to each other.
20 * This may seem useless (Hey, what's the point of having a constant column??),
21 * but some people find useful to copy data from different generated Excel files
22 * and join them in a single file. Different files may have different values in
23 * these constant columns, so they can use autofilters with them.
24 *
25 * @author epere4
26 * @since 09/03/2006
27 */
28 public class PropertyDtdStaticImpl extends AbstractPropertyDtd {
29 /***
30 * The value to be returned by {@link #evaluateExpression(Object)}.
31 */
32 private Object value;
33
34 /***
35 * Default constructor.
36 *
37 * @since 09/03/2006
38 */
39 public PropertyDtdStaticImpl() {
40 }
41
42 /***
43 * @param expression default value for
44 * {@link ar.com.epere4.java2excel.parser.PropertyDtd#
45 * getExpression()}. Cannot be null, because it is used as a key.
46 * @param value default value for {@link #getValue()}.
47 * @since 09/03/2006
48 */
49 public PropertyDtdStaticImpl(final String expression, final Object value) {
50 setValue(value);
51 setExpression(expression);
52 }
53
54 /***
55 * @param expression
56 * default value for
57 * {@link ar.com.epere4.java2excel.parser.PropertyDtd#
58 * getExpression()}. Cannot be null, because it is used as a key.
59 * @param title
60 * default value for
61 * {@link ar.com.epere4.java2excel.parser.PropertyDtd#
62 * getTitle()}.
63 * @param value
64 * default value for {@link #getValue()}.
65 * @since 09/03/2006
66 */
67 public PropertyDtdStaticImpl(final String expression, final String title,
68 final Object value) {
69 super(expression, title);
70 setValue(value);
71 }
72
73 /***
74 * @return Returns the value.
75 * @since 09/03/2006
76 */
77 public Object getValue() {
78 return value;
79 }
80
81 /***
82 * @param value
83 * The value to set.
84 * @since 09/03/2006
85 */
86 public void setValue(final Object value) {
87 this.value = value;
88 }
89
90 /***
91 * {@inheritDoc}
92 *
93 * This implementation just returs {@link #getValue()}.
94 *
95 * @see ar.com.epere4.java2excel.parser.PropertyDtd#
96 * evaluateExpression(java.lang.Object)
97 * @since 09/03/2006
98 */
99 public Object evaluateExpression(final Object element)
100 throws OgnlException {
101
102 return getValue();
103 }
104
105 }