View Javadoc

1   package org.apache.commons.ognl;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * This class has predefined instances that stand for OGNL's special "dynamic subscripts" for getting at the first,
24   * middle, or last elements of a list. In OGNL expressions, these subscripts look like special kinds of array indexes:
25   * [^] means the first element, [$] means the last, [|] means the middle, and [*] means the whole list.
26   * 
27   * @author Luke Blanshard (blanshlu@netscape.net)
28   * @author Drew Davidson (drew@ognl.org)
29   */
30  public class DynamicSubscript
31  {
32      public static final int FIRST = 0;
33  
34      public static final int MID = 1;
35  
36      public static final int LAST = 2;
37  
38      public static final int ALL = 3;
39  
40      public static final DynamicSubscript first = new DynamicSubscript( FIRST );
41  
42      public static final DynamicSubscript mid = new DynamicSubscript( MID );
43  
44      public static final DynamicSubscript last = new DynamicSubscript( LAST );
45  
46      public static final DynamicSubscript all = new DynamicSubscript( ALL );
47  
48      private int flag;
49  
50      private DynamicSubscript( int flag )
51      {
52          this.flag = flag;
53      }
54  
55      public int getFlag()
56      {
57          return flag;
58      }
59  
60      @Override
61      public String toString()
62      {
63          switch ( flag )
64          {
65              case FIRST:
66                  return "^";
67              case MID:
68                  return "|";
69              case LAST:
70                  return "$";
71              case ALL:
72                  return "*";
73              default:
74                  return "?"; // Won't happen
75          }
76      }
77  }