You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Adam Kudła <ad...@gmail.com> on 2012/02/02 04:12:53 UTC

[digester] ofTypeSpecifiedByAttribute doesnt work

Hi,

tonight I have spent 5 hours working over one bug in my app.

Unfortunately I digged to some place of code where I think I found a
bug in Digester

It is in: org.apache.commons.digester3.ObjectCreateRule

I think this part of code:
@Override
    public void begin( String namespace, String name, Attributes attributes )
        throws Exception
    {
        Class<?> clazz = this.clazz;

        if ( clazz == null )
        {
            // Identify the name of the class to instantiate
            String realClassName = className;
            if ( attributeName != null )
            {
                String value = attributes.getValue( attributeName );
                if ( value != null )
                {
                    realClassName = value;
                }
            }
            if ( getDigester().getLogger().isDebugEnabled() )
            {
                getDigester().getLogger().debug( format(
"[ObjectCreateRule]{%s} New '%s'",

getDigester().getMatch(),
                                                         realClassName ) );
            }

            // Instantiate the new object and push it on the context stack
            clazz = getDigester().getClassLoader().loadClass( realClassName );
        }

doesn't work in that way I want.

When I have specified this rule:
forPattern("neuralNetwork/layers/layer/neuron/activationFunction").createObject()
           .ofType(DefaultActivationFunction.class).ofTypeSpecifiedByAttribute("typeName").then().setProperties().then().setNext("setActivationFunction");

and having this XML:
<activationFunction type="org.kobrys.LinearActivationFunction" a="1" b="0"/>

and of course LinearActivationFunction is a subclass of
DefaultActivationFunction...

When is used method ofType(...) - it is set this.clazz which
automaticaly distable acces in the 'if' part of code body.



This code works but allways returns DefaultActivationFunction. Inside
ObjectCreateRule instance attributeName is not null so it looks like
if statement is some kind of wrong.

Am I doing something wrong? Or is it a bug?


Thanks
-- 
Adam Kudła
adamkudla@gmail.com

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


Re: [digester] ofTypeSpecifiedByAttribute doesnt work

Posted by Simone Tripodi <si...@apache.org>.
Hi Adam,
thanks for using the Digester :)

For what I can see, the rule specifies

    .ofTypeSpecifiedByAttribute( "typeName" )

when the xml is

    <activationFunction type="org.kobrys.LinearActivationFunction" a="1" b="0"/>

according to this snippet, the rule should be

    .ofTypeSpecifiedByAttribute( "type" )

Can you have a look at it? Please let me know!
TIA,
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



2012/2/2 Adam Kudła <ad...@gmail.com>:
> Hi,
>
> tonight I have spent 5 hours working over one bug in my app.
>
> Unfortunately I digged to some place of code where I think I found a
> bug in Digester
>
> It is in: org.apache.commons.digester3.ObjectCreateRule
>
> I think this part of code:
> @Override
>    public void begin( String namespace, String name, Attributes attributes )
>        throws Exception
>    {
>        Class<?> clazz = this.clazz;
>
>        if ( clazz == null )
>        {
>            // Identify the name of the class to instantiate
>            String realClassName = className;
>            if ( attributeName != null )
>            {
>                String value = attributes.getValue( attributeName );
>                if ( value != null )
>                {
>                    realClassName = value;
>                }
>            }
>            if ( getDigester().getLogger().isDebugEnabled() )
>            {
>                getDigester().getLogger().debug( format(
> "[ObjectCreateRule]{%s} New '%s'",
>
> getDigester().getMatch(),
>                                                         realClassName ) );
>            }
>
>            // Instantiate the new object and push it on the context stack
>            clazz = getDigester().getClassLoader().loadClass( realClassName );
>        }
>
> doesn't work in that way I want.
>
> When I have specified this rule:
> forPattern("neuralNetwork/layers/layer/neuron/activationFunction").createObject()
>           .ofType(DefaultActivationFunction.class).ofTypeSpecifiedByAttribute("typeName").then().setProperties().then().setNext("setActivationFunction");
>
> and having this XML:
> <activationFunction type="org.kobrys.LinearActivationFunction" a="1" b="0"/>
>
> and of course LinearActivationFunction is a subclass of
> DefaultActivationFunction...
>
> When is used method ofType(...) - it is set this.clazz which
> automaticaly distable acces in the 'if' part of code body.
>
>
>
> This code works but allways returns DefaultActivationFunction. Inside
> ObjectCreateRule instance attributeName is not null so it looks like
> if statement is some kind of wrong.
>
> Am I doing something wrong? Or is it a bug?
>
>
> Thanks
> --
> Adam Kudła
> adamkudla@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

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