You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Torsten Zesch <ze...@tk.informatik.tu-darmstadt.de> on 2007/11/01 18:40:31 UTC

Set configuration parameters of a collection reader before it is initialized

Hi all,

I have written a CollectionReader that reads from a database. I added
the database connection parameters as mandatory parameters to the
descriptor. They are initialized with the correct values for the
production database.

Now, I want to write some unit tests that connect to a (always
available) test database, as the production database might not be
available at testing time.
I tried it with the code below, but the the reader's initialize() method
is already called when

CollectionReader reader =
UIMAFramework.produceCollectionReader(specifier);

is executed. That means, the test will fail before it had the chance to
reconfigure the parameters.

Is there any way to set the configuration parameters of a collection
reader before it is actually initialized?

Thanks,
Torsten

<snip>
// a map that contains the configuration parameters
Map<String,Object> configParameters = new HashMap<String, Object>() {{
// fill the map with some parameters
...        

try {
    XMLInputSource xmlInput = new XMLInputSource(descriptorFileReader);
    ResourceSpecifier specifier =
UIMAFramework.getXMLParser().parseResourceSpecifier(xmlInput);

    CollectionReader reader =
UIMAFramework.produceCollectionReader(specifier);

    for (String key : configParameters.keySet()) {
        reader.setConfigParameterValue(key, configParameters.get(key));
    }
    reader.reconfigure();
            
    // testing the reader
    ...
         
}
// a lot of catches
</snip>

Re: Set configuration parameters of a collection reader before it is initialized

Posted by Adam Lally <al...@alum.rpi.edu>.
On 11/1/07, Torsten Zesch <ze...@tk.informatik.tu-darmstadt.de> wrote:
><snip/>
> Is there any way to set the configuration parameters of a collection
> reader before it is actually initialized?
>

Yes, it's possible to do this.  Instead of parseResourceSpecifier,
call parseCollectionReaderDescription.  Then you can call methods on
the CollectionReaderDescription object to change the parameter values.
 Effectively you're overriding the values that were in the descriptor,
before instantiating your component.  The methods to do this are
something like:

collectionReaderDescription.getCollectionReaderMetaData().getConfigurationParameterSettings().setParameterValue(name,value)

But I didn't test that so I might have gotten it slightly wrong.

-Adam