- From: Hiep Duong via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 20 Feb 2008 15:09:59 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/org/w3c/unicorn/request In directory hutz:/tmp/cvs-serv30553/org/w3c/unicorn/request Modified Files: Request.java UploadRequest.java DirectRequestPOST.java DirectRequestGET.java URIRequest.java Log Message: simplified observationresponse and generalize output format (now we can map a format type what defnied in the contract to a ResponseParser) Index: DirectRequestPOST.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/DirectRequestPOST.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- DirectRequestPOST.java 29 Nov 2007 14:11:58 -0000 1.3 +++ DirectRequestPOST.java 20 Feb 2008 15:09:57 -0000 1.4 @@ -12,12 +12,11 @@ import java.util.Map; import java.util.Random; -import javax.xml.bind.JAXBException; - import org.w3c.unicorn.contract.EnumInputMethod; -import org.w3c.unicorn.generated.observationresponse.Observationresponse; import org.w3c.unicorn.input.DirectInputModule; import org.w3c.unicorn.input.InputModule; +import org.w3c.unicorn.response.Response; +import org.w3c.unicorn.response.parser.ResponseParserFactory; /** * @author Damien LEROY @@ -44,7 +43,8 @@ protected DirectRequestPOST ( final String sURL, final String sInputParameterName, - final InputModule aInputModule) throws IOException { + final InputModule aInputModule, + final String responseType) throws IOException { super(); DirectRequestPOST.logger.trace("Constructor"); if (DirectRequestPOST.logger.isDebugEnabled()) { @@ -58,6 +58,7 @@ this.mapOfParameter = new Hashtable<String, String>(); this.sURL = sURL; this.addParameter(sInputParameterName, aInputModule.getStringContent()); + this.setResponseType(responseType); } @Override @@ -71,7 +72,7 @@ } @Override - public Observationresponse doRequest () throws JAXBException, IOException { + public Response doRequest () throws IOException { DirectRequestPOST.logger.trace("doRequest"); final URL aURL = new URL(sURL); this.aURLConnection = aURL.openConnection(); @@ -133,7 +134,8 @@ sResponse += new String(tByte); } DirectRequestPOST.logger.debug(sResponse);*/ - return (Observationresponse) this.aUnmarshaller.unmarshal(aURLConnection.getInputStream()); + //return this.aResponseParser.parse(aURLConnection.getInputStream()); + return ResponseParserFactory.parse(aURLConnection.getInputStream(), this.getResponseType()); } @Override Index: DirectRequestGET.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/DirectRequestGET.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- DirectRequestGET.java 29 Nov 2007 14:11:58 -0000 1.2 +++ DirectRequestGET.java 20 Feb 2008 15:09:57 -0000 1.3 @@ -9,12 +9,11 @@ import java.net.URLConnection; import java.net.URLEncoder; -import javax.xml.bind.JAXBException; - import org.w3c.unicorn.contract.EnumInputMethod; -import org.w3c.unicorn.generated.observationresponse.Observationresponse; import org.w3c.unicorn.input.DirectInputModule; import org.w3c.unicorn.input.InputModule; +import org.w3c.unicorn.response.Response; +import org.w3c.unicorn.response.parser.ResponseParserFactory; import org.w3c.unicorn.util.Property; /** @@ -29,7 +28,8 @@ protected DirectRequestGET ( final String sURL, final String sInputParameterName, - final InputModule aInputModule) throws IOException { + final InputModule aInputModule, + final String responseType) throws IOException { super(); DirectRequestGET.logger.trace("Constructor"); if (DirectRequestGET.logger.isDebugEnabled()) { @@ -42,6 +42,7 @@ } this.sURL = sURL; this.addParameter(sInputParameterName, aInputModule.getStringContent()); + this.setResponseType(responseType); } @Override @@ -61,7 +62,7 @@ } @Override - public Observationresponse doRequest () throws JAXBException, IOException { + public Response doRequest () throws IOException { DirectRequestGET.logger.trace("doRequest"); final URL aURL; if (null == this.sParameter) { @@ -72,7 +73,8 @@ } final URLConnection aURLConnection = aURL.openConnection(); aURLConnection.setRequestProperty("Accept-Language", this.sLang); - return (Observationresponse) this.aUnmarshaller.unmarshal(aURLConnection.getInputStream()); + //return this.aResponseParser.parse(aURLConnection.getInputStream()); + return ResponseParserFactory.parse(aURLConnection.getInputStream(), this.getResponseType()); } @Override Index: UploadRequest.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/UploadRequest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- UploadRequest.java 29 Nov 2007 14:11:58 -0000 1.3 +++ UploadRequest.java 20 Feb 2008 15:09:57 -0000 1.4 @@ -9,12 +9,11 @@ import java.util.Hashtable; import java.util.Map; -import javax.xml.bind.JAXBException; - import org.w3c.unicorn.contract.EnumInputMethod; -import org.w3c.unicorn.generated.observationresponse.Observationresponse; import org.w3c.unicorn.input.InputModule; import org.w3c.unicorn.input.UploadInputModule; +import org.w3c.unicorn.response.Response; +import org.w3c.unicorn.response.parser.ResponseParserFactory; import org.w3c.unicorn.util.ClientHttpRequest; /** @@ -32,7 +31,8 @@ protected UploadRequest ( final String sURL, final String sInputParameterName, - final InputModule aInputModule) throws MalformedURLException, IOException { + final InputModule aInputModule, + final String responseType) throws MalformedURLException, IOException { super(); UploadRequest.logger.trace("Constructor"); if (UploadRequest.logger.isDebugEnabled()) { @@ -52,6 +52,7 @@ this.sInputParameterName, this.aUploadInputModule.getFileName(), this.aUploadInputModule.getInputStream());*/ + this.setResponseType(responseType); } @Override @@ -66,7 +67,7 @@ } @Override - public Observationresponse doRequest() throws JAXBException, IOException { + public Response doRequest() throws IOException { UploadRequest.logger.trace("doRequest"); this.aClientHttpRequest = new ClientHttpRequest(sURL); UploadRequest.logger.debug("Lang : "+this.sLang+"."); @@ -84,8 +85,9 @@ } this.aClientHttpRequest.setParameter(sName, sValue); } - final Observationresponse aObservationResponse; - aObservationResponse = (Observationresponse) this.aUnmarshaller.unmarshal(this.aClientHttpRequest.post()); + final Response aObservationResponse; + //aObservationResponse = this.aResponseParser.parse(this.aClientHttpRequest.post()); + aObservationResponse = ResponseParserFactory.parse(this.aClientHttpRequest.post(), this.getResponseType()); return aObservationResponse; } Index: Request.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/Request.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Request.java 29 Nov 2007 14:11:58 -0000 1.3 +++ Request.java 20 Feb 2008 15:09:57 -0000 1.4 @@ -6,49 +6,25 @@ import java.io.IOException; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.unicorn.contract.EnumInputMethod; -import org.w3c.unicorn.generated.observationresponse.Observationresponse; import org.w3c.unicorn.input.InputModule; +import org.w3c.unicorn.response.parser.ResponseParser; /** * * @author Damien LEROY */ public abstract class Request { - protected static final Log logger = LogFactory.getLog("org.w3c.unicorn.request"); - - public Unmarshaller aUnmarshaller = null; - protected static JAXBContext aJAXBContext = null; - - static { - try { - Request.aJAXBContext = JAXBContext.newInstance("org.w3c.unicorn.generated.observationresponse"); - - } - catch (final JAXBException e) { - Request.logger.error("JAXBException : " + e.getMessage(), e); - e.printStackTrace(); - } - } + + //public ResponseParser aResponseParser; protected String sLang = null; - - public Request(){ - try { - this.aUnmarshaller = Request.aJAXBContext.createUnmarshaller(); - } catch (JAXBException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + protected String responseType=null; + public void setLang (final String sLang) throws IOException { Request.logger.debug("setLang("+sLang+")"); this.sLang = sLang; @@ -56,7 +32,7 @@ public abstract void addParameter (final String sName, final String sValue) throws IOException; - public abstract Observationresponse doRequest () throws JAXBException, IOException; + public abstract org.w3c.unicorn.response.Response doRequest () throws IOException; public abstract EnumInputMethod getInputMethod (); @@ -64,7 +40,8 @@ final InputModule aInputModule, final String sURL, final String sInputParameterName, - final boolean bIsPost) throws IOException { + final boolean bIsPost, + final String responseType) throws IOException { Request.logger.trace("createRequest"); @@ -77,14 +54,14 @@ switch (aInputModule.getEnumInputMethod()) { case DIRECT : if ( bIsPost) { - return new DirectRequestPOST(sURL, sInputParameterName, aInputModule); + return new DirectRequestPOST(sURL, sInputParameterName, aInputModule, responseType); } else { - return new DirectRequestGET(sURL, sInputParameterName, aInputModule); + return new DirectRequestGET(sURL, sInputParameterName, aInputModule, responseType); } case UPLOAD : - return new UploadRequest(sURL, sInputParameterName, aInputModule); + return new UploadRequest(sURL, sInputParameterName, aInputModule, responseType); case URI : - return new URIRequest(sURL, sInputParameterName, aInputModule); + return new URIRequest(sURL, sInputParameterName, aInputModule, responseType); } return null; } @@ -93,4 +70,12 @@ return "Abstract class org.w3c.unicorn.request.Request, toString function must be overrided."; } + public String getResponseType() { + return responseType; + } + + public void setResponseType(String responseType) { + this.responseType = responseType; + } + } Index: URIRequest.java =================================================================== RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/URIRequest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- URIRequest.java 29 Nov 2007 14:11:58 -0000 1.3 +++ URIRequest.java 20 Feb 2008 15:09:57 -0000 1.4 @@ -11,12 +11,11 @@ import java.net.URLConnection; import java.net.URLEncoder; -import javax.xml.bind.JAXBException; - import org.w3c.unicorn.contract.EnumInputMethod; -import org.w3c.unicorn.generated.observationresponse.Observationresponse; import org.w3c.unicorn.input.InputModule; import org.w3c.unicorn.input.URIInputModule; +import org.w3c.unicorn.response.Response; +import org.w3c.unicorn.response.parser.ResponseParserFactory; /** * Use to handle a request to a observer. @@ -30,7 +29,8 @@ protected URIRequest ( final String sURL, final String sInputParameterName, - final InputModule aInputModule) throws IOException { + final InputModule aInputModule, + final String responseType) throws IOException { super(); URIRequest.logger.trace("Constructor"); if (URIRequest.logger.isDebugEnabled()) { @@ -44,6 +44,7 @@ this.sURL = sURL; final URIInputModule aURIInputModule = (URIInputModule) aInputModule; this.addParameter(sInputParameterName, aURIInputModule.getURI()); + this.setResponseType(responseType); } public void addParameter ( @@ -63,7 +64,7 @@ URIRequest.logger.debug("Parameters : "+this.sParameter+"."); } - public Observationresponse doRequest () throws IOException, JAXBException { + public Response doRequest () throws IOException { URIRequest.logger.trace("doRequest"); if (URIRequest.logger.isDebugEnabled()) { URIRequest.logger.debug("URL : "+this.sURL+" ."); @@ -81,7 +82,8 @@ aURLConnection.setRequestProperty("Accept-Language", this.sLang); InputStream is = aURLConnection.getInputStream(); - Observationresponse res = (Observationresponse) this.aUnmarshaller.unmarshal(is); + //Response res = this.aResponseParser.parse(is); + Response res = ResponseParserFactory.parse(is, this.getResponseType()); return res; }
Received on Wednesday, 20 February 2008 15:10:10 UTC