1 50 package org.apache.avalon.excalibur.cli; 51 52 64 public final class CLOptionDescriptor 65 { 66 67 public static final int ARGUMENT_REQUIRED = 1 << 1; 68 69 public static final int ARGUMENT_OPTIONAL = 1 << 2; 70 71 public static final int ARGUMENT_DISALLOWED = 1 << 3; 72 73 public static final int ARGUMENTS_REQUIRED_2 = 1 << 4; 74 75 public static final int DUPLICATES_ALLOWED = 1 << 5; 76 77 private final int m_id; 78 private final int m_flags; 79 private final String m_name; 80 private final String m_description; 81 private final int[] m_incompatible; 82 83 91 public CLOptionDescriptor( final String name, 92 final int flags, 93 final int id, 94 final String description ) 95 { 96 this( name, flags, id, description, 97 ( ( flags & CLOptionDescriptor.DUPLICATES_ALLOWED ) > 0 ) 98 ? new int[ 0 ] : new int[]{id} ); 99 } 100 101 111 public CLOptionDescriptor( final String name, 112 final int flags, 113 final int id, 114 final String description, 115 final int[] incompatible ) 116 { 117 m_id = id; 118 m_name = name; 119 m_flags = flags; 120 m_description = description; 121 m_incompatible = incompatible; 122 123 int modeCount = 0; 124 if( ( ARGUMENT_REQUIRED & flags ) == ARGUMENT_REQUIRED ) 125 { 126 modeCount++; 127 } 128 if( ( ARGUMENT_OPTIONAL & flags ) == ARGUMENT_OPTIONAL ) 129 { 130 modeCount++; 131 } 132 if( ( ARGUMENT_DISALLOWED & flags ) == ARGUMENT_DISALLOWED ) 133 { 134 modeCount++; 135 } 136 if( ( ARGUMENTS_REQUIRED_2 & flags ) == ARGUMENTS_REQUIRED_2 ) 137 { 138 modeCount++; 139 } 140 141 if( 0 == modeCount ) 142 { 143 final String message = "No mode specified for option " + this; 144 throw new IllegalStateException ( message ); 145 } 146 else if( 1 != modeCount ) 147 { 148 final String message = "Multiple modes specified for option " + this; 149 throw new IllegalStateException ( message ); 150 } 151 } 152 153 161 public CLOptionDescriptor( final String name, 162 final int flags, 163 final int id, 164 final String description, 165 final CLOptionDescriptor[] incompatible ) 166 { 167 m_id = id; 168 m_name = name; 169 m_flags = flags; 170 m_description = description; 171 172 m_incompatible = new int[ incompatible.length ]; 173 for( int i = 0; i < incompatible.length; i++ ) 174 m_incompatible[ i ] = incompatible[ i ].getId(); 175 } 176 177 181 protected final int[] getIncompatble() 182 { 183 return getIncompatible(); 184 } 185 186 191 protected final int[] getIncompatible() 192 { 193 return m_incompatible; 194 } 195 196 201 public final String getDescription() 202 { 203 return m_description; 204 } 205 206 212 public final int getFlags() 213 { 214 return m_flags; 215 } 216 217 223 public final int getId() 224 { 225 return m_id; 226 } 227 228 233 public final String getName() 234 { 235 return m_name; 236 } 237 238 243 public final String toString() 244 { 245 final StringBuffer sb = new StringBuffer (); 246 sb.append( "[OptionDescriptor " ); 247 sb.append( m_name ); 248 sb.append( "[OptionDescriptor " ); 249 sb.append( m_name ); 250 sb.append( ", " ); 251 sb.append( m_id ); 252 sb.append( ", " ); 253 sb.append( m_flags ); 254 sb.append( ", " ); 255 sb.append( m_description ); 256 sb.append( " ]" ); 257 return sb.toString(); 258 } 259 } 260 | Popular Tags |