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/27 08:51:50 UTC

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

jmcnally    01/03/26 22:51:50

  Modified:    src/java/org/apache/turbine/services/intake IntakeTool.java
                        TurbineIntakeService.java
               src/java/org/apache/turbine/services/intake/model
                        BigDecimalField.java Field.java FieldFactory.java
                        Group.java IntakeValue.java IntegerField.java
               src/java/org/apache/turbine/services/intake/transform
                        XmlToAppData.java
               src/java/org/apache/turbine/services/intake/xmlmodel
                        XmlGroup.java
  Added:       src/java/org/apache/turbine/services/intake/model
                        ComboKeyField.java NumberKeyField.java
  Log:
  lots of bug fixes, clean up and optimization.
  starting to get some functionality working but still a little rough.
  
  Revision  Changes    Path
  1.5       +38 -28    jakarta-turbine/src/java/org/apache/turbine/services/intake/IntakeTool.java
  
  Index: IntakeTool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/intake/IntakeTool.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- IntakeTool.java	2001/03/21 01:05:16	1.4
  +++ IntakeTool.java	2001/03/27 06:51:45	1.5
  @@ -74,23 +74,33 @@
    * A Pull tool to make intake objects available to a template
    *
    * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
  - * @version $Id: IntakeTool.java,v 1.4 2001/03/21 01:05:16 jmcnally Exp $
  + * @version $Id: IntakeTool.java,v 1.5 2001/03/27 06:51:45 jmcnally Exp $
    */
   public class IntakeTool 
       implements ApplicationTool, Recyclable
   {
       private HashMap groups;
       private RunData data;
  +    private boolean allValid;
       // private String omToolKey;
       // private OMTool omTool;
   
       /** The cache of PullHelpers. **/
  -    private static Map pullMap = new HashMap();
  +    private Map pullMap = new HashMap();
   
       public IntakeTool()
       {
  -        groups = new HashMap();
  +        String[] groupNames = TurbineIntake.getGroupNames();
  +        groups = new HashMap((int)(1.25*groupNames.length + 1));
  +        pullMap = new HashMap((int)(1.25*groupNames.length + 1));
           // omToolKey = TurbineResources.getString("tool.intake.om");
  +
  +        for (int i=groupNames.length-1; i>=0; i--) 
  +        {
  +            pullMap.put(groupNames[i], new PullHelper(groupNames[i]));
  +        }
  +
  +        allValid = true;
       }
   
       /**
  @@ -100,12 +110,12 @@
       {
           data = (RunData)runData;
   
  -        String[] groupName = TurbineIntake.getGroupNames();
  -        for (int i=groupName.length-1; i>=0; i--) 
  +        String[] groupNames = TurbineIntake.getGroupNames();
  +        for (int i=groupNames.length-1; i>=0; i--) 
           {
               try
               {
  -                List foundGroups = TurbineIntake.getGroup(groupName[i])
  +                List foundGroups = TurbineIntake.getGroup(groupNames[i])
                       .getObjects(data);
                   if ( foundGroups != null ) 
                   {            
  @@ -114,6 +124,7 @@
                       {
                           Group group = (Group)iter.next();
                           groups.put(group.getObjectKey(), group);
  +                        allValid &= group.isAllValid();
                       }
                   }
               }
  @@ -171,38 +182,32 @@
               throws Exception
           {
           
  -            try {
               Group g = null;
   
  -            String inputKey = TurbineIntake.getGroupKey(groupName) 
  -                + obj.getQueryKey();
  -            if ( groups.containsKey(inputKey)) 
  +            try 
               {
  -                g = (Group)groups.get(inputKey);
  +                String inputKey = TurbineIntake.getGroupKey(groupName) 
  +                    + obj.getQueryKey();
  +                if ( groups.containsKey(inputKey)) 
  +                {
  +                    g = (Group)groups.get(inputKey);
  +                }
  +                else 
  +                {
  +                    g = TurbineIntake.getGroup(groupName); 
  +                    groups.put(inputKey, g);
  +                }
  +                return g.init(obj);
               }
  -            else 
  +            catch(Exception e)
               {
  -                g = TurbineIntake.getGroup(groupName); 
  -                groups.put(inputKey, g);
  +                Log.error(e);
               }
   
  -            return g.init(obj);
  -            }catch(Exception e){e.printStackTrace();}
  -            return null;
  -        
  +            return null;        
           }
       }
       
  -    /**
  -     * Used by the service to populate pullMap
  -     * @param groupName  groupName to key pullMap.
  -     * @param v  Value to assign to puller.
  -     */
  -    void addPuller(String groupName) 
  -    {
  -        pullMap.put(groupName, new IntakeTool.PullHelper(groupName));
  -    }
  -    
       
       public Object get(String groupName)
           throws Exception
  @@ -210,6 +215,10 @@
           return pullMap.get(groupName);
       }
   
  +    public boolean isAllValid()
  +    {
  +        return allValid;
  +    }
   
       /*
       public Group get(String groupName)
  @@ -274,6 +283,7 @@
   
           groups.clear(); 
           data = null;
  +        allValid = true;
   
           disposed = true;
       }
  
  
  
  1.5       +1 -49     jakarta-turbine/src/java/org/apache/turbine/services/intake/TurbineIntakeService.java
  
  Index: TurbineIntakeService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/intake/TurbineIntakeService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TurbineIntakeService.java	2001/03/21 00:17:07	1.4
  +++ TurbineIntakeService.java	2001/03/27 06:51:48	1.5
  @@ -76,7 +76,7 @@
    * on an XML specification.
    * 
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  - * @version $Id: TurbineIntakeService.java,v 1.4 2001/03/21 00:17:07 jmcnally Exp $
  + * @version $Id: TurbineIntakeService.java,v 1.5 2001/03/27 06:51:48 jmcnally Exp $
    */
   public class TurbineIntakeService
       extends TurbineBaseService
  @@ -141,17 +141,14 @@
               setterMap = new HashMap();
               // omTool = new OMTool();
               String pkg = appData.getBasePackage();
  -            IntakeTool it = new IntakeTool();
   
               List glist = appData.getGroups();
               for ( int i=glist.size()-1; i>=0; i-- )
               {
                   XmlGroup g = (XmlGroup)glist.get(i);
                   String groupName = g.getName();
  -                System.out.println("Group " + i + ": " + groupName);
                   groupNames[i] = groupName;
                   groupKeyMap.put(groupName, g.getKey());
  -                it.addPuller( groupName );
   
                   List classNames = g.getMapToObjects();
                   Iterator iter2 = classNames.iterator();
  @@ -323,51 +320,6 @@
           return instance;
       }
   
  -    /**
  -     * Gets an instance of a named group either from the pool
  -     * or by calling the Factory Service if the pool is empty and
  -     * then initialize it using the ParameterParser looking for 
  -     * a NEW id.
  -     *
  -     * @param groupName the name of the group.
  -     * @param pp the request parameters that may contain matching keys
  -     * @return a Group instance.
  -     * @throws TurbineException if recycling fails.
  -     * /
  -    public Group getGroup(String groupName, RunData data)
  -        throws Exception
  -    {
  -        Group instance = (Group)pollInstance(groupName);
  -        if ( instance == null ) 
  -        {
  -            appData.getGroup(groupName);
  -        }
  -        instance.init(data);
  -        return instance;
  -    }
  -
  -    /**
  -     * Gets an instance of a named group either from the pool
  -     * or by calling the Factory Service if the pool is empty and
  -     * then initialize it using the ParameterParser looking for id.
  -     *
  -     * @param groupName the name of the group.
  -     * @param pp the request parameters that may contain matching keys
  -     * @return a Group instance.
  -     * @throws TurbineException if recycling fails.
  -     * /
  -    public Group getGroup(String groupName, ParameterParser pp, String id)
  -        throws Exception
  -    {
  -        Group instance = (Group)pollInstance(groupName);
  -        if ( instance == null ) 
  -        {
  -            appData.getGroup(groupName);
  -        }
  -        instance.init(id, pp);
  -        return instance;
  -    }
  -    */
   
       /**
        * Puts a Group back to the pool.
  
  
  
  1.5       +1 -1      jakarta-turbine/src/java/org/apache/turbine/services/intake/model/BigDecimalField.java
  
  Index: BigDecimalField.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/intake/model/BigDecimalField.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BigDecimalField.java	2001/03/21 00:17:09	1.4
  +++ BigDecimalField.java	2001/03/27 06:51:48	1.5
  @@ -160,7 +160,7 @@
           {
               ival = new BigDecimal(val);
           }
  -        catch (NumberFormatException nfe)
  +        catch (Exception e)
           {
               valid_flag = false;
               ival = onError;
  
  
  
  1.5       +10 -1     jakarta-turbine/src/java/org/apache/turbine/services/intake/model/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/intake/model/Field.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Field.java	2001/03/21 00:17:10	1.4
  +++ Field.java	2001/03/27 06:51:48	1.5
  @@ -77,7 +77,7 @@
    * Base class for Intake generated input processing classes.
    *
    * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
  - * @version $Id: Field.java,v 1.4 2001/03/21 00:17:10 jmcnally Exp $
  + * @version $Id: Field.java,v 1.5 2001/03/27 06:51:48 jmcnally Exp $
    */
   public abstract class Field
   {
  @@ -97,11 +97,13 @@
       protected final String[] requires; 
       protected final String[] requiresMessage; 
       protected final boolean isMultiValued; 
  +    protected Object onError;
   
       protected final Group group;
    
       protected boolean set_flag;
       protected boolean valid_flag;
  +    protected boolean initialized;
       protected String message;
   
       protected OMTool omTool; 
  @@ -221,11 +223,17 @@
           {
               // iv.reconcileNotPresent();
           }
  +
  +        initialized = true;
           return this;
       }
   
       public Field init(Retrievable obj)
       {
  +        if ( !initialized ) 
  +        {
  +            valid_flag = true;
  +        }
           retrievable = obj;
           return this;
       }
  @@ -239,6 +247,7 @@
        */
       public void dispose()
       {
  +        initialized = false;
           set_flag = false;
           valid_flag = false;
           message = null;
  
  
  
  1.5       +75 -21    jakarta-turbine/src/java/org/apache/turbine/services/intake/model/FieldFactory.java
  
  Index: FieldFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/intake/model/FieldFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FieldFactory.java	2001/03/21 00:17:10	1.4
  +++ FieldFactory.java	2001/03/27 06:51:48	1.5
  @@ -73,10 +73,81 @@
    * Creates Field objects.
    *
    * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
  - * @version $Id: FieldFactory.java,v 1.4 2001/03/21 00:17:10 jmcnally Exp $
  + * @version $Id: FieldFactory.java,v 1.5 2001/03/27 06:51:48 jmcnally Exp $
    */
   public abstract class FieldFactory
   {
  +    private static Map fieldCtors = initFieldCtors();
  +
  +    private static Map initFieldCtors()
  +    {
  +        fieldCtors = new HashMap();
  +
  +        fieldCtors.put("int", new FieldFactory.FieldCtor()
  +            {
  +                public Field getInstance(XmlField f, Group g)
  +                    throws Exception
  +                {
  +                    return new IntegerField(f, g);
  +                }
  +            }
  +                       );
  +        fieldCtors.put("boolean", new FieldFactory.FieldCtor()
  +            {
  +                public Field getInstance(XmlField f, Group g)
  +                    throws Exception
  +                {
  +                    return new BooleanField(f, g);
  +                }
  +            }
  +                       );
  +        fieldCtors.put("String", new FieldFactory.FieldCtor()
  +            {
  +                public Field getInstance(XmlField f, Group g)
  +                    throws Exception
  +                {
  +                    return new StringField(f, g);
  +                }
  +            }
  +                       );
  +        fieldCtors.put("BigDecimal", new FieldFactory.FieldCtor()
  +            {
  +                public Field getInstance(XmlField f, Group g)
  +                    throws Exception
  +                {
  +                    return new BigDecimalField(f, g);
  +                }
  +            }
  +                       );
  +        fieldCtors.put("NumberKey", new FieldFactory.FieldCtor()
  +            {
  +                public Field getInstance(XmlField f, Group g)
  +                    throws Exception
  +                {
  +                    return new NumberKeyField(f, g);
  +                }
  +            }
  +                       );
  +        fieldCtors.put("ComboKey", new FieldFactory.FieldCtor()
  +            {
  +                public Field getInstance(XmlField f, Group g)
  +                    throws Exception
  +                {
  +                    return new ComboKeyField(f, g);
  +                }
  +            }
  +                       );
  +        return fieldCtors;
  +    }
  +
  +    private static abstract class FieldCtor
  +    {
  +        public Field getInstance(XmlField f, Group g) throws Exception 
  +        {
  +            return null;
  +        }
  +    }
  +
       /**
        * Creates a Field object appropriate for the type specified
        * in the xml file.
  @@ -85,30 +156,13 @@
        * @return a <code>Field</code> value
        */
       public static final Field getInstance(XmlField f, Group g)
  -        throws RESyntaxException, ClassNotFoundException,
  -               IntrospectionException, TurbineException, Exception
  +        throws Exception
       {
           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 if (f.getType().equals("boolean")) 
  -        {
  -            field = new BooleanField(f, g);
  -        }
  -        else 
  +        field = ((FieldCtor)fieldCtors.get(type)).getInstance(f, g);
  +        if ( field == null) 
           {
               throw new TurbineException("Unsupported type: " + type);
           }
  
  
  
  1.6       +49 -9     jakarta-turbine/src/java/org/apache/turbine/services/intake/model/Group.java
  
  Index: Group.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/intake/model/Group.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Group.java	2001/03/22 16:12:46	1.5
  +++ Group.java	2001/03/27 06:51:48	1.6
  @@ -101,12 +101,17 @@
       /**
        * A map of the fields in this group mapped by field name.
        */
  -    public final Map fields;
  +    public Map fields;
   
       /**
  +     * Map of the fields by mapToObject
  +     */
  +    public Map mapToObjectFields;
  +
  +    /**
        * An array of fields in this group.
        */
  -    public final Field[] fieldsArray;
  +    public Field[] fieldsArray;
   
       /**
        * The object id used to associate this group to a bean
  @@ -131,18 +136,38 @@
           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));
  +        mapToObjectFields = 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;
  +            fields.put(f.getName(), field);
  +
  +            // map fields by their mapToObject
  +            List tmpFields = (List)mapToObjectFields.get(f.getMapToObject());
  +            if ( tmpFields == null ) 
  +            {
  +                tmpFields = new ArrayList(size);
  +                mapToObjectFields.put(f.getMapToObject(), tmpFields);
  +            }
  +            tmpFields.add(field);
           }
  +
  +        // Change the mapToObjectFields values to Field[]
  +        Iterator keys = mapToObjectFields.keySet().iterator();
  +        while ( keys.hasNext() ) 
  +        {
  +            Object key = keys.next();
  +            List tmpFields = (List)mapToObjectFields.get(key);
  +            mapToObjectFields.put(key, 
  +                tmpFields.toArray(new Field[tmpFields.size()]));
  +        }
       } 
          
       /**
  @@ -165,7 +190,7 @@
        */
       public Group init(String key, RunData data)
       {
  -        this.oid = oid;
  +        this.oid = key;
           for (int i=fieldsArray.length-1; i>=0; i--) 
           {
               fieldsArray[i].init(data);
  @@ -183,13 +208,22 @@
       public Group init(Retrievable obj)
       {
           this.oid = obj.getQueryKey();
  -        for (int i=fieldsArray.length-1; i>=0; i--) 
  +
  +        Class cls = obj.getClass();
  +        while ( cls != null ) 
           {
  -            if (obj.getClass().getName().equals(fieldsArray[i].mapToObject))
  -            {
  -                fieldsArray[i].init(obj);
  +            Field[] flds = (Field[])mapToObjectFields.get(cls.getName());
  +            if ( flds != null ) 
  +            {                
  +                for (int i=flds.length-1; i>=0; i--) 
  +                {
  +                    flds[i].init(obj);
  +                }
               }
  +            
  +            cls = cls.getSuperclass();
           }
  +
           return this;
       }
   
  @@ -225,6 +259,11 @@
           return cid;
       }
   
  +    public String getOID()
  +    {
  +        return oid;
  +    }
  +
       /**
        * Describe <code>getObjectKey</code> method here.
        *
  @@ -327,6 +366,7 @@
       public void dispose()
       {
           oid = null;
  +
           for (int i=fieldsArray.length-1; i>=0; i--) 
           {
               fieldsArray[i].dispose();
  
  
  
  1.5       +18 -7     jakarta-turbine/src/java/org/apache/turbine/services/intake/model/IntakeValue.java
  
  Index: IntakeValue.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/intake/model/IntakeValue.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- IntakeValue.java	2001/03/21 00:17:11	1.4
  +++ IntakeValue.java	2001/03/27 06:51:48	1.5
  @@ -69,7 +69,7 @@
    * dealing with a parameter value
    *
    * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
  - * @version $Id: IntakeValue.java,v 1.4 2001/03/21 00:17:11 jmcnally Exp $
  + * @version $Id: IntakeValue.java,v 1.5 2001/03/27 06:51:48 jmcnally Exp $
    */
   public final class IntakeValue
   {
  @@ -129,12 +129,12 @@
           return testValue;
       }
   
  -    public String toString()
  +    public Object getValue()
       {
  -        Object valVal = null;
  +        Object val = null;
           try
           {
  -            valVal = getValidValue();
  +            val = getValidValue();
           }
           catch (Exception e)
           {
  @@ -142,12 +142,23 @@
           }
   
           if ( getTestValue() != null ) 
  +        {
  +            val = getTestValue();
  +        }
  +
  +        if ( val == null ) 
           {
  -            return getTestValue().toString();
  +            val = field.onError;
           }
  -        else if (valVal != null) 
  +        
  +        return val;
  +    }
  +
  +    public String toString()
  +    {
  +        if ( getValue() != null ) 
           {
  -            return valVal.toString();
  +            return getValue().toString();            
           }
           else 
           {
  
  
  
  1.4       +1 -1      jakarta-turbine/src/java/org/apache/turbine/services/intake/model/IntegerField.java
  
  Index: IntegerField.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/intake/model/IntegerField.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IntegerField.java	2001/03/14 07:27:31	1.3
  +++ IntegerField.java	2001/03/27 06:51:48	1.4
  @@ -153,7 +153,7 @@
           {
               ival = Integer.parseInt(val);
           }
  -        catch (NumberFormatException nfe)
  +        catch (Exception e)
           {
               valid_flag = false;
               ival = onError;
  
  
  
  1.1                  jakarta-turbine/src/java/org/apache/turbine/services/intake/model/ComboKeyField.java
  
  Index: ComboKeyField.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.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.*;
  import org.apache.turbine.services.intake.*;
  
  
  /**  */
  public class ComboKeyField extends Field
  {
      // protected final ComboKey onError;
  
      protected final ComboKey minValue;
      protected final String minValueMessage;
      protected final boolean minValueForce;
      protected final ComboKey maxValue;
      protected final String maxValueMessage;
      protected final boolean maxValueForce;
  
      public ComboKeyField(XmlField field, Group group)
          throws Exception
      {
          super(field, group);
  
          onError = new ComboKey();
  
          ComboKey tmpMinValue = null;
          String tmpMinValueMessage = null;
          boolean tmpMinValueForce = false;
          ComboKey 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 ComboKey(rule.getMinValue());
                  tmpMinValueMessage = rule.getMessage();
                  tmpMinValueForce = "force".equals(rule.getAction());
              }
  
              if ( rule.getMaxValue() != null )
              {
                  tmpMaxValue = new ComboKey(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());
              ComboKey[] ival = new ComboKey[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 ComboKey checkString(String val)
      {
          ComboKey ival = (ComboKey)onError;
          try
          {
              ival = new ComboKey(val);
          }
          catch (Exception e)
          {
              valid_flag = false;
              ival = (ComboKey)onError;
          }
  
          boolean b;
          if ( maxLength > 0 )
          {
              b = val.length() > maxLength; 
              if ( maxLengthForce  && b )
              {
                  val = val.substring(0, maxLength);
                  try
                  {
                      ival = new ComboKey(val);
                  }
                  catch (Exception e)
                  {
                      valid_flag = false;
                      ival = (ComboKey)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/NumberKeyField.java
  
  Index: NumberKeyField.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.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.*;
  import org.apache.turbine.services.intake.*;
  
  
  /**  */
  public class NumberKeyField extends Field
  {
      // protected final NumberKey onError;
  
      protected final NumberKey minValue;
      protected final String minValueMessage;
      protected final boolean minValueForce;
      protected final NumberKey maxValue;
      protected final String maxValueMessage;
      protected final boolean maxValueForce;
  
      public NumberKeyField(XmlField field, Group group)
          throws Exception
      {
          super(field, group);
  
          onError = new NumberKey();
  
          NumberKey tmpMinValue = null;
          String tmpMinValueMessage = null;
          boolean tmpMinValueForce = false;
          NumberKey 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 NumberKey(rule.getMinValue());
                  tmpMinValueMessage = rule.getMessage();
                  tmpMinValueForce = "force".equals(rule.getAction());
              }
  
              if ( rule.getMaxValue() != null )
              {
                  tmpMaxValue = new NumberKey(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());
              NumberKey[] ival = new NumberKey[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 NumberKey checkString(String val)
      {
          NumberKey ival = (NumberKey)onError;
          try
          {
              ival = new NumberKey(val);
          }
          catch (Exception e)
          {
              valid_flag = false;
              ival = (NumberKey)onError;
          }
  
          boolean b;
          if ( maxLength > 0 )
          {
              b = val.length() > maxLength; 
              if ( maxLengthForce  && b )
              {
                  val = val.substring(0, maxLength);
                  try
                  {
                      ival = new NumberKey(val);
                  }
                  catch (Exception e)
                  {
                      valid_flag = false;
                      ival = (NumberKey)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.2       +4 -6      jakarta-turbine/src/java/org/apache/turbine/services/intake/transform/XmlToAppData.java
  
  Index: XmlToAppData.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/intake/transform/XmlToAppData.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlToAppData.java	2001/03/09 11:38:10	1.1
  +++ XmlToAppData.java	2001/03/27 06:51:49	1.2
  @@ -73,7 +73,7 @@
    * 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 $
  + * @version $Id: XmlToAppData.java,v 1.2 2001/03/27 06:51:49 jmcnally Exp $
    */
   public class XmlToAppData extends DefaultHandler
   {
  @@ -109,9 +109,9 @@
           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.setFeature(
  +        //    "http://apache.org/xml/features/validation/dynamic", true);
  +        //parser.setFeature("http://xml.org/sax/features/validation", true);
               
           parser.setErrorHandler(this);
           
  @@ -119,8 +119,6 @@
           BufferedReader br = new BufferedReader (fr);
           try
           {
  -            System.out.println("xmlFile: " + xmlFile);
  -            
               InputSource is = new InputSource (br);
               parser.parse(is);
           }
  
  
  
  1.3       +1 -3      jakarta-turbine/src/java/org/apache/turbine/services/intake/xmlmodel/XmlGroup.java
  
  Index: XmlGroup.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine/src/java/org/apache/turbine/services/intake/xmlmodel/XmlGroup.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XmlGroup.java	2001/03/21 00:17:15	1.2
  +++ XmlGroup.java	2001/03/27 06:51:50	1.3
  @@ -66,7 +66,7 @@
    * 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.2 2001/03/21 00:17:15 jmcnally Exp $
  + * @version $Id: XmlGroup.java,v 1.3 2001/03/27 06:51:50 jmcnally Exp $
    */
   public class XmlGroup
   {
  @@ -195,7 +195,6 @@
           else if( field.getMapToProperty() != null 
                    && defaultMapToObject != null )
           {
  -        System.out.println("addField is called: " + defaultMapToObject);
               field.setMapToObject(defaultMapToObject);
           }
           
  @@ -271,7 +270,6 @@
               defaultMapToObject = parent.getBasePackage() + defaultMapToObject;
               mapToObjects.add(defaultMapToObject);
           }
  -        System.out.println("setAppData is called: " + defaultMapToObject);
       }
   
       /**
  
  
  

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