public void begin()

in commons-digester3-core/src/main/java/org/apache/commons/digester3/SetPropertyRule.java [63:130]


    public void begin( final String namespace, final String name, final Attributes attributes )
        throws Exception
    {
        if ( attributes.getLength() == 0 )
        {
            return;
        }

        // Identify the actual property name and value to be used
        String actualName = null;
        String actualValue = null;
        for ( int i = 0; i < attributes.getLength(); i++ )
        {
            String attributeName = attributes.getLocalName( i );
            if ( "".equals( attributeName ) )
            {
                attributeName = attributes.getQName( i );
            }
            final String value = attributes.getValue( i );
            if ( attributeName.equals( this.name ) )
            {
                actualName = value;
            }
            else if ( attributeName.equals( this.value ) )
            {
                actualValue = value;
            }
        }

        // Get a reference to the top object
        final Object top = getDigester().peek();

        // Log some debugging information
        if ( getDigester().getLogger().isDebugEnabled() )
        {
            getDigester().getLogger().debug( format( "[SetPropertiesRule]{%s} Set %s property %s to %s",
                                                     getDigester().getMatch(),
                                                     top.getClass().getName(),
                                                     actualName,
                                                     actualValue ) );
        }

        // Force an exception if the property does not exist
        // (BeanUtils.setProperty() silently returns in this case)
        //
        // This code should probably use PropertyUtils.isWriteable(),
        // like SetPropertiesRule does.
        if ( top instanceof DynaBean )
        {
            final DynaProperty desc = ( (DynaBean) top ).getDynaClass().getDynaProperty( actualName );
            if ( desc == null )
            {
                throw new NoSuchMethodException( "Bean has no property named " + actualName );
            }
        }
        else
        /* this is a standard JavaBean */
        {
            final PropertyDescriptor desc = getPropertyDescriptor( top, actualName );
            if ( desc == null )
            {
                throw new NoSuchMethodException( "Bean has no property named " + actualName );
            }
        }

        // Set the property (with conversion as necessary)
        setProperty( top, actualName, actualValue );
    }