1 23 24 package com.sun.enterprise.admin.util; 25 26 import com.sun.enterprise.admin.util.Assert; 27 import com.sun.enterprise.admin.util.AssertImpl; 28 import com.sun.enterprise.admin.util.Validator; 29 import com.sun.enterprise.admin.util.ValidatorResult; 30 31 41 42 public class ArgChecker 43 { 44 52 private final static boolean sChecksEnabled = true; 53 private final static AssertImpl sImpl; 54 55 static 56 { 57 sImpl = new AssertImpl("ArgChecker Failure", AssertImpl.sIllegalArgument); 60 sImpl.setWantStackTrace(false); 61 } 62 63 private ArgChecker() 64 { 65 Assert.assertit(false, "You can't call the ArgChecker constructor!"); 66 } 67 68 77 static public final void check( boolean b, Object msg ) 78 throws IllegalArgumentException 79 { 80 if ( sChecksEnabled ) 81 { 82 sImpl.assertIt(b, msg); 83 } 84 } 85 86 97 public static final void check(long value, long min, long max, 98 Object userMsg) 99 throws IllegalArgumentException 100 { 101 checkRange(value, min, max, userMsg); 102 } 103 104 119 public static final void checkRange(long value, long min, long max, 120 Object userMsg) 121 throws IllegalArgumentException 122 { 123 if ( sChecksEnabled ) 124 { 125 sImpl.assertRange(value, min, max, userMsg); 126 } 127 } 128 129 138 public static void checkValid(Object object, 139 String name, 140 Validator validator) 141 throws IllegalArgumentException 142 { 143 if ( sChecksEnabled ) 144 { 145 sImpl.assertValid(object, name, validator); 146 } 147 } 148 149 160 public static void check(Object object, 161 String name, 162 Validator validator) 163 throws IllegalArgumentException 164 { 165 checkValid(object, name, validator); 166 } 167 168 177 public static void checkValid(Object object, String name ) 178 throws IllegalArgumentException 179 { 180 final Validator validator = (object instanceof Validator ) ? 181 (Validator)object : 182 BaseValidator.getInstance(); 183 check( object, name, validator ); 184 } 185 186 195 public static void check(Object object, String name ) 196 throws IllegalArgumentException 197 { 198 checkValid( object, name); 199 } 200 201 207 public static void check(String checkMe, String name) 208 throws IllegalArgumentException 209 { 210 check(checkMe, name, StringValidator.getInstance()); 211 } 212 213 220 public static void check(String checkMe, int minimumLength, String name) 221 throws IllegalArgumentException 222 { 223 check(checkMe, name, new StringValidator(minimumLength)); 224 } 225 } 226 | Popular Tags |