Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 23324 invoked from network); 20 Sep 2009 18:33:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Sep 2009 18:33:19 -0000 Received: (qmail 46578 invoked by uid 500); 20 Sep 2009 18:33:18 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 46493 invoked by uid 500); 20 Sep 2009 18:33:18 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 46479 invoked by uid 99); 20 Sep 2009 18:33:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Sep 2009 18:33:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Sep 2009 18:33:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BCC9923888D2; Sun, 20 Sep 2009 18:32:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r817075 - in /tomcat/trunk: java/org/apache/tomcat/util/ java/org/apache/tomcat/util/buf/ java/org/apache/tomcat/util/http/ test/org/apache/catalina/tribes/demos/ Date: Sun, 20 Sep 2009 18:32:48 -0000 To: dev@tomcat.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090920183248.BCC9923888D2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: markt Date: Sun Sep 20 18:32:48 2009 New Revision: 817075 URL: http://svn.apache.org/viewvc?rev=817075&view=rev Log: Eclipse 3.5 has a new dead code detector. Fix various debug related logging issues found. Update copy of IntrospectionUtils in test suite (it was quicker than porting the individual fixes) Modified: tomcat/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java tomcat/trunk/test/org/apache/catalina/tribes/demos/IntrospectionUtils.java Modified: tomcat/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java?rev=817075&r1=817074&r2=817075&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java Sun Sep 20 18:32:48 2009 @@ -77,9 +77,8 @@ log.debug("No setAttribute in " + proxy.getClass()); return; } - if (false) - if (log.isDebugEnabled()) - log.debug("Setting " + n + "=" + v + " in " + proxy); + if (log.isDebugEnabled()) + log.debug("Setting " + n + "=" + v + " in " + proxy); executeM.invoke(proxy, new Object[] { n, v }); return; } @@ -259,8 +258,9 @@ * you can have setDebug(1). */ public static boolean setProperty(Object o, String name, String value) { - if (dbg > 1) - d("setProperty(" + o.getClass() + " " + name + "=" + value + ")"); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: setProperty(" + + o.getClass() + " " + name + "=" + value + ")"); String setter = "set" + capitalize(name); @@ -318,13 +318,16 @@ try { params[0] = InetAddress.getByName(value); } catch (UnknownHostException exc) { - d("Unable to resolve host name:" + value); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Unable to resolve host name:" + value); ok = false; } // Unknown type } else { - d("Unknown type " + paramType.getName()); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Unknown type " + + paramType.getName()); } if (ok) { @@ -371,23 +374,17 @@ } catch (IllegalArgumentException ex2) { log.warn("IAE " + o + " " + name + " " + value, ex2); } catch (SecurityException ex1) { - if (dbg > 0) - d("SecurityException for " + o.getClass() + " " + name + "=" - + value + ")"); - if (dbg > 1) - ex1.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: SecurityException for " + + o.getClass() + " " + name + "=" + value + ")", ex1); } catch (IllegalAccessException iae) { - if (dbg > 0) - d("IllegalAccessException for " + o.getClass() + " " + name - + "=" + value + ")"); - if (dbg > 1) - iae.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: IllegalAccessException for " + + o.getClass() + " " + name + "=" + value + ")", iae); } catch (InvocationTargetException ie) { - if (dbg > 0) - d("InvocationTargetException for " + o.getClass() + " " + name - + "=" + value + ")"); - if (dbg > 1) - ie.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: InvocationTargetException for " + + o.getClass() + " " + name + "=" + value + ")", ie); } return false; } @@ -425,22 +422,17 @@ } catch (IllegalArgumentException ex2) { log.warn("IAE " + o + " " + name, ex2); } catch (SecurityException ex1) { - if (dbg > 0) - d("SecurityException for " + o.getClass() + " " + name + ")"); - if (dbg > 1) - ex1.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: SecurityException for " + + o.getClass() + " " + name + ")", ex1); } catch (IllegalAccessException iae) { - if (dbg > 0) - d("IllegalAccessException for " + o.getClass() + " " + name - + ")"); - if (dbg > 1) - iae.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: IllegalAccessException for " + + o.getClass() + " " + name + ")", iae); } catch (InvocationTargetException ie) { - if (dbg > 0) - d("InvocationTargetException for " + o.getClass() + " " + name - + ")"); - if (dbg > 1) - ie.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: InvocationTargetException for " + + o.getClass() + " " + name + ")"); } return null; } @@ -460,10 +452,9 @@ } } } catch (Exception ex1) { - if (dbg > 0) - d("Exception for " + o.getClass() + " " + name); - if (dbg > 1) - ex1.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Exception for " + + o.getClass() + " " + name, ex1); } } @@ -787,11 +778,14 @@ public static Object callMethod1(Object target, String methodN, Object param1, String typeParam1, ClassLoader cl) throws Exception { if (target == null || param1 == null) { - d("Assert: Illegal params " + target + " " + param1); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Assert: Illegal params " + + target + " " + param1); } - if (dbg > 0) - d("callMethod1 " + target.getClass().getName() + " " - + param1.getClass().getName() + " " + typeParam1); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: callMethod1 " + + target.getClass().getName() + " " + + param1.getClass().getName() + " " + typeParam1); Class params[] = new Class[1]; if (typeParam1 == null) @@ -808,11 +802,14 @@ public static Object callMethod0(Object target, String methodN) throws Exception { if (target == null) { - d("Assert: Illegal params " + target); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Assert: Illegal params " + + target); return null; } - if (dbg > 0) - d("callMethod0 " + target.getClass().getName() + "." + methodN); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: callMethod0 " + + target.getClass().getName() + "." + methodN); Class params[] = new Class[0]; Method m = findMethod(target.getClass(), methodN, params); @@ -829,13 +826,14 @@ Method m = null; m = findMethod(target.getClass(), methodN, typeParams); if (m == null) { - d("Can't find method " + methodN + " in " + target + " CLASS " - + target.getClass()); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Can't find method " + methodN + + " in " + target + " CLASS " + target.getClass()); return null; } Object o = m.invoke(target, params); - if (dbg > 0) { + if (log.isDebugEnabled()) { // debug StringBuffer sb = new StringBuffer(); sb.append("" + target.getClass().getName() + "." + methodN + "( "); @@ -845,7 +843,7 @@ sb.append(params[i]); } sb.append(")"); - d(sb.toString()); + log.debug("IntrospectionUtils:" + sb.toString()); } return o; } @@ -871,12 +869,16 @@ try { result = InetAddress.getByName(object); } catch (UnknownHostException exc) { - d("Unable to resolve host name:" + object); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Unable to resolve host name:" + + object); } // Unknown type } else { - d("Unknown type " + paramType.getName()); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Unknown type " + + paramType.getName()); } if (result == null) { throw new IllegalArgumentException("Can't convert argument: " + object); @@ -899,11 +901,4 @@ } - // debug -------------------- - static final int dbg = 0; - - static void d(String s) { - if (log.isDebugEnabled()) - log.debug("IntrospectionUtils: " + s); - } } Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java?rev=817075&r1=817074&r2=817075&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java Sun Sep 20 18:32:48 2009 @@ -80,18 +80,19 @@ int cnt=conv.read( result, 0, size ); if( cnt <= 0 ) { // End of stream ! - we may be in a bad state - if( debug>0) - log( "EOF" ); + if(log.isDebugEnabled()) + log.debug("B2CConverter: EOF"); return; } - if( debug > 1 ) - log("Converted: " + new String( result, 0, cnt )); + if(log.isDebugEnabled()) + log.debug("B2CConverter: Converted: " + + new String(result, 0, cnt)); cb.append( result, 0, cnt ); limit = limit - (bbLengthBeforeRead - bb.getLength()); } } catch( IOException ex) { - if( debug>0) - log( "Reseting the converter " + ex.toString() ); + if(log.isDebugEnabled()) + log.debug("B2CConverter: Reseting the converter " + ex.toString()); reset(); throw ex; } @@ -106,12 +107,6 @@ conv=new ReadConvertor( iis, encoding ); } - private final int debug=0; - void log( String s ) { - if (log.isDebugEnabled()) - log.debug("B2CConverter: " + s ); - } - } // -------------------- Private implementation -------------------- Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java?rev=817075&r1=817074&r2=817075&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java Sun Sep 20 18:32:48 2009 @@ -44,7 +44,6 @@ private ByteChunk bb=null; private String encoding="UTF8"; - private static final int debug=0; public UEncoder() { initSafeChars(); @@ -75,10 +74,12 @@ for (int i = 0; i < s.length(); i++) { int c = s.charAt(i); if( safeChars.get( c ) ) { - if( debug > 0 ) log("Safe: " + (char)c); + if(log.isDebugEnabled()) + log.debug("Encoder: Safe: " + (char)c); buf.write((char)c); } else { - if( debug > 0 ) log("Unsafe: " + (char)c); + if(log.isDebugEnabled()) + log.debug("Encoder: Unsafe: " + (char)c); c2b.convert( (char)c ); // "surrogate" - UTF is _not_ 16 bit, but 21 !!!! @@ -87,7 +88,8 @@ if ( (i+1) < s.length()) { int d = s.charAt(i+1); if (d >= 0xDC00 && d <= 0xDFFF) { - if( debug > 0 ) log("Unsafe: " + c); + if(log.isDebugEnabled()) + log.debug("Encoder: Unsafe: " + c); c2b.convert( (char)d); i++; } @@ -110,10 +112,12 @@ for( int j=off; j< len; j++ ) { buf.write( '%' ); char ch = Character.forDigit((bytes[j] >> 4) & 0xF, 16); - if( debug > 0 ) log("Encode: " + ch); + if(log.isDebugEnabled()) + log.debug("Encoder: Encode: " + ch); buf.write(ch); ch = Character.forDigit(bytes[j] & 0xF, 16); - if( debug > 0 ) log("Encode: " + ch); + if(log.isDebugEnabled()) + log.debug("Encoder: Encode: " + ch); buf.write(ch); } } @@ -167,9 +171,4 @@ safeChars.set(')'); safeChars.set(','); } - - private static void log( String s ) { - if (log.isDebugEnabled()) - log.debug("Encoder: " + s ); - } } Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java?rev=817075&r1=817074&r2=817075&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/Cookies.java Sun Sep 20 18:32:48 2009 @@ -190,13 +190,15 @@ // Uncomment to test the new parsing code if( cookieValue.getType() == MessageBytes.T_BYTES ) { - if( dbg>0 ) log( "Parsing b[]: " + cookieValue.toString()); + if(log.isDebugEnabled()) + log.debug("Cookies: Parsing b[]: " + cookieValue.toString()); ByteChunk bc=cookieValue.getByteChunk(); processCookieHeader( bc.getBytes(), bc.getOffset(), bc.getLength()); } else { - if( dbg>0 ) log( "Parsing S: " + cookieValue.toString()); + if(log.isDebugEnabled()) + log.debug("Cookies: Parsing S: " + cookieValue.toString()); processCookieHeader( cookieValue.toString() ); } pos++;// search from the next position @@ -224,7 +226,8 @@ private void processCookieHeader( String cookieString ) { - if( dbg>0 ) log( "Parsing cookie header " + cookieString ); + if(log.isDebugEnabled()) + log.debug("Cookies: Parsing cookie header " + cookieString); // normal cookie, with a string value. // This is the original code, un-optimized - it shouldn't // happen in normal case @@ -248,7 +251,8 @@ cookie.getName().setString(name); cookie.getValue().setString(value); - if( dbg > 0 ) log( "Add cookie " + name + "=" + value); + if(log.isDebugEnabled()) + log.debug("Cookies: Add cookie " + name + "=" + value); } else { // we have a bad cookie.... just let it go } @@ -278,15 +282,6 @@ return value; } - - // log - static final int dbg=0; - public void log(String s ) { - if (log.isDebugEnabled()) - log.debug("Cookies: " + s); - } - - /** * Returns true if the byte is a separator character as * defined in RFC2619. Since this is called often, this @@ -426,7 +421,8 @@ // INVALID COOKIE, advance to next delimiter // The starting character of the cookie value was // not valid. - log("Invalid cookie. Value not a token or quoted value"); + log.info("Cookies: Invalid cookie." + + "Value not a token or quoted value"); while (pos < end && bytes[pos] != ';' && bytes[pos] != ',') {pos++; } @@ -525,7 +521,7 @@ } // Unknown cookie, complain - log("Unknown Special Cookie"); + log.info("Cookies: Unknown Special Cookie"); } else { // Normal Cookie sc = addCookie(); Modified: tomcat/trunk/test/org/apache/catalina/tribes/demos/IntrospectionUtils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/demos/IntrospectionUtils.java?rev=817075&r1=817074&r2=817075&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/tribes/demos/IntrospectionUtils.java (original) +++ tomcat/trunk/test/org/apache/catalina/tribes/demos/IntrospectionUtils.java Sun Sep 20 18:32:48 2009 @@ -29,8 +29,6 @@ import java.util.Hashtable; import java.util.StringTokenizer; import java.util.Vector; -import org.apache.juli.logging.LogFactory; -import org.apache.juli.logging.Log; // Depends: JDK1.1 @@ -39,9 +37,10 @@ */ public final class IntrospectionUtils { - - private static Log log= LogFactory.getLog( IntrospectionUtils.class ); - + + private static org.apache.juli.logging.Log log= + org.apache.juli.logging.LogFactory.getLog( IntrospectionUtils.class ); + /** * Call execute() - any ant-like task should work */ @@ -49,7 +48,7 @@ Method executeM = null; Class c = proxy.getClass(); Class params[] = new Class[0]; - // params[0]=args.getClass(); + // params[0]=args.getClass(); executeM = findMethod(c, method, params); if (executeM == null) { throw new RuntimeException("No execute in " + proxy.getClass()); @@ -78,9 +77,8 @@ log.debug("No setAttribute in " + proxy.getClass()); return; } - if (false) - if (log.isDebugEnabled()) - log.debug("Setting " + n + "=" + v + " in " + proxy); + if (log.isDebugEnabled()) + log.debug("Setting " + n + "=" + v + " in " + proxy); executeM.invoke(proxy, new Object[] { n, v }); return; } @@ -136,7 +134,7 @@ * Guess a product install/home by analyzing the class path. It works for * product using the pattern: lib/executable.jar or if executable.jar is * included in classpath by a shell script. ( java -jar also works ) - * + * * Insures both "install" and "home" System properties are set. If either or * both System properties are unset, "install" and "home" will be set to the * same value. This value will be the other System property that is set, or @@ -166,7 +164,7 @@ StringTokenizer st = new StringTokenizer(cpath, pathSep); while (st.hasMoreTokens()) { String path = st.nextToken(); - // log( "path " + path ); + // log( "path " + path ); if (path.endsWith(jarName)) { home = path.substring(0, path.length() - jarName.length()); try { @@ -259,15 +257,17 @@ * int or boolean we'll convert value to the right type before) - that means * you can have setDebug(1). */ - public static void setProperty(Object o, String name, String value) { - if (dbg > 1) - d("setProperty(" + o.getClass() + " " + name + "=" + value + ")"); + public static boolean setProperty(Object o, String name, String value) { + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: setProperty(" + + o.getClass() + " " + name + "=" + value + ")"); String setter = "set" + capitalize(name); try { Method methods[] = findMethods(o.getClass()); - Method setPropertyMethod = null; + Method setPropertyMethodVoid = null; + Method setPropertyMethodBool = null; // First, the ideal case - a setFoo( String ) method for (int i = 0; i < methods.length; i++) { @@ -276,7 +276,7 @@ && "java.lang.String".equals(paramT[0].getName())) { methods[i].invoke(o, new Object[] { value }); - return; + return true; } } @@ -318,56 +318,75 @@ try { params[0] = InetAddress.getByName(value); } catch (UnknownHostException exc) { - d("Unable to resolve host name:" + value); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Unable to resolve host name:" + value); ok = false; } // Unknown type } else { - d("Unknown type " + paramType.getName()); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Unknown type " + + paramType.getName()); } if (ok) { methods[i].invoke(o, params); - return; + return true; } } // save "setProperty" for later if ("setProperty".equals(methods[i].getName())) { - setPropertyMethod = methods[i]; + if (methods[i].getReturnType()==Boolean.TYPE){ + setPropertyMethodBool = methods[i]; + }else { + setPropertyMethodVoid = methods[i]; + } + } } // Ok, no setXXX found, try a setProperty("name", "value") - if (setPropertyMethod != null) { + if (setPropertyMethodBool != null || setPropertyMethodVoid != null) { Object params[] = new Object[2]; params[0] = name; params[1] = value; - setPropertyMethod.invoke(o, params); + if (setPropertyMethodBool != null) { + try { + return (Boolean) setPropertyMethodBool.invoke(o, params); + }catch (IllegalArgumentException biae) { + //the boolean method had the wrong + //parameter types. lets try the other + if (setPropertyMethodVoid!=null) { + setPropertyMethodVoid.invoke(o, params); + return true; + }else { + throw biae; + } + } + } else { + setPropertyMethodVoid.invoke(o, params); + return true; + } } } catch (IllegalArgumentException ex2) { log.warn("IAE " + o + " " + name + " " + value, ex2); } catch (SecurityException ex1) { - if (dbg > 0) - d("SecurityException for " + o.getClass() + " " + name + "=" - + value + ")"); - if (dbg > 1) - ex1.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: SecurityException for " + + o.getClass() + " " + name + "=" + value + ")", ex1); } catch (IllegalAccessException iae) { - if (dbg > 0) - d("IllegalAccessException for " + o.getClass() + " " + name - + "=" + value + ")"); - if (dbg > 1) - iae.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: IllegalAccessException for " + + o.getClass() + " " + name + "=" + value + ")", iae); } catch (InvocationTargetException ie) { - if (dbg > 0) - d("InvocationTargetException for " + o.getClass() + " " + name - + "=" + value + ")"); - if (dbg > 1) - ie.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: InvocationTargetException for " + + o.getClass() + " " + name + "=" + value + ")", ie); } + return false; } public static Object getProperty(Object o, String name) { @@ -403,27 +422,22 @@ } catch (IllegalArgumentException ex2) { log.warn("IAE " + o + " " + name, ex2); } catch (SecurityException ex1) { - if (dbg > 0) - d("SecurityException for " + o.getClass() + " " + name + ")"); - if (dbg > 1) - ex1.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: SecurityException for " + + o.getClass() + " " + name + ")", ex1); } catch (IllegalAccessException iae) { - if (dbg > 0) - d("IllegalAccessException for " + o.getClass() + " " + name - + ")"); - if (dbg > 1) - iae.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: IllegalAccessException for " + + o.getClass() + " " + name + ")", iae); } catch (InvocationTargetException ie) { - if (dbg > 0) - d("InvocationTargetException for " + o.getClass() + " " + name - + ")"); - if (dbg > 1) - ie.printStackTrace(); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: InvocationTargetException for " + + o.getClass() + " " + name + ")"); } return null; } - /** + /** */ public static void setProperty(Object o, String name) { String setter = "set" + capitalize(name); @@ -438,36 +452,20 @@ } } } catch (Exception ex1) { - if (dbg > 0) - d("Exception for " + o.getClass() + " " + name); - if (dbg > 1) - ex1.printStackTrace(); - } - } - - /** - * Replace ${NAME} with the property value - * - * @deprecated Use the explicit method - */ - public static String replaceProperties(String value, Object getter) { - if (getter instanceof Hashtable) - return replaceProperties(value, (Hashtable) getter, - null); - - if (getter instanceof PropertySource) { - PropertySource src[] = new PropertySource[] { (PropertySource) getter }; - return replaceProperties(value, null, src); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Exception for " + + o.getClass() + " " + name, ex1); } - return value; } /** * Replace ${NAME} with the property value */ public static String replaceProperties(String value, - Hashtable staticProp, - PropertySource dynamicProp[]) { + Hashtable staticProp, PropertySource dynamicProp[]) { + if (value.indexOf("$") < 0) { + return value; + } StringBuffer sb = new StringBuffer(); int prev = 0; // assert value!=nil @@ -492,7 +490,7 @@ String n = value.substring(pos + 2, endName); String v = null; if (staticProp != null) { - v = staticProp.get(n); + v = (String) staticProp.get(n); } if (v == null && dynamicProp != null) { for (int i = 0; i < dynamicProp.length; i++) { @@ -626,7 +624,7 @@ * Add elements from the classpath cp to a Vector jars as * file URLs (We use Vector for JDK 1.1 compat). *

- * + * * @param jars The jar list * @param cp a String classpath of directory or jar file elements * separated by path.separator delimiters. @@ -694,119 +692,13 @@ return getClassPath(jarsV); } - // -------------------- Mapping command line params to setters - - public static boolean processArgs(Object proxy, String args[]) - throws Exception { - String args0[] = null; - if (null != findMethod(proxy.getClass(), "getOptions1", new Class[] {})) { - args0 = (String[]) callMethod0(proxy, "getOptions1"); - } - - if (args0 == null) { - //args0=findVoidSetters(proxy.getClass()); - args0 = findBooleanSetters(proxy.getClass()); - } - Hashtable h = null; - if (null != findMethod(proxy.getClass(), "getOptionAliases", - new Class[] {})) { - h = (Hashtable) callMethod0(proxy, - "getOptionAliases"); - } - return processArgs(proxy, args, args0, null, h); - } - - public static boolean processArgs(Object proxy, String args[], - String args0[], String args1[], - Hashtable aliases) throws Exception { - for (int i = 0; i < args.length; i++) { - String arg = args[i]; - if (arg.startsWith("-")) - arg = arg.substring(1); - if (aliases != null && aliases.get(arg) != null) - arg = aliases.get(arg); - - if (args0 != null) { - boolean set = false; - for (int j = 0; j < args0.length; j++) { - if (args0[j].equalsIgnoreCase(arg)) { - setProperty(proxy, args0[j], "true"); - set = true; - break; - } - } - if (set) - continue; - } - if (args1 != null) { - for (int j = 0; j < args1.length; j++) { - if (args1[j].equalsIgnoreCase(arg)) { - i++; - if (i >= args.length) - return false; - setProperty(proxy, arg, args[i]); - break; - } - } - } else { - // if args1 is not specified,assume all other options have param - i++; - if (i >= args.length) - return false; - setProperty(proxy, arg, args[i]); - } - - } - return true; - } - // -------------------- other utils -------------------- public static void clear() { objectMethods.clear(); } - - public static String[] findVoidSetters(Class c) { - Method m[] = findMethods(c); - if (m == null) - return null; - Vector v = new Vector(); - for (int i = 0; i < m.length; i++) { - if (m[i].getName().startsWith("set") - && m[i].getParameterTypes().length == 0) { - String arg = m[i].getName().substring(3); - v.addElement(unCapitalize(arg)); - } - } - String s[] = new String[v.size()]; - for (int i = 0; i < s.length; i++) { - s[i] = v.elementAt(i); - } - return s; - } - - public static String[] findBooleanSetters(Class c) { - Method m[] = findMethods(c); - if (m == null) - return null; - Vector v = new Vector(); - for (int i = 0; i < m.length; i++) { - if (m[i].getName().startsWith("set") - && m[i].getParameterTypes().length == 1 - && "boolean".equalsIgnoreCase(m[i].getParameterTypes()[0] - .getName())) { - String arg = m[i].getName().substring(3); - v.addElement(unCapitalize(arg)); - } - } - String s[] = new String[v.size()]; - for (int i = 0; i < s.length; i++) { - s[i] = v.elementAt(i); - } - return s; - } - - static Hashtable, Method[]> objectMethods = - new Hashtable, Method[]>(); + + static Hashtable,Method[]> objectMethods = + new Hashtable,Method[]>(); public static Method[] findMethods(Class c) { Method methods[] = objectMethods.get(c); @@ -818,7 +710,8 @@ return methods; } - public static Method findMethod(Class c, String name, Class params[]) { + public static Method findMethod(Class c, String name, + Class params[]) { Method methods[] = findMethods(c); if (methods == null) return null; @@ -885,11 +778,14 @@ public static Object callMethod1(Object target, String methodN, Object param1, String typeParam1, ClassLoader cl) throws Exception { if (target == null || param1 == null) { - d("Assert: Illegal params " + target + " " + param1); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Assert: Illegal params " + + target + " " + param1); } - if (dbg > 0) - d("callMethod1 " + target.getClass().getName() + " " - + param1.getClass().getName() + " " + typeParam1); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: callMethod1 " + + target.getClass().getName() + " " + + param1.getClass().getName() + " " + typeParam1); Class params[] = new Class[1]; if (typeParam1 == null) @@ -906,11 +802,14 @@ public static Object callMethod0(Object target, String methodN) throws Exception { if (target == null) { - d("Assert: Illegal params " + target); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Assert: Illegal params " + + target); return null; } - if (dbg > 0) - d("callMethod0 " + target.getClass().getName() + "." + methodN); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: callMethod0 " + + target.getClass().getName() + "." + methodN); Class params[] = new Class[0]; Method m = findMethod(target.getClass(), methodN, params); @@ -927,13 +826,14 @@ Method m = null; m = findMethod(target.getClass(), methodN, typeParams); if (m == null) { - d("Can't find method " + methodN + " in " + target + " CLASS " - + target.getClass()); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Can't find method " + methodN + + " in " + target + " CLASS " + target.getClass()); return null; } Object o = m.invoke(target, params); - if (dbg > 0) { + if (log.isDebugEnabled()) { // debug StringBuffer sb = new StringBuffer(); sb.append("" + target.getClass().getName() + "." + methodN + "( "); @@ -943,7 +843,7 @@ sb.append(params[i]); } sb.append(")"); - d(sb.toString()); + log.debug("IntrospectionUtils:" + sb.toString()); } return o; } @@ -957,7 +857,6 @@ try { result = new Integer(object); } catch (NumberFormatException ex) { - // Ignore } // Try a setFoo ( boolean ) } else if ("java.lang.Boolean".equals(paramType.getName()) @@ -970,19 +869,23 @@ try { result = InetAddress.getByName(object); } catch (UnknownHostException exc) { - d("Unable to resolve host name:" + object); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Unable to resolve host name:" + + object); } // Unknown type } else { - d("Unknown type " + paramType.getName()); + if (log.isDebugEnabled()) + log.debug("IntrospectionUtils: Unknown type " + + paramType.getName()); } if (result == null) { throw new IllegalArgumentException("Can't convert argument: " + object); } return result; } - + // -------------------- Get property -------------------- // This provides a layer of abstraction @@ -998,11 +901,4 @@ } - // debug -------------------- - static final int dbg = 0; - - static void d(String s) { - if (log.isDebugEnabled()) - log.debug("IntrospectionUtils: " + s); - } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org