tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hans Bergsten <h...@gefionsoftware.com>
Subject cvs commit: jakarta-tomcat/src/share/org/apache/jasper/runtime JspRuntimeLibrary.java
Date Thu, 09 Dec 1999 03:10:42 GMT
bergsten    99/12/08 15:43:34

  Modified:    src/share/org/apache/jasper/runtime JspRuntimeLibrary.java
  Log:
  Correction to be able to use get/setProperty actions when the bean is not created 
  by a useBean action, received from Mandar Raje
  
  Revision  Changes    Path
  1.2       +184 -10   jakarta-tomcat/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java
  
  Index: JspRuntimeLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JspRuntimeLibrary.java    1999/10/09 00:20:40     1.1
  +++ JspRuntimeLibrary.java    1999/12/08 23:43:34     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
1.1 1999/1
0/09 00:20:40 duncan Exp $
  - * $Revision: 1.1 $
  - * $Date: 1999/10/09 00:20:40 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
1.2 1999/1
2/08 23:43:34 bergsten Exp $
  + * $Revision: 1.2 $
  + * $Date: 1999/12/08 23:43:34 $
    *
    * ====================================================================
    * 
  @@ -109,7 +109,7 @@
               }
       
               if ( t.equals(Boolean.class) || t.equals(Boolean.TYPE) ) {
  -                if (s.equalsIgnoreCase("on"))
  +                if (s.equalsIgnoreCase("on") || s.equalsIgnoreCase("true"))
                       s = "true";
                   else
                       s = "false";
  @@ -148,16 +148,17 @@
        while ( e.hasMoreElements() ) {
            String name  = (String) e.nextElement();
            String value = request.getParameter(name);
  -         if ( value == null || value.equals(""))
  +         if (value == null || value.equals(""))
                continue;
  -         introspecthelper(bean, name, value, request);
  +         introspecthelper(bean, name, value, request, name, true);
        }
       }
       // __end introspectMethod
       
       // __begin introspecthelperMethod
  -    public static void introspecthelper(Object bean, String name,
  -                                     String value, ServletRequest request) 
  +    public static void introspecthelper(Object bean, String prop,
  +                                     String value, ServletRequest request,
  +                                     String param, boolean ignoreMethodNF) 
                                        throws JasperException
       {
        try {
  @@ -169,7 +170,7 @@
                java.beans.PropertyDescriptor pd[]
                    = info.getPropertyDescriptors();
                for (int i = 0 ; i < pd.length ; i++) {
  -                 if ( pd[i].getName().equals(name) ) {
  +                 if ( pd[i].getName().equals(prop) ) {
                        method = pd[i].getWriteMethod();
                        type   = pd[i].getPropertyType();
                        break;
  @@ -178,8 +179,12 @@
            }
            if ( method != null ) {
                if (type.isArray()) {
  +                 if (request == null)
  +                     throw new JasperException("Can't set indexed property");
                    Class t = type.getComponentType();
  -                 String[] values = request.getParameterValues(name);
  +                 String[] values = request.getParameterValues(param);
  +                 //XXX Please check.
  +                 if(values == null) return;
                    if(t.equals(String.class)) {
                        method.invoke(bean, new Object[] { values });
                    } else {
  @@ -187,10 +192,16 @@
                        createTypedArray (bean, method, values, t); 
                    }
                } else {
  +                 //XXX please check.
  +                 if(value == null || value.equals("")) return;
                    Object oval = convert(value, type);
                    if ( oval != null )
                        method.invoke(bean, new Object[] { oval });
                }
  +         } else {
  +             if (!ignoreMethodNF)
  +                 throw new JasperException("Can't find method for " + prop);
  +             
            }
        } catch (Exception ex) {
            throw new JasperException (ex);
  @@ -398,5 +409,168 @@
       return new String(holdbuffer,0,bufcount);
       }
   
  +    // __begin lookupReadMethodMethod
  +    public static Object handleGetProperty(Object o, String prop)
  +    throws JasperException {
  +        java.lang.reflect.Method method = null;
  +     Object value = null;
  +        try {
  +            java.beans.BeanInfo info 
  +                = java.beans.Introspector.getBeanInfo(o.getClass());
  +            if ( info != null ) {
  +                java.beans.PropertyDescriptor pd[]
  +                    = info.getPropertyDescriptors();
  +                for (int i = 0 ; i < pd.length ; i++) {
  +                    if ( pd[i].getName().equalsIgnoreCase(prop) ) {
  +                        method = pd[i].getReadMethod();
  +                        break;
  +                    }
  +                }
  +            }
  +         if (method == null)
  +             throw new JasperException("CAn't find method for " + prop);
  +         value = method.invoke(o, null);
  +        } catch (Exception ex) {
  +         throw new JasperException (ex);
  +        }
  +        return value;
  +    }
  +    // __end lookupReadMethodMethod
  +
  +    public static void handleSetProperty(Object bean, String prop,
  +                                      Object value)
  +     throws JasperException
  +    {
  +     try {
  +         Method method = getMethod(bean, prop);
  +         method.invoke(bean, new Object[] { value });
  +     } catch (Exception ex) {
  +         throw new JasperException(ex);
  +     }
  +    }
  +    
  +    public static void handleSetProperty(Object bean, String prop,
  +                                      int value)
  +     throws JasperException
  +    {
  +     try {
  +         Method method = getMethod(bean, prop);
  +         method.invoke(bean, new Object[] { new Integer(value) });
  +     } catch (Exception ex) {
  +         throw new JasperException(ex);
  +     }       
  +    }
  +    
  +    public static void handleSetProperty(Object bean, String prop,
  +                                      short value)
  +     throws JasperException
  +    {
  +     try {
  +         Method method = getMethod(bean, prop);
  +         method.invoke(bean, new Object[] { new Short(value) });
  +     } catch (Exception ex) {
  +         throw new JasperException(ex);
  +     }       
  +    }
  +    
  +    public static void handleSetProperty(Object bean, String prop,
  +                                      long value)
  +     throws JasperException
  +    {
  +     try {
  +         Method method = getMethod(bean, prop);
  +         method.invoke(bean, new Object[] { new Long(value) });
  +     } catch (Exception ex) {
  +         throw new JasperException(ex);
  +     }       
  +    } 
  +    
  +    public static void handleSetProperty(Object bean, String prop,
  +                                      double value)
  +     throws JasperException
  +    {
  +     try {
  +         Method method = getMethod(bean, prop);
  +         method.invoke(bean, new Object[] { new Double(value) });
  +     } catch (Exception ex) {
  +         throw new JasperException(ex);
  +     }       
  +    }
  +    
  +    public static void handleSetProperty(Object bean, String prop,
  +                                      float value)
  +     throws JasperException
  +    {
  +     try {
  +         Method method = getMethod(bean, prop);
  +         method.invoke(bean, new Object[] { new Float(value) });
  +     } catch (Exception ex) {
  +         throw new JasperException(ex);
  +     }       
  +    }
  +    
  +    public static void handleSetProperty(Object bean, String prop,
  +                                      char value)
  +     throws JasperException
  +    {
  +     try {
  +         Method method = getMethod(bean, prop);
  +         method.invoke(bean, new Object[] { new Character(value) });
  +     } catch (Exception ex) {
  +         throw new JasperException(ex);
  +     }       
  +    }
   
  +    public static void handleSetProperty(Object bean, String prop,
  +                                      byte value)
  +     throws JasperException
  +    {
  +     try {
  +         Method method = getMethod(bean, prop);
  +         method.invoke(bean, new Object[] { new Byte(value) });
  +     } catch (Exception ex) {
  +         throw new JasperException(ex);
  +     }       
  +    }
  +    
  +    public static void handleSetProperty(Object bean, String prop,
  +                                      boolean value)
  +     throws JasperException
  +    {
  +     try {
  +         Method method = getMethod(bean, prop);
  +         method.invoke(bean, new Object[] { new Boolean(value) });
  +     } catch (Exception ex) {
  +         throw new JasperException(ex);
  +     }       
  +    }
  +    
  +    public static java.lang.reflect.Method getMethod(Object bean, String prop)
  +    throws JasperException {
  +     java.lang.reflect.Method method = null; 
  +     try {
  +         Class                    type   = null;
  +         java.beans.BeanInfo info
  +             = java.beans.Introspector.getBeanInfo(bean.getClass());
  +         if ( info != null ) {
  +             java.beans.PropertyDescriptor pd[]
  +                 = info.getPropertyDescriptors();
  +             for (int i = 0 ; i < pd.length ; i++) {
  +                 if ( pd[i].getName().equals(prop) ) {
  +                     method = pd[i].getWriteMethod();
  +                     type   = pd[i].getPropertyType();
  +                     break;
  +                 }
  +             }
  +         }
  +     } catch (Exception ex) {
  +         throw new JasperException (ex);
  +     }
  +     return method;
  +    }
  +    
   }
  +
  +
  +
  +
-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com

Mime
View raw message