FileDocCategorySizeDatePackage
ProgrammaticDigesterExample.javaAPI DocExample3068Wed May 18 09:39:04 BST 2005com.discursive.jccook.xml.bean

ProgrammaticDigesterExample

public class ProgrammaticDigesterExample extends Object

Fields Summary
private static Logger
logger
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] pArgs)

      LogInit.init(); 
        ProgrammaticDigesterExample example = new ProgrammaticDigesterExample();
        example.testDigest();
    
public voidtestDigest()


        List plays = new ArrayList();

        Digester digester = new Digester();
        Rules rules = digester.getRules();
        rules.add( "plays/play", new ObjectCreateRule("com.discursive.jccook.xml.bean.Play"));
        rules.add( "plays/play", new SetNextRule("add", "java.lang.Object") );
        rules.add( "plays/play", new SetPropertiesRule() );
        rules.add( "plays/play/name", new BeanPropertySetterRule("name") );
        rules.add( "plays/play/summary", new BeanPropertySetterRule("summary") );
        rules.add( "plays/play/author", new BeanPropertySetterRule("author") );
        rules.add( "plays/play/characters/character", new ObjectCreateRule("com.discursive.jccook.xml.bean.Character"));
        rules.add( "plays/play/characters/character", new SetNextRule("addCharacter", "com.discursive.jccook.xml.bean.Character"));
        rules.add( "plays/play/characters/character", new SetPropertiesRule() );
        rules.add( "plays/play/characters/character/name", new BeanPropertySetterRule("name") );
        rules.add( "plays/play/characters/character/description", new BeanPropertySetterRule("description") );
        digester.push(plays);

        InputStream input = getClass().getResourceAsStream("./plays.xml");
        digester.parse( input );
        
        System.out.println("Number of plays: " + plays.size());