commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick.Grim...@xtl.com
Subject Digester parse() casting exception
Date Tue, 09 Sep 2008 13:57:05 GMT

I've created a simple digester class, but for some reason it's throwing a
ClassCastException when the parse method is being called.

The message in the exception is: com.dsn.loadlink.HarvestDigester cannot be cast
to com.dsn.loadlink.Harvester

Here's my digester class:

package com.dsn.loadlink;

import java.io.File;
import java.io.IOException;
import org.xml.sax.SAXException;
import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @(#)HarvestDigester.java
 *
 *
 * @author
 * @version 1.00 2008/9/9
 */


public class HarvestDigester {

      private static Log log = LogFactory.getLog ( HarvestDigester.class );
      private Harvester harvester = null;

    public HarvestDigester ( String harvestFile ) {
      String routineName = "HarvestDigester";

      try {

            Digester digester = new Digester();
            digester.push ( this );
            digester.setValidating ( false );

            // Main Harvester class
            //digester.addObjectCreate ( "harvester", Harvester.class );
            digester.addObjectCreate ( "harvester", "com.dsn.loadlink.Harvester"
);

            // Datasources
            digester.addObjectCreate ( "harvester/datasources/datasource",
Datasource.class );
            digester.addBeanPropertySetter (
"harvester/datasources/datasource/name", "name" );
            digester.addBeanPropertySetter (
"harvester/datasources/datasource/driver", "driver" );
            digester.addBeanPropertySetter (
"harvester/datasources/datasource/url", "url" );
            digester.addBeanPropertySetter (
"harvester/datasources/datasource/username", "username" );
            digester.addBeanPropertySetter (
"harvester/datasources/datasource/password", "password" );
            digester.addBeanPropertySetter (
"harvester/datasources/datasource/library", "library" );
            digester.addSetNext ( "harvester/datasources/datasource",
"addDatasource" );

            // Tables
            digester.addObjectCreate ( "harvester/tables/table", Table.class );
            digester.addBeanPropertySetter (
"harvester/tables/table/sourceTable", "sourceTable" );
            digester.addBeanPropertySetter ( "harvester/tables/table/destTable",
"destTable" );
            digester.addSetNext ( "harvester/tables/table", "addTable" );

            // Fields
            digester.addObjectCreate ( "harvester/tables/table/field",
Field.class );
            digester.addBeanPropertySetter (
"harvester/tables/table/field/sourceField", "sourceField" );
            digester.addBeanPropertySetter (
"harvester/tables/table/field/destField", "destField" );
            digester.addSetNext ( "harvester/tables/table/field", "addField" );

            harvester = (Harvester) digester.parse ( new File ( harvestFile ) );

      } catch ( IOException ioe ) {
            if ( log.isErrorEnabled() )
                  log.error ( routineName + " - " + ioe.getMessage() );

            ioe.printStackTrace();

      } catch ( SAXException saxe ) {
            if ( log.isErrorEnabled() )
                  log.error ( routineName + " - " + saxe.getMessage() );

            saxe.printStackTrace();
      }
    }

    public Harvester getHarvester() {
      return harvester;
    }
}



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


Mime
View raw message