commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@gmail.com>
Subject Re: svn commit: r1210678 - in /commons/proper/digester/trunk/src: main/java/org/apache/commons/digester3/binder/ test/resources/org/apache/commons/digester3/xmlrules/
Date Mon, 05 Dec 2011 22:37:01 GMT
Note that in the testcase XML you don't need @params if you're using
the (boolean, double) constructor.  The default constructor arguments
were needed to avoid the NPEs that were thrown due to the (Boolean,
Double) constructor calling { this( booleanProperty.booleanValue(),
doubleProperty.doubleValue() ); }

Matt

On Mon, Dec 5, 2011 at 4:27 PM,  <simonetripodi@apache.org> wrote:
> Author: simonetripodi
> Date: Mon Dec  5 22:27:50 2011
> New Revision: 1210678
>
> URL: http://svn.apache.org/viewvc?rev=1210678&view=rev
> Log:
> [DIGESTER-154] The DigesterBinder is not able to load primitive classes by name
>
> Added:
>    commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
  (with props)
> Modified:
>    commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
>    commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
>    commons/proper/digester/trunk/src/test/resources/org/apache/commons/digester3/xmlrules/constructor-testrules.xml
>
> Added: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
> URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java?rev=1210678&view=auto
> ==============================================================================
> --- commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
(added)
> +++ commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
Mon Dec  5 22:27:50 2011
> @@ -0,0 +1,71 @@
> +package org.apache.commons.digester3.binder;
> +
> +import java.util.Collections;
> +import java.util.HashMap;
> +import java.util.Map;
> +
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +
> +final class BinderClassLoader
> +    extends ClassLoader
> +{
> +
> +    private static final Map<String, Class<?>> PRIMITIVE_TYPES;
> +    static
> +    {
> +        HashMap<String, Class<?>> primitiveTypes = new HashMap<String,
Class<?>>();
> +        primitiveTypes.put( "boolean", boolean.class );
> +        primitiveTypes.put( "byte", byte.class );
> +        primitiveTypes.put( "short", short.class );
> +        primitiveTypes.put( "int", int.class );
> +        primitiveTypes.put( "char", char.class );
> +        primitiveTypes.put( "long", long.class );
> +        primitiveTypes.put( "float", float.class );
> +        primitiveTypes.put( "double", double.class );
> +        PRIMITIVE_TYPES = Collections.unmodifiableMap( primitiveTypes );
> +    }
> +
> +    private final ClassLoader adaptedClassLoader;
> +
> +    public BinderClassLoader( ClassLoader adaptedClassLoader )
> +    {
> +        this.adaptedClassLoader = adaptedClassLoader;
> +    }
> +
> +    public ClassLoader getAdaptedClassLoader()
> +    {
> +        return adaptedClassLoader;
> +    }
> +
> +    /**
> +     * {@inheritDoc}
> +     */
> +    @Override
> +    protected synchronized Class<?> loadClass( String name, boolean resolve
)
> +        throws ClassNotFoundException
> +    {
> +        if ( PRIMITIVE_TYPES.containsKey( name ) )
> +        {
> +            return PRIMITIVE_TYPES.get( name );
> +        }
> +        return adaptedClassLoader.loadClass( name );
> +    }
> +
> +}
>
> Propchange: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
> ------------------------------------------------------------------------------
>    svn:keywords = Date Author Id Revision HeadURL
>
> Propchange: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/BinderClassLoader.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Modified: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
> URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java?rev=1210678&r1=1210677&r2=1210678&view=diff
> ==============================================================================
> --- commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
(original)
> +++ commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/DigesterLoader.java
Mon Dec  5 22:27:50 2011
> @@ -113,7 +113,7 @@ public final class DigesterLoader
>      * used to load Digester itself, is used, based on the value of the
>      * <code>useContextClassLoader</code> variable.
>      */
> -    private ClassLoader classLoader;
> +    private BinderClassLoader classLoader;
>
>     /**
>      * An optional class that substitutes values in attributes and body text. This
may be null and so a null check is
> @@ -196,7 +196,7 @@ public final class DigesterLoader
>             throw new IllegalArgumentException( "Parameter 'classLoader' cannot
be null" );
>         }
>
> -        this.classLoader = classLoader;
> +        this.classLoader = new BinderClassLoader( classLoader );
>         return this;
>     }
>
> @@ -550,7 +550,8 @@ public final class DigesterLoader
>         }
>
>         Digester digester = new Digester( reader );
> -        digester.setClassLoader( classLoader );
> +        // the ClassLoader adapter is no needed anymore
> +        digester.setClassLoader( classLoader.getAdaptedClassLoader() );
>         digester.setRules( rules );
>         digester.setSubstitutor( substitutor );
>         digester.registerAll( entityValidator );
>
> Modified: commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
> URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java?rev=1210678&r1=1210677&r2=1210678&view=diff
> ==============================================================================
> --- commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
(original)
> +++ commons/proper/digester/trunk/src/main/java/org/apache/commons/digester3/binder/ObjectCreateBuilder.java
Mon Dec  5 22:27:50 2011
> @@ -22,9 +22,6 @@ package org.apache.commons.digester3.bin
>  import static java.lang.String.format;
>
>  import java.util.Arrays;
> -import java.util.Collections;
> -import java.util.HashMap;
> -import java.util.Map;
>
>  import org.apache.commons.digester3.ObjectCreateRule;
>
> @@ -36,20 +33,7 @@ import org.apache.commons.digester3.Obje
>  public final class ObjectCreateBuilder
>     extends AbstractBackToLinkedRuleBuilder<ObjectCreateRule>
>  {
> -    private static final Map<String, Class<?>> PRIMITIVE_TYPES;
> -    static
> -    {
> -        HashMap<String, Class<?>> primitiveTypes = new HashMap<String,
Class<?>>();
> -        primitiveTypes.put("boolean", boolean.class);
> -        primitiveTypes.put("byte", byte.class);
> -        primitiveTypes.put("short", short.class);
> -        primitiveTypes.put("int", int.class);
> -        primitiveTypes.put("char", char.class);
> -        primitiveTypes.put("long", long.class);
> -        primitiveTypes.put("float", float.class);
> -        primitiveTypes.put("double", double.class);
> -        PRIMITIVE_TYPES = Collections.unmodifiableMap(primitiveTypes);
> -    }
> +
>
>     private final ClassLoader classLoader;
>
> @@ -151,11 +135,6 @@ public final class ObjectCreateBuilder
>         Class<?>[] paramTypes = new Class<?>[paramTypeNames.length];
>         for ( int i = 0; i < paramTypeNames.length; i++ )
>         {
> -            if ( PRIMITIVE_TYPES.containsKey( paramTypeNames[i] ) )
> -            {
> -                paramTypes[i] = PRIMITIVE_TYPES.get( paramTypeNames[i] );
> -                continue;
> -            }
>             try
>             {
>                 paramTypes[i] = classLoader.loadClass( paramTypeNames[i] );
>
> Modified: commons/proper/digester/trunk/src/test/resources/org/apache/commons/digester3/xmlrules/constructor-testrules.xml
> URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/test/resources/org/apache/commons/digester3/xmlrules/constructor-testrules.xml?rev=1210678&r1=1210677&r2=1210678&view=diff
> ==============================================================================
> --- commons/proper/digester/trunk/src/test/resources/org/apache/commons/digester3/xmlrules/constructor-testrules.xml
(original)
> +++ commons/proper/digester/trunk/src/test/resources/org/apache/commons/digester3/xmlrules/constructor-testrules.xml
Mon Dec  5 22:27:50 2011
> @@ -19,7 +19,7 @@
>  <digester-rules>
>   <pattern value="toplevel/bean">
>     <object-create-rule classname="org.apache.commons.digester3.TestBean"
> -      paramtypes="java.lang.Boolean,java.lang.Double" params="true,0" />
> +      paramtypes="boolean,double" params="true,0" />
>     <call-param-rule paramnumber="0" attrname="boolean" />
>     <call-param-rule paramnumber="1" attrname="double" />
>   </pattern>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message