001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.authorization;
018
019import org.apache.wicket.util.lang.EnumeratedType;
020import org.apache.wicket.util.string.Strings;
021
022/**
023 * A class for constructing singleton constants that represent a given component action that needs
024 * to be authorized. The Wicket core framework defines Component.RENDER and Component.ENABLE
025 * actions, but future versions of the framework may add more actions and user defined components
026 * can define their own actions as well.
027 * 
028 * @see org.apache.wicket.Component#RENDER
029 * @see org.apache.wicket.Component#ENABLE
030 * 
031 * @author Eelco Hillenius
032 * @author Jonathan Locke
033 * @since 1.2
034 */
035public class Action extends EnumeratedType
036{
037        /**
038         * RENDER action name (for consistent name and use in annotations).
039         * <p>
040         * DO NOT use for equals on Action, like
041         * 
042         * <pre>
043         * action.equals(Action.RENDER)
044         * </pre>
045         * 
046         * as you'll compare an action with a string. Rather, do:
047         * 
048         * <pre>
049         * action.equals(Component.RENDER)
050         * </pre>
051         * 
052         * </p>
053         */
054        public static final String RENDER = "RENDER";
055
056        /**
057         * ENABLE action name (for consistent name and use in annotations).
058         * <p>
059         * DO NOT use for equals on Action, like
060         * 
061         * <pre>
062         * action.equals(Action.ENABLE)
063         * </pre>
064         * 
065         * as you'll compare an action with a string. Rather, do:
066         * 
067         * <pre>
068         * action.equals(Component.ENABLE)
069         * </pre>
070         * 
071         * </p>
072         */
073        public static final String ENABLE = "ENABLE";
074
075        private static final long serialVersionUID = -1L;
076
077        /** The name of this action. */
078        private final String name;
079
080        /**
081         * Construct.
082         * 
083         * @param name
084         *            The name of this action for debug purposes
085         */
086        public Action(final String name)
087        {
088                super(name);
089                if (Strings.isEmpty(name))
090                {
091                        throw new IllegalArgumentException(
092                                "Name argument may not be null, whitespace or the empty string");
093                }
094
095                this.name = name;
096        }
097
098        /**
099         * @return The name of this action
100         */
101        public String getName()
102        {
103                return name;
104        }
105}