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  
20  package org.apache.myfaces.tobago.event;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  public enum PageAction {
26  
27    /**
28     * First page is requested
29     */
30    FIRST("First"),
31  
32    /**
33     * Next page is requested
34     */
35    NEXT("Next"),
36  
37    /**
38     * Previous page is requested
39     */
40    PREV("Prev"),
41  
42    /**
43     * Last page is requested
44     */
45    LAST("Last"),
46  
47    /**
48     * A specified row is requested
49     */
50    TO_ROW("ToRow"),
51  
52    /**
53     * A specified page is requested
54     */
55    TO_PAGE("ToPage");
56  
57    private String token;
58  
59    PageAction(String token) {
60      this.token = token;
61    }
62  
63    public String getToken() {
64      return token;
65    }
66    
67    private static final Map<String, PageAction> MAPPING;
68  
69    static {
70      MAPPING = new HashMap<String, PageAction>();
71  
72      for (PageAction action : PageAction.values()) {
73        MAPPING.put(action.getToken(), action);
74      }
75    }
76  
77    /**
78     * 
79     * @param name Name of the PageAction
80     * @return The matching page action (can't be null).
81     * @throws IllegalArgumentException When the name doesn't match any PageAction.
82     */
83    public static PageAction parse(String name) throws IllegalArgumentException {
84      PageAction value = MAPPING.get(name);
85      if (value != null) {
86        return value;
87      } else {
88        throw new IllegalArgumentException("Unknown name for PageAction: '" + name + "'");
89      }
90    }
91  }