Skip to Content
0
Former Member
Jul 23, 2010 at 08:55 PM

Java Mapping - ClassCastException SAX

20 Views

Hi experts,

I am developing a Java mapping program for a very specific situation. I chose to do that using SAX API, but I found a problem with that.

The following lines are throwing a ClassCastException during the mapping test in the Enterprise Service Builder (PI 7.1 EHP 4):

public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
try {
	InputPayload inputPayload = in.getInputPayload();
	InputStream inputStream = inputPayload.getInputStream();

	OutputPayload outputPayload = out.getOutputPayload();
	OutputStream outputStream = outputPayload.getOutputStream();

	// create a TransformerHandler for producing XML output
	SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
	TransformerHandler th = factory.newTransformerHandler();
	Result result = new StreamResult(outputStream);
	th.setResult(result);
// ...

I copied most of that from [this|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/4143] [original link is broken]; article.

After some tests, I realise that the Exception occurs in this line:

SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();

I believe that's because the method newInstance is returning something that cannot be converted into a SAXTransformerFactory, but I could not find another way from using the TransformerHandler that not doing so.

Is there anyway to fix that problem? Do you have other samples of SAX mapping?

Thanks anyway.