001 package org.apache.myfaces.tobago.event; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020 import java.util.HashMap; 021 import java.util.Map; 022 023 public enum PageAction { 024 025 /** 026 * First page is requested 027 */ 028 FIRST("First"), 029 030 /** 031 * Next page is requested 032 */ 033 NEXT("Next"), 034 035 /** 036 * Previous page is requested 037 */ 038 PREV("Prev"), 039 040 /** 041 * Last page is requested 042 */ 043 LAST("Last"), 044 045 /** 046 * A specified row is requested 047 */ 048 TO_ROW("ToRow"), 049 050 /** 051 * A specified page is requested 052 */ 053 TO_PAGE("ToPage"); 054 055 private String token; 056 057 PageAction(String token) { 058 this.token = token; 059 } 060 061 public String getToken() { 062 return token; 063 } 064 065 private static final Map<String, PageAction> MAPPING; 066 067 static { 068 MAPPING = new HashMap<String, PageAction>(); 069 070 for (PageAction action : PageAction.values()) { 071 MAPPING.put(action.getToken(), action); 072 } 073 } 074 075 /** 076 * 077 * @param name Name of the PageAction 078 * @return The matching page action (can't be null). 079 * @throws IllegalArgumentException When the name doesn't match any PageAction. 080 */ 081 public static PageAction parse(String name) throws IllegalArgumentException { 082 PageAction value = MAPPING.get(name); 083 if (value != null) { 084 return value; 085 } else { 086 throw new IllegalArgumentException("Unknown name for PageAction: '" + name + "'"); 087 } 088 } 089 }