Save This Page
Home » openjdk-7 » javax » xml » bind » helpers » [javadoc | source]
    1   /*
    2    * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   package javax.xml.bind.helpers;
   26   
   27   import java.text.MessageFormat;
   28   
   29   import javax.xml.bind.ValidationEvent;
   30   import javax.xml.bind.ValidationEventLocator;
   31   
   32   /**
   33    * Default implementation of the ValidationEvent interface.
   34    *
   35    * <p>
   36    * JAXB providers are allowed to use whatever class that implements
   37    * the ValidationEvent interface. This class is just provided for a
   38    * convenience.
   39    *
   40    * @author <ul><li>Kohsuke Kawaguchi, Sun Microsystems, Inc.</li></ul>
   41    * @see javax.xml.bind.Validator
   42    * @see javax.xml.bind.ValidationEventHandler
   43    * @see javax.xml.bind.ValidationEvent
   44    * @see javax.xml.bind.ValidationEventLocator
   45    * @since JAXB1.0
   46    */
   47   public class ValidationEventImpl implements ValidationEvent
   48   {
   49   
   50       /**
   51        * Create a new ValidationEventImpl.
   52        *
   53        * @param _severity The severity value for this event.  Must be one of
   54        * ValidationEvent.WARNING, ValidationEvent.ERROR, or
   55        * ValidationEvent.FATAL_ERROR
   56        * @param _message The text message for this event - may be null.
   57        * @param _locator The locator object for this event - may be null.
   58        * @throws IllegalArgumentException if an illegal severity field is supplied
   59        */
   60       public ValidationEventImpl( int _severity, String _message,
   61                                    ValidationEventLocator _locator ) {
   62   
   63           this(_severity,_message,_locator,null);
   64       }
   65   
   66       /**
   67        * Create a new ValidationEventImpl.
   68        *
   69        * @param _severity The severity value for this event.  Must be one of
   70        * ValidationEvent.WARNING, ValidationEvent.ERROR, or
   71        * ValidationEvent.FATAL_ERROR
   72        * @param _message The text message for this event - may be null.
   73        * @param _locator The locator object for this event - may be null.
   74        * @param _linkedException An optional linked exception that may provide
   75        * additional information about the event - may be null.
   76        * @throws IllegalArgumentException if an illegal severity field is supplied
   77        */
   78       public ValidationEventImpl( int _severity, String _message,
   79                                    ValidationEventLocator _locator,
   80                                    Throwable _linkedException ) {
   81   
   82           setSeverity( _severity );
   83           this.message = _message;
   84           this.locator = _locator;
   85           this.linkedException = _linkedException;
   86       }
   87   
   88       private int severity;
   89       private String message;
   90       private Throwable linkedException;
   91       private ValidationEventLocator locator;
   92   
   93       public int getSeverity() {
   94           return severity;
   95       }
   96   
   97   
   98       /**
   99        * Set the severity field of this event.
  100        *
  101        * @param _severity Must be one of ValidationEvent.WARNING,
  102        * ValidationEvent.ERROR, or ValidationEvent.FATAL_ERROR.
  103        * @throws IllegalArgumentException if an illegal severity field is supplied
  104        */
  105       public void setSeverity( int _severity ) {
  106   
  107           if( _severity != ValidationEvent.WARNING &&
  108               _severity != ValidationEvent.ERROR &&
  109               _severity != ValidationEvent.FATAL_ERROR ) {
  110                   throw new IllegalArgumentException(
  111                       Messages.format( Messages.ILLEGAL_SEVERITY ) );
  112           }
  113   
  114           this.severity = _severity;
  115       }
  116   
  117       public String getMessage() {
  118           return message;
  119       }
  120       /**
  121        * Set the message field of this event.
  122        *
  123        * @param _message String message - may be null.
  124        */
  125       public void setMessage( String _message ) {
  126           this.message = _message;
  127       }
  128   
  129       public Throwable getLinkedException() {
  130           return linkedException;
  131       }
  132       /**
  133        * Set the linked exception field of this event.
  134        *
  135        * @param _linkedException Optional linked exception - may be null.
  136        */
  137       public void setLinkedException( Throwable _linkedException ) {
  138           this.linkedException = _linkedException;
  139       }
  140   
  141       public ValidationEventLocator getLocator() {
  142           return locator;
  143       }
  144       /**
  145        * Set the locator object for this event.
  146        *
  147        * @param _locator The locator - may be null.
  148        */
  149       public void setLocator( ValidationEventLocator _locator ) {
  150           this.locator = _locator;
  151       }
  152   
  153       /**
  154        * Returns a string representation of this object in a format
  155        * helpful to debugging.
  156        *
  157        * @see Object#equals(Object)
  158        */
  159       public String toString() {
  160           String s;
  161           switch(getSeverity()) {
  162           case WARNING:   s="WARNING";break;
  163           case ERROR: s="ERROR";break;
  164           case FATAL_ERROR: s="FATAL_ERROR";break;
  165           default: s=String.valueOf(getSeverity());break;
  166           }
  167           return MessageFormat.format("[severity={0},message={1},locator={2}]",
  168               new Object[]{
  169                   s,
  170                   getMessage(),
  171                   getLocator()
  172               });
  173       }
  174   }

Save This Page
Home » openjdk-7 » javax » xml » bind » helpers » [javadoc | source]