001 /*
002 * Copyright 2005 Stephen J. McConnell.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.station.info;
020
021 import net.dpml.lang.Enum;
022
023 /**
024 * Lifestyle policy enumeration.
025 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
026 * @version 1.0.5
027 */
028 public final class StartupPolicy extends Enum
029 {
030 static final long serialVersionUID = 1L;
031
032 /**
033 * Disable policy.
034 */
035 public static final StartupPolicy DISABLED = new StartupPolicy( "disabled" );
036
037 /**
038 * Manual startup policy.
039 */
040 public static final StartupPolicy MANUAL = new StartupPolicy( "manual" );
041
042 /**
043 * Automatic startup policy.
044 */
045 public static final StartupPolicy AUTOMATIC = new StartupPolicy( "automatic" );
046
047 /**
048 * Array of scope enumeration values.
049 */
050 private static final StartupPolicy[] ENUM_VALUES = new StartupPolicy[]{DISABLED, MANUAL, AUTOMATIC};
051
052 /**
053 * Returns an array of activation enum values.
054 * @return the activation policies array
055 */
056 public static StartupPolicy[] values()
057 {
058 return ENUM_VALUES;
059 }
060
061 /**
062 * Internal constructor.
063 * @param label the enumeration label.
064 */
065 private StartupPolicy( String label )
066 {
067 super( label );
068 }
069
070 /**
071 * Return a string representation of the scope.
072 * @return the string value
073 */
074 public String toString()
075 {
076 return getName().toUpperCase();
077 }
078
079 /**
080 * Return a startup policy matching the supplied value.
081 * @param value the policy name
082 * @return the startup policy
083 * @exception NullPointerException if the value if null
084 * @exception IllegalArgumentException if the value if not recognized
085 */
086 public static StartupPolicy parse( String value ) throws NullPointerException, IllegalArgumentException
087 {
088 if( null == value )
089 {
090 throw new NullPointerException( "value" );
091 }
092 else if( value.equalsIgnoreCase( "disabled" ) )
093 {
094 return DISABLED;
095 }
096 else if( value.equalsIgnoreCase( "manual" ) )
097 {
098 return MANUAL;
099 }
100 else if( value.equalsIgnoreCase( "automatic" ) )
101 {
102 return AUTOMATIC;
103 }
104 else
105 {
106 final String error =
107 "Unrecognized startup policy argument [" + value + "]";
108 throw new IllegalArgumentException( error );
109 }
110 }
111 }
112