Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ClassValidator.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ClassValidator.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ClassValidator.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,37 +42,19 @@
  *
  * $Id$
  */
-
-
 package org.exolab.castor.xml;
 
 /**
- * The validation interface used for validating class instances
+ * The validation interface used for validating class instances.
  *
  * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
-**/
+ */
 public interface ClassValidator extends TypeValidator {
-    
-        
-    /**
-     * Validates the given Object. If the failFast argument is true
-     * an exception should be thrown when the first invalid field
-     * is encountered, otherwise the the validator should attempt
-     * to discover as many errors as possible before throwing
-     * a ValidationException.
-     *
-     * @param object the Object to validate
-     * @param failFast a boolean indicating whether or not the validator 
-     * class should throw an exception on the first error encountered.
-     * @throws ValidationException when the class is not valid.
-    **/
-    //public void validate(Object object, boolean failFast)
-    //    throws ValidationException;
-        
+
     /**
-     * Validates the given Object. An exception should be thrown 
-     * when the first invalid field is discovered.
+     * Validates the given Object. An exception should be thrown when the first
+     * invalid field is discovered.
      *
      * @param object the Object to validate
      * @param context the ValidationContext
@@ -77,10 +59,7 @@
      * @param object the Object to validate
      * @param context the ValidationContext
      * @throws ValidationException when the class is not valid.
-    **/
-    public void validate(Object object, ValidationContext context)
-        throws ValidationException;
+     */
+    public void validate(Object object, ValidationContext context) throws ValidationException;
 
-    
-    
-} //-- ClassValidator
\ No newline at end of file
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/DebugHandler.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/DebugHandler.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/DebugHandler.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,91 +42,102 @@
  *
  * $Id$
  */
-
 package org.exolab.castor.xml;
 
-//-- xml related imports
-import org.xml.sax.*;
-
+import java.io.PrintWriter;
 import java.io.Writer;
-import java.io.PrintWriter;
+
+import org.xml.sax.AttributeList;
+import org.xml.sax.DocumentHandler;
+import org.xml.sax.Locator;
 
 /**
- * A Simple DocumentHandler that intercepts SAX events and
- * prints them to the console
+ * A Simple SAX1 DocumentHandler that intercepts SAX events and prints them to
+ * the console. This class is not used during normal Castor operation, but
+ * exists so that during debugging one can replace a normal DocumentHandler with
+ * this one (which will proxy to the correct DocumentHandler).
+ * <p>
+ * FIXME:  As Castor moves internally to the SAX2 interface, this class should
+ * also be updated for SAX2.
+ *
  * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
-**/
+ */
 public class DebugHandler implements DocumentHandler {
-    
-    
-    /**
-     * The writer to report events to
-    **/
-    Writer _out = null;
-    
+
+    /** The writer to report events to. */
+    private Writer          _out     = null;
+    /** The DocumentHandler to forward events to. */
+    private DocumentHandler _handler = null;
+
     /**
-     * The DocumentHandler to forward events to
-    **/
-    DocumentHandler _handler = null;
-    
-    boolean newLine = false;
-    
-    /**
-     * Creates a new DebugHandler which forwards events to the
-     * given document handler
+     * Creates a new DebugHandler which forwards events to the given document
+     * handler.
+     *
      * @param handler the DocumentHandler to forward events to
-    **/
-    public DebugHandler(DocumentHandler handler) {
+     */
+    public DebugHandler(final DocumentHandler handler) {
         this(handler, null);
-    } //-- DebugHandler
-    
+    }
+
     /**
-     * Creates a new DebugHandler which forwards events to the
-     * given document handler
+     * Creates a new DebugHandler which forwards events to the given document
+     * handler.
+     *
      * @param handler the DocumentHandler to forward events to
      * @param out the Writer to print debug information to
-    **/
-    public DebugHandler(DocumentHandler handler, Writer out) {
-        if (out == null) this._out = new PrintWriter(System.out);
+     */
+    public DebugHandler(final DocumentHandler handler, final Writer out) {
+        if (out == null) {
+            this._out = new PrintWriter(System.out);
+        }
         this._handler = handler;
-    } //-- DebugHandler
-    
-    
-    //- DocumentHandler methods -/
-    
-    public void characters(char[] ch, int start, int length) 
-        throws org.xml.sax.SAXException
-    {
+    }
+
+    /**
+     * {@inheritDoc}
+     * Proxies the {@link org.sax.xml.DocumentHandler#characters(char[], int, int)}
+     * request to the proxy that is provided, printing debugging information
+     * before doing the proxy.
+     */
+    public void characters(final char[] ch, final int start, final int length) throws org.xml.sax.SAXException {
         try {
             _out.write(ch, start, length);
             _out.flush();
+        } catch (java.io.IOException ioe) {
+            ioe.printStackTrace();
         }
-        catch(java.io.IOException ioe) {
-            ioe.printStackTrace();
+
+        if (_handler != null) {
+            _handler.characters(ch, start, length);
         }
-        
-        if (_handler != null) _handler.characters(ch, start, length);
-        
-    } //-- characters
-    
-    public void endDocument()
-        throws org.xml.sax.SAXException
-    {
+    }
+
+    /**
+     * {@inheritDoc} Proxies the
+     * {@link org.sax.xml.DocumentHandler#endDocument()} request to the proxy
+     * that is provided, printing debugging information before doing the proxy.
+     */
+    public void endDocument() throws org.xml.sax.SAXException {
         try {
             _out.write("#endDocument\n");
             _out.flush();
+        } catch (java.io.IOException ioe) {
+            ioe.printStackTrace();
         }
-        catch(java.io.IOException ioe) {
-            ioe.printStackTrace();
+
+        if (_handler != null) {
+            _handler.endDocument();
         }
-        
-        if (_handler != null) _handler.endDocument();
-    } //-- endDocument
-    
-    public void endElement(String name) 
-        throws org.xml.sax.SAXException
-    {
+    }
+
+    /**
+     * {@inheritDoc} Proxies the
+     * {@link org.sax.xml.DocumentHandler#endElement(String)} request to the
+     * proxy that is provided, printing debugging information before doing the
+     * proxy.
+     */
+    public void endElement(final String name) throws org.xml.sax.SAXException {
         try {
             _out.write("</");
             _out.write(name);
@@ -132,25 +143,34 @@
             _out.write(name);
             _out.write(">\n");
             _out.flush();
-        }
-        catch(java.io.IOException ioe) {
+        } catch (java.io.IOException ioe) {
             ioe.printStackTrace();
         }
-        
-        if (_handler != null) _handler.endElement(name);
-    } //-- endElement
 
+        if (_handler != null) {
+            _handler.endElement(name);
+        }
+    }
 
-    public void ignorableWhitespace(char[] ch, int start, int length) 
-        throws org.xml.sax.SAXException
-    {
-        if (_handler != null) _handler.ignorableWhitespace(ch, start, length);
-        
-    } //-- ignorableWhitespace
+    /**
+     * {@inheritDoc} Proxies the
+     * {@link org.sax.xml.DocumentHandler#ignorableWhitespace(char[], int, int)}
+     * request to the proxy that is provided, printing debugging information
+     * before doing the proxy.
+     */
+    public void ignorableWhitespace(final char[] ch, final int start, final int length) throws org.xml.sax.SAXException {
+        if (_handler != null) {
+            _handler.ignorableWhitespace(ch, start, length);
+        }
+    }
 
-    public void processingInstruction(String target, String data) 
-        throws org.xml.sax.SAXException
-    {
+    /**
+     * {@inheritDoc} Proxies the
+     * {@link org.sax.xml.DocumentHandler#processingInstruction(String, String)}
+     * request to the proxy that is provided, printing debugging information
+     * before doing the proxy.
+     */
+    public void processingInstruction(final String target, final String data) throws org.xml.sax.SAXException {
         try {
             _out.write("--#processingInstruction\n");
             _out.write("target: ");
@@ -159,41 +179,56 @@
             _out.write(data);
             _out.write('\n');
             _out.flush();
+        } catch (java.io.IOException ioe) {
+            ioe.printStackTrace();
         }
-        catch(java.io.IOException ioe) {
-            ioe.printStackTrace();
+
+        if (_handler != null) {
+            _handler.processingInstruction(target, data);
+        }
+    }
+
+    /**
+     * {@inheritDoc} Proxies the
+     * {@link org.sax.xml.DocumentHandler#setDocumentLocator(Locator)} request
+     * to the proxy that is provided, printing debugging information before
+     * doing the proxy.
+     */
+    public void setDocumentLocator(final Locator locator) {
+        if (_handler != null) {
+            _handler.setDocumentLocator(locator);
         }
-        
-        if (_handler != null) _handler.processingInstruction(target, data);
+    }
 
-    } //-- processingInstruction
-    
-    public void setDocumentLocator(Locator locator) {
-        if (_handler != null) _handler.setDocumentLocator(locator);
-    } //-- setDocumentLocator
-    
-    public void startDocument()
-        throws org.xml.sax.SAXException
-    {
+    /**
+     * {@inheritDoc} Proxies the
+     * {@link org.sax.xml.DocumentHandler#startDocument()} request to the proxy
+     * that is provided, printing debugging information before doing the proxy.
+     */
+    public void startDocument() throws org.xml.sax.SAXException {
         try {
             _out.write("#startDocument\n");
             _out.flush();
+        } catch (java.io.IOException ioe) {
+            ioe.printStackTrace();
         }
-        catch(java.io.IOException ioe) {
-            ioe.printStackTrace();
+
+        if (_handler != null) {
+            _handler.startDocument();
         }
-        
-        if (_handler != null) _handler.startDocument();
-    } //-- startDocument
+    }
 
-    
-    public void startElement(String name, AttributeList atts) 
-        throws org.xml.sax.SAXException
-    {
+    /**
+     * {@inheritDoc} Proxies the
+     * {@link org.sax.xml.DocumentHandler#startElement(String, AttributeList)}
+     * request to the proxy that is provided, printing debugging information
+     * before doing the proxy.
+     */
+    public void startElement(final String name, final AttributeList atts) throws org.xml.sax.SAXException {
         try {
             _out.write('<');
             _out.write(name);
-            if ((atts != null) && (atts.getLength() > 0)) {
+            if (atts != null && atts.getLength() > 0) {
                 for (int i = 0; i < atts.getLength(); i++) {
                     _out.write(' ');
                     _out.write(atts.getName(i));
@@ -204,13 +239,13 @@
             }
             _out.write(">\n");
             _out.flush();
+        } catch (java.io.IOException ioe) {
+            ioe.printStackTrace();
         }
-        catch(java.io.IOException ioe) {
-            ioe.printStackTrace();
+
+        if (_handler != null) {
+            _handler.startElement(name, atts);
         }
-        
-        if (_handler != null) _handler.startElement(name, atts);
-    } //-- startElement
-    
-} //-- Marshaller
+    }
 
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/FieldValidator.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/FieldValidator.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/FieldValidator.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,8 +42,6 @@
  *
  * $Id$
  */
-
-
 package org.exolab.castor.xml;
 
 import java.lang.reflect.Array;
@@ -54,8 +52,8 @@
 import org.exolab.castor.mapping.FieldHandler;
 
 /**
- * Handles field validation
- * 
+ * Handles field validation.
+ *
  * @author <a href="mailto:kvisco-at-intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2004-10-08 22:58:55 -0600 (Fri, 08 Oct 2004) $
  */
@@ -60,274 +58,265 @@
  * @version $Revision$ $Date: 2004-10-08 22:58:55 -0600 (Fri, 08 Oct 2004) $
  */
 public class FieldValidator extends Validator {
-    
-    
-    private static final String ERROR_NAME = "-error-if-this-is-used-";
-    
-    private int minOccurs =  0;  //-- default minimum occurance
-    private int maxOccurs = -1;  //-- default maximum occurance [none]
 
-    private XMLFieldDescriptor _descriptor = null;
-    
-    /**
-     * The actual type validator which is used to validate
-     * single instances of the field.
-    **/
-    private TypeValidator      _validator = null;
-    
+    /** Default value for descriptor names. If a Descriptor XML name value is
+     * set to this, then no name has been assigned yet. */
+    private static final String ERROR_NAME   = "-error-if-this-is-used-";
+    /** Default minimum occurrance. */
+    private static final int    DEFAULT_MIN  = 0;
+    /** Default maximum occurrance. */
+    private static final int    DEFAULT_MAX  = -1;
+
+    /** Minimum number of occurrences for this element to pass validation. */
+    private int                 _minOccurs   = DEFAULT_MIN;
+    /** Maximum number of occurrences for this element to pass validation. */
+    private int                 _maxOccurs   = DEFAULT_MAX;
+    /** The Field Descriptor describing the field we validate. */
+    private XMLFieldDescriptor  _descriptor  = null;
+    /** The actual type validator which is used to validate single instances of
+     * the field. */
+    private TypeValidator       _validator   = null;
+
     /**
-     * Creates a default FieldValidator
-     *
-    **/
-    public FieldValidator() {    
+     * Creates a default FieldValidator.
+     */
+    public FieldValidator() {
         super();
-    } //-- FieldValidator 
+    }
 
     /**
-     * Creates a new FieldValidator using the given TypeValidator
+     * Creates a new FieldValidator using the given TypeValidator.
      * @param validator the TypeValidator to delegate validation to
-    **/
-    public FieldValidator(TypeValidator validator) {
+     */
+    public FieldValidator(final TypeValidator validator) {
         super();
         this._validator = validator;
-    } //-- FieldValidator
-    
+    }
+
     /**
      * Returns the mimimum number of occurances for a given object.
      *
-     * @return  The mimimum number of occurances for a given object. A zero value denotes
-     *          no lower bound (ie. the object is optional).
+     * @return The mimimum number of occurances for a given object. A zero value
+     *         denotes no lower bound (ie. the object is optional).
      */
     public int getMinOccurs() {
-        return minOccurs;
-    } //-- getMinOccurs
-    
+        return _minOccurs;
+    }
+
     /**
      * Returns the maximum number of occurances for a given object.
-     * 
-     * @return The maximum number of occurances for a given object. A negative value
-     *         denotes no upper bound.
+     *
+     * @return The maximum number of occurances for a given object. A negative
+     *         value denotes no upper bound.
      */
     public int getMaxOccurs() {
-        return maxOccurs;
-    } //-- getMaxOccurs
-    
+        return _maxOccurs;
+    }
+
     /**
-     * Returns true if a TypeValidator has been set
-     *
-     * @return true if a TypeValidator has been set
-    **/
+     * Returns the TypeValidator.
+     * @return the TypeValidator.
+     */
     public TypeValidator getTypeValidator() {
         return _validator;
-    } //-- getTypeValidator
-    
+    }
+
     /**
-     * Returns true if a TypeValidator has been set
-     *
-     * @return true if a TypeValidator has been set
-    **/
+     * Returns true if a TypeValidator has been set.
+     * @return true if a TypeValidator has been set.
+     */
     public boolean hasTypeValidator() {
-        return (_validator != null);
-    } //-- hasTypeValidator
-    
+        return _validator != null;
+    }
+
     /**
-     * Sets the mimimum number of occurances for a given object
+     * Sets the mimimum number of occurances for a given object. A zero, or
+     * negative value denotes no lower bound (i.e., the object is optional).
      *
-     * @param minOccurs the minimum number of times an object must occur
-     * in order to be valid.
-     * A zero, or negative value denotes no lower bound 
-     * (ie. the object is optional)
-    **/
-    public void setMinOccurs(int minOccurs) {
-        this.minOccurs = (minOccurs < 0) ? 0 : minOccurs;
-    } //-- setMinOccurs
-    
+     * @param minOccurs the minimum number of times an object must occur in
+     *        order to be valid.
+     */
+    public void setMinOccurs(final int minOccurs) {
+        this._minOccurs = (minOccurs < 0) ? 0 : minOccurs;
+    }
+
     /**
-     * Sets the maximum number of occurances for a given object
-     * 
-     * @param maxOccurs the maximum number of times an object
-     * may occur. A negative value denotes no upper bound.
-     * 
-    **/
-    public void setMaxOccurs(int maxOccurs) {
-        this.maxOccurs = maxOccurs;
-    } //-- setMaxOccurs
+     * Sets the maximum number of occurances for a given object. A negative
+     * value denotes no upper bound.
+     *
+     * @param maxOccurs the maximum number of times an object may occur.
+     */
+    public void setMaxOccurs(final int maxOccurs) {
+        this._maxOccurs = maxOccurs;
+    }
 
     /**
-     * Sets the field descriptor to use for obtaining information
-     * about the field to validate, such as the field name, the field
-     * handler, etc.
+     * Sets the field descriptor to use for obtaining information about the
+     * field to validate, such as the field name, the field handler, etc.
+     *
      * @param descriptor the field descriptor for the field to validate
-    **/
-    public void setDescriptor(XMLFieldDescriptor descriptor) {
+     */
+    public void setDescriptor(final XMLFieldDescriptor descriptor) {
         this._descriptor = descriptor;
-    } //-- setDescriptor
-    
-    public void setValidator(TypeValidator validator) {
+    }
+
+    public void setValidator(final TypeValidator validator) {
         this._validator = validator;
-    } //-- setValidator
-    
+    }
+
     /**
-     * Validates the given Object
+     * Validates the given Object.
      *
      * @param object the Object that contains the field to validate
-     * @param context the ValidationContext 
+     * @param context the ValidationContext
+     * @throws ValidationException if validation fails
      */
-    public void validate(Object object, ValidationContext context)
-        throws ValidationException
-    {
-        if (_descriptor == null) return;
-        if (object == null) return; 
-        
-        if (context.isValidated(object)) {
-        	return;
+    public void validate(final Object object, final ValidationContext context)
+                                                      throws ValidationException {
+        if (_descriptor == null || object == null || context.isValidated(object)) {
+            return;
+        }
+
+        // Don't validate "transient" fields.
+        if (_descriptor.isTransient()) {
+            return;
         }
-        
-        //-- don't validate "transient" fields...
-        if (_descriptor.isTransient()) return;
-           
+
         FieldHandler handler = _descriptor.getHandler();
-        
-        if (handler == null) return;
+        if (handler == null) {
+            return;
+        }
 
-        //-- get the value of the field
+        // Get the value of the field
         Object value = handler.getValue(object);
-        
         if (value == null) {
-            if (!_descriptor.isRequired() || _descriptor.isNillable()) return;            
-            String err = "The field '" + _descriptor.getFieldName() + "' ";
+            if (!_descriptor.isRequired() || _descriptor.isNillable()) {
+                return;
+            }
+            StringBuffer buff = new StringBuffer();
+            buff.append("The field '" + _descriptor.getFieldName() + "' ");
             if (!ERROR_NAME.equals(_descriptor.getXMLName())) {
-                err += "(whose xml name is '" + _descriptor.getXMLName() + "') ";
+                buff.append("(whose xml name is '" + _descriptor.getXMLName() + "') ");
             }
-            err += "is a required field of class '" + object.getClass().getName();
-            throw new ValidationException(err);
+            buff.append("is a required field of class '" + object.getClass().getName());
+            throw new ValidationException(buff.toString());
         }
-        
+
         if (_descriptor.isReference()) {
-        	if (_validator != null) {
-        		_validator.validate(value, context);
-        	}
-        	return;
+            if (_validator != null) {
+                _validator.validate(value, context);
+            }
+            return;
         }
-        
-        //-- prevent endless loop!
-        //-- have we seen this object yet?
+
+        // Prevent endless loop!  Have we seen this object yet?
         if (context != null) {
-            if (context.isValidated(object))
+            if (context.isValidated(object)) {
                 return;
+            }
             //-- mark object as processed
             context.addValidated(object);
         }
-        
+
+        // We are now ready to do actual validation
 
         Class type = value.getClass();
         int size = 1;
-            
+
         try {
-            
-            boolean byteArray = false;
             if (type.isArray()) {
-                byteArray = (type.getComponentType() == Byte.TYPE);
-                if (!byteArray) {
+                // We don't validate Byte array types
+                if (type.getComponentType() != Byte.TYPE) {
                     size = Array.getLength(value);
                     if (_validator != null) {
-                        for (int i = 0; i < size; i++)
+                        for (int i = 0; i < size; i++) {
                             _validator.validate(Array.get(value, i), context);
-                    }
-                    else {
-                        for (int i = 0; i < size; i++)
+                        }
+                    } else {
+                        for (int i = 0; i < size; i++) {
                             super.validate(Array.get(value, i), context);
+                        }
                     }
                 }
-            }
-            //-- <NOTE>
-            //-- The following code should be changed
-            //-- to use CollectionHandler
-            //-- </NOTE>
-            else if (value instanceof Enumeration) {
-                Enumeration enumeration = (Enumeration)value;
+            } else if (value instanceof Enumeration) {
+                // <NOTE>
+                // The following code should be changed to use CollectionHandler
+                // </NOTE>
                 size = 0;
-                while (enumeration.hasMoreElements()) {
+                for (Enumeration enumeration = (Enumeration)value; enumeration.hasMoreElements(); ) {
                     ++size;
-                    Object obj = enumeration.nextElement();
-                    if (_validator != null) 
-                        _validator.validate(obj, context);
-                    else
-                        super.validate(obj, context);
+                    validateInstance(context, enumeration.nextElement());
                 }
-            }
-            else if (value instanceof Vector) {
+            } else if (value instanceof Vector) {
                 Vector vector = (Vector)value;
                 size = vector.size();
                 for (int i = 0; i < size; i++) {
-                    if (_validator != null)
-                        _validator.validate(vector.elementAt(i), context);
-                    else
-                        super.validate(vector.elementAt(i), context);
+                    validateInstance(context, vector.elementAt(i));
                 }
-            }
-            else if (value instanceof List) {
+            } else if (value instanceof List) {
                 List list = (List)value;
                 size = list.size();
                 for (int i = 0; i < size; i++) {
-                    if (_validator != null)
-                        _validator.validate(list.get(i), context);
-                    else
-                        super.validate(list.get(i), context);
+                    validateInstance(context, list.get(i));
                 }
-            }
-            else {
-                if (_validator != null)
-                    _validator.validate(value, context);
-                else
-                    super.validate(value, context);
+            } else {
+                validateInstance(context, value);
             }
-        }
-        catch(ValidationException vx) {
+        } catch (ValidationException vx) {
             //-- add additional validation information
-            String err = "The following exception occured while validating field: " + 
-                _descriptor.getFieldName() + " of class: " + object.getClass().getName();
+            String err = "The following exception occured while validating field: "
+                         + _descriptor.getFieldName() + " of class: "
+                         + object.getClass().getName();
             throw new ValidationException(err, vx);
         }
-         
-            
-        //-- Check size of collection
-                
-        //-- check minimum
-        if (size < minOccurs) {
-            //-- If any items exist (size != 0) or the descriptor
-            //-- is marked as required then we need to report the
-            //-- error. Otherwise size == 0 and field is not
-            //-- required, so no error.
-            if ((size != 0) || (_descriptor.isRequired())) {
-                String err = "A minimum of " + minOccurs + " ";
-                err += _descriptor.getFieldName() + " object(s) ";
-                if (!ERROR_NAME.equals(_descriptor.getXMLName())) {
-                    err += "(whose xml name is '" + _descriptor.getXMLName() + "') ";
-                }
-                err += "are required for class: " + object.getClass().getName();
-                        
-                throw new ValidationException(err);
+
+        // Check sizes of collection
+
+        // Check minimum.
+        // If any items exist (size != 0) or the descriptor is marked as
+        // required then we need to report the error. Otherwise size == 0 and
+        // field is not required, so no error.
+        if (size < _minOccurs && (size != 0 || _descriptor.isRequired())) {
+            StringBuffer buff = new StringBuffer();
+            buff.append("A minimum of " + _minOccurs + " " + _descriptor.getFieldName()
+                        + " object(s) ");
+            if (!ERROR_NAME.equals(_descriptor.getXMLName())) {
+                buff.append("(whose xml name is '" + _descriptor.getXMLName() + "') ");
             }
+            buff.append("are required for class: " + object.getClass().getName());
+            throw new ValidationException(buff.toString());
         }
-                
-        //-- check maximum
-        if ((maxOccurs >= 0) && (size > maxOccurs)) {
-            String err = "A maximum of " + maxOccurs + " ";
-            err += _descriptor.getFieldName() + " object(s) ";
+
+        // Check maximum.
+        if (_maxOccurs >= 0 && size > _maxOccurs) {
+            StringBuffer buff = new StringBuffer();
+            buff.append("A maximum of " + _maxOccurs + " " + _descriptor.getFieldName()
+                         + " object(s) ");
             if (!ERROR_NAME.equals(_descriptor.getXMLName())) {
-                err += "(whose xml name is '" + _descriptor.getXMLName() + "') ";
+                buff.append("(whose xml name is '" + _descriptor.getXMLName() + "') ");
             }
-            err += "are required for class: " + object.getClass().getName() + ".";
-            throw new ValidationException(err);
+            buff.append("are allowed for class: " + object.getClass().getName() + ".");
+            throw new ValidationException(buff.toString());
         }
-        
+
         if (context != null) {
-        	context.removeValidated(object);
+            context.removeValidated(object);
         }
-        
-    } //-- validate
+    }
 
-    
-    
-} //-- FieldValidator
\ No newline at end of file
+    /**
+     * Validate an individual instance.
+     * @param context the validation context.
+     * @param value The instance to validate.
+     * @throws ValidationException if validation fails
+     */
+    private void validateInstance(final ValidationContext context, final Object value)
+                                                            throws ValidationException {
+        if (_validator != null) {
+            _validator.validate(value, context);
+        } else {
+            super.validate(value, context);
+        }
+    }
+
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/FileLocation.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/FileLocation.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/FileLocation.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,12 +42,10 @@
  *
  * $Id$
  */
-
 package org.exolab.castor.xml;
 
 /**
- * A simple FileLocation class used for finer grained detail of 
- * exceptions
+ * A simple FileLocation class used for finer grained detail of exceptions.
  *
  * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $
@@ -55,14 +53,16 @@
 public class FileLocation implements Location, java.io.Serializable {
     /** SerialVersionUID */
     private static final long serialVersionUID = 7112551880124131785L;
+    /** When a field is not available, this String is used to say so. */
+    private final static String NOT_AVAILABLE = "[not available]";
 
-    private final static String NOT_AVAILABLE = "[not available]";
-    
+    /** Filename for the file represented by this FileLocation. */
     private String _filename = null;
-    
+    /** Line number in the file for this FileLocation. */
     private int _line = -1;
+    /** Column number in the file for this FileLocation. */
     private int _col  = -1;
-    
+
     /**
      * Creates a new FileLocation
      */
@@ -68,8 +68,8 @@
      */
     public FileLocation() {
         super();
-    } //-- FileLocation()
-    
+    }
+
     /**
      * Creates a new FileLocation
      *
@@ -75,116 +75,113 @@
      *
      * @param filename the name of the file
      */
-    public FileLocation(String filename) {
+    public FileLocation(final String filename) {
         super();
         this._filename = filename;
-    } //-- FileLocation(String)
+    }
 
     /**
-     * Creates a new FileLocation
+     * Creates a new FileLocation.
      *
-     * @param line the line number 
+     * @param line the line number
      * @param column the column number within the specified line
      */
-    public FileLocation(int line, int column) {
+    public FileLocation(final int line, final int column) {
         super();
         this._line = line;
         this._col  = column;
-    } //-- FileLocation(int, int)
-    
+    }
+
     /**
-     * Creates a new FileLocation
+     * Creates a new FileLocation.
      *
      * @param filename the name of the file
-     * @param line the line number 
+     * @param line the line number
      * @param column the column number within the specified line
      */
-    public FileLocation(String filename, int line, int column) {
+    public FileLocation(final String filename, final int line, final int column) {
         super();
         this._filename = filename;
-        this._line = line;
-        this._col  = column;
-    } //-- FileLocation(String, int, int)
-    
+        this._line     = line;
+        this._col      = column;
+    }
+
     /**
-     * Returns the column number for this Location
-     *
-     * @return the column number for this Location
+     * Returns the column number for this FileLocation.
+     * @return the column number for this FileLocation.
      */
     public int getColumnNumber() {
         return _col;
-    } //-- getColumnNumber
-    
+    }
+
     /**
-     * Returns the name of the file to which this FileLocation refers
-     *
-     * @return the name of the file to which this FileLocation refers
+     * Returns the name of the file to which this FileLocation refers.
+     * @return the name of the file to which this FileLocation refers.
      */
     public String getFilename() {
         return _filename;
-    } //-- getFilename
-    
+    }
+
     /**
-     * Returns the line number for this location
-     *
-     * @return the line number for the FileLocation
+     * Returns the line number for this FileLocation.
+     * @return the line number for this FileLocation.
      */
     public int getLineNumber() {
         return _line;
-    } //-- getLineNumber
-    
+    }
+
     /**
-     * Sets the column number for this Location
-     *
-     * @param column the column number for this Location
+     * Sets the column number for this FileLocation.
+     * @param column the column number for this FileLocation
      */
-    public void setColumnNumber(int column) {
+    public void setColumnNumber(final int column) {
         this._col = column;
-    } //-- setColumnNumber
-    
+    }
+
     /**
-     * Sets the name of the file to which this FileLocation refers
-     *
-     * @param filename the name of the file to which this FileLocation 
-     * refers
+     * Sets the name of the file to which this FileLocation refers.
+     * @param filename the name of the file to which this FileLocation refers
      */
-    public void setFilename(String filename) {
+    public void setFilename(final String filename) {
         this._filename = filename;
-    } //-- setFilename
-    
+    }
+
     /**
-     * Sets the line number for this Location
-     *
-     * @param line the line number for this Location
+     * Sets the line number for this FileLocation.
+     * @param line the line number for this FileLocation
      */
-    public void setLineNumber(int line) {
+    public void setLineNumber(final int line) {
         this._line = line;
     } //-- setLineNumber
-    
+
     /**
-     * Returns the String representation of this Location
-     *
-     * @return the String representation of this Location
+     * Returns the String representation of this FileLocation.
+     * @return the String representation of this FileLocation.
      */
     public String toString() {
-        StringBuffer sb = new StringBuffer("file: ");
-        
-        if (_filename != null)
+        final StringBuffer sb = new StringBuffer("File: ");
+
+        if (_filename != null) {
             sb.append(_filename);
-        else
+        } else {
             sb.append(NOT_AVAILABLE);
-            
-        //-- line number
+        }
+
         sb.append("; line: ");
-        if (_line >= 0) sb.append(_line);
-        else sb.append(NOT_AVAILABLE);
-        
-        //-- column
+        if (_line >= 0) {
+            sb.append(_line);
+        } else {
+            sb.append(NOT_AVAILABLE);
+        }
+
         sb.append("; column: ");
-        if (_col >= 0) sb.append(_col);
-        else sb.append(NOT_AVAILABLE);
-        
+        if (_col >= 0) {
+            sb.append(_col);
+        } else {
+            sb.append(NOT_AVAILABLE);
+        }
+
         return sb.toString();
-    } //-- toString
-    
-} //-- Location
+    }
+
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/Location.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/Location.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/Location.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,20 +42,19 @@
  *
  * $Id$
  */
-
 package org.exolab.castor.xml;
 
 /**
- * A simple Location class used for fine grained detail of exceptions
+ * A simple Location class used for fine grained detail of exceptions.
  * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
-**/
+ */
 public interface Location {
-    
+
     /**
-     * Returns the String representation of this Location
-     * @return the String representation of this Location
-    **/
-    public String toString();   
-    
-} //-- Location
+     * Returns the String representation of this Location.
+     * @return the String representation of this Location.
+     */
+    public String toString();
+
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/NodeType.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/NodeType.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/NodeType.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,15 +42,12 @@
  *
  * $Id$
  */
-
-
 package org.exolab.castor.xml;
 
-
 /**
- * The possible node types for an XML field. A field can be represented
- * as an attribute, an element or text content. The default is
- * attribute.
+ * The possible node types for an XML field. A field can be represented as an
+ * attribute, an element or text content. The default is attribute.  This class
+ * is essentially a typesafe enumeration and the instances are immutable.
  *
  * @author <a href="arkin@intalio.com">Assaf Arkin</a>
  * @author <a href="kvisco@intalio.com">Keith Visco</a>
@@ -56,65 +53,48 @@
  * @author <a href="kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
  */
-public class NodeType
-{
+public final class NodeType {
 
+    /** The attribute type. */
+    public static final short    ATTRIBUTE = 0;
+    /** The element type. */
+    public static final short    ELEMENT   = 1;
+    /** The namespace node type. */
+    public static final short    NAMESPACE = 2;
+    /** The text type. */
+    public static final short    TEXT      = 3;
+    /** Attribute node type (<tt>attribute</tt>). This field will appear in
+     * the XML document as an element's attribute. */
+    public static final NodeType Attribute = new NodeType(NodeType.ATTRIBUTE, "attribute");
+    /** Element node type (<tt>element</tt>). This field will appear in the
+     * XML document as a contained element. */
+    public static final NodeType Element   = new NodeType(NodeType.ELEMENT, "element");
+    /** Namespace node type (<tt>namespace</tt>). This field will appear in
+     * the XML document as a namespace declaration. */
+    public static final NodeType Namespace = new NodeType(NodeType.NAMESPACE, "namespace");
+    /** Content node type (<tt>text</tt>). This field will appear in the XML
+     * document as the element text content. */
+    public static final NodeType Text      = new NodeType(NodeType.TEXT, "text");
 
-    /**
-     * The attribute type
-    **/
-    public static final short ATTRIBUTE  = 0;
-    
-    /**
-     * The element type
-    **/
-    public static final short ELEMENT    = 1;
-    
-    /**
-     * The namespace node type
-    **/
-    public static final short NAMESPACE  = 2;
-    
-    /**
-     * The text type
-    **/
-    public static final short TEXT       = 3;
-    
-    /**
-     * Attribute node type (<tt>attribute</tt>). This field will appear
-     * in the XML document as an element's attribute.
-     */
-    public static final NodeType Attribute 
-        = new NodeType( NodeType.ATTRIBUTE, "attribute" );
-
+    /** The name of this node type as it would appear in a mapping file. */
+    private final String         _name;
+    /** The type of this NodeType. */
+    private final short          _type;
 
     /**
-     * Element node type (<tt>element</tt>). This field will appear
-     * in the XML document as a contained element.
+     * Private constructor ... creates a new NodeType.
+     * @param type Type of node
+     * @param name Name for the node
      */
-    public static final NodeType Element 
-        = new NodeType( NodeType.ELEMENT, "element" );
-
-    /**
-     * Namespace node type (<tt>namespace</tt>). This field will appear
-     * in the XML document as a namespace declaration.
-     */
-    public static final NodeType Namespace
-        = new NodeType( NodeType.NAMESPACE, "namespace" );
-
+    private NodeType(final short type, final String name) {
+        _type = type;
+        _name = name;
+    }
 
     /**
-     * Content node type (<tt>text</tt>). This field will appear in
-     * the XML document as the element text content.
-     */
-    public static final NodeType Text 
-        = new NodeType( NodeType.TEXT, "text" );
-
-
-    /**
-     * Returns the node type from the name. If <tt>nodeType</tt>
-     * is null, return the default node type ({@link #Attribute}).
-     * Otherwise returns the named node type mode.
+     * Returns the node type from the name. If <tt>nodeType</tt> is null,
+     * return the default node type ({@link #Attribute}). Otherwise returns
+     * the named node type mode.
      *
      * @param nodeType The node type name
      * @return The node type
@@ -119,43 +99,30 @@
      * @param nodeType The node type name
      * @return The node type
      */
-    public static NodeType getNodeType( String nodeType )
-    {
-        if ( nodeType == null )
+    public static NodeType getNodeType(final String nodeType) {
+        if (nodeType == null) {
             return Attribute;
-        if ( nodeType.equals( Attribute._name ) )
-            return Attribute;        
-        if ( nodeType.equals( Namespace._name ) )
+        }
+        if (nodeType.equals(Attribute._name)) {
+            return Attribute;
+        }
+        if (nodeType.equals(Namespace._name)) {
             return Namespace;
-        if ( nodeType.equals( Element._name ) )
+        }
+        if (nodeType.equals(Element._name)) {
             return Element;
-        if ( nodeType.equals( Text._name ) )
+        }
+        if (nodeType.equals(Text._name)) {
             return Text;
-        throw new IllegalArgumentException( "Unrecognized node type" );
+        }
+        // We don't expect that this can happen without subclassing.
+        throw new IllegalArgumentException("Unrecognized node type");
     }
 
-
     /**
-     * The name of this node type as it would appear in a
-     * mapping file.
+     * Returns the type of this NodeType.
+     * @return the type of this NodeType.
      */
-    private String _name;
-
-    /**
-     * The type of this NodeType
-    **/
-    private short  _type = ELEMENT;
-    
-    private NodeType( short type, String name )
-    {
-        _name = name;
-        _type = type;
-    }
-
-    /**
-     * Returns the type of this NodeType
-     * @return the type of this NodeType
-    **/
     public short getType() {
         return _type;
     }
@@ -160,10 +127,12 @@
         return _type;
     }
 
-    public String toString()
-    {
+    /**
+     * Returns the name of this NodeType.
+     * @return the name of this NodeType.
+     */
+    public String toString() {
         return _name;
     }
 
-
-} //-- NodeType
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ProcessingInstruction.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ProcessingInstruction.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ProcessingInstruction.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,29 +42,22 @@
  *
  * $Id$
  */
-
 package org.exolab.castor.xml;
 
 /**
- * A class that represents an XML processing instruction.
+ * An immutable class that represents an XML processing instruction.
  *
  * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
-**/
+ */
 public class ProcessingInstruction {
-    
-    /**
-     * PI target
-    **/
-    private String _target = null;
-    
+
+    /** PI target. */
+    private final String _target;
+    /** PI data. */
+    private final String _data;
+
     /**
-     * PI data
-    **/
-    private String _data = null;
-    
-    
-    /** 
      * Creates a new processing instruction.
      *
      * @param target the target for the processing instruction.
@@ -69,28 +62,28 @@
      *
      * @param target the target for the processing instruction.
      * @param data the data for the processing instruction.
-    **/
-    public ProcessingInstruction(String target, String data) {
+     */
+    public ProcessingInstruction(final String target, final String data) {
         _target = target;
-        _data = data;
-    } //-- constructor: ProcessingInstruction
+        _data   = data;
+    }
 
-    /** 
+    /**
      * Returns the target for the processing instruction.
      *
      * @return the target for the processing instruction.
-    **/
+     */
     public String getTarget() {
         return _target;
-    } //-- getTarget
-    
-    /** 
+    }
+
+    /**
      * Returns the data for the processing instruction.
      *
      * @return the data for the processing instruction.
-    **/
+     */
     public String getData() {
         return _data;
-    } //-- getData
-    
-} //-- class: ProcessingInstruction
+    }
+
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ReferenceInfo.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ReferenceInfo.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ReferenceInfo.java	(working copy)
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2006 Werner Guttman
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.exolab.castor.xml;
 
 import org.exolab.castor.mapping.FieldDescriptor;
@@ -3,29 +18,29 @@
 import org.exolab.castor.mapping.FieldDescriptor;
 
 /**
- * Internal class used to save state for reference resolving
-**/
+ * Internal class used to save state for reference resolving.
+ * @author <a href="mailto:werner DOT guttmann AT gmx DOT net">Werner Guttmann</a>
+ * @version $Revision: 0000 $ $Date:$
+ */
 class ReferenceInfo {
-    
-    /**
-     * The ID(REF) value of the target object instance
-     */
-    private String id = null;
-    /**
-     * The target object referenced by this IDREF instance
-     */
-    private Object target = null;
-    /**
-     * XML Field descriptor referenced by this IDREF instance
-     */
-    private XMLFieldDescriptor descriptor = null;
+
+    /** The ID(REF) value of the target object instance. */
+    private final String id;
+    /** The target object referenced by this IDREF instance. */
+    private final Object target;
+    /** XML Field descriptor referenced by this IDREF instance. */
+    private final XMLFieldDescriptor descriptor;
+
+    /** The 'next' ReferenceInfo instance. */
+    private ReferenceInfo next = null;
+
     /**
-     * The 'next' ReferenceInfo instance
+     * Creates a new ReferenceInfo
+     * @param id
+     * @param target
+     * @param descriptor
      */
-    private ReferenceInfo next = null;
-
-    public ReferenceInfo(final String id, final Object target, final XMLFieldDescriptor descriptor)
-    {
+    public ReferenceInfo(final String id, final Object target, final XMLFieldDescriptor descriptor) {
         this.id = id;
         this.target = target;
         this.descriptor = descriptor;
@@ -32,7 +47,7 @@
     }
 
     /**
-     * Sets a refrence to the 'next' ReferenceInfo instance
+     * Sets a refrence to the 'next' ReferenceInfo instance.
      * @param info The 'next' ReferenceInfo instance.
      */
     public void setNext(ReferenceInfo info) {
@@ -40,8 +55,8 @@
     }
 
     /**
-     * Returns the field descriptor referenced by this IDREF instance
-     * @return the field descriptor referenced by this IDREF instance
+     * Returns the field descriptor referenced by this IDREF instance.
+     * @return the field descriptor referenced by this IDREF instance.
      */
     public FieldDescriptor getDescriptor() {
         return this.descriptor;
@@ -48,8 +63,8 @@
     }
 
     /**
-     * Returns the target object referenced by this IDREF instance
-     * @return the target object referenced by this IDREF instance
+     * Returns the target object referenced by this IDREF instance.
+     * @return the target object referenced by this IDREF instance.
      */
     public Object getTarget() {
         return this.target;
@@ -56,8 +71,8 @@
     }
 
     /**
-     * Returns the next 'ReferenceInfo' instance
-     * @return the next 'ReferenceInfo' instance
+     * Returns the next 'ReferenceInfo' instance.
+     * @return the next 'ReferenceInfo' instance.
      */
     public ReferenceInfo getNext() {
         return this.next;
@@ -64,8 +79,8 @@
     }
 
     /**
-     * Returns the ID value of the target object instance
-     * @return the ID value of the target object instance
+     * Returns the ID value of the target object instance.
+     * @return the ID value of the target object instance.
      */
     public String getId() {
         return this.id;
@@ -70,5 +85,5 @@
     public String getId() {
         return this.id;
     }
-}
 
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ResolverException.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ResolverException.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ResolverException.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -48,16 +48,16 @@
 
 /**
  * The exception class thrown by the ClassDescriptorResolver
- * 
+ *
  * @author <a href="mailto:keith (at) kvisco (dot) com">Keith Visco</a>
- * @version $REVISION$ $DATE$
+ * @version $Revision: $ $Date: $
  */
 public class ResolverException extends XMLException {
-    /** SerialVersionUID */
+    /** SerialVersionUID. */
     private static final long serialVersionUID = -8800218775708296399L;
 
     /**
-     * 
+     * {@inheritdoc}
      */
     public ResolverException() {
         super();
@@ -64,9 +64,10 @@
     }
 
     /**
-     * @param message
+     * {@inheritdoc}
+     * @param message the message for this Exception.
      */
-    public ResolverException(String message) {
+    public ResolverException(final String message) {
         super(message);
     }
 
@@ -71,9 +72,10 @@
     }
 
     /**
-     * @param exception
+     * {@inheritdoc}
+     * @param exception the nested exception
      */
-    public ResolverException(Throwable exception) {
+    public ResolverException(final Throwable exception) {
         super(exception);
     }
 
@@ -78,10 +80,11 @@
     }
 
     /**
-     * @param message
-     * @param errorCode
+     * {@inheritdoc}
+     * @param message the message for this Exception.
+     * @param errorCode the error code for this Exception.
      */
-    public ResolverException(String message, int errorCode) {
+    public ResolverException(final String message, final int errorCode) {
         super(message, errorCode);
     }
 
@@ -86,10 +89,11 @@
     }
 
     /**
-     * @param message
-     * @param exception
+     * {@inheritdoc}
+     * @param message the message for this Exception.
+     * @param exception the nested Exception.
      */
-    public ResolverException(String message, Throwable exception) {
+    public ResolverException(final String message, final Throwable exception) {
         super(message, exception);
     }
 
@@ -94,11 +98,12 @@
     }
 
     /**
-     * @param message
-     * @param exception
-     * @param errorCode
+     * {@inheritdoc}
+     * @param message the message for this Exception.
+     * @param exception the nested Exception.
+     * @param errorCode the error code for this Exception.
      */
-    public ResolverException(String message, Throwable exception, int errorCode) {
+    public ResolverException(final String message, final Throwable exception, final int errorCode) {
         super(message, exception, errorCode);
     }
 
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/SimpleTypeValidator.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/SimpleTypeValidator.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/SimpleTypeValidator.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,7 +42,6 @@
  *
  * $Id$
  */
-
 package org.exolab.castor.xml;
 
 import java.lang.reflect.Array;
@@ -49,91 +48,84 @@
 import java.util.Enumeration;
 import java.util.Vector;
 
-
 /**
- * A class for defining simple rules used for validating a content model
+ * A class for defining simple rules used for validating a content model.
  * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2004-10-01 07:25:46 -0600 (Fri, 01 Oct 2004) $
-**/
+ */
 public class SimpleTypeValidator implements TypeValidator {
-    
-    /**
-     * The minimum occurance that the node must appear
-    **/
+
+    /** The minimum number of occurences allowed. */
     private int minOccurs = 0;
-    
-    /**
-     * The maximum occurance that the node must appear
-    **/
+    /** The maximum number of occurences allowed. */
     private int maxOccurs = -1;
-    
-    /**
-     * The type validate to delegate validation to
-    **/
+    /** The type validate to delegate validation to. */
     private TypeValidator validator = null;
-    
+
     /**
-     * Creates a default SimpleTypeValidator
-    **/
+     * Creates a default SimpleTypeValidator.
+     */
     public SimpleTypeValidator() {
         super();
-    } //-- SimpleTypeValidator
-    
+    }
+
     /**
      * Creates a SimpleTypeValidator using the given TypeValidator for
-     * delegating validation
-    **/
-    public SimpleTypeValidator(TypeValidator validator) {
+     * delegating validation.
+     * @param validator The TypeValidator to use
+     */
+    public SimpleTypeValidator(final TypeValidator validator) {
         super();
         this.validator = validator;
-    } //-- SimpleTypeValidator
+    }
 
     /**
-     * Sets the maximum occurance that the described field may occur
-     * @param maxOccurs the maximum occurance that the descibed field 
-     * may occur.
-    **/
-    public void setMaxOccurs(int maxOccurs) {
+     * Sets the maximum number of times that the described field may occur.
+     *
+     * @param maxOccurs the maximum number of times that the described field may
+     *        occur.
+     */
+    public void setMaxOccurs(final int maxOccurs) {
         this.maxOccurs = maxOccurs;
-    } //-- setMaxOccurs
+    }
 
     /**
-     * Sets the minimum occurance that the described field may occur
-     * @param minOccurs the minimum occurance that the descibed field 
-     * may occur.
-    **/
-    public void setMinOccurs(int minOccurs) {
+     * Sets the minimum number of times that the described field may occur.
+     *
+     * @param minOccurs the minimum number of times that the described field may
+     *        occur.
+     */
+    public void setMinOccurs(final int minOccurs) {
         this.minOccurs = minOccurs;
-    } //-- setMinOccurs
-    
+    }
+
     /**
-     * Sets the TypeValidator to delegate validation to
-     * @param validator the TypeValidator to delegate validation to
-    **/
-    public void setValidator(TypeValidator validator) {
+     * Sets the TypeValidator to delegate validation to.
+     *
+     * @param validator the TypeValidator to delegate validation to.
+     */
+    public void setValidator(final TypeValidator validator) {
         this.validator = validator;
-    } //-- setValidator
-    
+    }
+
     /**
-     * Validates the given Object
+     * Validates the given Object.
      *
-     * @param object the Object to validate
-     * @param context the ValidationContext
+     * @param object the Object to validate.
+     * @param context the ValidationContext.
+     * @throws ValidationException if validation fails.
      */
-    public void validate(Object object, ValidationContext context)
-        throws ValidationException 
-    {
-        
+    public void validate(final Object object, final ValidationContext context) throws ValidationException {
         boolean required = (minOccurs > 0);
-        
-        if ((object == null) && (required)) {
+
+        if (object == null && required) {
             String err = "This field is required and cannot be null.";
             throw new ValidationException(err);
         }
-        
+
         if (object != null) {
             Class type = object.getClass();
-            
+
             int size = 1;
             boolean byteArray = false;
             if (type.isArray()) {
@@ -138,33 +130,35 @@
             boolean byteArray = false;
             if (type.isArray()) {
                 byteArray = (type.getComponentType() == Byte.TYPE);
-                if (!byteArray) size = Array.getLength(object);
+                if (!byteArray) {
+                    size = Array.getLength(object);
+                }
             }
-            
+
             //-- check minimum
             if (size < minOccurs) {
                 String err = "A minimum of " + minOccurs
-                    + " instance(s) of this field are required.";
+                             + " instance(s) of this field is required.";
                 throw new ValidationException(err);
             }
-            
+
             //-- check maximum
-            if ((maxOccurs >= 0) && (size > maxOccurs)) {
-                String err = "A maximum of " + maxOccurs + 
-                    " instance(s) of this field are required.";
+            if (maxOccurs >= 0 && size > maxOccurs) {
+                String err = "A maximum of " + maxOccurs
+                             + " instance(s) of this field are allowed.";
                 throw new ValidationException(err);
             }
-            
-            if (validator == null) return;
-            
+
+            if (validator == null) {
+                return;
+            }
+
             //-- check type
             if (isPrimitive(type) || (type == String.class)) {
                 validator.validate(object, context);
-            }
-            else if (byteArray) { 
+            } else if (byteArray) {
                 //-- do nothing for now
-            }
-            else if (type.isArray()) {
+            } else if (type.isArray()) {
                 size = Array.getLength(object);
                 for (int i = 0; i < size; i++) {
                     validator.validate(Array.get(object, i), context);
@@ -169,13 +163,12 @@
                 for (int i = 0; i < size; i++) {
                     validator.validate(Array.get(object, i), context);
                 }
-            }
-            else if (object instanceof java.util.Enumeration) {
+            } else if (object instanceof java.util.Enumeration) {
                 Enumeration enumeration = (Enumeration)object;
-                while (enumeration.hasMoreElements())
+                while (enumeration.hasMoreElements()) {
                     validator.validate(enumeration.nextElement(), context);
-            }
-            else if (object instanceof java.util.Vector) {
+                }
+            } else if (object instanceof java.util.Vector) {
                 Vector vector = (Vector)object;
                 for (int i = 0; i < vector.size(); i++) {
                     validator.validate(vector.elementAt(i), context);
@@ -180,41 +173,32 @@
                 for (int i = 0; i < vector.size(); i++) {
                     validator.validate(vector.elementAt(i), context);
                 }
+            } else {
+                validator.validate(object, context);
             }
-            else validator.validate(object, context);
         }
-            
-    } //-- validate
-    
+    }
+
     //-------------------/
     //- Private Methods -/
     //-------------------/
-    
+
     /**
-     * Returns true if the given class type should be
-     * treated as a primitive. Wrapper objects such
-     * as java.lang.Integer, and java.lang.Float, will
-     * be treated as primitives.
+     * Returns true if the given class type should be treated as a primitive.
+     * Wrapper objects such as java.lang.Integer, and java.lang.Float, will be
+     * treated as primitives.
+     *
      * @param type the Class to check
-     * @return true if the given class should be treated
-     * as a primitive type.
-    **/
-    private boolean isPrimitive(Class type) {
-        
-        if (type.isPrimitive()) return true;
-        
-        if ((type == Boolean.class)   ||
-            (type == Byte.class)      ||
-            (type == Character.class) ||
-            (type == Double.class)    ||
-            (type == Float.class)     ||
-            (type == Integer.class)   ||
-            (type == Long.class)      ||
-            (type == Short.class)) 
+     * @return true if the given class should be treated as a primitive type.
+     */
+    private boolean isPrimitive(final Class type) {
+        if (type.isPrimitive()) {
             return true;
-            
-       return false;
-       
-    } //-- isPrimitive
-    
-} //-- SimpleTypeValidator
\ No newline at end of file
+        }
+
+        return (type == Boolean.class || type == Byte.class || type == Character.class
+                || type == Double.class || type == Float.class || type == Integer.class
+                || type == Long.class || type == Short.class);
+    }
+
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/TypeValidator.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/TypeValidator.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/TypeValidator.java	(working copy)
@@ -45,7 +45,7 @@
 package org.exolab.castor.xml;
 
 /**
- * The basic type validation interface class
+ * The basic type validation interface class.
  *
  * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
@@ -59,6 +59,7 @@
      * @param context the ValidationContext
      * @throws ValidationException if the object fails validation.
      */
-    public void validate(Object object, ValidationContext context) throws ValidationException;
+    public void validate(final Object object, final ValidationContext context)
+                                                         throws ValidationException;
 
-} //-- TypeValidator
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java	(working copy)
@@ -559,7 +559,7 @@
      *
      * @author <a href="mailto:stevendolg AT gxm DOT at">Steven Dolg</a>
      */
-    private class ClassCache {
+    static private class ClassCache {
 
         /**
          * A list of classes that could not be loaded.
@@ -622,7 +622,7 @@
      *
      * @author <a href="mailto:stevendolg AT gxm DOT at">Steven Dolg</a>
      */
-    private class DescriptorCache {
+    static private class DescriptorCache {
 
         private static final String PKG_CDR_LIST_FILE       = ".castor.cdr";
         private static final String PKG_MAPPING_FILE        = ".castor.xml";
@@ -1017,7 +1017,7 @@
     /**
      * A locally used implementation of ClassDescriptorEnumeration
      */
-    class XCDEnumerator implements ClassDescriptorEnumeration {
+    static class XCDEnumerator implements ClassDescriptorEnumeration {
 
         private final Iterator _descriptors;
 
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ValidationContext.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ValidationContext.java	(revision 6731)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ValidationContext.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,10 +42,9 @@
  *
  * $Id$
  */
-
-
 package org.exolab.castor.xml;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -62,53 +61,34 @@
  * @version $Revision$ $Date: 2004-10-06 02:10:17 -0600 (Wed, 06 Oct 2004) $
  */
 public class ValidationContext {
-    
+
+    /** Logger for debugging and error information. */
     private static final Log LOG = LogFactory.getLog(ValidationContext.class);
-    
-    /**
-     * The Castor configuration
-     */
-    private Configuration _config = null;
-    
-    /**
-     * A flag to indicate fail-fast validation. When true
-     * The first error encounted will cause a Validation
-     * Exception, when false, the validator should
-     * attempt to validate as much as possible collecting
-     * as many errors as possible before throwing
-     * a validation exception.
-     */
-    private boolean _failFast = true;
-    
-    /**
-     * The ClassDescriptorResolver to be used for loading
-     * and resolving ClassDescriptors during validation
-     */
-    private XMLClassDescriptorResolver _resolver = null;
-    
-    /**
-     * List of objects marked as validated
-     */
-    private Set _validated = new HashSet();
-    
-    /**
-     * Set of already encountered IDs (of type <xsd:ID>)
-     */
-    private Set _ids = new HashSet(); 
-    
-    /**
-     * Set of temporary unreseolved IDREFS;
-     */
-    private Set _unresolvedIdrefs = new HashSet(); 
-    
+
+    /** The Castor configuration. */
+    private Configuration              _config           = null;
+    /** A flag to indicate fail-fast validation. When true, the first error
+     * encounted will cause a Validation Exception. When false, the validator
+     * should attempt to validate as much as possible, collecting as many errors
+     * as possible before throwing a validation exception. */
+    private boolean                    _failFast         = true;
+    /** The ClassDescriptorResolver to be used for loading and resolving
+     * ClassDescriptors during validation. */
+    private XMLClassDescriptorResolver _resolver         = null;
+    /** The List of objects marked as validated. */
+    private final Set                  _validated        = new HashSet();
+    /** The Set of already encountered IDs (of type &lt;xsd:ID>). */
+    private final Set                  _ids              = new HashSet();
+    /** The Set of temporary unreseolved IDREFS. */
+    private final Set                  _unresolvedIdrefs = new HashSet();
+
     /**
-     * Creates a new ValidationContext
+     * Creates a new ValidationContext.
      */
     public ValidationContext() {
         super();
-    } //-- ValidationContext
-    
-    
+    }
+
     /**
      * Returns the Configuration to use during validation.
      *
@@ -117,10 +97,10 @@
      public Configuration getConfiguration() {
         if (_config == null) {
             _config = LocalConfiguration.getInstance();
-        } 
+        }
         return _config;
-     } //-- getConfiguration
-     
+     }
+
     /**
      * Returns the ClassDescriptorResolver to use during validation.
      *
@@ -128,18 +108,16 @@
      */
     public XMLClassDescriptorResolver getResolver() {
         return _resolver;
-    } //-- setResolver
-     
+    }
+
     /**
-     * Returns true if the validation process should fail
-     * upon first error encountered, otherwise the validation
-     * processs will attempt to validate as much as possible
-     * (even after the first error is encountered) and collect as
-     * many errors before either returning (no errors) or
-     * throwing a validationException containing the list of
-     * errors.
-     *
-     * <b>NOTE: DISABLEING OF FAIL-FAST IS NOT YET ENABLED.</b>
+     * Returns true if the validation process should fail upon first error
+     * encountered, otherwise the validation processs will attempt to validate
+     * as much as possible (even after the first error is encountered) and
+     * collect as many errors before either returning (no errors) or throwing a
+     * validationException containing the list of errors.
+     * <p>
+     * <b>NOTE: DISABLING OF FAIL-FAST IS NOT YET ENABLED.</b>
      *
      * @return true if fail-fast processing is enabled.
      */
@@ -145,14 +123,14 @@
      */
     public boolean isFailFast() {
         return _failFast;
-    } //-- isFailFast
-    
+    }
+
     /**
-     * Sets the Configuration used during validation
+     * Sets the Configuration used during validation.
      *
      * @param config the Configuration to use
      */
-    public void setConfiguration(Configuration config) {
+    public void setConfiguration(final Configuration config) {
         _config = config;
     }
 
@@ -157,28 +135,24 @@
     }
 
     /**
-     * Sets the fail-fast flag. Fail-fast is enabled by default.
-     * When fail-fast is enabled (default or by setting the
-     * flag to true) the validation process will throw an 
-     * exception upon the first error encountered.
-     * When fail-fast is disabled (by setting the flag to false)
-     * the validation processs will attempt to validate even
-     * after the first error is encountered and collect as
-     * many errors before either returning (no errors) or
-     * throwing a validationException containing the list of
-     * errors.
+     * Sets the fail-fast flag. Fail-fast is enabled by default. When fail-fast
+     * is enabled (default or by setting the flag to true) the validation
+     * process will throw an exception upon the first error encountered. When
+     * fail-fast is disabled (by setting the flag to false) the validation
+     * processs will attempt to validate even after the first error is
+     * encountered and collect as many errors before either returning (no
+     * errors) or throwing a validationException containing the list of errors.
+     * <p>
+     * <b>NOTE: DISABLING FAIL-FAST IS NOT YET ENABLED.</b>
      *
-     * <b>NOTE: DISABLEING FAIL-FAST IS NOT YET ENABLED.</b>
-     *
-     * @param failFast a boolean that when true enables fail-fast
-     * validation, otherwise the validator will attempt to validate
-     * as much as it can reporting as many errors as possible before
-     * returning.
+     * @param failFast a boolean that when true enables fail-fast validation,
+     *        otherwise the validator will attempt to validate as much as it can
+     *        reporting as many errors as possible before returning.
      */
-    public void setFailFast(boolean failFast) {
+    public void setFailFast(final boolean failFast) {
         _failFast = failFast;
-    } //-- setFailFast
-    
+    }
+
     /**
      * Sets the ClassDescriptorResolver to use during validation.
      *
@@ -184,34 +158,34 @@
      *
      * @param resolver the ClassDescriptorResolver to use.
      */
-    public void setResolver(XMLClassDescriptorResolver resolver) {
+    public void setResolver(final XMLClassDescriptorResolver resolver) {
         _resolver = resolver;
-    } //-- setResolver
+    }
 
     /**
-     * Checks whetehr an object has already been validated
+     * Checks whether an object has already been validated.
      * @param object The object for which the check should be performed
      * @return True if the object specified has already been validated.
      */
-    protected boolean isValidated(Object object) {
+    public boolean isValidated(final Object object) { /* FIXME: Should be protected */
         LOG.trace("Called isValidated(" + object + ")");
         return _validated.contains(object);
     }
-    
+
     /**
-     * Adds the specified object to the cache of already validated objects
+     * Adds the specified object to the cache of already validated objects.
      * @param object Object about to be validated.
      */
-    protected void addValidated(Object object) {
+    public void addValidated(final Object object) { /* FIXME: Should be protected */
         LOG.trace("Called addValidated(" + object + ")");
         _validated.add(object);
     }
-    
+
     /**
-     * Removes the specified object from the cache of already validated objects
+     * Removes the specified object from the cache of already validated objects.
      * @param object The object to be removed from the cache.
      */
-    protected void removeValidated(Object object) {
+    public void removeValidated(final Object object) { /* FIXME: Should be protected */
         LOG.trace("Called removeValidated(" + object + ")");
         _validated.remove(object);
     }
@@ -217,11 +191,15 @@
     }
 
     /**
-     * Adds current ID (as seen during (un)marshalling) to ID cache
+     * Adds current ID (as seen during (un)marshalling) to the ID cache. If this
+     * ID was previously added to the Set of unresolved IDs, then remove it from
+     * that Set.
+     *
      * @param id The current ID
      * @throws ValidationException If an ID is used more than once.
+     * @see #getUnresolvedIdRefs()
      */
-    public void addID(String id) throws ValidationException {
+    public void addID(final String id) throws ValidationException {
         if (!_ids.contains(id)) {
             _ids.add(id);
             _unresolvedIdrefs.remove(id);
@@ -226,21 +204,39 @@
             _ids.add(id);
             _unresolvedIdrefs.remove(id);
         } else {
-            throw new ValidationException ("ID " + id + " already used within current document.");
+            throw new ValidationException ("ID " + id + " is already used within current document.");
         }
     }
 
-    public boolean checkIdRef(String id) {
+    /**
+     * Checks an ID Reference, returning true if the provided ID is known. If
+     * the provided ID is not known, it is added to the Set of unresolved ID
+     * references.  Note that if this ID is later found, it will be removed
+     * from this Set.
+     *
+     * @param id The ID to check.
+     * @return true if the provided ID is known.
+     * @see #getUnresolvedIdRefs()
+     */
+    public boolean checkIdRef(final String id) {
         if (!_ids.contains(id)) {
             _unresolvedIdrefs.add(id);
+            return false;
         }
-        return _ids.contains(id);
+        return true;
     }
 
+    /**
+     * Returns the Set of unresolved ID references. The Set returns is not
+     * modifiable, but is available to be used to list all unresolved
+     * references.
+     *
+     * @return the Set of unresolved ID references.
+     */
     public Set getUnresolvedIdRefs() {
-        return _unresolvedIdrefs;
+        return Collections.unmodifiableSet(_unresolvedIdrefs);
     }
-    
+
     /**
      * Life-cycle method for proper 'shutdown operations'.
      */
@@ -246,8 +242,8 @@
      */
     public void cleanup() {
         _ids.clear();
-        // TODO: enable ???? !!
-        // _validated.clear();
+        _validated.clear();
+        _unresolvedIdrefs.clear();
     }
-       
-} //-- ValidationContext
\ No newline at end of file
+
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ValidationException.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ValidationException.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/ValidationException.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,14 +42,13 @@
  *
  * $Id$
  */
-
 package org.exolab.castor.xml;
 
 /**
- * An exception that can be used to signal XML validation errors
+ * An Exception that can be used to signal XML validation errors.
  * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2005-12-13 14:58:48 -0700 (Tue, 13 Dec 2005) $
-**/
+ */
 public class ValidationException extends XMLException {
     /** SerialVersionUID */
     private static final long serialVersionUID = 2220902174700444631L;
@@ -54,32 +53,26 @@
     /** SerialVersionUID */
     private static final long serialVersionUID = 2220902174700444631L;
 
-    /**
-     * The location for this Exception
-     */
-    private Location  _location   = null;
-    
+    /** The location for this Exception. */
+    private Location            _location   = null;
+    /** The next Exception in the list, allowing the reporting of several
+     * validation Exceptions. */
+    private ValidationException _next       = null;
+
     /**
-     * The next exception in the list, allows for reporting
-     * of several validation exceptions
+     * Creates a new ValidationException with no message or nested Exception.
      */
-    private ValidationException _next = null;
-    
-    /**
-     * Creates a new ValidationException with no message,
-     * or nested Exception
-    **/
     public ValidationException() {
         super();
-    } //-- ValidationException
-    
+    }
+
     /**
      * Creates a new ValidationException with the given message.
      * @param message the message for this Exception
-    **/
-    public ValidationException(String message) {
+     */
+    public ValidationException(final String message) {
         super(message);
-    } //-- ValidationException(String)
+    }
 
     /**
      * Creates a new ValidationException with the given message.
@@ -85,108 +78,109 @@
      * Creates a new ValidationException with the given message.
      * @param message the message for this Exception
      * @param errorCode the errorCode for this Exception
-    **/
-    public ValidationException(String message, int errorCode) {
+     */
+    public ValidationException(final String message, final int errorCode) {
         super(message, errorCode);
-    } //-- ValidationException(String)
-    
+    }
+
     /**
-     * Creates a new ValidationException with the given nested
-     * exception.
-     * @param exception the nested exception
-    **/
-    public ValidationException(Throwable exception) {
+     * Creates a new ValidationException with the given nested Exception.
+     * @param exception the nested Exception
+     */
+    public ValidationException(final Throwable exception) {
         super(exception);
-    } //-- ValidationException(Exception)
+    }
 
     /**
-     * Creates a new ValidationException with the given message
-     * and nested exception.
-     * @param message the detail message for this exception
-     * @param exception the nested exception
-    **/
-    public ValidationException(String message, Throwable exception) {
+     * Creates a new ValidationException with the given message and nested
+     * Exception.
+     *
+     * @param message the detail message for this Exception
+     * @param exception the nested Exception
+     */
+    public ValidationException(final String message, final Throwable exception) {
         super(message, exception);
-    } //-- ValidationException(String, Exception)
+    }
 
     /**
-     * Creates a new ValidationException with the given message,
-     * nested exception, and errorCode.
-     * @param message the detail message for this exception
-     * @param exception the nested exception
+     * Creates a new ValidationException with the given message, nested
+     * Exception, and errorCode.
+     *
+     * @param message the detail message for this Exception
+     * @param exception the nested Exception
      * @param errorCode the errorCode for this Exception
-    **/
-    public ValidationException
-        (String message, Exception exception, int errorCode) 
-    {
+     */
+    public ValidationException(final String message, final Exception exception,
+                               final int errorCode) {
         super(message, exception, errorCode);
-    } //-- ValidationException(String, Exception, int)
-        
+    }
+
     /**
-     * Returns the location of the exception
+     * Returns the location of the Exception.
      *
-     * @return the location of the exception
+     * @return the location of the Exception.
      */
     public Location getLocation() {
         return _location;
-    } //-- getLocation
-    
+    }
+
     /**
-     * Returns the next ValidationException in the list, or null
-     * if no additional validation exceptions exist.
+     * Returns the next ValidationException in the list, or null if no
+     * additional validation exceptions exist.
      *
-     * @return the next ValidationException in the list, or null if
-     * there are no additional exceptions.
+     * @return the next ValidationException in the list, or null if there are no
+     *         additional Exceptions.
      */
     public ValidationException getNext() {
         return _next;
-    } //-- getNext
-    
+    }
+
     /**
      * Sets the location information for this ValidationException.
-     * 
-     * @param location The location information for this validation exception.
+     *
+     * @param location The location information for this validation Exception.
      */
-    public void setLocation(Location location) {
+    public void setLocation(final Location location) {
         _location = location;
-    } //-- setLocation
-    
+    }
+
     /**
-     * Removes the given ValidationException from the current
-     * list of ValidationException.
+     * Removes the given ValidationException from the current list of
+     * ValidationException.
      *
      * @param exception the ValidationException to remove
-     * @return true if the given ValidationException was
-     * successfully removed.
+     * @return true if the given ValidationException was successfully removed.
      */
-    protected boolean remove(ValidationException exception) {
-        
-        if (exception == null) return false;
-        
-        ValidationException current = _next;
+    protected boolean remove(final ValidationException exception) {
+        if (exception == null) {
+            return false;
+        }
+
         ValidationException previous = this;
-        while (current != null) {
+        for (ValidationException current = _next; current != null;
+                                                  previous = current, current = current._next) {
             if (current == exception) {
-                previous._next = current._next; 
+                previous._next = current._next;
                 current._next = null;
                 return true;
             }
-            current = current._next;
         }
         return false;
-    } //-- remove
-    
+    }
+
     /**
-     * Adds the given ValidationException as the last exception
-     * in the list. This is equivalent to calling #setNext if no
-     * additional ValidationException(s) exist.
+     * Adds the given ValidationException as the last exception in the list.
+     * This is equivalent to calling {@link #setNext} if no additional
+     * ValidationException(s) exist.
      *
-     * @param exception the ValidationException to set as the last
-     * exception in the list.
+     * @param exception the ValidationException to set as the last exception in
+     *        the list.
      */
-    protected void setLast(ValidationException exception) {
-        if (exception == null) return;
-        
+    protected void setLast(final ValidationException exception) {
+        if (exception == null) {
+            return;
+        }
+
         ValidationException current = this;
         while (current._next != null) {
             current = current._next;
@@ -192,64 +186,64 @@
             current = current._next;
         }
         current._next = exception;
-    } //-- setLast
-    
+    }
+
     /**
-     * Sets the given ValidationException as the next exception
-     * in the list. This method will overwrite any existing
-     * ValidationException that may already exist as the next
-     * exception.
+     * Sets the given ValidationException as the next Exception in the list.
+     * This method will overwrite any existing ValidationException that may
+     * already exist as the next Exception.
      *
-     * @param exception the ValidationException to set as the next
-     * exception in the list.
+     * @param exception the ValidationException to set as the next Exception in
+     *        the list.
      */
-    protected void setNext(ValidationException exception) {
+    protected void setNext(final ValidationException exception) {
         _next = exception;
-    } //-- setNext
-    
+    }
 
     /**
-     * Returns the String representation of this Exception
-     * @return the String representation of this Exception
-    **/
+     * Returns the String representation of this ValidationException.
+     * @return the String representation of this ValidationException.
+     */
     public String toString() {
-        StringBuffer sb = new StringBuffer();
+        final StringBuffer sb = new StringBuffer();
         if (getNext() != null) {
             int count = 1;
-            ValidationException vx = this;
-            while (vx != null) {
+            for (ValidationException vx = this; vx != null; vx = vx.getNext()) {
                 if (count > 1) {
-                    sb.append('\n');
-                    sb.append('\n');
+                    sb.append("\n\n");
                 }
                 sb.append(count);
-                sb.append(". ValidationException: ");
-                String message = vx.getMessage();
-                if (message != null) sb.append(message);
-                Location location = getLocation();
-                if (location != null) {
-                    sb.append(";\n   - location of error: ");
-                    sb.append(location.toString());
-                }
-                vx = vx.getNext();
+                sb.append(". ");
+                dumpOneException(sb, vx);
                 ++count;
             }
+        } else {
+            dumpOneException(sb, this);
         }
-        else {
-            sb.append("ValidationException: ");
-            String message = getMessage();
-            if (message != null) sb.append(message);
-            if (_location != null) {
-                sb.append(";\n   - location of error: ");
-                sb.append(_location.toString());
-            }
-            Throwable t = getCause();
-            if (t!=null) {
-                sb.append("\n");
-                sb.append(t.getMessage());
-            }
+        return sb.toString();
+    }
+
+    /**
+     * Dump information for a single ValidationException.
+     * @param sb The StringBuffer to which we print information
+     * @param vx The ValidationException for which we print information.
+     */
+    private void dumpOneException(final StringBuffer sb, final ValidationException vx) {
+        sb.append("ValidationException: ");
+        String message = vx.getMessage();
+        if (message != null) {
+            sb.append(message);
+        }
+        Location location = vx.getLocation();
+        if (location != null) {
+            sb.append(";\n   - location of error: ");
+            sb.append(location.toString());
+        }
+        Throwable t = vx.getCause();
+        if (t != null) {
+            sb.append("\n");
+            sb.append(t.getMessage());
         }
-        return sb.toString();
-    } //-- toString
+    }
 
-} //-- ValidationException
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/Validator.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/Validator.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/Validator.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -47,8 +47,6 @@
  *
  * $Id$
  */
-
-
 package org.exolab.castor.xml;
 
 import org.castor.mapping.BindingType;
@@ -55,9 +53,8 @@
 import org.exolab.castor.mapping.FieldDescriptor;
 
 /**
- * A class which can perform Validation on an Object model.
- * This class uses the ClassDescriptors and FieldDescriptors
- * to perform the validation.
+ * A class which can perform Validation on an Object model. This class uses the
+ * ClassDescriptors and FieldDescriptors to perform the validation.
  *
  * @author <a href="mailto:keith AT kvisco DOT com">Keith Visco</a>
  * @version $Revision$ $Date: 2005-02-28 17:43:25 -0700 (Mon, 28 Feb 2005) $
@@ -65,8 +62,8 @@
 public class Validator implements ClassValidator {
 
     /**
-     * Creates a new Validator
-    **/
+     * Creates a new Validator.
+     */
     public Validator() {
         super();
     } //-- Validator
@@ -72,36 +69,36 @@
     } //-- Validator
 
     /**
-     * Validates the given Object
+     * Validates the given Object.
      *
      * @param object the Object to validate
+     * @throws ValidationException if validation fails.
      */
-    public void validate(Object object) 
-        throws ValidationException
-    {
-        validate(object, (ValidationContext)null);
-    } //-- validate
-    
+    public void validate(final Object object) throws ValidationException {
+        validate(object, (ValidationContext) null);
+    }
+
     /**
-     * Validates the given Object
+     * Validates the given Object.
      *
      * @param object the Object to validate
      * @param context the ValidationContext to use during validation.
+     * @throws ValidationException if validation fails.
      */
-    public void validate(Object object, ValidationContext context)
-        throws ValidationException
-    {
-
+    public void validate(final Object object, final ValidationContext context)
+                                                     throws ValidationException {
         if (object == null) {
             throw new ValidationException("Cannot validate a null Object.");
         }
-        
+
         if (context == null) {
-            context = new ValidationContext();
+            validate(object, new ValidationContext());
+            return;
         }
 
         if (context.getResolver() == null) {
-            context.setResolver((XMLClassDescriptorResolver) ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML));
+            context.setResolver((XMLClassDescriptorResolver)
+                                 ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML));
         }
 
         XMLClassDescriptor classDesc = null;
@@ -109,8 +106,7 @@
         if (! MarshalFramework.isPrimitive(object.getClass())) {
             try {
                 classDesc = context.getResolver().resolveXML(object.getClass());
-            }
-            catch(ResolverException rx) {
+            } catch (ResolverException rx) {
                 throw new ValidationException(rx);
             }
         }
@@ -116,19 +112,18 @@
         }
 
         //-- we cannot validate an object if ClassDescriptor is null
-        if (classDesc == null) return;
-
-        TypeValidator validator = classDesc.getValidator();
+        if (classDesc == null) {
+            return;
+        }
 
         XMLFieldDescriptor fieldDesc = null;
-        
+
         try {
+            TypeValidator validator = classDesc.getValidator();
             if (validator != null) {
                 validator.validate(object, context);
-            }
-            //-- default validation
-            else {
-                //-- just validate each field
+            } else {
+                // Default validation -- just validate each field
                 FieldDescriptor[] fields = classDesc.getFields();
                 if (fields != null) {
                     for (int i = 0; i < fields.length; i++) {
@@ -133,16 +128,17 @@
                 if (fields != null) {
                     for (int i = 0; i < fields.length; i++) {
                         fieldDesc = (XMLFieldDescriptor)fields[i];
-                        if (fieldDesc == null) continue;
-                        FieldValidator fieldValidator
-                            = fieldDesc.getValidator();
-                        if (fieldValidator != null)
+                        if (fieldDesc == null) {
+                            continue;
+                        }
+                        FieldValidator fieldValidator = fieldDesc.getValidator();
+                        if (fieldValidator != null) {
                             fieldValidator.validate(object, context);
+                        }
                     }
                 }
             }
-        }
-        catch (ValidationException vx) {
+        } catch (ValidationException vx) {
             //-- add location information
             XPathLocation loc = (XPathLocation)vx.getLocation();
             if (loc == null) {
@@ -149,14 +145,16 @@
                 loc = new XPathLocation();
                 vx.setLocation(loc);
                 if (fieldDesc != null) {
-                    if (fieldDesc.getNodeType() == NodeType.Attribute)
+                    if (fieldDesc.getNodeType() == NodeType.Attribute) {
                         loc.addAttribute(fieldDesc.getXMLName());
-                    else
+                    } else {
                         loc.addChild(fieldDesc.getXMLName());
+                    }
                 }
             }
-            if (classDesc.getXMLName() != null)
+            if (classDesc.getXMLName() != null) {
                  loc.addParent(classDesc.getXMLName());
+            }
             throw vx;
         }
 
@@ -164,28 +162,8 @@
             String err = "Unresolved IDREfs: " + context.getUnresolvedIdRefs().toString();
             throw new ValidationException(err);
         }
-        
-    } //-- validate
-    
+    }
+
     // TODO: add cleanup life-cycle method to be called from outside
 
-    /**
-     * Validates an Object model, ClassDescriptor classes will be used
-     * to perform Validation. If no ClassDescriptor class exists, one
-     * will be dynamically created
-     * @param the given Object in which to validate
-     * @param cdResolver the ClassDescriptorResolver used for finding
-     * XMLClassDescriptors, this may be null
-    **
-    public static void validate
-        (Object object, ClassDescriptorResolver cdResolver)
-        throws ValidationException
-    {
-        Validator validator = new Validator();
-        validator.setResolver(cdResolver);
-        validator.validate(object);
-    } //-- validate
-
-    */
-
-} //-- Validator
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/XMLFieldDescriptor.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/XMLFieldDescriptor.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/XMLFieldDescriptor.java	(working copy)
@@ -19,7 +19,7 @@
 
 /**
  * XML field descriptor. Wraps {@link FieldDescriptor} and adds
- * XML-related information, type conversion, etc.
+ * XML-related information, type conversion, and so on.
  *
  * @author <a href="mailto:arkin AT intalio DOT com">Assaf Arkin</a>
  * @author <a href="mailto:keith AT kvisco DOT com">Keith Visco</a>
@@ -27,18 +27,18 @@
  * @version $Revision$ $Date: 2004-09-17 00:47:41 -0600 (Fri, 17 Sep 2004) $
  */
 public interface XMLFieldDescriptor extends FieldDescriptor {
-    /** The xml:space property */
+    /** The xml:space property. */
     String PROPERTY_XML_SPACE = "xml:space";
-    
-    /** The xml:lang property */
+
+    /** The xml:lang property. */
     String PROPERTY_XML_LANG = "xml:lang";
-    
+
     /**
-     * Returns the index within the constructor argument array where the 
-     * value of this field should be. A value less than zero indicates
-     * that the value of this field is set via a normal setter method
-     * and not via the constructor.
-     *
+     * Returns the index within the constructor argument array where the value
+     * of this field should be. A value less than zero indicates that the value
+     * of this field is set via a normal setter method and not via the
+     * constructor.
+     * <p>
      * Note: This only applies to attribute mapped fields at this time.
      *
      * @return the index within the constructor argument array for this field.
@@ -47,13 +47,12 @@
     int getConstructorArgumentIndex();
 
     /**
-     * Returns true if the value of the field represented by this 
-     * descriptor should be set via the constructor of the containing
-     * class. This is only valid for attribute mapped fields.
+     * Returns true if the value of the field represented by this descriptor
+     * should be set via the constructor of the containing class. This is only
+     * valid for attribute mapped fields.
      *
-     * @return true if the value of the field represented by this 
-     * descriptor should be set via the constructor of the containing
-     * class.
+     * @return true if the value of the field represented by this descriptor
+     *         should be set via the constructor of the containing class.
      */
     boolean isConstructorArgument();
 
@@ -59,23 +58,20 @@
 
     /**
      * Returns the "relative" XML path for the field being described.
-     *
-     * In most cases, this will be null. However sometimes a
-     * field may be mapped to a nested element. In which case 
-     * the value returned by this method should be the nested
-     * element name. If more than one level of nesting is
-     * needed each nested element name should be separated by
-     * by a path separator (forward slash '/').
-     *
-     * The location path name is "relative" to the parent Class. The
-     * name of the parent should not be included in the path.
-     *
-     * 
+     * <p>
+     * In most cases, this will be null. However sometimes a field may be mapped
+     * to a nested element. In which case the value returned by this method
+     * should be the nested element name. If more than one level of nesting is
+     * needed each nested element name should be separated by by a path
+     * separator (forward slash '/').
+     * <p>
+     * The location path name is "relative" to the parent Class. The name of the
+     * parent should not be included in the path.
+     * <p>
      * For example, give the following two classes:
-     * <code>
-     *
-     *    class Root {    
-     *        Bar bar;    
+     * <pre>
+     *    class Root {
+     *        Bar bar;
      *    }
      *
      *    class Bar {
@@ -81,11 +77,11 @@
      *    class Bar {
      *       String value;
      *    }
-     * </code>
+     * </pre>
      *
      * And the following XML:
      *
-     * <code>
+     * <pre>
      *    &lt;root&gt;
      *       &lt;foo&gt;
      *          &lt;bar&gt; value of bar &lt;/bar&gt;
@@ -91,18 +87,16 @@
      *          &lt;bar&gt; value of bar &lt;/bar&gt;
      *       &lt;/foo&gt;
      *    &lt;/root&gt;
-     * </code>
+     * </pre>
      *
-     * Since foo has no associated class, the path for 'bar'
-     * would be: "foo"
-     * 
+     * Since foo has no associated class, the path for 'bar' would be: "foo"
+     *
      * @return The "relative" XML path for the field being described.
      */
     String getLocationPath();
-    
+
     /**
-     * Return the "suggested" namespace prefix to use when marshalling
-     * as XML.
+     * Return the "suggested" namespace prefix to use when marshaling as XML.
      *
      * @return the "suggested" namespace prefix.
      */
@@ -109,8 +103,8 @@
     String getNameSpacePrefix();
 
     /**
-     * Returns the namespace URI to be used when marshalling and
-     * unmarshalling as XML.
+     * Returns the namespace URI to be used when marshaling and unmarshaling as
+     * XML.
      *
      * @return the namespace URI.
      */
@@ -117,9 +111,8 @@
     String getNameSpaceURI();
 
     /**
-     * Returns the NodeType of the Field being described. The
-     * NodeType represents the Type of Node that the Field will
-     * be marshalled into XML as.
+     * Returns the NodeType of the Field being described. The NodeType
+     * represents the Type of Node that the Field will be marshaled into XML as.
      *
      * @return the NodeType of the Field being described.
      */
@@ -124,16 +117,15 @@
      * @return the NodeType of the Field being described.
      */
     NodeType getNodeType();
-    
-    /**     
-     * Returns the value property with the given name or null
-     * if no such property exists. This method is useful for
-     * future evolutions of this interface as well as for
-     * user-defined extensions. See class declared properties
-     * for built-in properties.
+
+    /**
+     * Returns the value property with the given name or null if no such
+     * property exists. This method is useful for future evolutions of this
+     * interface as well as for user-defined extensions. See class declared
+     * properties for built-in properties.
      *
-     * @param propertyName the name of the property whose value
-     * should be returned.
+     * @param propertyName the name of the property whose value should be
+     *        returned.
      *
      * @return the value of the property, or null.
      */
@@ -138,7 +130,7 @@
      * @return the value of the property, or null.
      */
     String getProperty(String propertyName);
-    
+
     /**
      * Returns the XML Schema type of the XML field being described.
      *
@@ -147,9 +139,8 @@
     String getSchemaType();
 
     /**
-     * Returns a specific validator for the field described by
-     * this descriptor. A null value may be returned
-     * if no specific validator exists.
+     * Returns a specific validator for the field described by this descriptor.
+     * A null value may be returned if no specific validator exists.
      *
      * @return the field validator for the described field
      */
@@ -165,7 +156,7 @@
     /**
      * Returns true if the field described by this descriptor is a container
      * field. A container is a field that is not a first-class object,
-     * and should therefore have no XML representation. 
+     * and should therefore have no XML representation.
      *
      * @return true if the field is a container
      */
@@ -172,11 +163,11 @@
     boolean isContainer();
 
     /**
-     * Returns the incremental flag which when true indicates that this
-     * member may be safely added before the unmarshaller is finished
-     * unmarshalling it.
-     * @return true if the Object can safely be added before the unmarshaller
-     * is finished unmarshalling the Object.
+     * Returns the incremental flag which when true indicates that this member
+     * may be safely added before the unmarshaler is finished unmarshaling it.
+     *
+     * @return true if the Object can safely be added before the unmarshaler is
+     *         finished unmarshaling the Object.
      */
     boolean isIncremental();
 
@@ -181,20 +172,21 @@
     boolean isIncremental();
 
     /**
-     * Returns true if the field described by this descriptor
-     * is Map or Hashtable. If this method returns true, it
-     * must also return true for any call to #isMultivalued.
-     * 
-     * @return true if the field described by this desciptor is
-     * a Map or Hashtable, otherwise false.
+     * Returns true if the field described by this descriptor is Map or
+     * Hashtable. If this method returns true, it must also return true for any
+     * call to {@link #isMultivalued}.
+     *
+     * @return true if the field described by this desciptor is a Map or
+     *         Hashtable, otherwise false.
      */
     boolean isMapped();
-    
+
     /**
-     * Returns true if the field described by this descriptor can
-     * contain more than one value
-     * @return true if the field described by this descriptor can
-     * contain more than one value
+     * Returns true if the field described by this descriptor can contain more
+     * than one value.
+     *
+     * @return true if the field described by this descriptor can contain more
+     *         than one value
      */
     boolean isMultivalued();
 
@@ -199,20 +191,21 @@
     boolean isMultivalued();
 
     /**
-     * Returns true if the field described by this descriptor
-     * may be nillable. A nillable field is one that may
-     * have empty content and still be valid. Please see
-     * the XML Schema 1.0 Recommendation for more information
-     * on nillable.
-     * 
+     * Returns true if the field described by this descriptor may be nillable. A
+     * nillable field is one that may have empty content and still be valid.
+     * Please see the XML Schema 1.0 Recommendation for more information on
+     * nillable.
+     *
      * @return true if the field may be nillable.
      */
     boolean isNillable();
-    
+
     /**
-     * Returns true if the field described by this descriptor is
-     * a reference (ie. IDREF) to another object in the
-     * "Object Model" (XML tree)
+     * Returns true if the field described by this descriptor is a reference
+     * (ie. IDREF) to another object in the "Object Model" (e.g., XML tree).
+     *
+     * @return true if the field described by this descriptor is a reference to
+     *         another object in the "Object Model"
      */
     boolean isReference();
 
@@ -217,13 +210,14 @@
     boolean isReference();
 
     /**
-     * Returns true if this descriptor can be used to handle elements
-     * or attributes with the given XML name. By default this method
-     * simply compares the given XML name with the internal XML name.
-     * This method can be overridden to provide more complex matching.
+     * Returns true if this descriptor can be used to handle elements or
+     * attributes with the given XML name. By default this method simply
+     * compares the given XML name with the internal XML name. This method can
+     * be overridden to provide more complex matching.
+     *
      * @param xmlName the XML name to compare
-     * @return true if this descriptor can be used to handle elements
-     * or attributes with the given XML name.
+     * @return true if this descriptor can be used to handle elements or
+     *         attributes with the given XML name.
      */
     boolean matches(String xmlName);
 
@@ -228,15 +222,17 @@
     boolean matches(String xmlName);
 
     /**
-     * Returns true if this descriptor can be used to handle elements
-     * or attributes with the given XML name. By default this method
-     * simply compares the given XML name with the internal XML name.
-     * This method can be overridden to provide more complex matching.
+     * Returns true if this descriptor can be used to handle elements or
+     * attributes with the given XML name. By default this method simply
+     * compares the given XML name with the internal XML name. This method can
+     * be overridden to provide more complex matching.
+     *
      * @param xmlName the XML name to compare
-     * @param namespace the namespace URI 
+     * @param namespace the namespace URI
      *
-     * @return true if this descriptor can be used to handle elements
-     * or attributes with the given XML name.
+     * @return true if this descriptor can be used to handle elements or
+     *         attributes with the given XML name.
      */
     boolean matches(String xmlName, String namespace);
-}
\ No newline at end of file
+
+}
Index: /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/XPathLocation.java
===================================================================
--- /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/XPathLocation.java	(revision 6760)
+++ /home/ekuns/workspace/castor-4/src/main/java/org/exolab/castor/xml/XPathLocation.java	(working copy)
@@ -1,4 +1,4 @@
-/**
+/*
  * Redistribution and use of this software and associated documentation
  * ("Software"), with or without modification, are permitted provided
  * that the following conditions are met:
@@ -42,7 +42,6 @@
  *
  * $Id$
  */
-
 package org.exolab.castor.xml;
 
 import java.util.Vector;
@@ -48,63 +47,67 @@
 import java.util.Vector;
 
 /**
- * A very simple XPath location class for use
- * with the ValidationException. This class only
- * supports the parent "/" operator and element names.
+ * A very simple XPath location class for use with the ValidationException. This
+ * class only supports the parent "/" operator and element names.
+ *
  * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
  * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $
-**/
+ */
 public class XPathLocation implements Location {
-    
-    
-    Vector path = null;
-    
-    boolean allowChildrenOrAtts = true;
-    
+
+    /** Our XPath, built up one String at a time. */
+    private final Vector path                = new Vector();
+    /** If we have reached the logical end of XPath (i.e., an attribute), set to false. */
+    private boolean      allowChildrenOrAtts = true;
+
     /**
-     * Creates a default XPathLocation
-    **/
+     * Creates a default XPathLocation.
+     */
     public XPathLocation() {
         super();
-        path = new Vector();
-    } //-- XPathLocation
+    }
 
-    public void addAttribute(String name) {
+    /**
+     * Adds an attribute to the XPath location.
+     * @param name the name of the attribute
+     */
+    public void addAttribute(final String name) {
         if (allowChildrenOrAtts) {
             allowChildrenOrAtts = false;
-            path.addElement("@"+name);
+            path.addElement("@" + name);
         }
-    } //-- addAttribute
-    
+    }
+
     /**
-     * Adds the name as a child of the current path
+     * Adds the given element name as a child of the current path.
      * @param name the name to add as a child
-    **/
-    public void addChild(String name) {
+     */
+    public void addChild(final String name) {
         if (allowChildrenOrAtts) {
             path.addElement(name);
         }
-    } //-- addChild
-    
+    }
+
     /**
-     * Adds the name as a parent of the current path
+     * Adds the name as a parent of the current path.
      * @param name the name to add as a parent
-    **/
-    public void addParent(String name) {
+     */
+    public void addParent(final String name) {
         path.insertElementAt(name, 0);
-    } //-- addParent
-    
+    }
+
     /**
-     * Returns the String representation of this XPathLocation
-    **/
+     * Returns the String representation of this XPathLocation.
+     * @return the String representation of this XPathLocation.
+     */
     public String toString() {
         StringBuffer buf = new StringBuffer("XPATH: ");
-        
+
         for (int i = 0; i < path.size(); i++) {
-            if (i > 0) buf.append('/');
+            buf.append('/');
             buf.append((String)path.elementAt(i));
         }
         return buf.toString();
-    } //-- toString
-    
-} //-- XPathLocation
\ No newline at end of file
+    }
+
+}

