View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.view.facelets.tag.jstl.core;
20  
21  import javax.el.ELContext;
22  import javax.el.ValueExpression;
23  
24  /**
25   * @author Jacob Hookom
26   * @version $Id$
27   */
28  public final class IndexedValueExpression extends ValueExpression
29  {
30  
31      /**
32       * 
33       */
34      private static final long serialVersionUID = 1L;
35  
36      private final Integer i;
37  
38      private final ValueExpression orig;
39  
40      /**
41       * 
42       */
43      public IndexedValueExpression(ValueExpression orig, int i)
44      {
45          this.i = Integer.valueOf(i);
46          this.orig = orig;
47      }
48  
49      /*
50       * (non-Javadoc)
51       * 
52       * @see javax.el.ValueExpression#getValue(javax.el.ELContext)
53       */
54      public Object getValue(ELContext context)
55      {
56          Object base = this.orig.getValue(context);
57          if (base != null)
58          {
59              context.setPropertyResolved(false);
60              return context.getELResolver().getValue(context, base, i);
61          }
62          return null;
63      }
64  
65      /*
66       * (non-Javadoc)
67       * 
68       * @see javax.el.ValueExpression#setValue(javax.el.ELContext, java.lang.Object)
69       */
70      public void setValue(ELContext context, Object value)
71      {
72          Object base = this.orig.getValue(context);
73          if (base != null)
74          {
75              context.setPropertyResolved(false);
76              context.getELResolver().setValue(context, base, i, value);
77          }
78      }
79  
80      /*
81       * (non-Javadoc)
82       * 
83       * @see javax.el.ValueExpression#isReadOnly(javax.el.ELContext)
84       */
85      public boolean isReadOnly(ELContext context)
86      {
87          Object base = this.orig.getValue(context);
88          if (base != null)
89          {
90              context.setPropertyResolved(false);
91              return context.getELResolver().isReadOnly(context, base, i);
92          }
93          return true;
94      }
95  
96      /*
97       * (non-Javadoc)
98       * 
99       * @see javax.el.ValueExpression#getType(javax.el.ELContext)
100      */
101     public Class getType(ELContext context)
102     {
103         Object base = this.orig.getValue(context);
104         if (base != null)
105         {
106             context.setPropertyResolved(false);
107             return context.getELResolver().getType(context, base, i);
108         }
109         return null;
110     }
111 
112     /*
113      * (non-Javadoc)
114      * 
115      * @see javax.el.ValueExpression#getExpectedType()
116      */
117     public Class getExpectedType()
118     {
119         return Object.class;
120     }
121 
122     /*
123      * (non-Javadoc)
124      * 
125      * @see javax.el.Expression#getExpressionString()
126      */
127     public String getExpressionString()
128     {
129         return this.orig.getExpressionString();
130     }
131 
132     /*
133      * (non-Javadoc)
134      * 
135      * @see javax.el.Expression#equals(java.lang.Object)
136      */
137     public boolean equals(Object obj)
138     {
139         return this.orig.equals(obj);
140     }
141 
142     /*
143      * (non-Javadoc)
144      * 
145      * @see javax.el.Expression#hashCode()
146      */
147     public int hashCode()
148     {
149         return this.orig.hashCode();
150     }
151 
152     /*
153      * (non-Javadoc)
154      * 
155      * @see javax.el.Expression#isLiteralText()
156      */
157     public boolean isLiteralText()
158     {
159         return false;
160     }
161 
162 }