KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > lang > jstl > ComplexValue


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
17 package org.apache.taglibs.standard.lang.jstl;
18
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 /**
23  *
24  * <p>Represents a dynamic value, which consists of a prefix and an
25  * optional set of ValueSuffix elements. A prefix is something like
26  * an identifier, and a suffix is something like a "property of" or
27  * "indexed element of" operator.
28  *
29  * @author Nathan Abramson - Art Technology Group
30  * @author Shawn Bayern
31  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: pierred $
32  **/

33
34 public class ComplexValue
35   extends Expression
36 {
37   //-------------------------------------
38
// Properties
39
//-------------------------------------
40
// property prefix
41

42   Expression mPrefix;
43   public Expression getPrefix ()
44   { return mPrefix; }
45   public void setPrefix (Expression pPrefix)
46   { mPrefix = pPrefix; }
47
48   //-------------------------------------
49
// property suffixes
50

51   List JavaDoc mSuffixes;
52   public List JavaDoc getSuffixes ()
53   { return mSuffixes; }
54   public void setSuffixes (List JavaDoc pSuffixes)
55   { mSuffixes = pSuffixes; }
56
57   //-------------------------------------
58
/**
59    *
60    * Constructor
61    **/

62   public ComplexValue (Expression pPrefix,
63                List JavaDoc pSuffixes)
64   {
65     mPrefix = pPrefix;
66     mSuffixes = pSuffixes;
67   }
68
69   //-------------------------------------
70
// Expression methods
71
//-------------------------------------
72
/**
73    *
74    * Returns the expression in the expression language syntax
75    **/

76   public String JavaDoc getExpressionString ()
77   {
78     StringBuffer JavaDoc buf = new StringBuffer JavaDoc ();
79     buf.append (mPrefix.getExpressionString ());
80
81     for (int i = 0; mSuffixes != null && i < mSuffixes.size (); i++) {
82       ValueSuffix suffix = (ValueSuffix) mSuffixes.get (i);
83       buf.append (suffix.getExpressionString ());
84     }
85
86     return buf.toString ();
87   }
88
89   //-------------------------------------
90
/**
91    *
92    * Evaluates by evaluating the prefix, then applying the suffixes
93    **/

94   public Object JavaDoc evaluate (Object JavaDoc pContext,
95               VariableResolver pResolver,
96               Map JavaDoc functions,
97               String JavaDoc defaultPrefix,
98               Logger pLogger)
99     throws ELException
100   {
101     Object JavaDoc ret = mPrefix.evaluate (pContext, pResolver, functions,
102                    defaultPrefix, pLogger);
103
104     // Apply the suffixes
105
for (int i = 0; mSuffixes != null && i < mSuffixes.size (); i++) {
106       ValueSuffix suffix = (ValueSuffix) mSuffixes.get (i);
107       ret = suffix.evaluate (ret, pContext, pResolver, functions,
108                  defaultPrefix, pLogger);
109     }
110
111     return ret;
112   }
113
114   //-------------------------------------
115
}
116
Popular Tags