You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2001/03/09 12:38:13 UTC

cvs commit: jakarta-turbine/src/java/org/apache/turbine/services/intake/xmlmodel AppData.java Rule.java XmlField.java XmlGroup.java

jmcnally    01/03/09 03:38:13

  Added:       src/java/org/apache/turbine/services/intake
                        IntakePullSystem.java IntakeService.java
                        Retrievable.java TurbineIntake.java
                        TurbineIntakeService.java
               src/java/org/apache/turbine/services/intake/model
                        BigDecimalField.java Field.java FieldFactory.java
                        Group.java IntakeValue.java IntakeValueMapWrap.java
                        IntegerField.java StringField.java
               src/java/org/apache/turbine/services/intake/transform
                        DTDResolver.java XmlToAppData.java
               src/java/org/apache/turbine/services/intake/xmlmodel
                        AppData.java Rule.java XmlField.java XmlGroup.java
  Log:
  preliminary intake service.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/IntakePullSystem.java
  
  Index: IntakePullSystem.java
  ===================================================================
  package org.apache.turbine.services.intake;
  
  // JDK classes
  import java.util.*;
  
  // Turbine classes
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.StringUtils;
  import org.apache.turbine.util.ParameterParser;
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.services.intake.model.*;
  
  public class IntakePullSystem 
  {
      private RunData data;
      private HashMap groups;
  
      public IntakePullSystem(RunData data)
      {
          this.data = data;
          groups = new HashMap();
      }
  
      public Group get(String groupName)
          throws Exception
      {
          return get(groupName, Group.NEW);
      }
  
      public Group get(String groupName, String key)
          throws Exception
      {
          Group g = null;
  
          String inputKey = TurbineIntake.getGroupKey(groupName) + key;
          if ( groups.containsKey(inputKey)) 
          {
              g = (Group)groups.get(inputKey);
          }
          else 
          {
              g = TurbineIntake.getInstance(groupName)
                  .init(key, data.getParameters()); 
              groups.put(inputKey, g);
          }
  
          return g;
      }
  
      public void releaseGroups()
      {
          Iterator iter = groups.values().iterator();
          while ( iter.hasNext() ) 
          {
              Group g = (Group)iter.next();
              TurbineIntake.putInstance(g);
          }
          groups = null;
      }
  }
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/IntakeService.java
  
  Index: IntakeService.java
  ===================================================================
  package org.apache.turbine.services.intake;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.util.pool.Recyclable;
  import org.apache.turbine.services.intake.xmlmodel.*;
  import org.apache.turbine.services.intake.model.*;
  
  /**
   * This service provides access to input processing objects based
   * on an XML specification.
   * 
   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
   * @version $Id: IntakeService.java,v 1.1 2001/03/09 11:38:05 jmcnally Exp $
   */
  public interface IntakeService
  {
      /**
       * The key under which this service is stored in TurbineServices.
       */
      public static final String SERVICE_NAME = "IntakeService";
  
      /**
       * The property specifying the location of the xml specification.
       */
      public static final String XML_PATH = "xml.path";
  
      /**
       * The default pool capacity.
       */
      public static final int DEFAULT_POOL_CAPACITY = 1024;
  
      /**
       * Gets an instance of a specified group either from the pool
       * or by instatiating a Group if the pool is empty.
       *
       * @param groupName the group.
       * @return the instance.
       * @throws TurbineException if recycling fails.
       */
      public Group getInstance(String groupName)
          throws Exception;
  
      /**
       * Puts a group back to the pool.
       * @param instance the object instance to recycle.
       * @return true if the instance was accepted.
       */
      public boolean putInstance(Group instance);
  
      /**
       * Gets the capacity of the pool for a named group.
       *
       * @param groupName the name of the group.
       */
      public int getCapacity(String groupName);
  
      /**
       * Sets the capacity of the pool for a named group.
       * Note that the pool will be cleared after the change.
       *
       * @param groupName the name of the group.
       * @param capacity the new capacity.
       */
      public void setCapacity(String groupName,
                              int capacity);
  
      /**
       * Gets the current size of the pool for a named group.
       *
       * @param groupName the name of the group.
       */
      public int getSize(String groupName);
  
      /**
       * Clears instances of a named group from the pool.
       *
       * @param groupName the name of the group.
       */
      public void clearPool(String groupName);
  
      /**
       * Clears all instances from the pool.
       */
      public void clearPool();
  
      /**
       * Gets the key (usually a short identifier) for a group.
       *
       * @param groupName the name of the group.
       * @return the the key.
       */
      public String getGroupKey(String groupName);
  
      /**
       * Gets an object associated with the fields in a group.
       *
       * @param groupName the name of the group.
       * @return the Retrievable object.
       */
      public Retrievable getRetrievableObject(String groupName);
  }
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/Retrievable.java
  
  Index: Retrievable.java
  ===================================================================
  package org.apache.turbine.services.intake;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  // Java Core Classes
  import java.io.*;
  
  /**
   * This interface marks a class that has a retrieve(String) method.
   *
   * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
   * @version $Id: Retrievable.java,v 1.1 2001/03/09 11:38:05 jmcnally Exp $
   */
  public interface Retrievable
  {
      /**
       * Gets an object of the same type as the object implementing
       * this method according to the key.
       *
       * @return the object that matches the key
       */
      public Object retrieve(String key);
  }
  
  
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/TurbineIntake.java
  
  Index: TurbineIntake.java
  ===================================================================
  package org.apache.turbine.services.intake;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  // Turbine Stuff
  import org.apache.turbine.services.TurbineServices;
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.services.intake.xmlmodel.*;
  import org.apache.turbine.services.intake.model.*;
  
  /**
   * This is a Facade class for IntakeService.
   *
   * This class provides static methods that call related methods of the 
   * implementation of the IntakeService used by the System, according to
   * the settings in TurbineResources.
   *
   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
   * @version $Id: TurbineIntake.java,v 1.1 2001/03/09 11:38:05 jmcnally Exp $
   */
  public abstract class TurbineIntake
  {
      /**
       * Gets an instance of a specified group either from the pool
       * or by instatiating a Group if the pool is empty.
       *
       * @param groupName the group.
       * @return the instance.
       * @throws TurbineException if recycling fails.
       */
      public static Group getInstance(String groupName)
          throws Exception
      {
          return getService().getInstance(groupName);
      }
  
      /**
       * Puts a group back to the pool.
       * @param instance the object instance to recycle.
       * @return true if the instance was accepted.
       */
      public static boolean putInstance(Group instance)
      {
          return getService().putInstance(instance);
      }
  
      /**
       * Gets the capacity of the pool for a named group.
       *
       * @param groupName the name of the group.
       */
      public static int getCapacity(String groupName)
      {
          return getService().getCapacity(groupName);
      }
  
      /**
       * Sets the capacity of the pool for a named group.
       * Note that the pool will be cleared after the change.
       *
       * @param groupName the name of the group.
       * @param capacity the new capacity.
       */
      public static void setCapacity(String groupName, int capacity)
      {
          getService().setCapacity(groupName, capacity);
      }
  
      /**
       * Gets the current size of the pool for a named group.
       *
       * @param groupName the name of the group.
       */
      public static int getSize(String groupName)
      {
          return getService().getSize(groupName);
      }
  
      /**
       * Clears instances of a named group from the pool.
       *
       * @param groupName the name of the group.
       */
      public static void clearPool(String groupName)
      {
          getService().clearPool(groupName);
      }
  
      /**
       * Clears all instances from the pool.
       */
      public static void clearPool()
      {
          getService().clearPool();
      }
  
      /**
       * Gets the key (usually a short identifier) for a group.
       *
       * @param groupName the name of the group.
       * @return the the key.
       */
      public static String getGroupKey(String groupName)
      {
          return getService().getGroupKey(groupName);
      }
  
      /**
       * Gets an object associated with the fields in a group.
       *
       * @param groupName the name of the group.
       * @return the Retrievable object.
       */
      public static Retrievable getRetrievableObject(String groupName)
      {
          return getService().getRetrievableObject(groupName);
      }
  
      /**
       * Utility method for accessing the service 
       * implementation
       *
       * @return a IntakeService implementation instance
       */
      private static IntakeService getService()
      {
          return (IntakeService)TurbineServices
              .getInstance().getService(IntakeService.SERVICE_NAME);
      }
      
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/TurbineIntakeService.java
  
  Index: TurbineIntakeService.java
  ===================================================================
  package org.apache.turbine.services.intake;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  // Java Core Classes
  import java.io.*;
  import java.util.*;
  import javax.servlet.*;
  
  // Turbine Utility Classes
  import org.apache.turbine.services.*;
  import org.apache.turbine.services.resources.TurbineResources;
  import org.apache.turbine.util.*;
  import org.apache.turbine.util.pool.*;
  import org.apache.turbine.services.intake.xmlmodel.*;
  import org.apache.turbine.services.intake.model.*;
  import org.apache.turbine.services.intake.transform.*;
  
  /**
   * This service provides access to input processing objects based
   * on an XML specification.
   * 
   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
   * @version $Id: TurbineIntakeService.java,v 1.1 2001/03/09 11:38:05 jmcnally Exp $
   */
  public class TurbineIntakeService
      extends TurbineBaseService
      implements IntakeService
  {
      private static final String XML_PATH = "xmlpath";
  
      /** The cache of groups. **/
      private Map groupKeyMap;
  
      /** A cache of Retrievable objects, used by Fields to load values */
      private Map objectMap;
  
      /** The top element of the object tree */
      private AppData appData;
  
      /**
       * The pool repository, one pool for each class.
       */
      private HashMap poolRepository = new HashMap();
  
      /**
       * Constructor.
       */
      public TurbineIntakeService()
      {
      }
  
      /**
       * Called the first time the Service is used.
       *
       * @param config A ServletConfig.
       */
      public void init(ServletConfig config)
          throws InitializationException
      {
          Properties props = getProperties();
          
          try
          {
              String xmlPath = props.getProperty(XML_PATH);
  
              // If possible, transform paths to be webapp root relative.
              xmlPath = ServletUtils.expandRelative(
                  config, xmlPath);
  
              XmlToAppData xmlApp = new XmlToAppData();
              appData = xmlApp.parseFile(xmlPath);
  
              groupKeyMap = new HashMap();
              objectMap = new HashMap();
              String pkg = appData.getBasePackage();
  
              Iterator iter = appData.getGroups().iterator();            
              while ( iter.hasNext() ) 
              {
                  XmlGroup g = (XmlGroup)iter.next();
                  groupKeyMap.put(g.getName(), g.getKey());
  
                  List classNames = g.getMapToObjects();
                  Iterator iter2 = classNames.iterator();
                  while (iter2.hasNext()) 
                  {
                      String className = (String)iter2.next();
                      if ( !objectMap.containsKey(className) ) 
                      {
                          Retrievable obj = (Retrievable)
                              Class.forName(pkg + className).newInstance();
                          objectMap.put(className, obj);
                      }
                  }
              }
  
              setInit(true);
          }
          catch (Exception e)
          {
              throw new InitializationException(
                  "TurbineIntakeService failed to initialize", e);
          }
      }
  
      /**
       * An inner class for group specific pools.
       */
      private class PoolBuffer
      {
          /**
           * A buffer for class instances.
           */
          private BoundedBuffer pool;
  
          /**
           * A cache for recycling methods.
           */
          private HashMap recyclers;
  
          /**
           * Contructs a new pool buffer with a specific capacity.
           *
           * @param capacity a capacity.
           */
          public PoolBuffer(int capacity)
          {
              pool = new BoundedBuffer(capacity);
          }
  
          /**
           * Polls for an instance from the pool.
           *
           * @return an instance or null.
           */
          public Group poll()
              throws TurbineException
          {
              Group instance = (Group)pool.poll();
              if ((instance != null) &&
                  (instance instanceof Recyclable))
              {
                  try
                  {
                      ((Recyclable) instance).recycle();
                  }
                  catch (Exception x)
                  {
                      throw new TurbineException("Recycling failed for " + 
                          instance.getClass().getName(),x);
                  }
              }
              return instance;
          }
  
          /**
           * Offers an instance to the pool.
           *
           * @param instance an instance.
           */
          public boolean offer(Group instance)
          {
              try
              {
                  ((Recyclable) instance).dispose();
              }
              catch (Exception x)
              {
                  return false;
              }
              return pool.offer(instance);
          }
  
          /**
           * Returns the capacity of the pool.
           *
           * @return the capacity.
           */
          public int capacity()
          {
              return pool.capacity();
          }
  
          /**
           * Returns the size of the pool.
           *
           * @return the size.
           */
          public int size()
          {
              return pool.size();
          }
      }
  
      /**
       * Gets an instance of a named group either from the pool
       * or by calling the Factory Service if the pool is empty.
       *
       * @param groupName the name of the group.
       * @return the instance.
       * @throws TurbineException if recycling fails.
       */
      public Group getInstance(String groupName)
          throws Exception
      {
          Group instance = (Group)pollInstance(groupName);
          return instance == null ?
              new Group( appData.getGroup(groupName) ) : instance;
      }
  
      /**
       * Puts a Group back to the pool.
       *
       * @param instance the object instance to recycle.
       * @return true if the instance was accepted.
       */
      public boolean putInstance(Group instance)
      {
          if (instance != null)
          {
              HashMap repository = poolRepository;
              String name = instance.getName();
              PoolBuffer pool = (PoolBuffer) repository.get(name);
              if (pool == null)
              {
                  pool = new PoolBuffer(instance.getPoolCapacity());
                  repository = (HashMap) repository.clone();
                  repository.put(name,pool);
                  poolRepository = repository;
              }
              return pool.offer(instance);
          }
          else
              return false;
      }
  
      /**
       * Gets the capacity of the pool for a named group.
       *
       * @param name the name of the class.
       */
      public int getCapacity(String name)
      {
          int capacity = DEFAULT_POOL_CAPACITY;
          PoolBuffer pool = (PoolBuffer) poolRepository.get(name);
          if ( pool == null ) 
          {        
              try
              {
                  capacity = Integer
                      .parseInt(appData.getGroup(name).getPoolCapacity());
              }
              catch (NumberFormatException nfe) {}
          }
          else 
          {
              capacity = pool.capacity();
          }
          
          return capacity;
      }
  
      /**
       * Sets the capacity of the pool for a group.
       * Note that the pool will be cleared after the change.
       *
       * @param name the name of the group.
       * @param capacity the new capacity.
       */
      public void setCapacity(String name,
                              int capacity)
      {
          HashMap repository = poolRepository;
          repository = repository != null ?
              (HashMap) repository.clone() : new HashMap();
          repository.put(name,new PoolBuffer(capacity));
          poolRepository = repository;
      }
  
      /**
       * Gets the current size of the pool for a group.
       *
       * @param name the name of the group.
       */
      public int getSize(String name)
      {
          PoolBuffer pool = (PoolBuffer) poolRepository.get(name);
          return pool != null ? pool.size() : 0;
      }
  
      /**
       * Clears instances of a group from the pool.
       *
       * @param name the name of the group.
       */
      public void clearPool(String name)
      {
          throw new Error("Not implemented");
          /* FIXME!! We need to worry about objects that are checked out
  
          HashMap repository = poolRepository;
          if (repository.get(name) != null)
          {
              repository = (HashMap) repository.clone();
              repository.remove(name);
              poolRepository = repository;
          }
          */
      }
  
      /**
       * Clears all instances from the pool.
       */
      public void clearPool()
      {
          throw new Error("Not implemented");
          /* FIXME!! We need to worry about objects that are checked out
          poolRepository = new HashMap();
          */
      }
  
      /**
       * Polls and recycles an object of the named group from the pool.
       *
       * @param groupName the name of the group.
       * @return the object or null.
       * @throws TurbineException if recycling fails.
       */
      private Object pollInstance(String groupName)
          throws TurbineException
      {
          PoolBuffer pool = (PoolBuffer) poolRepository.get(groupName);
          return pool != null ? pool.poll() : null;
      }
  
      /**
       * Gets the key (usually a short identifier) for a group.
       *
       * @param groupName the name of the group.
       * @return the the key.
       */
      public String getGroupKey(String groupName)
      {
          return (String)groupKeyMap.get(groupName);
      }
  
      /**
       * Gets an object associated with the fields in a group.
       *
       * @param groupName the name of the group.
       * @return the Retrievable object.
       */
      public Retrievable getRetrievableObject(String groupName)
      {
          return (Retrievable)objectMap.get(groupName);
      }
  
  }
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/model/BigDecimalField.java
  
  Index: BigDecimalField.java
  ===================================================================
  package org.apache.turbine.services.intake.model;
  
  // JDK classes
  import java.util.*;
  import java.beans.*;
  import java.math.BigDecimal;
  
  import org.apache.regexp.RE;
  import org.apache.regexp.RESyntaxException;
  
  // Turbine classes
  import org.apache.turbine.om.*;
  import org.apache.turbine.util.ObjectUtils;
  import org.apache.turbine.util.StringUtils;
  import org.apache.turbine.util.ParameterParser;
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.services.intake.xmlmodel.*;
  
  
  /**  */
  public class BigDecimalField extends Field
  {
      protected final BigDecimal onError;
  
      protected final BigDecimal minValue;
      protected final String minValueMessage;
      protected final boolean minValueForce;
      protected final BigDecimal maxValue;
      protected final String maxValueMessage;
      protected final boolean maxValueForce;
  
      public BigDecimalField(XmlField field, Group group)
          throws RESyntaxException, ClassNotFoundException, 
                 IntrospectionException 
      {
          super(field, group);
          onError = new BigDecimal(field.getOnError());
          
          BigDecimal tmpMinValue = null;
          String tmpMinValueMessage = null;
          boolean tmpMinValueForce = false;
          BigDecimal tmpMaxValue = null;
          String tmpMaxValueMessage = null;
          boolean tmpMaxValueForce = false;
          for (int i=0; i<field.getRules().size(); i++) 
          {
              Rule rule = (Rule)field.getRules().get(i);
  
              if ( rule.getMinValue() != null )
              {
                  tmpMinValue = new BigDecimal(rule.getMinValue());
                  tmpMinValueMessage = rule.getMessage();
                  tmpMinValueForce = "force".equals(rule.getAction());
              }
  
              if ( rule.getMaxValue() != null )
              {
                  tmpMaxValue = new BigDecimal(rule.getMaxValue());
                  tmpMaxValueMessage = rule.getMessage();
                  tmpMaxValueForce = "force".equals(rule.getAction());
              }
          }  
          minValue = tmpMinValue;
          minValueMessage  = tmpMinValueMessage;
          minValueForce  = tmpMinValueForce;
          maxValue = tmpMaxValue;
          maxValueMessage  = tmpMaxValueMessage;
          maxValueForce  = tmpMaxValueForce;
      }
      
      /**
       * Compares request data with constraints and sets the valid flag.
       */
      protected void doValidate(ParameterParser pp)
      {
          if ( isMultiValued  ) 
          {
              String[] ss = pp.getStrings(getKey());
              BigDecimal[] ival = new BigDecimal[ss.length];
              for (int i=0; i<ss.length; i++) 
              {
                  ival[i] = checkString(ss[i]);
              }
              iv.setTestValue(ival);
          }
          else 
          {
              iv.setTestValue( checkString(pp.getString(getKey())) );
          }
      }
  
      /**
       * Compares request data with constraints and sets the valid flag.
       */
      private BigDecimal checkString(String val)
      {
          BigDecimal ival = onError;
          try
          {
              ival = new BigDecimal(val);
          }
          catch (NumberFormatException nfe)
          {
              valid_flag = false;
              ival = onError;
          }
  
          boolean b;
          if ( maxLength > 0 )
          {
              b = val.length() > maxLength; 
              if ( maxLengthForce  && b )
              {
                  val = val.substring(0, maxLength);
                  try
                  {
                      ival = new BigDecimal(val);
                  }
                  catch (NumberFormatException nfe)
                  {
                      valid_flag = false;
                      ival = onError;
                  }
              }
              else 
              {
                  valid_flag &= !b;
              }
              if (maxLengthMessage != null && b)
              {
                  message = maxLengthMessage;
              }
          }
  
          if ( minValue != null )
          {
              b = ival.compareTo(minValue) < 0;
              if ( minValueForce  && b )
              {
                  ival = minValue;
              }
              else 
              {
                  valid_flag &= !b;
              }
              if (minValueForce  && b)
              {
                  message = minValueMessage;
              } 
          }
  
          if ( maxValue != null  )
          {
              b = ival.compareTo(maxValue) > 0;
              if ( maxValueForce  && b )
              {
                  ival = maxValue;
              }
              else 
              {
                  valid_flag &= !b;
              }
              if (maxValueForce  && b)
              {
                  message = maxValueMessage;
              } 
          }
          return ival;
      }
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/model/Field.java
  
  Index: Field.java
  ===================================================================
  package org.apache.turbine.services.intake.model;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  // JDK classes
  import java.util.*;
  import java.beans.*;
  import java.lang.reflect.*;
  
  import org.apache.regexp.RE;
  import org.apache.regexp.RESyntaxException;
  
  // Turbine classes
  import org.apache.turbine.om.*;
  import org.apache.turbine.util.ObjectUtils;
  import org.apache.turbine.util.StringUtils;
  import org.apache.turbine.util.ParameterParser;
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.services.intake.xmlmodel.*;
  import org.apache.turbine.services.intake.*;
  
  /**
   * Base class for Intake generated input processing classes.
   *
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: Field.java,v 1.1 2001/03/09 11:38:08 jmcnally Exp $
   */
  public abstract class Field
  {
      protected final String name;
      protected final String key;
      protected final Retrievable mapToObject; 
      protected final Method getter;
      protected final Method setter;
  
      protected final RE regexp;
      protected final String regexpMessage; 
      protected final int minLength;
      protected final String minLengthMessage; 
      protected final int maxLength;
      protected final String maxLengthMessage; 
      protected final boolean maxLengthForce; 
      protected final String[] requires; 
      protected final String[] requiresMessage; 
      protected final boolean isMultiValued; 
  
      protected final Group group;
   
      protected boolean set_flag;
      protected boolean valid_flag;
      protected String message;
  
      protected IntakeValue iv;
  
      public Field(XmlField field, Group group)
          throws RESyntaxException, ClassNotFoundException,
                 IntrospectionException 
      {
          this.group = group;
          key = field.getKey();
          name = field.getName();
          isMultiValued  = field.isMultiValued();
  
          int requires_index = 0;
          for (int i=0; i<field.getRules().size(); i++) 
          {
              Rule rule = (Rule)field.getRules().get(i);
              if ( rule.getRequiresProp()!=null )
              {
                  requires_index++;
              }
          }
          requires = new String[requires_index]; 
          requiresMessage  = new String[requires_index];
          
          requires_index = 0;
          RE tmpRE = null;
          String tmpREMessage = null;
          int tmpMinLength = 0;
          String tmpMinLengthMessage = null;            
          int tmpMaxLength = 0;
          String tmpMaxLengthMessage = null;
          boolean tmpMaxLengthForce = false;
          for (int i=0; i<field.getRules().size(); i++) 
          {
              Rule rule = (Rule)field.getRules().get(i);
              
              if ( rule.getMask() != null ) 
              {
                  tmpRE = new RE(rule.getMask());            
                  tmpREMessage = rule.getMessage();
              }
  
              if ( rule.getMinLength() != null )
              {
                  tmpMinLength = Integer.parseInt(rule.getMinLength());
                  tmpMinLengthMessage = rule.getMessage();
              }
  
              if ( rule.getMaxLength() != null )
              {
                  tmpMaxLength = Integer.parseInt(rule.getMaxLength());
                  tmpMaxLengthMessage = rule.getMessage();
                  tmpMaxLengthForce = "force".equals(rule.getAction());
              }
  
              if ( field.getGroup()!=null && rule.getRequiresProp()!=null )
              {
                  requires[requires_index] = rule.getRequiresProp();
                  requiresMessage[requires_index] = rule.getMessage();
                  requires_index++;
              }
          }
          regexp = tmpRE;
          regexpMessage  = tmpREMessage;
          minLength = tmpMinLength;
          minLengthMessage  = tmpMinLengthMessage;
          maxLength = tmpMaxLength;
          maxLengthMessage  = tmpMaxLengthMessage;
          maxLengthForce  = tmpMaxLengthForce;
  
          iv = getNewIntakeValue(name);
          Retrievable tmpMapToObject = null;
          if ( field.getMapToObject() != null ) 
          {
              tmpMapToObject = TurbineIntake
                  .getRetrievableObject(field.getMapToObject());
          }
          mapToObject = tmpMapToObject;
  
          // Uses bean introspection to set writable properties of bean from
          // the parameters, where a (case-insensitive) name match between
          // the bean property and the parameter is looked for.
          PropertyDescriptor[] props = Introspector
              .getBeanInfo(mapToObject.getClass()).getPropertyDescriptors();
  
          Method tmpGetter = null;
          Method tmpSetter = null;
          String propName = field.getMapToProperty();
          for (int i=props.length-1; i>=0 ; i--)
          {
              if ( propName.equals(props[i].getName())) 
              {
                  tmpGetter = props[i].getReadMethod();
                  tmpSetter = props[i].getWriteMethod();
                  break;
              }
          }
          getter = tmpGetter;
          setter = tmpSetter;
      }
  
   
      public Field init(ParameterParser pp) //, User user)
      {
          valid_flag = true;
  
          /*
          IntakeValueMapWrap ivs = user.getTemp(IntakeValueMapWrap.KEY);
          if ( ivs == null )
          {
              ivs = new IntakeValueMapWrap();
              user.setTemp(IntakeValueMapWrap.KEY, ivs);
          }
          
          if (ivs.contains(key))
          {
              iv = ivs.get(key);
          }
          else 
          {
              iv = getNewIntakeValue(NAME);
              ivs.put(iv);
          }
          */
  
          
  
          if ( pp.containsKey(getKey()) )
          {
              set_flag = true;
              if (validate(pp))
              {
                  // iv.reconcileNotValid(pp);
              }
          }
          else
          {
              // iv.reconcileNotPresent();
          }
          return this;
      }
  
      protected IntakeValue getNewIntakeValue(String property)
      {
          return new IntakeValue(property, this);
      }
  
      /**
       * Get the key used to identify the field.
       * @return the query data key.
       */
      public String getKey()
      {
          if ( group == null ) 
          {
              return getKey();
          }
          else 
          {
              return group.getObjectKey() + getKey();
          }        
      }
      
      /**
       * Get the value of $field.Name.
       * @return value of $field.Name
       */
      public IntakeValue getValue() 
      {
          return iv;
      }
      
      public boolean isValid()
      {
          return valid_flag;
      }
  
      public boolean isSet()
      {
          return set_flag;
      }
  
      public String getMessage()
      {
          return message;
      }
  
      /**
       * Compares request data with constraints and sets the valid flag.
       */
      protected boolean validate(ParameterParser pp)
      {
          if ( isMultiValued  ) 
          {
              String[] ss = pp.getStrings(getKey());             
              for (int i=0; i<ss.length; i++) 
              {
                  checkString(ss[i]);
              }
          }
          else 
          {
              checkString(pp.getString(getKey()));             
          }
  
          if ( group != null && requires.length > 0 )
          {
              for (int i=0; i<requires.length; i++) 
              {
                  boolean b = pp.containsKey(((Field)group.get(requires[i]))
                                             .getKey());
                  valid_flag &= b;
                  if (requiresMessage[i] != null && !b)
                  {
                      message = requiresMessage[i];
                  }                 
              }
          }
  
          doValidate(pp);
          return valid_flag;
      }
  
      /**
       * Compares request data with constraints and sets the valid flag.
       * To be implemented in subclasses
       */
      protected abstract void doValidate(ParameterParser pp);
  
      /**
       * Compares request data with constraints and sets the valid flag.
       */
      private void checkString(String val)
      {
          boolean b;
          if ( regexp != null )
          {
              b = regexp.match(val);
              valid_flag &= b;
              if (regexpMessage  != null && !b)
              {
                  message = regexpMessage;
              } 
          }
  
          if ( minLength > 0 )
          {
              b = val.length() < minLength; 
              valid_flag &= !b;
              if (minLengthMessage  != null && b)
              {
                  message = minLengthMessage;
              } 
          }
  
      }
      
      public String toString()
      {
          return iv.toString();
      }
  
  }
  
      /* this stuff does not belong here delete it 
      public void getProperty($appData.BasePackage$field.MapToObject obj) 
      //    throws TurbineException
      {
              setValue(obj.get${field.MapToProperty}();
      }
  
      /* *
       * Calls a setter method on obj, if this field has been set.  Does not
       * check validity as it is assumed this will have been checked prior
       * to calling this method.
       * @exception throws a TurbineException if called and the input
       * was not valid.
       * /
      public void setProperty($appData.BasePackage$field.MapToObject obj) 
          throws TurbineException
      {
          if (!isValid()) 
          {
     	        throw new TurbineException(
                  "Attempted to assign an invalid input.");
          }
          if (isSet())
          {
              try
              {
                  obj.set${field.MapToProperty}(getValue());
              }
              catch ( Exception e)
              {
                  throw new TurbineException("An exception prevented the" +
                      " mapping to $appData.BasePackage$field.MapToObject", e);
              }
          }
      }
      */
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/model/FieldFactory.java
  
  Index: FieldFactory.java
  ===================================================================
  package org.apache.turbine.services.intake.model;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  
  // JDK classes
  import java.util.*;
  import java.beans.*;
  
  import org.apache.regexp.RE;
  import org.apache.regexp.RESyntaxException;
  
  // Turbine classes
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.services.intake.xmlmodel.*;
  
  
  /**
   * Creates Field objects.
   *
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: FieldFactory.java,v 1.1 2001/03/09 11:38:08 jmcnally Exp $
   */
  public abstract class FieldFactory
  {
      /**
       * Creates a Field object appropriate for the type specified
       * in the xml file.
       *
       * @param f a <code>XmlField</code> value
       * @return a <code>Field</code> value
       */
      public static final Field getInstance(XmlField f, Group g)
          throws RESyntaxException, ClassNotFoundException,
                 IntrospectionException, TurbineException
      {
          Field field = null;
          String type = f.getType();
  
          if ( type.equals("int") ) 
          {
              field = new IntegerField(f, g);
          }
          else if (f.getType().equals("String") 
                   || f.getType().equals("ComboKey")) 
          {
              field = new StringField(f, g);
          }
          else if (f.getType().equals("NumberKey")) 
          {
              field = new BigDecimalField(f, g);
          }
          else 
          {
              throw new TurbineException("Unsupported type: " + type);
          }
          
          return field;
      }
  }
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/model/Group.java
  
  Index: Group.java
  ===================================================================
  package org.apache.turbine.services.intake.model;
  
  // JDK classes
  import java.util.*;
  import java.beans.*;
  
  import org.apache.regexp.RESyntaxException;
  
  // Turbine classes
  import org.apache.turbine.util.ObjectUtils;
  import org.apache.turbine.util.StringUtils;
  import org.apache.turbine.util.ParameterParser;
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.services.intake.xmlmodel.*;
  import org.apache.turbine.services.intake.*;
  
  /** Holds a group of Fields */
  public class Group
  {
      public static final String NEW = "0";
      public final String cid;
      public final String name;
      public final int poolCapacity;
      public final Map fields;
      public final Field[] fieldsArray;
  
      protected String oid;
  
      public Group(XmlGroup group)
          throws RESyntaxException, ClassNotFoundException,
                 IntrospectionException, TurbineException
      {
          cid = group.getKey();
          name = group.getName();
          poolCapacity = Integer.parseInt(group.getPoolCapacity());
          
          List inputFields = group.getFields();
          int size = inputFields.size();
          fields = new HashMap((int)(1.25*size + 1));
          fieldsArray = new Field[size];
          for (int i=size-1; i>=0; i--) 
          {
              XmlField f = (XmlField)inputFields.get(i);
              Field field = FieldFactory.getInstance(f, this);
              fields.put(f.getName(), field);
              fieldsArray[i]= field;
          }
      } 
         
      public Group init(ParameterParser pp)
      {
          return init(NEW, pp);
      }
  
      public Group init(String oid, ParameterParser pp)
      {
          this.oid = oid;
          for (int i=fieldsArray.length-1; i>=0; i--) 
          {
              fieldsArray[i].init(pp);
          }
          return this;
      }
  
      public String getName()
      {
          return name;
      }
  
      public int getPoolCapacity()
      {
          return poolCapacity;
      }
  
      public String getCID()
      {
          return cid;
      }
  
      public String getObjectKey()
      {
          return cid + oid;
      }
  
      public ArrayList getObjects(ParameterParser pp)
          throws Exception
      {
          ArrayList objs = null;
          String[] oids = pp.getStrings(getCID());
          if (oids != null)
          {
              objs = new ArrayList(oids.length);
              for (int i=oids.length-1; i>=0; i--)
              {
                  objs.add( TurbineIntake.getInstance(name).init(oids[i], pp) );
              }
          }
          return objs;
      }  
      
      /**
       * Get the Field .
       * @return Field.
       */
      public Field get(String fieldName)
      {
          return (Field)fields.get(fieldName);
      }
  
      public boolean isAllValid()
      {
          boolean valid = true;
          for (int i=fieldsArray.length-1; i>=0; i--) 
          {
              valid &= fieldsArray[i].isValid();
          }
          return valid;
      }
  
      /**
       * Calls a setter methods on obj, for fields which have been set.
       * @exception throws up any Exceptions resulting from failure to 
       * check input validity.
       */
      public void setProperties(Object obj) 
          throws TurbineException
      {
          for (int i=fieldsArray.length-1; i>=0; i--) 
          {
              if (obj.getClass().equals(fieldsArray[i].mapToObject.getClass()))
              {
                  fieldsArray[i].getValue().setProperty(obj);
              }
          }
      }
  }
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/model/IntakeValue.java
  
  Index: IntakeValue.java
  ===================================================================
  package org.apache.turbine.services.intake.model;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  
  // JDK classes
  import java.util.HashMap;
  
  // Turbine classes
  import org.apache.turbine.services.intake.*;
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.util.Log;
  
  
  /**
   * This class is supposed to encapsulate the functionality for
   * dealing with a parameter value
   *
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: IntakeValue.java,v 1.1 2001/03/09 11:38:09 jmcnally Exp $
   */
  public final class IntakeValue
  {
      private static final String EMPTY = "";
      private Object validValue;
      private Object testValue;
      private String propertyName;
      private Field field;
      Object[] valArray;
      
      IntakeValue(String propertyName, Field field)
      {
          this.field = field;
          this.propertyName = propertyName;
          valArray = new Object[1];
      }
  
      void setValidValue(Object obj)
      {
          validValue = obj;
      }
  
      public Object getValidValue()
          throws Exception
      {
          if ( validValue == null) 
          {
              String key = field.group.oid;
              Object obj = field.mapToObject.retrieve(key);
              getProperty(obj);
          }
          
          return validValue;
      }
  
      void setTestValue(Object obj)
      {
          testValue = obj;
      }
  
      public Object getTestValue()
      {
          return testValue;
      }
  
      public String toString()
      {
          Object valVal = null;
          try
          {
              valVal = getValidValue();
          }
          catch (Exception e)
          {
              Log.error(e);
          }
  
          if ( getTestValue() != null ) 
          {
              return getTestValue().toString();
          }
          else if (valVal != null) 
          {
              return valVal.toString();
          }
          else 
          {
              return EMPTY;
          }
      }
          
      /**
       * Loads the valid value from a bean
       */
      public void getProperty(Object obj) 
          throws Exception
      {
          validValue = field.getter.invoke(obj, null);
      }
  
      /**
       * Calls a setter method on obj, if this field has been set.  
       * @exception throws a TurbineException if called and the input
       * was not valid.
       */
      public void setProperty(Object obj) 
      // public void setProperty($appData.BasePackage$field.MapToObject obj) 
          throws TurbineException
      {
          if (!field.isValid()) 
          {
     	        throw new TurbineException(
                  "Attempted to assign an invalid input.");
          }
          if (field.isSet())
          {
              try
              {
                  valArray[0] = getTestValue();
                  field.setter.invoke(obj, valArray);
              }
              catch ( Exception e)
              {
                  throw new TurbineException("An exception prevented the" +
                      " mapping to " + obj, e);
              }
          }
      }
  }
  
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/model/IntakeValueMapWrap.java
  
  Index: IntakeValueMapWrap.java
  ===================================================================
  package org.apache.turbine.services.intake.base;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  
  // JDK classes
  import java.util.HashMap;
  
  // Turbine classes
  
  
  /**
   * A simple wrapper on a HashMap to hold IntakeValue's
   *
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: IntakeValueMapWrap.java,v 1.1 2001/03/09 11:38:09 jmcnally Exp $
   */
  public final class IntakeValueMapWrap
  {
      /*
      private HashMap map;
      private User user;
      int counter;
      
      public IntakeValueMapWrap(User user)
      {
          this.user = user;
          counter = user.getSessionAccessCount();
          map = new HashMap();
      }
  
      public IntakeValue get(String key)
      {
          if ( counter != user.getSessionAccessCount() ) 
          {
              updateMap();
          }
          
          return (IntakeValue) map.get(key);
      }
  
      public void put(IntakeValue iv)
      {
          if ( counter != user.getSessionAccessCount() ) 
          {
              updateMap();
          }
          String key = iv.getKey();
          map.put(key, iv);
          // iv.setSessionCounter(counter);
      }
  
      public boolean contains(String key)
      {
          if ( counter != user.getSessionAccessCount() ) 
          {
              updateMap();
          }
          return map.containsKey(key);
      }
  
      private void updateMap()
      {
          /*  this is complicating things too much, try for a non-session
              approach
          counter = user.getSessionAccessCount();
          for () 
          {
              
          }
          * /
      }
      */
  }
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/model/IntegerField.java
  
  Index: IntegerField.java
  ===================================================================
  package org.apache.turbine.services.intake.model;
  
  // JDK classes
  import java.util.*;
  import java.beans.*;
  
  import org.apache.regexp.RE;
  import org.apache.regexp.RESyntaxException;
  
  // Turbine classes
  import org.apache.turbine.om.*;
  import org.apache.turbine.util.ObjectUtils;
  import org.apache.turbine.util.StringUtils;
  import org.apache.turbine.util.ParameterParser;
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.services.intake.xmlmodel.*;
  
  
  /**  */
  public class IntegerField extends Field
  {
      protected final int onError;
  
      protected final int minValue;
      protected final String minValueMessage;
      protected final boolean minValueForce;
      protected final int maxValue;
      protected final String maxValueMessage;
      protected final boolean maxValueForce;
  
      public IntegerField(XmlField field, Group group)
          throws RESyntaxException, ClassNotFoundException,
                 IntrospectionException 
      {
          super(field, group);
          onError = Integer.parseInt(field.getOnError());
          
          int tmpMinValue = Integer.MIN_VALUE;
          String tmpMinValueMessage = null;
          boolean tmpMinValueForce = false;
          int tmpMaxValue = Integer.MAX_VALUE;
          String tmpMaxValueMessage = null;
          boolean tmpMaxValueForce = false;
          for (int i=0; i<field.getRules().size(); i++) 
          {
              Rule rule = (Rule)field.getRules().get(i);
  
              if ( rule.getMinValue() != null )
              {
                  tmpMinValue = Integer.parseInt(rule.getMinValue());
                  tmpMinValueMessage = rule.getMessage();
                  tmpMinValueForce = "force".equals(rule.getAction());
              }
  
              if ( rule.getMaxValue() != null )
              {
                  tmpMaxValue = Integer.parseInt(rule.getMaxValue());
                  tmpMaxValueMessage = rule.getMessage();
                  tmpMaxValueForce = "force".equals(rule.getAction());
              }
          }  
          minValue = tmpMinValue;
          minValueMessage  = tmpMinValueMessage;
          minValueForce  = tmpMinValueForce;
          maxValue = tmpMaxValue;
          maxValueMessage  = tmpMaxValueMessage;
          maxValueForce  = tmpMaxValueForce;
      }
      
      /**
       * Compares request data with constraints and sets the valid flag.
       */
      protected void doValidate(ParameterParser pp)
      {
          if ( isMultiValued  ) 
          {
              String[] ss = pp.getStrings(getKey());
              int[] ival = new int[ss.length];
              for (int i=0; i<ss.length; i++) 
              {
                  ival[i] = checkString(ss[i]);
              }
              iv.setTestValue(ival);
          }
          else 
          {
              iv.setTestValue(new Integer(checkString(pp.getString(getKey()))));
          }
      }
  
      /**
       * Compares request data with constraints and sets the valid flag.
       */
      private int checkString(String val)
      {
          int ival = onError;
          try
          {
              ival = Integer.parseInt(val);
          }
          catch (NumberFormatException nfe)
          {
              valid_flag = false;
              ival = onError;
          }
  
          boolean b;
          if ( maxLength > 0 )
          {
              b = val.length() > maxLength; 
              if ( maxLengthForce  && b )
              {
                  val = val.substring(0, maxLength);
                  try
                  {
                      ival = Integer.parseInt(val);
                  }
                  catch (NumberFormatException nfe)
                  {
                      valid_flag = false;
                      ival = onError;
                  }
              }
              else 
              {
                  valid_flag &= !b;
              }
              if (maxLengthMessage  != null && b)
              {
                  message = maxLengthMessage;
              }
          }
  
          if ( minValue != Integer.MIN_VALUE )
          {
              b = ival < minValue;
              if ( minValueForce  && b )
              {
                  ival = minValue;
              }
              else 
              {
                  valid_flag &= !b;
              }
              if (minValueForce  && b)
              {
                  message = minValueMessage;
              } 
          }
  
          if ( maxValue != Integer.MAX_VALUE  )
          {
              b = ival > maxValue;
              if ( maxValueForce  && b )
              {
                  ival = maxValue;
              }
              else 
              {
                  valid_flag &= !b;
              }
              if (maxValueForce  && b)
              {
                  message = maxValueMessage;
              } 
          }
          return ival;
      }
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/model/StringField.java
  
  Index: StringField.java
  ===================================================================
  package org.apache.turbine.services.intake.model;
  
  // JDK classes
  import java.util.*;
  import java.beans.*;
  
  import org.apache.regexp.RESyntaxException;
  
  // Turbine classes
  import org.apache.turbine.om.*;
  import org.apache.turbine.util.ObjectUtils;
  import org.apache.turbine.util.StringUtils;
  import org.apache.turbine.util.ParameterParser;
  import org.apache.turbine.util.Log;
  import org.apache.turbine.util.TurbineException;
  import org.apache.turbine.services.intake.xmlmodel.*;
  
  
  /**
   * Base class for Intake generated input processing classes.
   *
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: StringField.java,v 1.1 2001/03/09 11:38:09 jmcnally Exp $
   */
  public class StringField extends Field
  {    
      public StringField(XmlField field, Group group)
          throws RESyntaxException, ClassNotFoundException,
                 IntrospectionException 
      {
          super(field, group);
      }
  
      /**
       * Compares request data with constraints and sets the valid flag.
       */
      protected void doValidate(ParameterParser pp)
      {
          if ( isMultiValued ) 
          {
              String[] ss = pp.getStrings(getKey());
              String[] sval = new String[ss.length];
              for (int i=0; i<ss.length; i++) 
              {
                  sval[i] = checkString(ss[i]);
              }
              iv.setTestValue(sval);
          }
          else 
          {
              iv.setTestValue(checkString(pp.getString(getKey())));
          }
      }
      
      /**
       * Compares request data with constraints and sets the valid flag.
       */
      private String checkString(String val)
      {
          boolean b;
          if ( maxLength > 0 )
          {
              b = val.length() > maxLength; 
              if ( maxLengthForce  && b )
              {
                  val = val.substring(0, maxLength);
              }
              else 
              {
                  valid_flag &= !b;
              }
              if (maxLengthMessage  != null && b)
              {
                  message = maxLengthMessage;
              }
          }
          return val;
      }
  
  }
  
  
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/transform/DTDResolver.java
  
  Index: DTDResolver.java
  ===================================================================
  package org.apache.turbine.services.intake.transform;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  // JDK classes
  import java.io.*;
  import java.net.URL;
  import java.util.*;
  
  // Xerces classes
  import org.xml.sax.*;
  import org.xml.sax.helpers.*;
  import org.apache.xerces.parsers.*;
  
  // Turbine
  import org.apache.turbine.services.db.*;
  
  /**
   * A resolver to get the database.dtd file for the XML parser from the jar.
   * This does not work with jdk1.3 on linux, see
   * <a href="http://developer.java.sun.com/developer/bugParade/bugs/4337703.html">
   * Bug 4337703</a>
   *
   * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
   * @version $Id: DTDResolver.java,v 1.1 2001/03/09 11:38:10 jmcnally Exp $
   */
  public class DTDResolver implements EntityResolver
  {
      /** InputSource for database.dtd */
      InputSource databaseDTD = null;
  
      /**
       * constructor
       */
      public DTDResolver()
      {
          try
          {
              URL url = getClass().getResource("constraints.dtd");
              if (url != null)  // jdk1.3 on linux allways returns null!!
                  databaseDTD = new InputSource(url.openStream());
          }
          catch (Exception ex)
          {
              ex.printStackTrace();
          }
      }
  
      /**
       * called by the XML parser
       *
       * @return an InputSource for the database.dtd file
       */
      public InputSource resolveEntity(String publicId, String systemId)
      {
          if (databaseDTD != null &&
              "http://java.apache.org/turbine/dtd/constraints.dtd".equals(systemId))
          {
              System.out.println("Resolver: use constraints.dtd");
              return databaseDTD;
          }
          else
          {
              System.out.println("Resolver: used " + systemId);
              return getInputSource(systemId);
          }
      } // resolveEntity(String, String)
  
      /**
       * get an InputSource for an URL String
       *
       * @param urlString
       * @return an InputSource for the URL String
       */
      public InputSource getInputSource(String urlString)
      {
          try
          {
              URL url = new URL(urlString);
              return new InputSource(url.openStream());
          }
          catch (IOException ex)
          {
              ex.printStackTrace();
          }
          return new InputSource();
      } // getInputSource(String)
  }
  
  
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/transform/XmlToAppData.java
  
  Index: XmlToAppData.java
  ===================================================================
  package org.apache.turbine.services.intake.transform;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  // JDK classes
  import java.io.*;
  import java.util.*;
  
  // Xerces classes
  import org.xml.sax.*;
  import org.xml.sax.helpers.*;
  import org.apache.xerces.parsers.*;
  
  // Turbine
  import org.apache.turbine.services.db.*;
  import org.apache.turbine.services.intake.xmlmodel.*;
  
  /**
   * A Class that is used to parse an input
   * xml schema file and creates and AppData java structure.
   * It uses apache Xerces to do the xml parsing.
   *
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: XmlToAppData.java,v 1.1 2001/03/09 11:38:10 jmcnally Exp $
   */
  public class XmlToAppData extends DefaultHandler
  {
      private AppData app;
      private XmlGroup currGroup;
      private XmlField currField;
      private Rule currRule;
      private String currElement;
  
      /**
       * Default custructor
       */
      public XmlToAppData()
      {
          app = new AppData();
      }
  
  
      /**
       * Parse and xml input file and returns a newly
       * created and populated AppData structure
       */
      public AppData parseFile(String xmlFile)
          throws Exception
      {
          SAXParser parser = new SAXParser();
          
          // set the Resolver for the database DTD
          DTDResolver dtdResolver = new DTDResolver();
          parser.setEntityResolver(dtdResolver);
  
          // We don't use an external content handler - we use this object
          parser.setContentHandler(this);
          
          // Validate the input file
          parser.setFeature(
              "http://apache.org/xml/features/validation/dynamic", true);
          parser.setFeature("http://xml.org/sax/features/validation", true);
              
          parser.setErrorHandler(this);
          
          FileReader fr = new FileReader (xmlFile);
          BufferedReader br = new BufferedReader (fr);
          try
          {
              System.out.println("xmlFile: " + xmlFile);
              
              InputSource is = new InputSource (br);
              parser.parse(is);
          }
          finally
          {
              br.close();
          }
  
          return app;
      }
  
  
  
      /**
       * Handles opening elements of the xml file.
       */
      public void startElement(String uri, String localName, 
                               String rawName, Attributes attributes)
      {
          currElement = rawName;
          if (rawName.equals("input-data"))
          {
              app.loadFromXML(attributes);
          }
          else if (rawName.equals("group"))
          {
              currGroup = app.addGroup(attributes);
          }
          else if (rawName.equals("field"))
          {
              currField = currGroup.addField(attributes);
          }
          else if (rawName.equals("rule"))
          {
              currRule = currField.addRule(attributes);
          }
      }
  
  
      /**
       * Handles the character data, which we are using to specify the
       * error message.
       */
      public void characters(char[] mesgArray, int start, int length)
      {
          String cdata = new String(mesgArray, start, length).trim();
          if ( "rule".equals(currElement) && cdata.length() > 0) 
          {
              currRule.setMessage(cdata);
          }
      }
  
      public void warning(SAXParseException spe)
      {
          System.out.println("Warning Line: " + spe.getLineNumber() +
                             " Row: " + spe.getColumnNumber() +
                             " Msg: " + spe.getMessage());
      }
      public void error(SAXParseException spe)
      {
          System.out.println("Error Line: " + spe.getLineNumber() +
                             " Row: " + spe.getColumnNumber() +
                             " Msg: " + spe.getMessage());
      }
      public void fatalError(SAXParseException spe)
      {
          System.out.println("Fatal Error Line: " + spe.getLineNumber() +
                             " Row: " + spe.getColumnNumber() +
                             " Msg: " + spe.getMessage());
      }
  
  
  
  }
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/xmlmodel/AppData.java
  
  Index: AppData.java
  ===================================================================
  package org.apache.turbine.services.intake.xmlmodel;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  // JDK
  import java.io.*;
  import java.util.*;
  
  // Xerces
  import org.xml.sax.*;
  
  /**
   * A class for holding application data structures.
   *
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: AppData.java,v 1.1 2001/03/09 11:38:12 jmcnally Exp $
   */
  public class AppData
  {
  
      private List inputs;
      private String basePackage;
  
      /**
       * Default Constructor
       */
      public AppData()
      {
          inputs = new ArrayList();
      }
  
      /**
       * Imports a column from an XML specification
       */
      public void loadFromXML (Attributes attrib)
      {
          String basePkg = attrib.getValue("basePackage");
          if ( basePkg == null )
          {
              setBasePackage("");
          }
          else
          {            
              setBasePackage(basePkg);
          }
      }
  
      /**
       * Return a collection of input sections (<group>)
       */
      public List getGroups()
      {
          return inputs;
      }
  
      public XmlGroup getGroup(String groupName)
      {
          XmlGroup group = null;
          Iterator iter = inputs.iterator();
          do 
          {
              group = (XmlGroup)iter.next();
      
          } while (!group.getName().equals(groupName));
          
          return group;
      }
  
      /**
       * An utility method to add a new input group from
       * an xml attribute.
       */
      public XmlGroup addGroup(Attributes attrib)
      {
          XmlGroup input = new XmlGroup();
          input.loadFromXML(attrib);
          addGroup(input);
          return input;
      }
  
      /**
       * Add an input group to the vector and sets the
       * AppData property to this AppData
       */
      public void addGroup(XmlGroup input)
      {
          input.setAppData(this);
          inputs.add(input);
      }
  
      
      /**
       * Get the value of basePackage.
       * @return value of basePackage.
       */
      public String getBasePackage() 
      {
          return basePackage;
      }
      
      /**
       * Set the value of basePackage.
       * @param v  Value to assign to basePackage.
       */
      public void setBasePackage(String  v) 
      {
          this.basePackage = v;
      }
      
      /**
       * Creats a string representation of this AppData.
       * The representation is given in xml format.
       */
      public String toString()
      {
          StringBuffer result = new StringBuffer();
  
          result.append ("<app-data>\n");
          for (Iterator iter = inputs.iterator() ; iter.hasNext() ;)
          {
              result.append (iter.next());
          }
          result.append ("</app-data>");
          return result.toString();
    }
  }
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/xmlmodel/Rule.java
  
  Index: Rule.java
  ===================================================================
  package org.apache.turbine.services.intake.xmlmodel;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  // JDK
  import java.io.*;
  import java.util.*;
  
  // Xerces
  import org.xml.sax.*;
  import org.xml.sax.helpers.*;
  
  import org.apache.turbine.util.StringUtils;
  
  /**
   * A Class for holding data about a constraint on a property.
   *
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: Rule.java,v 1.1 2001/03/09 11:38:12 jmcnally Exp $
   */
  public class Rule
  {
      private String mask;
      private String minLength;
      private String maxLength;
      private String minValue;
      private String maxValue;
      private String requireProp;
      private String message;
      private String action;
      private XmlField parent;
  
      /**
       * Default Constructor
       */
      public Rule()
      {
      }
  
      /**
       * Imports a column from an XML specification
       */
      public void loadFromXML (Attributes attrib)
      {
          setMask(attrib.getValue("mask"));
          setMinLength(attrib.getValue("minLength"));
          setMaxLength(attrib.getValue("maxLength"));
          setMinValue(attrib.getValue("minValue"));
          setMaxValue(attrib.getValue("maxValue"));
          setRequiresProp(attrib.getValue("requires"));
          setAction(attrib.getValue("action"));
      }
  
  
      /**
       * Set the regexp used to verify parameter
       */
      public void setMask(String newMask)
      {
          mask = newMask;
      }
      /**
       * Get regexp used to verify a parameter
       */
      public String getMask()
      {
          return mask;
      }
  
      /**
       * Set the name of the property
       */
      public void setRequiresProp(String newRequireProp)
      {
          requireProp = newRequireProp;
      }
  
      /**
       * Get the name of the property
       */
      public String getRequiresProp()
      {
          return StringUtils.removeUnderScores(requireProp);
      }
  
      /**
       * Set the minimum length of the parameter value
       */
      public void setMinLength(String length)
      {
          minLength = length;
      }
      /**
       * Get minimum length of the parameter value
       */
      public String getMinLength()
      {
          return minLength;
      }
  
      /**
       * Set the maximum length of the parameter value
       */
      public void setMaxLength(String length)
      {
          maxLength = length;
      }
      /**
       * Get maximum length of the parameter value
       */
      public String getMaxLength()
      {
          return maxLength;
      }
  
      /**
       * Set the minimum value of the parameter
       */
      public void setMinValue(String value)
      {
          minValue = value;
      }
      /**
       * Get minimum value of the parameter
       */
      public String getMinValue()
      {
          return minValue;
      }
  
      /**
       * Set the maximum value of the parameter
       */
      public void setMaxValue(String value)
      {
          maxValue = value;
      }
      /**
       * Get maximum value of the parameter
       */
      public String getMaxValue()
      {
          return maxValue;
      }
  
      /**
       * Set the error message
       */
      public void setMessage(String newMessage)
      {
          message = newMessage;
      }
  
      /**
       * Get the error message
       */
      public String getMessage()
      {
          return message;
      }
      /**
       * Set the action to take on failure
       */
      public void setAction(String newAction)
      {
          action = newAction;
      }
  
      /**
       * Get the action to take on failure
       */
      public String getAction()
      {
          if ( action == null) 
          {
              action = "invalidate";    
          }
          return action;
      }
  
      /**
       * Set the parent Field of the rule
       */
      public void setField(XmlField parent)
      {
          this.parent = parent;
      }
  
      /**
       * Get the parent Field of the rule
       */
      public XmlField getField()
      {
          return parent;
      }
  
      /**
       * String representation of the column. This
       * is an xml representation.
       */
      public String toString()
      {
          StringBuffer result = new StringBuffer();
  
          if (mask != null)
          {
              result.append(" mask=\""+mask+"\"");
          }        
          if (minLength != null)
          {
              result.append(" minLength=\""+minLength+"\"");
          }        
          if (maxLength != null)
          {
              result.append(" maxLength=\""+maxLength+"\"");
          }        
          if (minValue != null)
          {
              result.append(" minValue=\""+minValue+"\"");
          }        
          if (maxValue != null)
          {
              result.append(" maxValue=\""+maxValue+"\"");
          }        
          if (requireProp != null)
          {
              result.append(" requires=\""+requireProp+"\"");
          }        
          if (action != null)
          {
              result.append(" action=\""+action+"\"");
          }        
  
          result.append(">\n");
  
          if (message != null)
          {
              result.append(message);
          }        
  
          result.append("</rule>\n");
          return result.toString();
      }
  
  }
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/xmlmodel/XmlField.java
  
  Index: XmlField.java
  ===================================================================
  package org.apache.turbine.services.intake.xmlmodel;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  // JDK
  import java.io.*;
  import java.util.*;
  
  // Xerces
  import org.xml.sax.*;
  import org.xml.sax.helpers.*;
  
  import org.apache.turbine.util.StringUtils;
  
  /**
   * A Class for holding data about a property used in an Application.
   *
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: XmlField.java,v 1.1 2001/03/09 11:38:12 jmcnally Exp $
   */
  public class XmlField
  {
      private String baseClass;
      private String name;
      private String key;
      private String type;
      private String onError;
      private String multiValued;
      private XmlGroup parent;
      private Vector rules;
      private String mapToObject;
      private String mapToProperty;
  
      private static HashMap defaultOnErrors = new HashMap(15);
      private static HashMap convertHash = new HashMap(15);
      private static HashMap convertArrayHash = new HashMap(15);
      // static
      {
          defaultOnErrors.put("boolean", "false");
          defaultOnErrors.put("byte", "-1");
          defaultOnErrors.put("short", "-1");
          defaultOnErrors.put("int", "-1");
          defaultOnErrors.put("long", "-1");
          defaultOnErrors.put("float", "-1.0f");
          defaultOnErrors.put("double", "-1.0");
          defaultOnErrors.put("BigDecimal", "new BigDecimal(\"-1.0\")");
          // defaultOnErrors.put("BigInteger", "new BigInteger(\"-1\")");
  
          convertHash.put("boolean", "getBoolean");
          convertHash.put("byte", "getByte");
          convertHash.put("short", "getShort");
          convertHash.put("int", "getInt");
          convertHash.put("long", "getLong");
          convertHash.put("float", "getFloat");
          convertHash.put("double", "getDouble");
          convertHash.put("Date", "getDate");
          convertHash.put("BigDecimal", "getBigDecimal");
          // convertHash.put("BigInteger", "getBigInteger");
  
          convertHash.put("boolean[]", 
                          "Boolean.valueOf(stringValue[i]).booleanValue()");
          convertArrayHash.put("byte[]", 
                               "Byte.valueOf(stringValue[i]).byteValue()");
          convertArrayHash.put("short[]", 
                               "Short.valueOf(stringValue[i]).shortValue()");
          convertArrayHash.put("int[]", "Integer.parseInt(stringValue[i])");
          convertArrayHash.put("long[]", "Long.parseLong(stringValue[i])");
          convertArrayHash.put("float[]", 
                               "Float.valueOf(stringValue[i]).floatValue()");
          convertArrayHash.put("double[]", 
                               "Double.valueOf(stringValue[i]).doubleValue()");
          convertArrayHash.put("Date[]", "FIXME!!");
          convertArrayHash.put("BigDecimal[]", "new BigDecimal(stringValue[i])");
          // convertHash.put("BigInteger", "new BigInteger(stringValue)");
      }    
      /**
       * Default Constructor
       */
      public XmlField()
      {
          rules = new Vector();
      }
  
  
      /**
       * Creates a new column and set the name
       */
      public XmlField(String name)
      {
          this.name = name;
          rules = new Vector();
      }
  
      /**
       * Imports a column from an XML specification
       */
      public void loadFromXML (Attributes attrib)
      {
          setBaseClass(attrib.getValue("baseClass"));
          setName(attrib.getValue("name"));
          key = attrib.getValue("key");
          type = attrib.getValue("type");
          setOnError(attrib.getValue("onError"));
          setMultiValued(attrib.getValue("multiValued"));
  
          String mapObj = attrib.getValue("mapToObject");
          if ( mapObj != null ) 
          {
              setMapToObject(mapObj);            
          }
  
          String mapProp = attrib.getValue("mapToProperty");
          if ( mapProp != null ) 
          {
              setMapToProperty(mapProp);            
          }
      }
  
  
      /**
       * Get the name of the property
       */
      public String getRawName()
      {
          return name;
      }
  
      /**
       * Get the name of the property
       */
      public String getName()
      {
          return StringUtils.removeUnderScores(name);
      }
  
      /**
       * Set the name of the property
       */
      public void setName(String newName)
      {
          name = newName;
      }
  
      /**
       * Set the parameter key of the property
       */
      public void setKey(String newKey)
      {
          key = newKey;
      }
      /**
       * Get the parameter key of the property
       */
      public String getKey()
      {
          return key;
      }
  
      /**
       * Set the type of the property
       */
      public void setType(String newType)
      {
          type = newType;
      }
  
      /**
       * Get the type of the property
       */
      public String getType()
      {
          if ( isMultiValued() ) 
          {
              return type + "[]";    
          }   
          return type;
      }
  
      /**
       * Set the base class of the field
       */
      public void setBaseClass(String newBaseClass)
      {
          baseClass = newBaseClass;
      }
  
      /**
       * Get the base class of the field
       */
      public String getBaseClass()
      {
          return baseClass;
      }
  
      /**
       * Set the value of the property, if a conversion error occurs.
       */
      public void setOnError(String newOnError)
      {
          onError = newOnError;
      }
  
      /**
       * Get the value of the property, if a conversion error occurs.
       */
      public String getOnError()
      {
          if ( onError == null && defaultOnErrors.containsKey(getType()) ) 
          {
              onError = (String)defaultOnErrors.get(getType());
          }
          return onError;
      }
  
      /**
       * Set whether this class can have multiple values
       */
      public void setMultiValued(String newMultiValued)
      {
          multiValued = newMultiValued;
      }
  
      /**
       * can this field have several values?
       */
      public boolean isMultiValued()
      {
          if ( multiValued != null && multiValued.equals("true") )
          {
              return true;
          }
          return false;
      }
  
      /**
       * Set the name of the object that takes this input
       */
      public void setMapToObject(String obj)
      {
          mapToObject = obj;
      }
  
      /**
       * Get the name of the object that takes this input
       */
      public String getMapToObject()
      {
          return mapToObject;
      }
  
      /**
       * Set the property method that takes this input
       */
      public void setMapToProperty(String prop)
      {
          mapToProperty = prop;
      }
  
      /**
       * Get the property method that takes this input
       */
      public String getMapToProperty()
      {
          return mapToProperty;
      }
      
      public String getVariable()
      {
          String firstChar = getName().substring(0,1).toLowerCase();
          return firstChar + getName().substring(1);
      }
  
      public String getPPMethod()
      {
          String result = null;
          if ( convertHash.containsKey(getType())) 
          {
              result = (String)convertHash.get(getType());    
          }
          return result;
      }        
  
      public String getArrayConvert()
      {
          String result = null;
          if ( convertArrayHash.containsKey(getType())) 
          {
              result = (String)convertArrayHash.get(getType());    
          }
          return result;
      }        
  
      /**
       * Set the parent XmlGroup of the property
       */
      public void setGroup(XmlGroup parent)
      {
          this.parent = parent;
      }
  
      /**
       * Get the parent XmlGroup of the property
       */
      public XmlGroup getGroup()
      {
          return parent;
      }
  
  
      /**
       * A utility function to create a new rule
       * from attrib and add it to this property.
       */
      public Rule addRule(Attributes attrib)
      {
          Rule rule = new Rule();
          rule.loadFromXML(attrib);
          addRule(rule);
  
          return rule;
      }
  
      /**
       * Adds a new rule to the rules vector and set the
       * parent property of the rule to this property
       */
      public void addRule(Rule rule)
      {
          rule.setField(this);
          rules.addElement(rule);
      }
  
      public Vector getRules()
      {
          return rules;
      }
  
      /**
       * String representation of the column. This
       * is an xml representation.
       */
      public String toString()
      {
          StringBuffer result = new StringBuffer();
          result.append(" <field name=\""+name+"\"");
          result.append(" key=\""+key+"\"");
          result.append(" type=\""+type+"\"");
  
          if (onError != null)
          {
              result.append(" onError=\""+onError+"\"");
          }
          if (mapToObject != null)
          {
              result.append(" mapToObject=\""+mapToObject+"\"");
          }
          if (mapToProperty != null)
          {
              result.append(" mapToProperty=\""+mapToProperty+"\"");
          }
  
          result.append(">\n");
  
          if (rules != null)
          {
              for (Enumeration e = rules.elements() ; e.hasMoreElements() ;)
              {
                  result.append(e.nextElement());
              }
          }        
  
          result.append("</field>\n");
          return result.toString();
      }
  
  }
  
  
  
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/xmlmodel/XmlGroup.java
  
  Index: XmlGroup.java
  ===================================================================
  package org.apache.turbine.services.intake.xmlmodel;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 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" and "Apache Software Foundation" and 
   *    "Apache Turbine" 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",
   *    "Apache Turbine", 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 (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/>.
   */
  
  // JDK
  import java.io.*;
  import java.util.*;
  
  // Xerces
  import org.xml.sax.*;
  import org.xml.sax.helpers.*;
  
  /**
   * A Class for holding data about a grouping of inputs used in an Application.
   *
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: XmlGroup.java,v 1.1 2001/03/09 11:38:12 jmcnally Exp $
   */
  public class XmlGroup
  {
      private List fields;
      private List mapToObjects;
      private String defaultMapToObject;
      private AppData parent;
      private String classname;
      private String key;
      private String poolCapacity;
  
      /**
       * Constructs a input group object
       */
      public XmlGroup()
      {
          fields = new ArrayList();
          mapToObjects = new ArrayList(2);
      }
  
      /**
       * Load the input group object from an xml tag.
       */
      public void loadFromXML (Attributes attrib)
      {
          classname = attrib.getValue("class");
          key = attrib.getValue("key");
          poolCapacity = attrib.getValue("pool-capacity");
          
          String objName = attrib.getValue("mapToObject");
          if ( objName != null ) 
          {
              defaultMapToObject = objName;
              mapToObjects.add(objName);
          }
      }
  
      /**
       * Get the class name that handles this group
       */
      public String getName()
      {
          return classname;
      }
  
      /**
       * Set the class name that handles this group
       */
      public void setName(String newClass)
      {
          classname = newClass;
      }
  
      /**
       * Get the key used to reference this group in input (form)
       */
      public String getKey()
      {
          return key;
      }
  
      /**
       * Set the key used to reference this group in input (form)
       */
      public void setKey(String newKey)
      {
          key = newKey;
      }
  
  
      /**
       * The maximum number of classes specific to this group
       * allowed at one time.
       *
       * @return an <code>String</code> value
       */
      public String getPoolCapacity()
      {
          return poolCapacity;
      }
  
      /**
       * A utility function to create a new field
       * from attrib and add it to this input group.
       */
      public XmlField addField(Attributes attrib)
      {
          XmlField field = new XmlField();
          field.loadFromXML(attrib);
          addField(field);
  
          return field;
      }
  
      /**
       * Adds a new field to the fields list and set the
       * parent group of the field to the current group
       */
      public void addField(XmlField field)
      {
          field.setGroup(this);
  
          // if this field has an object defined for mapping,
          // add it to the list
          if ( field.getMapToObject() != null ) 
          {
              boolean isNewObject = true;
              for ( int i=0; i<mapToObjects.size(); i++ ) 
              {
                  if ( mapToObjects.get(i).equals(field.getMapToObject()) ) 
                  {
                      isNewObject = false;
                      break;
                  }
              }
              if ( isNewObject ) 
              {
                  mapToObjects.add(field.getMapToObject());
              }
          }
          // if a mapToProperty exists, set the object to this group's default
          else if( field.getMapToProperty() != null 
                   && defaultMapToObject != null )
          {
              field.setMapToObject(defaultMapToObject);
          }
          
          fields.add(field);
      }
  
      /**
       * Returns a collection of fields in this input group
       */
      public List getFields()
      {
          return fields;
      }
  
      /**
       * Utility method to get the number of fields in this input group
       */
      public int getNumFields()
      {
          return fields.size();
      }
  
  
      /**
       * Returns a Specified field.
       * @return Return a XmlField object or null if it does not exist.
       */
      public XmlField getField(String name)
      {
          String curName;
  
          for (Iterator iter = fields.iterator() ; iter.hasNext() ;)
          {
              XmlField field = (XmlField) iter.next();
              curName = field.getRawName();
              if (curName.equals(name))
              {
                  return field;
              }
          }
          return null;
      }
  
      /**
       * Returns true if the input group contains a spesified field
       */
      public boolean containsField(XmlField field)
      {
          return fields.contains (field);
      }
  
      /**
       * Returns true if the input group contains a specified field
       */
      public boolean containsField(String name)
      {
          return (getField (name) != null);
      }
  
      public List getMapToObjects()
      {
          return mapToObjects;
      }
  
      /**
       * Set the parent of the database
       */
      public void setAppData(AppData parent)
      {
          this.parent = parent;
      }
  
      /**
       * Get the parent of the input group
       */
      public AppData getAppData()
      {
          return parent;
      }
  
      /**
       * A String which might be used as a variable of this class
       */
      public String getVariable()
      {
          String firstChar = getName().substring(0,1).toLowerCase();
          return firstChar + getName().substring(1);
      }
  
  
      /**
       * Creates a string representation of this input group. This
       * is an xml representation.
       */
      public String toString()
      {
          StringBuffer result = new StringBuffer();
  
          result.append ("<group class=\"").append(classname);
          result.append(" key=\""+key+"\"");
          result.append(">\n");
  
          if (fields != null)
          {
              for (Iterator iter = fields.iterator() ; iter.hasNext() ;)
              {
                  result.append(iter.next());
              }
          }        
  
          result.append ("</group>\n");
  
          return result.toString();
      }
  
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org