Advertisement
Guest User

Untitled

a guest
Dec 31st, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. *
  6. * Software distributed under the License is distributed on an "AS IS"
  7. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  8. * License for the specific language governing rights and limitations
  9. * under the License.
  10. *
  11. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  12. */
  13. package org.openmrs.validator;
  14.  
  15. import org.apache.commons.logging.Log;
  16. import org.apache.commons.logging.LogFactory;
  17. import org.openmrs.RelationshipType;
  18. import org.openmrs.annotation.Handler;
  19. import org.springframework.validation.Errors;
  20. import org.springframework.validation.ValidationUtils;
  21. import org.springframework.validation.Validator;
  22.  
  23. /**
  24. * Validates attributes on the {@link RelationshipType} object.
  25. *
  26. * @since 1.10
  27. */
  28. @Handler(supports = { RelationshipType.class }, order = 50)
  29. public class RelationshipTypeValidator implements Validator {
  30.  
  31. /** Log for this class and subclasses */
  32. protected final Log log = LogFactory.getLog(getClass());
  33.  
  34. /**
  35. * Determines if the command object being submitted is a valid type
  36. *
  37. * @see org.springframework.validation.Validator#supports(java.lang.Class)
  38. */
  39. @SuppressWarnings("unchecked")
  40. public boolean supports(Class c) {
  41. return c.equals(RelationshipType.class);
  42. }
  43.  
  44. /**
  45. * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
  46. * @should fail validation if name is null or empty or whitespace
  47. * @should fail validation if description is null or empty or whitespace
  48. */
  49. public void validate(Object obj, Errors errors) {
  50. RelationshipType relationshipType = (RelationshipType) obj;
  51. if (relationshipType == null) {
  52. errors.rejectValue("relationshipType", "error.general");
  53.  
  54. }
  55. else {
  56.  
  57. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "aIsToB", "Enter A is to B to continue");
  58. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "bIsToA", "Enter B is to A to continue");
  59. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "Enter Description to continue");
  60.  
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement