001 /* 002 * Copyright 2004 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.metro.info; 020 021 import net.dpml.lang.Enum; 022 023 /** 024 * Collection policy enummeration. 025 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 026 * @version 1.2.0 027 */ 028 public final class CollectionPolicy extends Enum 029 { 030 //------------------------------------------------------------------- 031 // static 032 //------------------------------------------------------------------- 033 034 /** 035 * Serial version identifier. 036 */ 037 static final long serialVersionUID = 1L; 038 039 /** 040 * Weak collection policy. 041 */ 042 public static final CollectionPolicy WEAK = new CollectionPolicy( "weak" ); 043 044 /** 045 * Soft collection policy. 046 */ 047 public static final CollectionPolicy SOFT = new CollectionPolicy( "soft" ); 048 049 /** 050 * Hard collection policy. 051 */ 052 public static final CollectionPolicy HARD = new CollectionPolicy( "hard" ); 053 054 /** 055 * Collection policy to be established at system discretion. 056 */ 057 public static final CollectionPolicy SYSTEM = new CollectionPolicy( "system" ); 058 059 /** 060 * Array of static activation policy enumeration values. 061 */ 062 private static final CollectionPolicy[] ENUM_VALUES = 063 new CollectionPolicy[]{WEAK, SOFT, HARD, SYSTEM}; 064 065 /** 066 * Returns an array of activation enum values. 067 * @return the activation policies array 068 */ 069 public static CollectionPolicy[] values() 070 { 071 return ENUM_VALUES; 072 } 073 074 /** 075 * Internal constructor. 076 * @param label the enumeration label. 077 */ 078 private CollectionPolicy( String label ) 079 { 080 super( label ); 081 } 082 083 /** 084 * Return a string representation of this enumeration. 085 * @return the string value 086 */ 087 public String toString() 088 { 089 return getName().toUpperCase(); 090 } 091 092 /** 093 * Parse the supplied name. 094 * @param value the value to parse 095 * @return the collection policy 096 */ 097 public static CollectionPolicy parse( String value ) 098 { 099 if( value.equalsIgnoreCase( "hard" ) ) 100 { 101 return HARD; 102 } 103 else if( value.equalsIgnoreCase( "soft" ) ) 104 { 105 return SOFT; 106 } 107 else if( value.equalsIgnoreCase( "weak" ) ) 108 { 109 return WEAK; 110 } 111 else if( value.equalsIgnoreCase( "system" ) ) 112 { 113 return SYSTEM; 114 } 115 else 116 { 117 final String error = 118 "Unrecognized collection policy argument [" + value + "]"; 119 throw new IllegalArgumentException( error ); 120 } 121 } 122 }