Save This Page
Home » jdo2-model-2.3-ea-src » org.apache.jdo.model » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    * 
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    * Unless required by applicable law or agreed to in writing, software 
   12    * distributed under the License is distributed on an "AS IS" BASIS, 
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
   14    * See the License for the specific language governing permissions and 
   15    * limitations under the License.
   16    */
   17   
   18   package org.apache.jdo.model;
   19   
   20   import org.apache.jdo.util.I18NHelper;
   21   
   22   /**
   23    * This exception indicates a problem during model validation.
   24    *
   25    * @author Michael Bouschen
   26    * @since JDO 1.0.1
   27    */
   28   public class ModelValidationException 
   29       extends ModelException
   30   {
   31   	/** Constant representing an error. */
   32   	public static final int ERROR = 0;
   33   
   34   	/** Constant representing a warning. */
   35   	public static final int WARNING = 1;
   36   
   37   	/** 
   38        * This field holds the type -- one of {@link #ERROR} or {@link #WARNING}
   39   	 */
   40   	private int type;
   41   
   42   	/** 
   43        * This field holds the offending object -- the one being validated 
   44   	 * when the problem occurred
   45   	 */
   46   	private Object offendingObject;
   47   
   48       /** I18N support */
   49       private static I18NHelper msg = 
   50           I18NHelper.getInstance(ModelValidationException.class);
   51   
   52       /**
   53        * Creates new <code>ModelValidationException</code> of type 
   54        * {@link #ERROR} with <code>null</code> as the offending object and
   55        * no detail message.
   56        */
   57       public ModelValidationException() 
   58       {
   59          this(ERROR, null, null); 
   60       }
   61       
   62       /**
   63        * Constructs a <code>ModelValidationException</code> of type 
   64        * {@link #ERROR} with <code>null</code> as the offending object and
   65        * with the specified detail message. 
   66        * @param message the detail message.
   67        */
   68       public ModelValidationException(String message)
   69       {
   70           this(ERROR, null, message);
   71       }
   72   
   73   	/**
   74   	 * Constructs a <code>ModelValidationException</code> of type 
   75   	 * {@link #ERROR} with the specified offending object and no 
   76   	 * detail message.
   77   	 * @param offendingObject the offending object.
   78   	 */
   79   	public ModelValidationException (Object offendingObject)
   80   	{
   81   		this(ERROR, offendingObject, null);
   82   	}
   83   
   84   	/**
   85   	 * Constructs a <code>ModelValidationException</code> of type 
   86   	 * {@link #ERROR} with the specified offending object and detail
   87        * message .
   88   	 * @param offendingObject the offending object.
   89   	 * @param message the detail message.
   90   	 */
   91   	public ModelValidationException (Object offendingObject, String message)
   92   	{
   93   		this(ERROR, offendingObject, message);
   94   	}
   95   
   96   	/**
   97   	 * Constructs a <code>ModelValidationException</code> of the specified 
   98   	 * type with the specified detail message and offending object. 
   99   	 * @param errorType the type -- one of {@link #ERROR} or 
  100        * {@link #WARNING}. 
  101   	 * @param offendingObject the offending object.
  102   	 * @param message the detail message.
  103   	 */
  104   	public ModelValidationException(int errorType, Object offendingObject,
  105                                       String message)
  106   	{
  107   		super(message);
  108   		this.type = errorType;
  109   		this.offendingObject = offendingObject;
  110   	}
  111   
  112   	/**
  113   	 * Get the offending object -- the one being validated when the problem 
  114   	 * occurred.
  115   	 */
  116   	public Object getOffendingObject () 
  117       { 
  118           return offendingObject; 
  119       }
  120   
  121   	/**
  122   	 * Get the type -- one of {@link #ERROR} or {@link #WARNING}.
  123   	 */
  124   	public int getType() 
  125       { 
  126           return type; 
  127       }
  128   
  129   	/**
  130   	* Returns the error message string of this throwable object.
  131   	* @return the error message string of this 
  132   	* <code>ModelValidationException</code>, prepended with the warning string 
  133   	* if the type is {@link #WARNING}
  134   	*
  135   	*/
  136   	public String getMessage ()
  137   	{
  138   		String message = super.getMessage();
  139   		if ((WARNING == getType()) && 
  140               (message != null) && (message.length() > 0)) {
  141   			message	= msg.msg("MSG_OffendingObject") + message; //NOI18N
  142   		}
  143   		return message;
  144   	}
  145       /** 
  146        * The <code>String</code> representation includes the name of the class,
  147        * the descriptive comment (if any),
  148        * and the <code>String</code> representation of the cause (if any).
  149        * @return the <code>String</code>.
  150        */
  151       public String toString() 
  152       {
  153           StringBuffer sb = new StringBuffer();
  154           sb.append(super.toString());
  155           // include offending object information
  156           if (offendingObject != null) {
  157               sb.append("\n");  //NOI18N
  158               sb.append(msg.msg("MSG_OffendingObject"));  //NOI18N
  159               sb.append(offendingObject.toString());
  160           }
  161           return sb.toString();
  162       }
  163     
  164   }

Save This Page
Home » jdo2-model-2.3-ea-src » org.apache.jdo.model » [javadoc | source]