Package org.apache.commons.digester3.plugins

Examples of org.apache.commons.digester3.plugins.PluginException


     */
    @Test
    public void testCallMethodOnly()
        throws Exception
    {
        Digester digester = newLoader( new AbstractRulesModule()
        {

            @Override
            protected void configure()
            {
View Full Code Here


     */
    @Test
    public void testSettingProperties()
        throws SAXException, IOException
    {
        Digester digester = newLoader( new AbstractRulesModule()
        {

            @Override
            protected void configure()
            {
                forPattern( "employee" ).createObject().ofType( Employee.class )
                    .then()
                    .callMethod( "setLastName" ).withParamTypes( "java.lang.String" );
                forPattern( "employee/lastName" ).callParam().ofIndex( 0 );
            }

        }).newDigester();

        // Parse our test input

        // an exception will be thrown if the method can't be found
        Employee employee = digester.parse( getInputStream( "Test5.xml" ) );
        assertEquals( "Failed to call Employee.setLastName", "Last Name", employee.getLastName() );

        digester = newLoader( new AbstractRulesModule()
        {

            @Override
            protected void configure()
            {
                forPattern( "employee" ).createObject().ofType( Employee.class )
                    .then()
                    .callMethod( "setAge" ).withParamTypes( int.class );
                forPattern( "employee/age" ).callParam();
            }

        }).newDigester();

        // Parse our test input
        // an exception will be thrown if the method can't be found
        employee = digester.parse( getInputStream( "Test5.xml" ) );
        assertEquals( "Failed to call Employee.setAge", 21, employee.getAge() );

        digester = newLoader( new AbstractRulesModule()
        {

            @Override
            protected void configure()
            {
                forPattern( "employee" ).createObject().ofType( Employee.class )
                    .then()
                    .callMethod( "setActive" ).withParamTypes( boolean.class );
                forPattern( "employee/active" ).callParam();
            }

        }).newDigester();

        // Parse our test input
        // an exception will be thrown if the method can't be found
        employee = digester.parse( getInputStream( "Test5.xml" ) );
        assertEquals( "Failed to call Employee.setActive", true, employee.isActive() );

        digester = newLoader( new AbstractRulesModule()
        {

            @Override
            protected void configure()
            {
View Full Code Here

     */
    @Test
    public void testParamsFromStack()
        throws SAXException, IOException
    {
        Digester digester = newLoader( new AbstractRulesModule()
        {

            @Override
            protected void configure()
            {
View Full Code Here

     */
    @Test
    public void testOrderNestedPartA()
        throws Exception
    {
        Digester digester = newLoader( new AbstractRulesModule()
        {

            @Override
            protected void configure()
            {
View Full Code Here

     */
    @Test
    public void testOrderNestedPartB()
        throws Exception
    {
        Digester digester = newLoader( new AbstractRulesModule()
        {

            @Override
            protected void configure()
            {
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void handle( SetProperty annotation, Field element, RulesBinder rulesBinder )
    {
        SetPropertiesBuilder builder = rulesBinder
            .forPattern( annotation.pattern() )
            .withNamespaceURI( annotation.namespaceURI() )
            .setProperties();

        if ( annotation.attributeName() != null && annotation.attributeName().length() > 0
            && !element.getName().equals( annotation.attributeName() ) )
        {
            builder.addAlias( annotation.attributeName(), element.getName() );
        }
    }
View Full Code Here

        // or id is specified in the xml file.
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules( rc );

        PluginCreateRule pcr = new PluginCreateRule( Widget.class, TextLabel.class );
        digester.addRule( "root/widget", pcr );
        digester.addSetNext( "root/widget", "addChild" );

        Container root = new Container();
        digester.push( root );
View Full Code Here

        // not to have one of plugin-class or plugin-id specified
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules( rc );

        PluginCreateRule pcr = new PluginCreateRule( Widget.class );
        digester.addRule( "root/widget", pcr );
        digester.addSetNext( "root/widget", "addChild" );

        Container root = new Container();
        digester.push( root );
View Full Code Here

        // plugin base class.
        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules( rc );

        PluginCreateRule pcr = new PluginCreateRule( Widget.class, Object.class );
        digester.addRule( "root/widget", pcr );
        digester.addSetNext( "root/widget", "addChild" );

        Container root = new Container();
        digester.push( root );
View Full Code Here

        {
            is = new FileInputStream( rulesFileName );
        }
        catch ( IOException ioe )
        {
            throw new PluginException( "Unable to process file [" + rulesFileName + "]", ioe );
        }

        try
        {
            RuleLoader loader = new LoaderFromStream( is );
            return loader;
        }
        catch ( Exception e )
        {
            throw new PluginException( "Unable to load xmlrules from file [" + rulesFileName + "]", e );
        }
        finally
        {
            try
            {
                is.close();
            }
            catch ( IOException ioe )
            {
                throw new PluginException( "Unable to close stream for file [" + rulesFileName + "]", ioe );
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.digester3.plugins.PluginException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.