Wednesday, April 20, 2011
CUFP | Commercial Users of Functional Programming
CUFP | Commercial Users of Functional Programming
Tuesday, March 15, 2011
Spring Batch -- Unplugged
<bean id="itemWriter015" class="org.springframework.batch.item.file.FlatFileItemWriter">
<property name="resource" value="file:rdm.txt" />
<property name="lineAggregator">
<bean class="org.springframework.batch.item.file.transform.FormatterLineAggregator">
<property name="fieldExtractor">
<bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<property name="names" value="actionType,crmOrderNumber" />
</bean>
</property>
<property name="format" value="015%1s%9s" />
</bean>
</property>
</bean>
As you can see, there is also a mapper involve that uses the OXM marshallers from Spring to map an order XML to domain model objects. The domain model objects have standard getters and setters. The getters are utilized by the FormatterLineAggregator; another Spring Batch object.
FormatterLineAggregator
The FormatterLineAggregator has something called a field extractor which is an instance of the Spring Batch BeanWrapperFieldExtractor class. It is on the BeanWrapperFieldExtractor where you provide the list of properties you want to write out using the line aggregator. The values in this list must match the getter methods of the object you pass to the item writer's 'write' method. As in:
ListsohList = new ArrayList ();
sohList.add(stockOrder.getHeader());
try {
getFfiw015().open(new ExecutionContext());
getFfiw015().write(sohList);
getFfiw015().close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Here I am passing something called a stock order object that has get methods for the actionType and crmOrderNumber members. These values were set by reading the XML and unmarshalling into the stock order domain model objects.
Spring OXM Unmarshalling
To configure XML unmarshalling to Java, here is the bean definitions from the application context:
<bean id="sodMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.gap.gid.stockorder.model.StockOrder</value>
</list>
</property>
<property name="schemas">
<list>
<value>classpath:com/gap/gid/stockorder/model/schema/omssod.xsd</value>
</list>
</property>
</bean>
<bean id="stockOrderMapper" class="com.gap.gid.stockorder.model.StockOrderMapper">
<property name="marshaller">
<ref bean="sodMarshaller" />
</property>
<property name="unmarshaller">
<ref bean="sodMarshaller" />
</property>
</bean>
After grabbing the XML message off the queue, hand it off to the mapper/unmarshaller:
InputStream is = null;
StockOrder stockOrder = null;
try {
is = new ByteArrayInputStream(xmlMessage.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
stockOrder = (StockOrder) stockOrderMapper.readObjectFromXml(new StreamSource(is));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The unmarshaller knows which elements to map to which object members by using annotations:
@XmlRootElement(name="StockOrder")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType
public class StockOrder implements Serializable {
/**
*
*/
private static final long serialVersionUID = 9126450659071953120L;
/**
*
*/
@XmlElement(name="StockOrderHeader")
private StockOrderHeader header;
/**
* @return the header
*/
public StockOrderHeader getHeader() {
return header;
}
/**
* @param header the header to set
*/
public void setHeader(StockOrderHeader header) {
this.header = header;
}
}
Monday, January 31, 2011
Rails Sample App Status (part 3)
Thursday, January 27, 2011
Rails Sample App Status (part 2)
Wednesday, January 19, 2011
Random Grails Links
| | Thank you for joining last week’s webinar “What's new with Groovy & Grails Tooling in the SpringSource Tool Suite?” The webinar recording and slides are now posted. - Grails is an advanced and innovative open source web application platform delivering new levels of developer productivity. Visit www.grails.org to download Grails 1.3.6, view available Grails plugins, and get the latest news. - Groovy is the leading open source dynamic language for the Java Virtual machine offering a flexible Java-like syntax that most Java developers can learn in a matter of hours. Visit http://groovy.codehaus.org to download Groovy 1.7, read the release notes and access other resources. |
Wednesday, December 1, 2010
Rails Sample App Status
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /var/lib/gems/1.8
- /home/balexander/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--http-proxy http://XXXX"
- :sources => ["http://gems.rubyforge.org", "http://gems.github.com"]
- REMOTE SOURCES:
- http://gems.rubyforge.org
- http://gems.github.com
balexander@ubuntu001:~/SampleApp$ script/console development
Loading development environment (Rails 2.2.3)