You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dg...@apache.org on 2003/05/02 07:36:35 UTC

cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResults.java

dgraham     2003/05/01 22:36:35

  Modified:    validator/src/share/org/apache/commons/validator
                        ValidatorResults.java
  Log:
  Formatting and minor changes.
  
  Revision  Changes    Path
  1.4       +165 -153  jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResults.java
  
  Index: ValidatorResults.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResults.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ValidatorResults.java	19 Sep 2002 17:11:46 -0000	1.3
  +++ ValidatorResults.java	2 May 2003 05:36:35 -0000	1.4
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,7 +59,6 @@
    *
    */
   
  -
   package org.apache.commons.validator;
   
   import java.io.Serializable;
  @@ -68,164 +67,177 @@
   import java.util.Iterator;
   import java.util.Map;
   
  -
   /**
    * <p>This contains the results of a set of 
    * validation rules processed on JavaBean.</p>
    *
    * @author David Winterfeldt
    * @author James Turner
  + * @author David Graham
    * @version $Revision$ $Date$
   */
   public class ValidatorResults implements Serializable {
   
  -   /**
  -    * Map of validation results .
  -   */
  -   protected Map hResults = new HashMap();
  -
  -    /** 
  -     * Merge another ValidatorResults into mine
  +	/**
  +	 * Map of validation results.
  +	 */
  +	protected Map hResults = new HashMap();
  +
  +	/** 
  +	 * Merge another ValidatorResults into mine.
  +	 */
  +	public void merge(ValidatorResults results) {
  +		this.hResults.putAll(results.hResults);
  +	}
  +
  +	/**
  +	 * Add a the result of a validator action.
  +	 */
  +	public void add(Field field, String validatorName, boolean result) {
  +		add(field, validatorName, result, null);
  +	}
  +
  +	/**
  +	 * Add a the result of a validator action.
  +	 */
  +	public void add(
  +		Field field,
  +		String validatorName,
  +		boolean result,
  +		Object value) {
  +            
  +		ValidatorResult validatorResult = null;
  +
  +		if (hResults.containsKey(field.getKey())) {
  +			validatorResult = (ValidatorResult) hResults.get(field.getKey());
  +		} else {
  +			validatorResult = new ValidatorResult(field);
  +		}
  +
  +		validatorResult.add(validatorName, result, value);
  +
  +		hResults.put(field.getKey(), validatorResult);
  +	}
  +
  +	/**
  +	 * Clear all results recorded by this object.
  +	 */
  +	public void clear() {
  +		hResults.clear();
  +	}
  +
  +	/**
  +	 * Return <code>true</code> if there are no messages recorded
  +	 * in this collection, or <code>false</code> otherwise.
  +     * @deprecated Use isEmpty() instead.
  +	 */
  +	public boolean empty() {
  +		return this.isEmpty();
  +	}
  +    
  +    /**
  +     * Return <code>true</code> if there are no messages recorded
  +     * in this collection, or <code>false</code> otherwise.
        */
  -
  -    public void merge(ValidatorResults res) {
  -	this.hResults.putAll(res.hResults);
  +    public boolean isEmpty() {
  +        return this.hResults.isEmpty();
       }
  -	
   
  -   /**
  -    * Add a the result of a validator action.
  -   */
  -   public void add(Field field, String validatorName, boolean bResult) {
  -      add(field, validatorName, bResult, null);
  -   }
  -
  -   /**
  -    * Add a the result of a validator action.
  -   */
  -   public void add(Field field, String validatorName, boolean bResult, Object value) {
  -      ValidatorResult result = null;
  -      
  -      if (hResults.containsKey(field.getKey())) {
  -         result = (ValidatorResult)hResults.get(field.getKey());
  -      } else {
  -         result = new ValidatorResult(field);
  -      }
  -      
  -      result.add(validatorName, bResult, value);
  -      
  -      hResults.put(field.getKey(), result);
  -   }
  -
  -   /**
  -    * Clear all results recorded by this object.
  -    */
  -   public void clear() {
  -       hResults.clear();
  -   }
  -
  -
  -   /**
  -    * Return <code>true</code> if there are no messages recorded
  -    * in this collection, or <code>false</code> otherwise.
  -    */
  -   public boolean empty() {
  -       return (hResults.size() == 0);
  -   }
  -
  -   /**
  -    * Gets the <code>ValidatorResult</code> associated 
  -    * with the key passed in.  The key the <code>ValidatorResult</code> 
  -    * is stored under is the <code>Field</code>'s getKey method.
  -    *
  -    * @param	key		The key generated from <code>Field</code>.
  -   */
  -   public ValidatorResult getValidatorResult(String key) {
  -      return ((hResults.containsKey(key)) ? ((ValidatorResult)hResults.get(key)) : null);
  -   }
  -   
  -   /**
  -    * Return the set of all recorded messages, without distinction
  -    * by which property the messages are associated with.  If there are
  -    * no messages recorded, an empty enumeration is returned.
  -   */
  -   public Iterator get() {
  -      if (hResults.size() == 0) {
  -         return (Collections.EMPTY_LIST.iterator());
  -      }
  -      
  -      return hResults.keySet().iterator();
  -      //
  -      //ArrayList results = new ArrayList();
  -      //
  -      //for (Iterator i =  actionItems.iterator(); i.hasNext(); ) {
  -      //   ActionMessageItem ami = (ActionMessageItem)i.next();
  -      //
  -      //   for (Iterator messages =  ami.getList().iterator(); messages.hasNext(); )
  -      //      results.add(messages.next());
  -      //}
  -      //
  -      //return (results.iterator());
  -
  -   }
  -
  -
  -   /**
  -    * Return the set of messages related to a specific property.
  -    * If there are no such messages, an empty enumeration is returned.
  -    *
  -    * @param property Property name (or ActionMessages.GLOBAL_MESSAGE)
  -    */
  -   //public Iterator get(String property) {
  -
  -       //ActionMessageItem ami = (ActionMessageItem) messages.get(property);
  -       //
  -       //if (ami == null)
  -       //   return (Collections.EMPTY_LIST.iterator());
  -       //else
  -       //   return (ami.getList().iterator());
  -
  -   //}
  -
  -
  -   /**
  -    * Return the set of property names for which at least one message has
  -    * been recorded.  If there are no messages, an empty Iterator is returned.
  -    * If you have recorded global messages, the String value of
  -    * <code>ActionMessages.GLOBAL_MESSAGE</code> will be one of the returned
  -    * property names.
  -    */
  -   public Iterator properties() {
  -      return (hResults.keySet().iterator());
  -   }
  -   
  -   /**
  -    * Get a <code>Map</code> of any <code>Object</code>s 
  -    * returned from validation routines.
  -   */
  -   public Map getResultValueMap() {
  -      Map results = new HashMap();
  -      
  -      for (Iterator i = hResults.keySet().iterator(); i.hasNext(); ) {
  -         String propertyKey = (String)i.next();
  -         ValidatorResult vr = (ValidatorResult)hResults.get(propertyKey);
  -         
  -         Map hActions = vr.getActionMap();
  -         for (Iterator x = hActions.keySet().iterator(); x.hasNext(); ) {
  -            String actionKey = (String)x.next();   
  -            ValidatorResult.ResultStatus rs = (ValidatorResult.ResultStatus)hActions.get(actionKey);
  -
  -            if (rs != null) {
  -               Object result = rs.getResult();
  -
  -               if (result != null && !(result instanceof Boolean)) {
  -                  results.put(propertyKey, result);
  -               }
  -            }
  -         }   
  -      }
  -      
  -      return results;
  -   }
  -   
  +	/**
  +	 * Gets the <code>ValidatorResult</code> associated 
  +	 * with the key passed in.  The key the <code>ValidatorResult</code> 
  +	 * is stored under is the <code>Field</code>'s getKey method.
  +	 *
  +	 * @param	key		The key generated from <code>Field</code>.
  +	 */
  +	public ValidatorResult getValidatorResult(String key) {
  +		return (
  +			(hResults.containsKey(key))
  +				? ((ValidatorResult) hResults.get(key))
  +				: null);
  +	}
  +
  +	/**
  +	 * Return the set of all recorded messages, without distinction
  +	 * by which property the messages are associated with.  If there are
  +	 * no messages recorded, an empty enumeration is returned.
  +	 */
  +	public Iterator get() {
  +		if (hResults.isEmpty()) {
  +			return Collections.EMPTY_LIST.iterator();
  +		}
  +
  +		return hResults.keySet().iterator();
  +		//
  +		//ArrayList results = new ArrayList();
  +		//
  +		//for (Iterator i =  actionItems.iterator(); i.hasNext(); ) {
  +		//   ActionMessageItem ami = (ActionMessageItem)i.next();
  +		//
  +		//   for (Iterator messages =  ami.getList().iterator(); messages.hasNext(); )
  +		//      results.add(messages.next());
  +		//}
  +		//
  +		//return (results.iterator());
  +
  +	}
  +
  +	/**
  +	 * Return the set of messages related to a specific property.
  +	 * If there are no such messages, an empty enumeration is returned.
  +	 *
  +	 * @param property Property name (or ActionMessages.GLOBAL_MESSAGE)
  +	 */
  +	//public Iterator get(String property) {
  +
  +	//ActionMessageItem ami = (ActionMessageItem) messages.get(property);
  +	//
  +	//if (ami == null)
  +	//   return (Collections.EMPTY_LIST.iterator());
  +	//else
  +	//   return (ami.getList().iterator());
  +
  +	//}
  +
  +	/**
  +	 * Return the set of property names for which at least one message has
  +	 * been recorded.  If there are no messages, an empty Iterator is returned.
  +	 * If you have recorded global messages, the String value of
  +	 * <code>ActionMessages.GLOBAL_MESSAGE</code> will be one of the returned
  +	 * property names.
  +	 */
  +	public Iterator properties() {
  +		return hResults.keySet().iterator();
  +	}
  +
  +	/**
  +	 * Get a <code>Map</code> of any <code>Object</code>s 
  +	 * returned from validation routines.
  +	 */
  +	public Map getResultValueMap() {
  +		Map results = new HashMap();
  +
  +		for (Iterator i = hResults.keySet().iterator(); i.hasNext();) {
  +			String propertyKey = (String) i.next();
  +			ValidatorResult vr = (ValidatorResult) hResults.get(propertyKey);
  +
  +			Map actions = vr.getActionMap();
  +			for (Iterator x = actions.keySet().iterator(); x.hasNext();) {
  +				String actionKey = (String) x.next();
  +				ValidatorResult.ResultStatus rs =
  +					(ValidatorResult.ResultStatus) actions.get(actionKey);
  +
  +				if (rs != null) {
  +					Object result = rs.getResult();
  +
  +					if (result != null && !(result instanceof Boolean)) {
  +						results.put(propertyKey, result);
  +					}
  +				}
  +			}
  +		}
  +
  +		return results;
  +	}
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org