1 17 package org.apache.commons.cli.avalon; 18 20 29 public final class CLOptionDescriptor 30 { 31 32 public static final int ARGUMENT_REQUIRED = 1 << 1; 33 34 public static final int ARGUMENT_OPTIONAL = 1 << 2; 35 36 public static final int ARGUMENT_DISALLOWED = 1 << 3; 37 38 public static final int ARGUMENTS_REQUIRED_2 = 1 << 4; 39 40 public static final int DUPLICATES_ALLOWED = 1 << 5; 41 42 private final int m_id; 43 private final int m_flags; 44 private final String m_name; 45 private final String m_description; 46 private final int[] m_incompatible; 47 48 56 public CLOptionDescriptor( final String name, 57 final int flags, 58 final int id, 59 final String description ) 60 { 61 this( name, flags, id, description, 62 ((flags & CLOptionDescriptor.DUPLICATES_ALLOWED) > 0) 63 ? new int[0] : new int[]{id} ); 64 } 65 66 76 public CLOptionDescriptor( final String name, 77 final int flags, 78 final int id, 79 final String description, 80 final int[] incompatible ) 81 { 82 m_id = id; 83 m_name = name; 84 m_flags = flags; 85 m_description = description; 86 m_incompatible = incompatible; 87 88 int modeCount = 0; 89 if( (ARGUMENT_REQUIRED & flags) == ARGUMENT_REQUIRED ) 90 { 91 modeCount++; 92 } 93 if( (ARGUMENT_OPTIONAL & flags) == ARGUMENT_OPTIONAL ) 94 { 95 modeCount++; 96 } 97 if( (ARGUMENT_DISALLOWED & flags) == ARGUMENT_DISALLOWED ) 98 { 99 modeCount++; 100 } 101 if( (ARGUMENTS_REQUIRED_2 & flags) == ARGUMENTS_REQUIRED_2 ) 102 { 103 modeCount++; 104 } 105 106 if( 0 == modeCount ) 107 { 108 final String message = "No mode specified for option " + this; 109 throw new IllegalStateException ( message ); 110 } 111 else if( 1 != modeCount ) 112 { 113 final String message = "Multiple modes specified for option " + this; 114 throw new IllegalStateException ( message ); 115 } 116 } 117 118 126 public CLOptionDescriptor( final String name, 127 final int flags, 128 final int id, 129 final String description, 130 final CLOptionDescriptor[] incompatible ) 131 { 132 m_id = id; 133 m_name = name; 134 m_flags = flags; 135 m_description = description; 136 137 m_incompatible = new int[incompatible.length]; 138 for( int i = 0; i < incompatible.length; i++ ) 139 { 140 m_incompatible[i] = incompatible[i].getId(); 141 } 142 } 143 144 148 protected final int[] getIncompatble() 149 { 150 return getIncompatible(); 151 } 152 153 158 protected final int[] getIncompatible() 159 { 160 return m_incompatible; 161 } 162 163 168 public final String getDescription() 169 { 170 return m_description; 171 } 172 173 179 public final int getFlags() 180 { 181 return m_flags; 182 } 183 184 190 public final int getId() 191 { 192 return m_id; 193 } 194 195 200 public final String getName() 201 { 202 return m_name; 203 } 204 205 210 public final String toString() 211 { 212 final StringBuffer sb = new StringBuffer (); 213 sb.append( "[OptionDescriptor " ); 214 sb.append( m_name ); 215 sb.append( "[OptionDescriptor " ); 216 sb.append( m_name ); 217 sb.append( ", " ); 218 sb.append( m_id ); 219 sb.append( ", " ); 220 sb.append( m_flags ); 221 sb.append( ", " ); 222 sb.append( m_description ); 223 sb.append( " ]" ); 224 return sb.toString(); 225 } 226 } 227 | Popular Tags |