axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Wilson <s.wil...@bangor.ac.uk>
Subject Deserializing an XSL-transformed response
Date Thu, 17 Mar 2005 01:17:00 GMT
I have a bit of an odd problem:

My application is a search adapter for a federated search system; it 
calls a remote search service, which returns some results in its native 
schema format. This is deserialized into my RecordData bean that AXIS 
has helpfully generated, with the results lurking in the '_any' value 
(the other value being Srw_DcType dc).

I use XSL to take the contents of '_any' and transform them into Dublin 
Core, then insert this back into the RecordData bean instance.

However, I now need to deserialize the resulting data so I can do some 
further work on it (such as vocab mapping) before I return it for 
output to the federated search engine that called my adapter. I'd like 
to make RecordData.dc actually have the deserialized value of the 
transformation output.

The problem is, automated serialization only happens in Axis at the end 
of a SOAP call; I can't figure out a way of programmatically invoking a 
BeanDeserializer on my transformed XML, even though I have everything 
Axis needs already in place (a generated type, registered, and working 
- when a call is invoked).

Some source code below will, I hope, show you what I'm after:

/*
  * Created on Mar 16, 2005
  *
  */
package au.edu.mq.melcoe.mams.adapter.search.handler;

import gov.loc.www.zing.srw.RecordsType;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.dom.DOMResult;
import org.apache.axis.message.MessageElement;
import java.io.StringReader;
import org.w3c.dom.*;
/**
  * Performs an XSL transformation on a results set, and places the 
results into
  * the RecordsType passed in.
  *
  * @author Scott Wilson
  */
public class XslMetadataProcessor implements IMetadataProcessor {
	
	private String stylesheet;
	
	public XslMetadataProcessor(String stylesheet){
		this.stylesheet = stylesheet;
	}
	
	public RecordsType processRecords(RecordsType records) throws 
Exception{
		//return records;
		if(stylesheet != null && records != null){
			
			for (int i=0;i<records.getRecord().length;i++){
				
				MessageElement[] msg = 
records.getRecord(i).getRecordData().get_any();
				DOMResult out = new DOMResult();
				StreamSource src = new StreamSource(new 
StringReader(msg[0].getAsString()));
				
				try{
					javax.xml.transform.TransformerFactory tFactory =
						javax.xml.transform.TransformerFactory.newInstance();
					javax.xml.transform.Transformer transformer = 
tFactory.newTransformer
					(new StreamSource("META-INF/stylesheets/"+this.stylesheet));
					transformer.transform (src, out);
					Document outDoc = (Document)out.getNode();
					msg[0] = new 
MessageElement((Element)outDoc.getElementsByTagName("*").item(0));
				} catch (Exception ex){
					ex.printStackTrace();
					throw new Exception("Transformation could not be completed");
				}
				// OK, we now have the record transformed, and the output is inside
				// the "_any" part of the record. time to deserialize it - but how?
				// I'd like to write :
				// Srw_dcType dc = new Srw_dcType(SOME MAGIC HERE);
				// records.getRecord(i).getRecordData().setDc(dc);
			}

		} else {
			throw new Exception("Stylesheet not defined");
		}
		return records;
	}
}

Mime
View raw message