-
1. Re: How to reference objects stored in Smooks ExecutionContext?
tfennelly Feb 11, 2010 4:56 AM (in response to edx)Hi Edward.
The data map that the Freemarker templates etc see is stored in a Map off the ExecutionContext. Setting bean instances in it is done via the BeanRepository.addBean(String, Object) method.
So, the code in your FileFetchExecute class might look something like:
ExecutionContext execContext = smooks.createExecutionContext(); BeanRepository beanRepo = BeanRepository.getInstance(execContext); beanRepo.addBean("inputFile", theFile); smooks.filterSource(new StreamSource(new FileReader(theFile)));
Then in the FreeMarker template, you reference this bean like any other e.g.
<splitMessage srcPath="${inputFile.absolutePath}"> ..... </splitMessage>
The API around th bean context has been cleaned up a little in Smooks v1.3, where we introduced the BeanContext class as a first class construct in Smooks Core and made it accessible directly on the ExecutionContext i.e. the above code would be something like execContext.getBeanContext().addBean(...), which is a little more obvious.
-
2. Re: How to reference objects stored in Smooks ExecutionContext?
edx Feb 11, 2010 7:19 AM (in response to tfennelly)Thanks Tom,
your answer is very helpful.
Edward
-
3. Re: How to reference objects stored in Smooks ExecutionContext?
edx Feb 11, 2010 5:05 PM (in response to tfennelly)Tom,
I spent one day trying to find out why it is not working for me.
The clue is in the proper selection of the overloaded method smooks.filterSource(...).
We need here filterSource() that submits already prepared ExecutionContext,
otherwise filterSource() (like in your advice) creates new one where our beans are not referenced.
Edward
-
4. Re: How to reference objects stored in Smooks ExecutionContext?
tfennelly Feb 12, 2010 5:17 AM (in response to edx)Oh of course... I forgot to do that in the sameple code... sorry. So the sample code should have been (diff is call to filterSource method):
ExecutionContext execContext = smooks.createExecutionContext(); BeanRepository beanRepo = BeanRepository.getInstance(execContext); beanRepo.addBean("inputFile", theFile); smooks.filterSource(execContext, new StreamSource(new FileReader(theFile)));