juergen     02/03/14 22:12:13

  Added:       src/webdav/server/org/apache/slide/webdav/util
                        ViolatedPrecondition.java
  Log:
  Initial revision.
  (ralf)
  
  Revision  Changes    Path
  1.1                  
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/ViolatedPrecondition.java
  
  Index: ViolatedPrecondition.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/ViolatedPrecondition.java,v
 1.1 2002/03/15 06:12:13 juergen Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/15 06:12:13 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  package org.apache.slide.webdav.util;
  
  // import list
  import org.apache.util.WebdavStatus;
  
  /**
   * This class encapsulates the status code and name of the precondition
   * that has been violated.
   *
   * @version $Revision: 1.1 $
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Ralf Stuckert</a>
   **/
  public class ViolatedPrecondition {
  
      /**
       * String constant for the message of the IllegalArgumentException
       * that might be thrown in {@link #ViolatedPrecondition the constructor}
       * if the parameter <code>precondition</code> is <code>null</code>.
       */
      public static final String PRECONDITION_MUST_NOT_BE_NULL = "Parameter 
'precondition' must not be null";
      
      /**
       * String constant for the message returned by method
       * {@link #getInvalidStatusCodeMessage getInvalidStatusCodeMessage()}.
       */
      private static final String INVALID_STATUS_CODE = "Status code must be eiter 404 
(Forbidden) or 409 (Conflict), but is: ";
      
      
      /**
       * The status of the violated precondition.
       * Must be either <code>403 (Forbidden)</code> or
       * <code>409 (Conflict)</code>.
       */
      protected int statusCode = WebdavStatus.SC_FORBIDDEN;
      
      /**
       * The precondition that has been violated.
       */
      protected String precondition = null;
  
      
      /**
       * Creates a ViolatedPrecondition.
       *
       * @pre      precondition != null
       * @pre      (statusCode == 403) || (statusCode == 409)
       *
       * @param      precondition  the name of the violated precondition. Must not
       *                           be <code>null</code>.
       * @param      statusCode    the status of the violated precondition.
       *                           Must be either <code>403 (Forbidden)</code> or
       *                           <code>409 (Conflict)</code>.
       *
       * @throws IllegalArgumentException if the <code>precondition</code> is
       *                                  <code>null</code>, or if the parameter
       *                                  <code>statusCode</code> is neither
       *                                  <code>403 (Forbidden)</code>
       *                                  nor <code>409 (Conflict)</code>.
       */
      public ViolatedPrecondition(String precondition, int statusCode) {
          
          if (precondition == null) {
              throw new IllegalArgumentException(PRECONDITION_MUST_NOT_BE_NULL);
          }
          
          if ( (statusCode != WebdavStatus.SC_FORBIDDEN) && (statusCode != 
WebdavStatus.SC_CONFLICT) ) {
              throw new 
IllegalArgumentException(getInvalidStatusCodeMessage(statusCode));
          }
  
          this.precondition = precondition;
          this.statusCode = statusCode;
      }
      
      /**
       * Returns the name of the violated precondition.
       *
       * @return     the name of the violated precondition.
       */
      public String getPrecondition() {
          return precondition;
      }
      
      /**
       * Returns the status of the violated precondition.
       *
       * @return     the status of the violated precondition.
       */
      public int getStatusCode() {
          return statusCode;
      }
      
      /**
       * Returns the message for the message of the IllegalArgumentException
       * that might be thrown in {@link #ViolatedPrecondition the constructor}
       * if the parameter <code>statusCode</code> is neither <code>403 
(Forbidden)</code>
       * nor <code>409 (Conflict)</code>.
       *
       * @param      actualStatusCode  the actual status code.
       *
       * @return     the message for the IllegalArgumentException.
       */
      public static String getInvalidStatusCodeMessage(int actualStatusCode) {
          return INVALID_STATUS_CODE + actualStatusCode;
      }
  }
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to