commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nicola...@apache.org
Subject cvs commit: jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/helpers/elementprocessor/types Attribute.java BooleanConverter.java BooleanResult.java NumericConverter.java NumericResult.java Validator.java
Date Thu, 25 Jul 2002 13:18:58 GMT
nicolaken    2002/07/25 06:18:58

  Added:       morphos/src/java/org/apache/commons/morphos/helpers/elementprocessor/types
                        Attribute.java BooleanConverter.java
                        BooleanResult.java NumericConverter.java
                        NumericResult.java Validator.java
  Log:
  Initial Morphos codebase, based on the discussions on commons-dev.
  Corrently the Factories and pipelining are not yet done, although there are
  already the interfaces.
  The main class, Morphos, currently uses the HSSFMorpher hardcoded.
  The only Morpher supplied is the HSSFMorpher.
  To try, run
    ant examples
  and look in the build directory.
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/helpers/elementprocessor/types/Attribute.java
  
  Index: Attribute.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.commons.morphos.helpers.elementprocessor.types;
  
  /**
   * Encapsulation of a single XML element attribute in a way that
   * shields the consumer from the data's XML origins.
   *
   * @author Marc Johnson (marc_johnson27591@hotmail.com)
   */
  
  public class Attribute
  {
      private String _name;
      private String _value;
  
      /**
       * Constructor
       *
       * @param name the name of the Attribute, the left hand side of
       *             the '=' of an XML element's attribute.
       * @param value the value of the Attribute, the right hand side of
       *              the '=' of an XML element's attribute.
       *
       * @exception IllegalArgumentException is thrown if name is null
       *            or empty, or if value is null.
       */
  
      public Attribute(final String name, final String value)
      {
          if ((name == null) || (name.length() == 0))
          {
              throw new IllegalArgumentException(
                  "Attribute name is null or empty");
          }
          if (value == null)
          {
              throw new IllegalArgumentException("Attribute value is null");
          }
          _name  = name;
          _value = value;
      }
  
      /**
       * Get the name of the Attribute.
       *
       * @return the name of the Attribute
       */
  
      public String getName()
      {
          return _name;
      }
  
      /**
       *  Get the value of the Attribute as a String.
       *
       * @return the value of the Attribute as a String
       */
  
      public String getValue()
      {
          return _value;
      }
  
      /**
       * A convenience method to get the value of the Attribute as an
       * int.
       *
       * @return the value of the Attribute as an int
       *
       * @exception NumberFormatException if the value is not an int
       */
  
      public int getValueAsInt()
      {
          return Integer.parseInt(_value);
      }
  
      /**
       * A convenience method to get the value of the Attribute as a
       * short.
       *
       * @return the value of the Attribute as a short
       *
       * @exception NumberFormatException if the value is not a short
       */
  
      public short getValueAsShort()
      {
          return Short.parseShort(_value);
      }
  
      /**
       * A convenience method to get the value of the Attribute as a long.
       *
       * @return the value of the Attribute as a long
       *
       * @exception NumberFormatException if the value is not a long
       */
  
      public long getValueAsLong()
      {
          return Long.parseLong(_value);
      }
  
      /**
       * A convenience method to get the value of the attribute as a
       * boolean. Understands these value strings in a case-insensitive
       * fashion:
       * <ul>
       *     <li>t/f
       *     <li>true/false
       *     <li>y/n
       *     <li>yes/no
       * </ul>
       *
       * @return the value of the Attribute as a boolean
       *
       * @exception IllegalArgumentException if the value does not
       *            represent a boolean
       */
  
      public boolean getValueAsBoolean()
      {
          boolean rvalue = false;
  
          if (_value.equalsIgnoreCase("t") || _value.equalsIgnoreCase("y")
                  || _value.equalsIgnoreCase("yes")
                  || _value.equalsIgnoreCase("true"))
          {
              rvalue = true;
          }
          else if (_value.equalsIgnoreCase("f") || _value.equalsIgnoreCase("n")
                   || _value.equalsIgnoreCase("no")
                   || _value.equalsIgnoreCase("false"))
          {
              rvalue = false;
          }
          else
          {
              throw new IllegalArgumentException(
                  "Value [" + _value + "] does not represent a boolean value");
          }
          return rvalue;
      }
  }   // end public class Attribute
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/helpers/elementprocessor/types/BooleanConverter.java
  
  Index: BooleanConverter.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.commons.morphos.helpers.elementprocessor.types;
  
  import java.io.IOException;
  
  /**
   * This class knows how to convert strings into numbers, and also
   * knows how to check the results against certain criteria
   *
   * @author Marc Johnson (marc_johnson27591@hotmail.com)
   */
  
  public class BooleanConverter
  {
      private static final String        _true_values[]  =
      {
          "1", "true"
      };
      private static final String        _false_values[] =
      {
          "0", "false"
      };
      private static final BooleanResult _true_result    =
          new BooleanResult(true);
      private static final BooleanResult _false_result   =
          new BooleanResult(false);
  
      private BooleanConverter()
      {
      }
  
      /**
       * Given a string that is expected to hold a boolean, get the
       * boolean value.
       *
       * @param value the string holding the boolean
       *
       * @return a BooleanResult object containing either the boolean
       *         value or an exception generated if there was a problem
       *         with the value;
       */
  
      public static BooleanResult extractBoolean(final String value)
      {
          String        input  = (value == null) ? ""
                                                 : value.trim();
          BooleanResult result = null;
  
          for (int k = 0; k < _true_values.length; k++)
          {
              if (_true_values[ k ].equalsIgnoreCase(input))
              {
                  result = _true_result;
                  break;
              }
          }
          if (result == null)
          {
              for (int k = 0; k < _false_values.length; k++)
              {
                  if (_false_values[ k ].equalsIgnoreCase(input))
                  {
                      result = _false_result;
                      break;
                  }
              }
          }
          if (result == null)
          {
              result = new BooleanResult(
                  new IOException("\"" + input + "\" is not a boolean value"));
          }
          return result;
      }
  }   // end public class BooleanConverter
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/helpers/elementprocessor/types/BooleanResult.java
  
  Index: BooleanResult.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.commons.morphos.helpers.elementprocessor.types;
  
  import java.io.IOException;
  
  /**
   * This class holds the result of a boolean conversion. The result is
   * either a valid value, or an IOException that was created by the
   * boolean converter
   *
   * @author Marc Johnson (marc_johnson27591@hotmail.com)
   */
  
  public class BooleanResult
  {
      private boolean     _value;
      private IOException _exception;
  
      /**
       * Constructor; package scope, as only a boolean converter should
       * generate one of these
       *
       * @param value the boolean value
       */
  
      BooleanResult(final boolean value)
      {
          this();
          _value = value;
      }
  
      /**
       * Constructor; package scope, as only a boolean converter should
       * generate one of these
       *
       * @param exception the exception to be thrown
       */
  
      BooleanResult(final IOException exception)
      {
          this();
          _exception = exception;
      }
  
      private BooleanResult()
      {
          _value     = false;
          _exception = null;
      }
  
      /**
       * Get the value as a boolean
       *
       * @return the value as a boolean
       *
       * @exception IOException if there was a problem converting the
       *            value
       */
  
      public boolean booleanValue()
          throws IOException
      {
          if (_exception != null)
          {
              throw _exception;
          }
          return _value;
      }
  }   // end public class BooleanResult
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/helpers/elementprocessor/types/NumericConverter.java
  
  Index: NumericConverter.java
  ===================================================================
  
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.commons.morphos.helpers.elementprocessor.types;
  
  import java.io.IOException;
  
  /**
   * This class knows how to convert strings into numbers, and also
   * knows how to check the results against certain criteria
   *
   * @author Marc Johnson (marc_johnson27591@hotmail.com)
   */
  
  public class NumericConverter
  {
      private static final Validator _non_negative_validator = new Validator()
      {
          public IOException validate(final Number number)
          {
              IOException e = null;
  
              if (number.intValue() < 0)
              {
                  e = new IOException("\"" + number.intValue()
                                      + "\" is not a non-negative integer");
              }
              return e;
          }
      };
      private static final Validator _positive_validator = new Validator()
      {
          public IOException validate(final Number number)
          {
              IOException e = null;
  
              if (number.intValue() < 1)
              {
                  e = new IOException("\"" + number.intValue()
                                      + "\" is not a positive integer");
              }
              return e;
          }
      };
  
      private NumericConverter()
      {
      }
  
      /**
       * Shortcut for extractDouble without a Validator
       *
       * @param value the string holding the double
       * @param validator a Validator object; if null, no additional
       *                  validation will be performed
       *
       * @return a NumericResult object containing either the double
       *         value or an exception generated if there was a problem
       *         with the value;
       */
  
      public static NumericResult extractDouble(final String value)
      {
          return extractDouble(value, null);
      }
  
      /**
       * Given a string that is expected to hold a double, get the double value.
       *
       * @param value the string holding the double
       * @param validator a Validator object; if null, no additional
       *                  validation will be performed
       *
       * @return a NumericResult object containing either the double
       *         value or an exception generated if there was a problem
       *         with the value;
       */
  
      public static NumericResult extractDouble(final String value,
                                                final Validator validator)
      {
          String        input  = (value == null) ? ""
                                                 : value.trim();
          NumericResult result = null;
  
          try
          {
              Number      number    = new Double(input);
              IOException exception = null;
  
              if (validator != null)
              {
                  exception = validator.validate(number);
              }
              if (exception == null)
              {
                  result = new NumericResult(number);
              }
              else
              {
                  result = new NumericResult(exception);
              }
          }
          catch (NumberFormatException ignored)
          {
              result = new NumericResult(
                  new IOException(
                      "\"" + input + "\" does not represent a double value"));
          }
          return result;
      }
  
      /**
       * Shortcut for extractInteger without a Validator
       *
       * @param value the string holding the integer
       * @param validator a Validator object; if null, no additional
       *                  validation will be performed
       *
       * @return a NumericResult object containing either the integer
       *         value or an exception generated if there was a problem
       *         with the value;
       */
  
      public static NumericResult extractInteger(final String value)
      {
          return extractInteger(value, null);
      }
  
      /**
       * Given a string that is expected to hold a integer, get the integer value.
       *
       * @param value the string holding the integer
       * @param validator a Validator object; if null, no additional
       *                  validation will be performed
       *
       * @return a NumericResult object containing either the integer
       *         value or an exception generated if there was a problem
       *         with the value;
       */
  
      public static NumericResult extractInteger(final String value,
                                                 final Validator validator)
      {
          String        input  = (value == null) ? ""
                                                 : value.trim();
          NumericResult result = null;
  
          try
          {
              Number      number    = new Integer(input);
              IOException exception = null;
  
              if (validator != null)
              {
                  exception = validator.validate(number);
              }
              if (exception == null)
              {
                  result = new NumericResult(number);
              }
              else
              {
                  result = new NumericResult(exception);
              }
          }
          catch (NumberFormatException ignored)
          {
              result = new NumericResult(
                  new IOException(
                      "\"" + input + "\" does not represent an integer value"));
          }
          return result;
      }
  
      /**
       * extract a positive integer (i.e., an integer with a range of 1
       * ... MAX_VALUE)
       *
       * @param value the string holding the value
       *
       * @return a NumericResult object containing either the integer
       *         value or an exception generated if there was a problem
       *         with the value;
       */
  
      public static NumericResult extractPositiveInteger(final String value)
      {
          return extractInteger(value, _positive_validator);
      }
  
      /**
       * extract a non-negative integer (i.e., an integer with a range
       * of 1 ... MAX_VALUE)
       *
       * @param value the string holding the value
       *
       * @return a NumericResult object containing either the integer
       *         value or an exception generated if there was a problem
       *         with the value;
       */
  
      public static NumericResult extractNonNegativeInteger(final String value)
      {
          return extractInteger(value, _non_negative_validator);
      }
  }   // end public class NumericConverter
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/helpers/elementprocessor/types/NumericResult.java
  
  Index: NumericResult.java
  ===================================================================
  
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.commons.morphos.helpers.elementprocessor.types;
  
  import java.io.IOException;
  
  /**
   * This class holds the result of a numeric conversion. The result is
   * either a valid value, or an IOException that was created by the
   * numeric converter
   *
   * @author Marc Johnson (marc_johnson27591@hotmail.com)
   */
  
  public class NumericResult
  {
      private Number      _value;
      private IOException _exception;
  
      /**
       * Constructor
       *
       * @param value the numeric value
       */
  
      public NumericResult(final Number value)
      {
          this();
          _value = value;
      }
  
      /**
       * Constructor
       *
       * @param exception the exception to be thrown
       */
  
      public NumericResult(final IOException exception)
      {
          this();
          _exception = exception;
      }
  
      private NumericResult()
      {
          _value     = null;
          _exception = null;
      }
  
      /**
       * Get the value, if possible, as an int
       *
       * @return the value, as an int
       *
       * @exception IOException if there was a problem converting the
       *            number
       */
  
      public int intValue()
          throws IOException
      {
          return value().intValue();
      }
  
      /**
       * Get the value, if possible, as a double
       *
       * @return the value, as a double
       *
       * @exception IOException if there was a problem converting the
       *            number
       */
  
      public double doubleValue()
          throws IOException
      {
          return value().doubleValue();
      }
  
      private Number value()
          throws IOException
      {
          if (_exception != null)
          {
              throw _exception;
          }
          return _value;
      }
  }   // end public class NumericResult
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/helpers/elementprocessor/types/Validator.java
  
  Index: Validator.java
  ===================================================================
  
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.commons.morphos.helpers.elementprocessor.types;
  
  import java.io.IOException;
  
  /**
   * This interface allows a client of NumericConverter to apply more
   * restrictive rules to the number that the NumericConverter obtained.
   *
   * @author Marc Johnson (marc_johnson27591@hotmail.com)
   */
  
  public interface Validator
  {
  
      /**
       * Is this number valid? If so, return a null
       * IOException. Otherwise, return an IOException whose message
       * explains why the number is not valid.
       *
       * @param number the Number holding the value. Guaranteed non-null
       *
       * @return a null IOException if the value is ok, else a real
       *         IOException
       */
  
      public IOException validate(final Number number);
  }   // end public interface Validator
  
  
  

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


Mime
View raw message