001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: Syntax.java,v 1.3 2008/06/25 05:43:45 qcheng Exp $
026 *
027 */
028
029
030package com.sun.identity.policy;
031
032/**
033 * Provides an enum like support for the syntax of values
034 * such as ANY, NONE, LIST, CONSTANT, SINGLE_CHOICE, MULTIPLE_CHOICE
035 * In other words, provides access to a set of finite values and enforces 
036 * new values can not be created by users
037 *
038 * @supported.all.api
039 */
040public final class Syntax {
041
042    /**
043     * value is a free form text, would be typically shown in as editable 
044     *  text field
045     */
046    public static final Syntax ANY = new Syntax("ANY");
047
048    /**
049     * value is a free form multi list text field
050     */
051    public static final Syntax LIST = new Syntax("LIST");
052
053    /**
054     * value is a free form text, could also search from a large set of values
055     */
056    public static final Syntax ANY_SEARCHABLE = new Syntax("ANY_SEARCHABLE");
057
058    /**
059     * no value is allowed
060     */
061    public static final Syntax NONE = new Syntax("NONE");
062
063    /**
064     * value is a constant string, would be typically shown as non 
065     *  editable text
066     */
067    public static final Syntax CONSTANT = new Syntax("CONSTANT");
068
069    /**
070     * value is a single  choice from a list
071     */
072    public static final Syntax SINGLE_CHOICE = new Syntax("SINGLE_CHOICE");
073
074    /**
075     * value is multiple choice from list
076     */
077    public static final Syntax MULTIPLE_CHOICE = new Syntax("MULTIPLE_CHOICE");
078
079    private String _type;
080
081    private Syntax(String type) {
082        _type = type;
083    }
084
085    /**
086     * Returns the string representation of this object.
087     *  
088     *  @return string representation of this Syntax
089     */
090    public String toString() {
091        return _type;
092    }
093
094    /**
095     * Checks whether the argument object is equal to this Syntax
096     * 
097     * @param arg Syntax object for comparison.
098     * @return <code>true</code> if the argument object is equal
099     *         to this Syntax, else <code>false</code>
100     */
101    public boolean equals(Object arg) {
102        boolean equalObjects = false;
103        if ( arg == null ) {
104            equalObjects = false;
105        } else if ( arg == this ) {
106            equalObjects = true;
107        } else if ( !(arg instanceof Syntax) ) {
108            equalObjects = false;
109        } else if ( _type.equals(((Syntax)arg)._type)) {
110            equalObjects = true;
111        }
112        return equalObjects;
113   }
114}