01: /*
02: * Copyright 2006, 2007 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.el.tree.impl.ast;
17:
18: import javax.el.ELContext;
19: import javax.el.ELException;
20: import javax.el.MethodInfo;
21:
22: import de.odysseus.el.misc.LocalMessages;
23: import de.odysseus.el.misc.TypeConversions;
24: import de.odysseus.el.tree.Bindings;
25:
26: public final class AstText extends AstNode {
27: private final String value;
28:
29: public AstText(String value) {
30: this .value = value;
31: }
32:
33: public boolean isLiteralText() {
34: return true;
35: }
36:
37: public boolean isLeftValue() {
38: return false;
39: }
40:
41: public Class<?> getType(Bindings bindings, ELContext context) {
42: return null;
43: }
44:
45: public boolean isReadOnly(Bindings bindings, ELContext context) {
46: return true;
47: }
48:
49: public void setValue(Bindings bindings, ELContext context,
50: Object value) {
51: throw new ELException(LocalMessages
52: .get("error.value.set.rvalue"));
53: }
54:
55: @Override
56: public Object eval(Bindings bindings, ELContext context) {
57: return value;
58: }
59:
60: public MethodInfo getMethodInfo(Bindings bindings,
61: ELContext context, Class returnType, Class[] paramTypes) {
62: return null;
63: }
64:
65: public Object invoke(Bindings bindings, ELContext context,
66: Class returnType, Class[] paramTypes, Object[] paramValues) {
67: return returnType == null ? value : TypeConversions
68: .coerceToType(value, returnType);
69: }
70:
71: @Override
72: public String toString() {
73: return "\"" + value + "\"";
74: }
75:
76: @Override
77: public void appendStructure(StringBuilder b, Bindings bindings) {
78: int end = value.length() - 1;
79: for (int i = 0; i < end; i++) {
80: char c = value.charAt(i);
81: if ((c == '#' || c == '$') && value.charAt(i + 1) == '{') {
82: b.append('\\');
83: }
84: b.append(c);
85: }
86: if (end >= 0) {
87: b.append(value.charAt(end));
88: }
89: }
90:
91: public int getCardinality() {
92: return 0;
93: }
94:
95: public AstNode getChild(int i) {
96: return null;
97: }
98: }
|