You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2001/03/04 04:42:53 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/xml XmlMapper.java

costin      01/03/03 19:42:53

  Modified:    src/share/org/apache/tomcat/util/xml XmlMapper.java
  Log:
  Explicit import ( XmlMapper depends only on IntrospectionUtils ), remove
  duplicated code  ( the introspection code is also used in other
  places )
  
  Revision  Changes    Path
  1.31      +2 -103    jakarta-tomcat/src/share/org/apache/tomcat/util/xml/XmlMapper.java
  
  Index: XmlMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/xml/XmlMapper.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- XmlMapper.java	2001/02/09 07:51:34	1.30
  +++ XmlMapper.java	2001/03/04 03:42:53	1.31
  @@ -1,6 +1,6 @@
   package org.apache.tomcat.util.xml;
   
  -import org.apache.tomcat.util.*;
  +import org.apache.tomcat.util.IntrospectionUtils;
   import java.beans.*;
   import java.io.*;
   import java.io.IOException;
  @@ -692,110 +692,9 @@
   	    String name=attributes.getName(i);
   	    String value=attributes.getValue(i);
   
  -	    setProperty( ctx, elem, name, value );
  +	    IntrospectionUtils.setProperty( elem, name, value );
   	}
  -
       }
  -
  -    /** Find a method with the right name
  -	If found, call the method ( if param is int or boolean we'll convert
  -	value to the right type before) - that means you can have setDebug(1).
  -    */
  -    static void setProperty( SaxContext ctx, Object o, String name,
  -			     String value ) {
  -	if( ctx.getDebug() > 1 ) ctx.log("setProperty(" +
  -					 o.getClass() + " " +  name + "="  +
  -					 value  +")" );
  -
  -	String setter= "set" +capitalize(name);
  -
  -	try {
  -	    Method methods[]=o.getClass().getMethods();
  -	    Method setPropertyMethod=null;
  -
  -	    // First, the ideal case - a setFoo( String ) method
  -	    for( int i=0; i< methods.length; i++ ) {
  -		Class paramT[]=methods[i].getParameterTypes();
  -		if( setter.equals( methods[i].getName() ) &&
  -		    paramT.length == 1 &&
  -		    "java.lang.String".equals( paramT[0].getName())) {
  -
  -		    methods[i].invoke( o, new Object[] { value } );
  -		    return;
  -		}
  -	    }
  -
  -	    // Try a setFoo ( int ) or ( boolean )
  -	    for( int i=0; i< methods.length; i++ ) {
  -		boolean ok=true;
  -		if( setter.equals( methods[i].getName() ) &&
  -		    methods[i].getParameterTypes().length == 1) {
  -
  -		    // match - find the type and invoke it
  -		    Class paramType=methods[i].getParameterTypes()[0];
  -		    Object params[]=new Object[1];
  -		    if ("java.lang.Integer".equals( paramType.getName()) ||
  -			"int".equals( paramType.getName())) {
  -			try {
  -			    params[0]=new Integer(value);
  -			} catch( NumberFormatException ex ) {ok=false;}
  -		    } else if ("java.lang.Boolean".
  -			       equals( paramType.getName()) ||
  -			"boolean".equals( paramType.getName())) {
  -			params[0]=new Boolean(value);
  -		    } else {
  -			ctx.log("Unknown type " + paramType.getName() );
  -		    }
  -
  -		    if( ok ) {
  -			methods[i].invoke( o, params );
  -			return;
  -		    }
  -		}
  -
  -		// save "setProperty" for later
  -		if( "setProperty".equals( methods[i].getName())) {
  -		    setPropertyMethod=methods[i];
  -		}
  -	    }
  -
  -	    // Ok, no setXXX found, try a setProperty("name", "value")
  -	    if( setPropertyMethod != null ) {
  -		Object params[]=new Object[2];
  -		params[0]=name;
  -		params[1]=value;
  -		setPropertyMethod.invoke( o, params );
  -	    }
  -
  -	} catch( SecurityException ex1 ) {
  -	    if( ctx.getDebug() > 0 )
  -		ctx.log("SecurityException for " + o.getClass() + " " +
  -			name + "="  + value  +")" );
  -	    if( ctx.getDebug() > 1 ) ex1.printStackTrace();
  -	} catch (IllegalAccessException iae) {
  -	    if( ctx.getDebug() > 0 )
  -		ctx.log("IllegalAccessException for " +
  -			o.getClass() + " " +  name + "="  + value  +")" );
  -	    if( ctx.getDebug() > 1 ) iae.printStackTrace();
  -	} catch (InvocationTargetException ie) {
  -	    if( ctx.getDebug() > 0 )
  -		ctx.log("InvocationTargetException for " + o.getClass() +
  -			" " +  name + "="  + value  +")" );
  -	    if( ctx.getDebug() > 1 ) ie.printStackTrace();
  -	}
  -    }
  -
  -    /** Reverse of Introspector.decapitalize
  -     */
  -    static String capitalize(String name) {
  -	if (name == null || name.length() == 0) {
  -	    return name;
  -	}
  -	char chars[] = name.toCharArray();
  -	chars[0] = Character.toUpperCase(chars[0]);
  -	return new String(chars);
  -    }
  -
   }