Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/aendvari/griffin/bean/transform/InspectedBean.java


1   /*
2    * InspectedBean.java
3    *
4    * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5    *
6    * See the file LICENSE for terms of use.
7    *
8    */
9   
10  package com.aendvari.griffin.bean.transform;
11  
12  import java.beans.*;
13  import java.util.*;
14  
15  import java.lang.reflect.*;
16  import java.lang.NoSuchMethodException;
17  import java.lang.IllegalAccessException;
18  
19  import com.aendvari.common.util.*;
20  
21  import com.aendvari.common.model.*;
22  
23  
24  /**
25   * <p>
26   * Inspects the given bean or class for all get/set methods and
27   * stores them for later accessing based on their bean property name
28   * </p>
29   *
30   * @author  Scott Milne
31   *
32   */
33  
34  public class InspectedBean
35  {
36    /** the bean object instance */
37    private Object beanObject;
38  
39    /** a HashMap of set methods for this bean. Key is the property name of the "set". */
40    private HashMap beanSetMethods;
41  
42    /** used internally for maintaining <code>HashMap</code> parameter methods. */
43    private HashMap beanSetHashMaps;
44  
45    /** a HashMap of get methods for this bean. Key is the property name of the "get". */
46    private HashMap beanGetMethods;
47  
48  
49    /**
50     * Create a new <code>InspectorBean</code> instance.
51     *
52     * @param    object        The bean object to inspect.
53     *
54     * @throws              Throws <code>Exception</code> if initialization goes wrong.
55     *
56     */
57  
58    public InspectedBean( Object object )
59      throws Exception
60    {
61      beanObject = object;
62  
63      // initilize the inspector
64      initilize();
65    }
66  
67    /**
68     * Create a new <code>InspectorBean</code> instance.
69     *
70     * @param    objectType      The <code>Class</code> type of the bean to inspect.
71     *
72     * @throws              Throws <code>Exception</code> if initialization goes wrong.
73     *
74     */
75  
76    public InspectedBean( Class objectType )
77      throws Exception
78    {
79      // now create an instance of the class
80      try
81      {
82        // create an instance of the given class
83        beanObject = objectType.newInstance();
84      }
85      /*
86       * ClassNotFoundException
87       * NoSuchMethodException
88       * IllegalAccessException
89       *
90       */
91      catch (Exception exception)
92      {
93        throw new Exception("[InspectedBean] Class Not Found: " + objectType.getName() + ". ExceptionStackTrace: " + ExceptionUtil.getStackTrace(exception));
94      }
95  
96      // initilize the inspector
97      initilize();
98    }
99  
100   /**
101    * Create a new <code>InspectorBean</code> instance.
102    *
103    * @param    beanType      The <code>Class</code> name of the bean to inspect.
104    *
105    * @throws              Throws <code>Exception</code> if initialization goes wrong.
106    *
107    */
108 
109   public InspectedBean( String beanType )
110     throws Exception
111   {
112     // lookup the class object by name
113     Class objectType = null;
114 
115     try
116     {
117       objectType = Class.forName(beanType);
118     }
119     catch(ClassNotFoundException exception)
120     {
121       throw new Exception("[InspectedBean] Class Not Found: " + beanType + ". ExceptionStackTrace: " + ExceptionUtil.getStackTrace(exception));
122     }
123 
124     // now create an instance of the class
125     try
126     {
127       // create an instance of the given class
128       beanObject = objectType.newInstance();
129     }
130     /*
131      * ClassNotFoundException
132      * NoSuchMethodException
133      * IllegalAccessException
134      *
135      */
136     catch (Exception exception)
137     {
138       throw new Exception("[InspectedBean] Class Not Instantiated: " + beanType + ". ExceptionStackTrace: " + ExceptionUtil.getStackTrace(exception));
139     }
140 
141     // initilize the inspector
142     initilize();
143   }
144 
145 
146   /**
147    * Initialization of the <code>InspectorBean</code>.
148    *
149    * @throws    Throws <code>Exception</code> if initiliazation goes wrong.
150    *
151    */
152 
153   private void initilize()
154     throws Exception
155   {
156     beanGetMethods = new HashMap();
157     beanSetMethods = new HashMap();
158     beanSetHashMaps = new HashMap();
159 
160     retrieveMethods();
161   }
162 
163 
164   /**
165    * Gets all the set/get methods for this bean and store into a <code>HashMap</code> based on their property name.
166    *
167    * @throws    Throws <code>Exception</code> if something goes wrong.
168    *
169    */
170 
171   private void retrieveMethods()
172     throws Exception
173   {
174     try
175     {
176       // transverse the bean
177       BeanInfo beanInfo = Introspector.getBeanInfo( beanObject.getClass() );
178 
179       // get all the properties of the bean
180       PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
181 
182       // for each property, get the set/get methods if available
183       int index=0;
184       for (index=0; index<propertyDescriptors.length; index++)
185       {
186         PropertyDescriptor property = propertyDescriptors[index];
187 
188         // if this propery descriptor is for a method that
189         // gets/sets a reference to this object itself, ignore it
190         if (beanObject.getClass() == property.getPropertyType())
191         {
192           continue;
193         }
194 
195                 // test to make sure the property is valid
196                 try
197                 {
198                     if( !property.getPropertyType().equals(Class.class) )
199                     {
200                         // nothing
201                     }
202                 }
203                 catch(Exception e)
204                 {
205                     throw new Exception("[retrieveMethods] The access method for property: " + property.getName() + " in object: " + beanObject.getClass() + " is invalid.");
206                 }
207 
208         // skip the type "class", it is actually the bean itself
209         if( !property.getPropertyType().equals(Class.class) )
210         {
211           //
212           // Set Methods
213           //
214 
215           // get the "set" method of the property
216           Method setMethod = property.getWriteMethod();
217 
218           // if null, that means there was no "set" method for the property
219           if( setMethod != null )
220           {
221             //
222             // Get the first parameter of the "set" method.
223             //
224             // Working on this assumption:
225             //    A bean "set" (non-indexed) has only one parameter?
226             //
227             Class[] params = setMethod.getParameterTypes();
228             if( params.length > 0 )
229             {
230               Class param = params[0];
231 
232               // create a bean set method instance for this method
233                             try
234                             {
235                      BeanSetMethod beanMethod = new BeanSetMethod(setMethod, param);
236     
237                   // store the instance into the HashMap keyed by its property name
238                   beanSetMethods.put( property.getName(), beanMethod );
239                             }
240                             catch(Exception e)
241                             {
242                                 throw new Exception("[retrieveMethods] The set method: " + setMethod + " for property: " + property.getName() + " could not be instantiated.");
243                             }
244             }
245           }
246 
247           //
248           // Get Methods
249           //
250 
251           // use reflection to ask the bean property for it's value
252           Method getMethod = property.getReadMethod();
253 
254           // make sure they have a read method for this property
255           if( getMethod != null )
256           {
257              try
258              {
259                 // create a bean get method object
260                 BeanGetMethod beanMethod = new BeanGetMethod(getMethod);
261 
262                 // store the instance into the HashMap keyed by its property name
263                 beanGetMethods.put( property.getName(), beanMethod );
264                         }
265                         catch(Exception e)
266                         {
267                             throw new Exception("[retrieveMethods] The get method: " + getMethod + " for property: " + property.getName() + " could not be instantiated.");
268                         }
269           }
270         }
271       }
272     }
273     catch (Exception exception)
274     {
275       throw new Exception("[retrieveMethods] Object: " + beanObject.getClass() + " could not be completed. ExceptionStackTrace: " + ExceptionUtil.getStackTrace(exception));
276     }
277   }
278 
279 
280   /**
281    * Get an instance of the <code>InspectedBean</code>.
282    *
283    */
284 
285   public Object getBeanInstance()
286     throws Exception
287   {
288     executeSetMethods();
289 
290     return beanObject;
291   }
292 
293   /**
294    * Get the bean object.
295    *
296    */
297 
298   public Object getBeanObject()
299     throws Exception
300   {
301     return beanObject;
302   }
303 
304 
305   //
306   // "get" management Methods
307   //
308 
309   /**
310    * Get the <code>HashMap</code> of all the get methods for this bean.
311    *
312    */
313 
314   public HashMap getGetMethods()
315   {
316     return beanGetMethods;
317   }
318 
319 
320   /**
321    * Executes the get method matched to the property name on the give bean object.
322    *
323    * @param    propertyName        The name of the property that the method matches.
324    * @param    beanObj            The bean object top call the method on.
325    *
326    * @return                  The <code>Object</code> returned from the method call.
327    *
328    * @throws                   Throws <code>Exception</code> if something goes wrong.
329    *
330    */
331 
332   public Object executeGetMethod( String propertyName, Object beanObj )
333     throws Exception
334   {
335     BeanGetMethod getMethod = (BeanGetMethod)beanGetMethods.get(propertyName);
336 
337     if (getMethod != null)
338     {
339       return getMethod.executeGetMethod( beanObj );
340     }
341 
342     return null;
343   }
344 
345 
346   /**
347    * Returns the get method matched to the property name of the inspected bean.
348    *
349    * @param    propertyName        The name of the property that the method matches.
350    *
351    * @return                  A {@link BeanGetMethod} instance.
352    *
353    * @throws                   Throws <code>Exception</code> if something goes wrong.
354    *
355    */
356 
357   public BeanGetMethod getBeanGetMethod( String propertyName )
358     throws Exception
359   {
360     BeanGetMethod getMethod = (BeanGetMethod)beanGetMethods.get(propertyName);
361 
362     return getMethod;
363   }
364 
365 
366   //
367   // "set" management Methods
368   //
369 
370   /**
371    * Get the <code>Class</code> type for the set method parameter.
372    *
373    * @param    propertyName        The name of the method property you wish to get the <code>Class</code> parameter of.
374    *
375    * @return                  A <code>Class</code> that is the set method parameter.
376    *
377    */
378 
379   public Class getSetMethodParamClass( String propertyName )
380   {
381     BeanSetMethod beanMethod = (BeanSetMethod)beanSetMethods.get(propertyName);
382 
383     if( beanMethod == null )
384     {
385       return null;
386     }
387 
388     Class paramClass = beanMethod.getParamClass();
389 
390     return paramClass;
391   }
392 
393 
394   /**
395    * Get the value (as <code>Object</code>) for the set method parameter.
396    *
397    * @param    propertyName        The name of the method property you wish to get the <code>Class</code> parameter of.
398    *
399    * @return                  The value as an <code>Object</code> for the set method.
400    *
401    */
402 
403   public Object getSetMethodParamValue( String propertyName )
404   {
405     BeanSetMethod beanMethod = (BeanSetMethod)beanSetMethods.get(propertyName);
406 
407     if( beanMethod == null )
408     {
409       return null;
410     }
411 
412     Object paramValue = beanMethod.getParamValue();
413 
414     return paramValue;
415   }
416 
417 
418   /**
419    * Set the parameter value of (or add to if <code>array[]</code>, <code>Collection</code> or <code>Map</code>) the method.
420    *
421    * @param    propertyName        The name of the method property you wish to get the <code>Class</code> parameter of.
422    * @param    value            The <code>Object</code> to place into the method parameter.
423    *
424    */
425 
426   public void addSetMethodParamValue( String propertyName, Object value )
427   {
428     BeanSetMethod beanMethod = (BeanSetMethod)beanSetMethods.get(propertyName);
429 
430     if( beanMethod == null )
431     {
432       return;
433     }
434 
435     Object paramValue = beanMethod.getParamValue();
436     Class paramClass = beanMethod.getParamClass();
437 
438     if( paramClass.isPrimitive() )
439     {
440       beanMethod.addPrimitiveValue(value);
441     }
442     else if( paramClass.isArray() )
443     {
444       beanMethod.addArrayValue(value);
445     }
446     // if the object is a Set type
447     else if( paramValue instanceof Collection )
448     {
449       beanMethod.addCollectionValue(value);
450     }
451     // if the property is another Bean, convert it as well
452     else if(
453       !paramClass.isPrimitive() &&
454       !BeanTransformer.isJavaUtilClass(paramValue) &&
455       !BeanTransformer.isJavaLangClass(paramValue)
456     )
457     {
458       beanMethod.addSimpleValue(value);
459     }
460     else
461     {
462       beanMethod.addSimpleValue(value);
463     }
464   }
465 
466 
467   /**
468    * Executes all set methods for this bean assigning each property the method parameter.
469    *
470    * @throws                   Throws <code>Exception</code> if something goes wrong.
471    *
472    */
473 
474   private void executeSetMethods()
475     throws Exception
476   {
477     Iterator keysIterator = beanSetMethods.keySet().iterator();
478     while (keysIterator.hasNext())
479     {
480       String key = (String)keysIterator.next();
481       BeanSetMethod beanMethod = (BeanSetMethod)beanSetMethods.get(key);
482 
483       Object paramValue = beanMethod.getParamValue();
484       Class paramClass = beanMethod.getParamClass();
485 
486       if( paramClass.isPrimitive() )
487       {
488         beanMethod.executeSetMethod(beanObject);
489       }
490       else if( paramClass.isArray() )
491       {
492         beanMethod.executeSetMethod(beanObject);
493       }
494       else if( paramValue instanceof Map )
495       {
496         beanMethod.executeSetMethod(beanObject);
497       }
498       // if the object is a Set type
499       else if( paramValue instanceof Collection )
500       {
501         beanMethod.executeSetMethod(beanObject);
502       }
503       // if the property is another Bean, convert it as well
504       else if(
505         !paramClass.isPrimitive() &&
506         !BeanTransformer.isJavaUtilClass(paramValue) &&
507         !BeanTransformer.isJavaLangClass(paramValue)
508       )
509       {
510         beanMethod.executeSetMethod(beanObject);
511       }
512       else
513       {
514         beanMethod.executeSetMethod(beanObject);
515       }
516     }
517   }
518 
519 
520   /**
521    * Create a <code>Map</code> instance for holding key/value pairs of the <code>HashMap</code> method parameter.
522    * This is a temporary set of values used for building a <code>Map</code> of key/value pairs while
523    * reading data at different points.
524    * <p>
525    * <code><pre>
526    *    createSetMethodParamMap()
527    *
528    *      .. do some stuff ..
529    *
530    *    addSetMethodParamMapKey()    <-- you must call (in either order) a set key
531    *    addSetMethodParamMapValue()    <-- and a set value before calling that same
532    *                    <-- one again. ie: setKey, setKey is wrong.
533    *
534    *      .. do some more stuff ..
535    *
536    *    addSetMethodParamMap() <-- this is called after all sets have been made
537    *
538    * </pre></code>
539    * </p>
540    *
541    * @param    propertyName        The name of the method property you wish to get the <code>Class</code> parameter of.
542    *
543    */
544 
545   public void createSetMethodParamMap( String propertyName )
546   {
547     beanSetHashMaps.put( propertyName, new HashMapKeyValuePairs() );
548   }
549 
550 
551   /**
552    * Sets the temporary <code>Map</code> instance into the <code>HashMap</code> method parameter.
553    * Only call this after all data reading has been completed for the Map.
554    *
555    * @param    propertyName        The name of the method property you wish to get the <code>Class</code> parameter of.
556    *
557    */
558 
559   public void addSetMethodParamMap( String propertyName )
560   {
561     BeanSetMethod beanMethod = (BeanSetMethod)beanSetMethods.get(propertyName);
562 
563     if( beanMethod == null )
564     {
565       return;
566     }
567 
568     HashMapKeyValuePairs pairs = (HashMapKeyValuePairs)beanSetHashMaps.get(propertyName);
569 
570     HashSet keys = pairs.getKeys();
571     HashSet values = pairs.getValues();
572 
573     Iterator keysIterator = keys.iterator();
574     Iterator valuesIterator = values.iterator();
575 
576     while (keysIterator.hasNext())
577     {
578       Object key = (Object)keysIterator.next();
579       Object value = (Object)valuesIterator.next();
580 
581       beanMethod.addMapValue(key, value);
582     }
583   }
584 
585 
586   /**
587    * Sets the key into the temporary <code>Map</code> for the given property
588    *
589    * @param    propertyName        The name of the method property you wish to get the <code>Class</code> parameter of.
590    * @param    key              The key for the Map;
591    *
592    */
593 
594   public void addSetMethodParamMapKey( String propertyName, Object key )
595   {
596     HashMapKeyValuePairs pairs = (HashMapKeyValuePairs)beanSetHashMaps.get(propertyName);
597     pairs.addKey(key);
598   }
599 
600 
601   /**
602    * Sets the value into the temporary <code>Map</code> for the given property
603    *
604    * @param    propertyName        The name of the method property you wish to get the <code>Class</code> parameter of.
605    * @param    value              The value for the Map;
606    *
607    */
608 
609   public void addSetMethodParamMapValue( String propertyName, Object value )
610   {
611     HashMapKeyValuePairs pairs = (HashMapKeyValuePairs)beanSetHashMaps.get(propertyName);
612     pairs.addValue(value);
613   }
614 
615 
616   ////////////////////////////////////////////////////
617   //
618   // Internal Classes
619   //
620   ////////////////////////////////////////////////////
621 
622 
623   /**
624    * Internal class used to help maintain <code>Map</code> entries for this bean.
625    *
626    */
627 
628   private class HashMapKeyValuePairs
629   {
630     private HashSet keys;
631     private HashSet values;
632 
633     public HashMapKeyValuePairs()
634     {
635       keys = new HashSet();
636       values = new HashSet();
637     }
638 
639     public void addKey( Object key ) { keys.add(key); }
640     public void addValue( Object value ) { values.add(value); }
641 
642     public HashSet getKeys() { return keys; }
643     public HashSet getValues() { return values; }
644   }
645 
646 
647   /**
648    * Internal class used to hold a "get" method
649    *
650    */
651 
652   public class BeanGetMethod
653   {
654     /** the Method object for this "get" */
655     private Method method;
656 
657     /** get the method instance */
658     public Method getMethod() { return method; }
659 
660 
661     /**
662      * Constructor
663      *
664      * @param    setMethod      The Method object for this "get".
665      *
666      */
667 
668     public BeanGetMethod( Method setMethod )
669     {
670       method = setMethod;
671     }
672 
673 
674     /**
675      * Executes the "get" method for the bean, on the given bean instance.
676      *
677      * @param    beanObject      The bean object to execute the "get" on.
678      *
679      * @return              The "value" returned from the "get".
680      *
681      * @throws              Throws an <code>Exception</code> if something goes wrong.
682      *
683      */
684 
685     public Object executeGetMethod( Object beanObject )
686       throws Exception
687     {
688       try
689       {
690         // assumes a "get" method has no parameters
691         Object returnObj = method.invoke( beanObject, null );
692         return returnObj;
693       }
694       catch (Exception exception)
695       {
696         throw new Exception(
697           "[executeGetMethod] Method Invoke Failure: " +
698           "method=" + method + ", " +
699           "object=" + beanObject + ". " +
700           "ExceptionStackTrace: " + ExceptionUtil.getStackTrace(exception));
701       }
702     }
703   }
704 
705 
706   /**
707    * Internal class used to hold a "set" method
708    *
709    */
710 
711   private class BeanSetMethod
712   {
713     /** used to determine if the method should be used when <code>executeSetMethod()</code> is called. */
714     private boolean methodActive;
715 
716     /** the <code>Method</code> object for this "set" method */
717     private Method method;
718 
719     /** the <code>Class</code> type of the "set" parameter */
720     private Class paramClass;
721 
722     /**
723      * The <code>Class</code> type of the "set" parameter.
724      * This is the same as the <code>paramClass</code> except for when an <code>array[]</code> is the
725      * parameter type.. Then this is set to the <code>Class</code> type of a single array item.
726      *
727      */
728     private Class paramType;
729 
730     /** the <code>Object</code> instance of the "set" parameter */
731     private Object paramValue;
732 
733 
734     /* Accessors */
735 
736     public Method getMethod() { return method; }
737     public Class getParamType() { return paramType; }
738     public Object getParamValue() { return paramValue; }
739     public Class getParamClass() { return paramClass; }
740 
741 
742     /* Constructors */
743 
744     /**
745      * Create a new <code>BeanSetMethod</code>.
746      *
747      * @param    setMethod      The <code>Method</code> object for this "set".
748      * @param    setParam      The <code>Class</code> type of the parameter.
749      *
750      * @throws              <code>Exception</code> if something goes wrong.
751      *
752      */
753 
754     public BeanSetMethod( Method setMethod, Class setParam )
755       throws Exception
756     {
757       methodActive = false;
758       this.method = setMethod;
759       this.paramClass = setParam;
760 
761       // if the parameter class type is a primitive
762       if( paramClass.isPrimitive() )
763       {
764         // get the type of the param
765         paramType = paramClass;
766 
767         // create an empty primitive. This gets reset by addPrimitiveValue()
768         addPrimitiveValue("0");
769       }
770       // the parameter is an array[]
771       else if( paramClass.isArray() )
772       {
773         // get the type of the param
774         paramType = setParam.getComponentType();
775 
776         // For now, use an ArrayList, we'll convert this to an array[] later.
777         // This avoid constant re-allocation of the array[].
778         //
779         // See convertArrayParam() for convertion method
780         paramValue = new ArrayList();
781       }
782       // it's an object of some type. Could be bean, or any other object
783       else
784       {
785         // get the type of the param
786         paramType = paramClass;
787 
788         try
789         {
790           // create a new instance of the object
791           paramValue = paramClass.newInstance();
792         }
793         catch (Exception exception)
794         {
795           throw new Exception("[BeanSetMethod] Class Not Instantiated: " + paramClass + ". ExceptionStackTrace: " + ExceptionUtil.getStackTrace(exception));
796         }
797       }
798 
799       // make sure this method is not active yet
800       methodActive = false;
801     }
802 
803 
804     /**
805      * Executes this method with it's parameter value.
806      *
807      * @param    beanObject        The bean to execute this method on.
808      *
809      * @throws                Throws <code>Exception</code> if the method call fails.
810      *
811      */
812 
813     public void executeSetMethod( Object beanObject )
814       throws Exception
815     {
816       // if the param is an array[], convert the ArrayList into the array[] first
817       if( paramClass.isArray() )
818       {
819         convertArrayParam();
820       }
821 
822       // if the method is active, execute it
823       if( methodActive )
824       {
825         Object[] args = {paramValue};
826         
827         try
828         {
829           method.invoke( beanObject, args );
830         }
831         catch (Exception exception)
832         {
833           throw new Exception(
834             "[executeSetMethod] Method Invoke Failure: " +
835             "method=" + method + ", " +
836             "object=" + beanObject + ", " +
837             "parameter=" + paramValue + ". " +
838             "ExceptionStackTrace: " + ExceptionUtil.getStackTrace(exception));
839         }
840       }
841     }
842 
843 
844     /**
845      * Used to set a simple (<code>Object</code>) parameter.
846      *
847      * @param    setValue        The object to set as the parameter of this method.
848      *
849      */
850 
851     public void addSimpleValue( Object setValue )
852     {
853       methodActive = true;
854       paramValue = setValue;
855     }
856 
857 
858     /**
859      * Used to set a value into the <code>array[]</code> method parameter.
860      *
861      * @param    setValue        The object to add to the parameter of this method.
862      *
863      */
864 
865     public void addArrayValue( Object setValue )
866     {
867       methodActive = true;
868 
869       ArrayList list = (ArrayList)paramValue;
870       list.add(setValue);
871     }
872 
873     private void convertArrayParam()
874     {
875       // get the temp array list
876       ArrayList list = (ArrayList)paramValue;
877 
878       // create an array[] of the paramType and replace the paramValue with it
879       paramValue = Array.newInstance(paramType, list.size());
880 
881       // for each value in the ArrayList
882       Iterator valuesIterator = list.iterator();
883 
884       int index = 0;
885 
886       while (valuesIterator.hasNext())
887       {
888         Object setValue = (Object)valuesIterator.next();
889 
890         if( paramType == int.class )
891         {
892           Array.setInt(paramValue, index, Integer.parseInt((String)setValue));
893         }
894         else if( paramType == boolean.class )
895         {
896           Array.setBoolean(paramValue, index, new Boolean((String)setValue).booleanValue());
897         }
898         else if( paramType == byte.class )
899         {
900           Array.setByte(paramValue, index, Byte.parseByte((String)setValue));
901         }
902         else if( paramType == char.class )
903         {
904           Array.setChar(paramValue, index, ((Character)setValue).charValue());
905         }
906         else if( paramType == double.class )
907         {
908           Array.setDouble(paramValue, index, Double.parseDouble((String)setValue));
909         }
910         else if( paramType == float.class )
911         {
912           Array.setFloat(paramValue, index, Float.parseFloat((String)setValue));
913         }
914         else if( paramType == long.class )
915         {
916           Array.setLong(paramValue, index, Long.parseLong((String)setValue));
917         }
918         else if( paramType == short.class )
919         {
920           Array.setShort(paramValue, index, Short.parseShort((String)setValue));
921         }
922         // a "real" Object
923         else
924         {
925           Array.set(paramValue, index, setValue);
926         }
927 
928         index++;
929       }
930     }
931 
932 
933     /**
934      * Used to set a value into the <code>Collection</code> method parameter.
935      *
936      * @param    setValue        The <code>Object</code> to add to the parameter of this method.
937      *
938      */
939 
940     public void addCollectionValue( Object setValue )
941     {
942       methodActive = true;
943 
944       Collection collection = (Collection)paramValue;
945       collection.add(setValue);
946     }
947 
948 
949     /**
950      * Used to set a value into the <code>Map</code> method parameter.
951      *
952      * @param    key            The key for the map entry.
953      * @param    value          The value for the map entry.
954      *
955      */
956 
957     public void addMapValue( Object key, Object value )
958     {
959       methodActive = true;
960 
961       Map map = (Map)paramValue;
962       map.put(key, value);
963     }
964 
965 
966     /**
967      * Used to set a primitive-based parameter.
968      *
969      * @param    setValue        The <code>Object</code> to set as the parameter of this method.
970      *
971      */
972 
973     public void addPrimitiveValue( Object setValue )
974     {
975       methodActive = true;
976 
977       if( paramType == boolean.class )
978       {
979         paramValue =  Boolean.valueOf((String)setValue);
980       }
981       else if( paramType == int.class )
982       {
983         String sSetValue = (String)setValue;
984 
985         if (sSetValue.equals(""))
986         {
987           paramValue = new Integer(0);
988         }
989         else
990         {
991           try
992           {
993             paramValue =  Integer.valueOf(sSetValue);
994           }
995           catch (NumberFormatException exception)
996           {
997             paramValue = new Integer(0);
998           }
999         }
1000      }
1001      else if( paramType == byte.class )
1002      {
1003        paramValue =  Byte.valueOf((String)setValue);
1004      }
1005      else if( paramType == char.class )
1006      {
1007        paramValue =  new Character(((Character)setValue).charValue());
1008      }
1009      else if( paramType == double.class )
1010      {
1011        String sSetValue = (String)setValue;
1012
1013        if (sSetValue.equals(""))
1014        {
1015          paramValue = new Double(0);
1016        }
1017        else
1018        {
1019          try
1020          {
1021            paramValue =  Double.valueOf(sSetValue);
1022          }
1023          catch (NumberFormatException exception)
1024          {
1025            paramValue = new Integer(0);
1026          }
1027        }
1028      }
1029      else if( paramType == float.class )
1030      {
1031        String sSetValue = (String)setValue;
1032
1033        if (sSetValue.equals(""))
1034        {
1035          paramValue = new Float(0);
1036        }
1037        else
1038        {
1039          try
1040          {
1041            paramValue =  Float.valueOf(sSetValue);
1042          }
1043          catch (NumberFormatException exception)
1044          {
1045            paramValue = new Float(0);
1046          }
1047        }
1048      }
1049      else if( paramType == long.class )
1050      {
1051        String sSetValue = (String)setValue;
1052
1053        if (sSetValue.equals(""))
1054        {
1055          paramValue = new Long(0);
1056        }
1057        else
1058        {
1059          try
1060          {
1061            paramValue =  Long.valueOf(sSetValue);
1062          }
1063          catch (NumberFormatException exception)
1064          {
1065            paramValue = new Long(0);
1066          }
1067        }
1068      }
1069      else if( paramType == short.class )
1070      {
1071        String sSetValue = (String)setValue;
1072
1073        if (sSetValue.equals(""))
1074        {
1075          paramValue = new Short((short)0);
1076        }
1077        else
1078        {
1079          try
1080          {
1081            paramValue =  Short.valueOf(sSetValue);
1082          }
1083          catch (NumberFormatException exception)
1084          {
1085            paramValue = new Short((short)0);
1086          }
1087        }
1088      }
1089    }
1090  }
1091}
1092