Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ConstantPropertyVariable |
|
| 1.75;1.75 |
1 | /* | |
2 | * Copyright (C) 1998-2000 Semiotek Inc. All Rights Reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted under the terms of either of the following | |
6 | * Open Source licenses: | |
7 | * | |
8 | * The GNU General Public License, version 2, or any later version, as | |
9 | * published by the Free Software Foundation | |
10 | * (http://www.fsf.org/copyleft/gpl.html); | |
11 | * | |
12 | * or | |
13 | * | |
14 | * The Semiotek Public License (http://webmacro.org/LICENSE.) | |
15 | * | |
16 | * This software is provided "as is", with NO WARRANTY, not even the | |
17 | * implied warranties of fitness to purpose, or merchantability. You | |
18 | * assume all risks and liabilities associated with its use. | |
19 | * | |
20 | * See www.webmacro.org for more information on the WebMacro project. | |
21 | */ | |
22 | ||
23 | ||
24 | package org.webmacro.engine; | |
25 | ||
26 | import org.webmacro.Context; | |
27 | import org.webmacro.PropertyException; | |
28 | ||
29 | ||
30 | /** | |
31 | * Operate on bean properties of a compile-time constant | |
32 | * @author Brian Goetz | |
33 | * @since 1.1 | |
34 | */ | |
35 | public class ConstantPropertyVariable extends Variable | |
36 | { | |
37 | ||
38 | private Object value; | |
39 | ||
40 | /** | |
41 | * No special initialization | |
42 | */ | |
43 | ConstantPropertyVariable (Object value, Object names[]) | |
44 | { | |
45 | 0 | super(names); |
46 | 0 | this.value = value; |
47 | 0 | } |
48 | ||
49 | /** | |
50 | * Look up my value in the corresponding Map, possibly using introspection, | |
51 | * and return it | |
52 | * @exception PropertyException If the property does not exist | |
53 | */ | |
54 | public final Object getValue (Context context) | |
55 | throws PropertyException | |
56 | { | |
57 | 0 | if (value == null) |
58 | 0 | throw new PropertyException.NullValueException(_names[0].toString()); |
59 | else | |
60 | 0 | return context.getBroker() |
61 | ._propertyOperators.getProperty(context, value, _names, 1); | |
62 | } | |
63 | ||
64 | /** | |
65 | * Look up my the value of this variable in the specified Map, possibly | |
66 | * using introspection, and set it to the supplied value. | |
67 | * @exception PropertyException If the property does not exist | |
68 | */ | |
69 | public final void setValue (Context context, Object newValue) | |
70 | throws PropertyException | |
71 | { | |
72 | 0 | throw new PropertyException("Cannot set properties of a constant"); |
73 | } | |
74 | ||
75 | /** | |
76 | * Return a string representation naming the variable for | |
77 | * debugging purposes. | |
78 | */ | |
79 | public final String toString () | |
80 | { | |
81 | 0 | return "constant-property:" + getVariableName(); |
82 | } | |
83 | ||
84 | } |