Advertisement
Guest User

Untitled

a guest
Dec 29th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 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.Validator;
  21.  
  22. /**
  23. * Validates attributes on the {@link RelationshipType} object.
  24. *
  25. * @since 1.10
  26. */
  27. @Handler(supports = { RelationshipType.class }, order = 50)
  28. public class RelationshipTypeValidator implements Validator {
  29.  
  30. /** Log for this class and subclasses */
  31. protected final Log log = LogFactory.getLog(getClass());
  32.  
  33. /**
  34. * Determines if the command object being submitted is a valid type
  35. *
  36. * @see org.springframework.validation.Validator#supports(java.lang.Class)
  37. */
  38. @SuppressWarnings("unchecked")
  39. public boolean supports(Class c) {
  40. return c.equals(RelationshipType.class);
  41. }
  42.  
  43. /**
  44. * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
  45. * @should fail validation if name is null or empty or whitespace
  46. * @should fail validation if description is null or empty or whitespace
  47. */
  48. public void validate(Object obj, Errors errors) {
  49. RelationshipType relationshipType = (RelationshipType) obj;
  50. if (relationshipType == null) {
  51. errors.rejectValue("relationshipType", "error.general");
  52. }
  53.  
  54. if (RelationshipType.aIsToB == null) {
  55. errors.rejectValue("aIsToB", "error.general");
  56. }
  57. if (RelationshipType.bIsToA == null) {
  58. errors.rejectValue("bIsToA", "error.general");
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement