837c24a07138674674209cfea18ed8324f04c202.svn-base 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package cn.com.goldenwater.dcproj.util;
  2. import cn.com.goldenwater.target.CheckException;
  3. import org.springframework.context.MessageSource;
  4. import java.util.Arrays;
  5. public class CheckUtil {
  6. private static MessageSource resources;
  7. public static void setResources(MessageSource resources) {
  8. CheckUtil.resources = resources;
  9. }
  10. public static void check(boolean condition, String msgKey, Object... args) {
  11. if (!condition) {
  12. fail(msgKey, args);
  13. }
  14. }
  15. public static void notEmpty(String str, String msgKey, Object... args) {
  16. if (str == null || str.isEmpty()) {
  17. fail(msgKey, args);
  18. }
  19. }
  20. public static void notNull(Object obj, String msgKey, Object... args) {
  21. if (obj == null) {
  22. fail(msgKey, args);
  23. }
  24. }
  25. private static void fail(String msgKey, Object... args) {
  26. throw new CheckException(msgKey + ": " + Arrays.toString(args));
  27. // throw new CheckException(resources.getMessage(msgKey, args, Locale.CHINA));
  28. }
  29. }