Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 88377 invoked from network); 10 May 2002 04:33:47 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 10 May 2002 04:33:47 -0000 Received: (qmail 3673 invoked by uid 97); 10 May 2002 04:33:56 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 3644 invoked by uid 97); 10 May 2002 04:33:55 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 3633 invoked by uid 97); 10 May 2002 04:33:55 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Date: 10 May 2002 04:33:41 -0000 Message-ID: <20020510043341.65161.qmail@icarus.apache.org> From: mcconnell@apache.org To: jakarta-avalon-excalibur-cvs@apache.org Subject: cvs commit: jakarta-avalon-excalibur/context/src/java/org/apache/excalibur/context ContextUtility.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 mcconnell 02/05/09 21:33:41 Modified: context/src/java/org/apache/excalibur/context ContextUtility.java Log: style cleanup Revision Changes Path 1.2 +67 -27 jakarta-avalon-excalibur/context/src/java/org/apache/excalibur/context/ContextUtility.java Index: ContextUtility.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/context/src/java/org/apache/excalibur/context/ContextUtility.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ContextUtility.java 10 May 2002 03:54:54 -0000 1.1 +++ ContextUtility.java 10 May 2002 04:33:41 -0000 1.2 @@ -17,7 +17,8 @@ import org.apache.avalon.framework.logger.Logger; /** - * @version $Id: ContextUtility.java,v 1.1 2002/05/10 03:54:54 mcconnell Exp $ + * @version $Id: ContextUtility.java,v 1.2 2002/05/10 04:33:41 mcconnell Exp $ + * @author Stephen McConnell */ public class ContextUtility { @@ -28,6 +29,9 @@ /** * Create context-attributes from entrys within -tag in config + * @param config the context configuration + * @return Context a context instance + * @exception ConfigurationException if a context related error occurs */ public static Context createContextFromConfiguration( Configuration config ) throws ConfigurationException @@ -37,23 +41,34 @@ /** * Create context-attributes from entrys within -tag in config + * @param parent the parent context + * @param config the configuration element describing the context parameters + * @return Context a context instance + * @exception ConfigurationException if a context related error occurs */ - public static Context createContextFromConfiguration( Context parent, Configuration config ) - throws ConfigurationException + public static Context createContextFromConfiguration( + Context parent, Configuration config ) + throws ConfigurationException { return createContextFromConfiguration( parent, config, null ); } /** * Create context-attributes from entrys within -tag in config + * @param parent the parent context + * @param config the configuration element describing the context parameters + * @param log a logging channel + * @return Context a context instance + * @exception ConfigurationException if a context related error occurs */ - public static Context createContextFromConfiguration( Context parent, Configuration config, Logger log ) - throws ConfigurationException + public static Context createContextFromConfiguration( + Context parent, Configuration config, Logger log ) + throws ConfigurationException { ClassLoader loader = Thread.currentThread().getContextClassLoader(); String contextClassName = config.getAttribute( "class", - "org.apache.avalon.framework.context.DefaultContext" ); + "org.apache.avalon.framework.context.DefaultContext" ); Class contextClass = null; @@ -64,7 +79,8 @@ } catch( ClassNotFoundException cnfe ) { - throw new ConfigurationException( "Could not find context class " + contextClassName, cnfe ); + throw new ConfigurationException( + "Could not find context class " + contextClassName, cnfe ); } Map map = new Hashtable(); @@ -77,19 +93,25 @@ } catch( Throwable e ) { - throw new ConfigurationException( "Unexpected exception while creating custom context form " - + contextClassName, e ); + throw new ConfigurationException( + "Unexpected exception while creating custom context form " + + contextClassName, e ); } final Configuration[] entrys = config.getChildren( "entry" ); for( int i = 0; i < entrys.length; i++ ) { - final String className = entrys[ i ].getAttribute( "type", "java.lang.String" ); - final String paramName = entrys[ i ].getAttribute( "name", null ); + final String className = entrys[ i ].getAttribute( + "type", "java.lang.String" ); + final String paramName = entrys[ i ].getAttribute( + "name", null ); if( paramName == null ) - throw new ConfigurationException( "missing name for context-entry" ); + { + throw new ConfigurationException( + "missing name for context-entry" ); + } try { @@ -105,12 +127,17 @@ Class[] consObjects = {Class.forName( "java.lang.String" )}; Constructor cons = params[ 0 ].getConstructor( consObjects ); values = new Object[ 1 ]; - Object[] consValues = {getContextValue( map, entry.getAttribute( "value" ) )}; + Object[] consValues = { + getContextValue( map, entry.getAttribute( "value" ) ) + }; values[ 0 ] = cons.newInstance( consValues ); if( log != null ) + { log.debug( "add context-attr '" + paramName - + "' class '" + className + "' with value '" + consValues[ 0 ] + "'" ); + + "' class '" + className + + "' with value '" + consValues[ 0 ] + "'" ); + } } else { @@ -121,27 +148,34 @@ values = new Object[ entryChilds.length ]; if( log != null ) + { log.debug( "add context-attr '" + paramName - + "' class '" + className + "' with " - + entryChilds.length + " values" ); + + "' class '" + className + "' with " + + entryChilds.length + " values" ); + } for( int p = 0; p < entryChilds.length; p++ ) { - String paramClassName = entryChilds[ p ].getAttribute( "type", "java.lang.String" ); + String paramClassName = entryChilds[ p ].getAttribute( + "type", "java.lang.String" ); String paramValue = entryChilds[ p ].getAttribute( "value", null ); if( paramValue == null ) { if( log != null ) + { log.debug( "value" + ( p + 1 ) + ": class '" + paramClassName + "' no value" ); + } } else { paramValue = getContextValue( map, paramValue ); if( log != null ) + { log.debug( "value" + ( p + 1 ) + ": class '" - + paramClassName + "' value '" + paramValue + "'" ); + + paramClassName + "' value '" + paramValue + "'" ); + } } try @@ -222,7 +256,8 @@ catch( final ClassNotFoundException e ) { throw new ConfigurationException( - "incorrect type '" + className + "' for context-attribute '" + paramName + "'", + "incorrect type '" + className + + "' for context-attribute '" + paramName + "'", e ); } @@ -249,7 +284,8 @@ catch( Exception e ) { throw new ConfigurationException( - "Error add context-attribute '" + paramName + "' from Configuration", e ); + "Error add context-attribute '" + paramName + + "' from Configuration", e ); } } return context; @@ -258,10 +294,13 @@ /** * Resolving an attribute value by replacing ${context-param} with * the corresponding param out of current context. - * - * @throws ConfigurationException if context-param does not exists + * @param map a map + * @param rawValue a raw value + * @return String the context attribute value + * @exception ConfigurationException if context-param does not exists */ - private static String getContextValue( Map map, String rawValue ) throws ConfigurationException + private static String getContextValue( Map map, String rawValue ) + throws ConfigurationException { StringBuffer result = new StringBuffer( "" ); int i = 0; @@ -273,12 +312,13 @@ result.append( rawValue.substring( i, j ) ); } int k = rawValue.indexOf( '}', j ); - final String ctx_name = rawValue.substring( j + 2, k ); - final Object ctx = map.get( ctx_name ); + final String ctxName = rawValue.substring( j + 2, k ); + final Object ctx = map.get( ctxName ); if( ctx == null ) + { throw new ConfigurationException( - "missing entry '" + ctx_name + "' in Context" ); - + "missing entry '" + ctxName + "' in Context" ); + } result.append( ctx.toString() ); i = k + 1; } -- To unsubscribe, e-mail: For additional commands, e-mail: