Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@apache.org Received: (qmail 55266 invoked from network); 6 Jun 2002 00:58:56 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 6 Jun 2002 00:58:56 -0000 Received: (qmail 22216 invoked by uid 97); 6 Jun 2002 00:58:58 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-dev@jakarta.apache.org Received: (qmail 22199 invoked by uid 97); 6 Jun 2002 00:58:58 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Developers List" Reply-To: "Tomcat Developers List" Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 22183 invoked by uid 97); 6 Jun 2002 00:58:57 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Date: 6 Jun 2002 00:58:45 -0000 Message-ID: <20020606005845.79276.qmail@icarus.apache.org> From: costin@apache.org To: jakarta-tomcat-connectors-cvs@apache.org Subject: cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util IntrospectionUtils.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N costin 2002/06/05 17:58:45 Modified: util/java/org/apache/tomcat/util IntrospectionUtils.java Log: Few additions to the introspector to manage gets. Also a bit of cleanup in replaceProperties - explicitely set the Hashtable and the source for dynamic properties. Revision Changes Path 1.5 +99 -6 jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/IntrospectionUtils.java Index: IntrospectionUtils.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/IntrospectionUtils.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- IntrospectionUtils.java 17 May 2002 02:32:12 -0000 1.4 +++ IntrospectionUtils.java 6 Jun 2002 00:58:45 -0000 1.5 @@ -114,6 +114,26 @@ return; } + + /** + * Call void getAttribute( String ) + */ + public static Object getAttribute( Object proxy, String n) + throws Exception + { + Method executeM=null; + Class c=proxy.getClass(); + Class params[]=new Class[1]; + params[0]= String.class; + executeM=findMethod( c, "getAttribute", params ); + if( executeM == null ) { + System.out.println("No getAttribute in " + proxy.getClass() ); + return null; + } + return executeM.invoke(proxy, new Object[] { n }); + } + + /** Construct a URLClassLoader. Will compile and work in JDK1.1 too. */ public static ClassLoader getURLClassLoader( URL urls[], @@ -372,6 +392,58 @@ } } + public static Object getProperty( Object o, String name ) { + String getter= "get" +capitalize(name); + + try { + Method methods[]=findMethods( o.getClass() ); + Method getPropertyMethod=null; + + // First, the ideal case - a getFoo() method + for( int i=0; i< methods.length; i++ ) { + Class paramT[]=methods[i].getParameterTypes(); + if( getter.equals( methods[i].getName() ) && + paramT.length == 0 ) { + return methods[i].invoke( o, null ); + } + + if( "getProperty".equals( methods[i].getName())) { + getPropertyMethod=methods[i]; + } + if( "getAttribute".equals( methods[i].getName())) { + getPropertyMethod=methods[i]; + } + } + + // Ok, no setXXX found, try a getProperty("name") + if( getPropertyMethod != null ) { + Object params[]=new Object[1]; + params[0]=name; + getPropertyMethod.invoke( o, params ); + } + + } catch( IllegalArgumentException ex2 ) { + System.err.println("IAE " + o + " " + name ); + ex2.printStackTrace(); + } catch( SecurityException ex1 ) { + if( dbg > 0 ) + d("SecurityException for " + o.getClass() + " " + + name + ")" ); + if( dbg > 1 ) ex1.printStackTrace(); + } catch (IllegalAccessException iae) { + if( dbg > 0 ) + d("IllegalAccessException for " + + o.getClass() + " " + name +")" ); + if( dbg > 1 ) iae.printStackTrace(); + } catch (InvocationTargetException ie) { + if( dbg > 0 ) + d("InvocationTargetException for " + o.getClass() + + " " + name +")" ); + if( dbg > 1 ) ie.printStackTrace(); + } + return null; + } + /** */ public static void setProperty( Object o, String name ) { @@ -396,12 +468,27 @@ } /** 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); + } + return value; + } + + /** Replace ${NAME} with the property value + */ + public static String replaceProperties(String value, + Hashtable staticProp, PropertySource dynamicProp[] ) + { StringBuffer sb=new StringBuffer(); - int i=0; int prev=0; // assert value!=nil int pos; @@ -425,10 +512,16 @@ } String n=value.substring( pos+2, endName ); String v= null; - if( getter instanceof Hashtable ) { - v=(String)((Hashtable)getter).get(n); - } else if ( getter instanceof PropertySource ) { - v=((PropertySource)getter).getProperty( n ); + if( staticProp != null ) { + v=(String)((Hashtable)staticProp).get(n); + } + if( v==null && dynamicProp != null) { + for( int i=0; i For additional commands, e-mail: