commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Haytham Samad <samad.hayt...@gmail.com>
Subject [chain] Getting null catalog when using LookupCommand
Date Thu, 07 Apr 2005 01:32:20 GMT
I keep getting a null catalog returned to me when I run this example
taken from an onjava article.  I am using Chains 1.0.  

Any idea why this is happening?

<catalog name="auto-sales">	
	<define    name="test-command"
			className="com.jadecove.chain.sample.TestPropertiesCommand"/>
			
	  <chain name="sell-vehicle">
		<command   id="GetCustomerInfo"
			className="com.jadecove.chain.sample.GetCustomerInfo"/>
		<command   id="TestDriveVehicle"
			className="com.jadecove.chain.sample.TestDriveVehicle"/>
		<command   id="NegotiateSale"
			className="com.jadecove.chain.sample.NegotiateSale"/>
		<command
			className="org.apache.commons.chain.generic.LookupCommand"
			catalogName="auto-sales"
			name="arrange-financing"
			optional="false"/>
		
		<command   id="CloseSale"
			className="com.jadecove.chain.sample.CloseSale"/>
		<test-command name="JoeSmith"/>
	  </chain>
	  <chain name="arrange-financing">
		<command   id="ArrangeFinancing"
			className="com.jadecove.chain.sample.ArrangeFinancingFilter"/>
	  </chain>
</catalog>

/**
 * Load and run the catalog.
 */
package com.jadecove.chain.sample;

import java.net.URL;

import org.apache.commons.chain.Catalog;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
import org.apache.commons.chain.config.ConfigParser;
import org.apache.commons.chain.impl.CatalogFactoryBase;

/**
 * @author
 *
 */
public class CatalogLoader {
    
    private static final String CONFIG_FILE = 
        "/com/jadecove/chain/sample/chain-config.xml";
    private ConfigParser parser;
    private Catalog catalog;
    
    public CatalogLoader() {
        parser = new ConfigParser();
    }
    public Catalog getCatalog() throws Exception {
        if (catalog == null) {
            URL resource = getClass().getClassLoader().getResource(CONFIG_FILE);
                        
            URL configFile = this.getClass().getResource(CONFIG_FILE);
            if(configFile==null){
                System.out.println("Config file is null");
            }
            System.out.println("Resource path is " + configFile.getFile());
            parser.parse(this.getClass().getResource(CONFIG_FILE));
        }
        catalog = CatalogFactoryBase.getInstance().getCatalog();
        return catalog;
    }
    public static void main(String[] args) throws Exception {
        CatalogLoader loader = new CatalogLoader();
        Catalog sampleCatalog = loader.getCatalog();
        
        if(sampleCatalog==null){
            throw new NullPointerException("catalog not initialized correctly");
        }
        Command command = sampleCatalog.getCommand("sell-vehicle");
        Context ctx = new SellVehicleContext();
        command.execute(ctx);
    }
}

The call loader.getCatalog() always returns a null catalog.

Thanks



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


Mime
View raw message