uk.org.ogsadai.activity
Class ResponseDocumentBuilder

java.lang.Object
  |
  +--uk.org.ogsadai.activity.ResponseDocumentBuilder
All Implemented Interfaces:
ResponseBuilder

public class ResponseDocumentBuilder
extends java.lang.Object
implements ResponseBuilder

A ResponseBuilder to assemble an OGSA-DAI response document that conforms to the OGSA-DAI response document XML schema.

Author:
The OGSA-DAI Project Team

Field Summary
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement.
private static DAILogger LOG
          Logger object for logging in this class.
(package private)  org.w3c.dom.Document mResponse
          The response document that is being built.
(package private)  org.w3c.dom.Element mRootElement
          Reference to the response document's root element for convenience.
 
Constructor Summary
ResponseDocumentBuilder()
          Constructor - creates a skeleton response document.
 
Method Summary
private  void addClientException(org.w3c.dom.Document doc, org.w3c.dom.Element parent, java.lang.Throwable exception)
          This method adds information about an exception arising due to information provided by a client, to an XML document.
private  void addClientExceptionAuthz(org.w3c.dom.Document doc, org.w3c.dom.Element parent, DAIAuthorizationException exception)
          This method adds information about an authorization exception, to an XML document.
private  void addClientExceptionDetail(org.w3c.dom.Document doc, org.w3c.dom.Element parent, java.lang.Throwable exception)
          This method adds information about an exception arising due to information provided by a client, to an XML document.
private  void addServerException(org.w3c.dom.Document doc, org.w3c.dom.Element parent, java.lang.Throwable exception)
          This method adds information about an internal server-side exception, details of which should not be exposed to a client, to an XML document.
 void buildError(java.lang.String name, java.lang.Throwable cause)
          Assembles part of the response document describing an error that has occurred while processing part of a request.
 void buildRequestError(java.lang.String cause)
          Assembles the part of the response document describing the status of a request that has failed due to an error.
 void buildRequestStatus(ProcessingStatus status)
          Assembles the part of the response document describing the status of the request.
 void buildResult(java.lang.String name, ProcessingStatus status, byte[] data)
          Assembles part of the response document describing the result of processing part of the request.
 void buildResult(java.lang.String name, Status status, byte[] data)
          Assembles part of the response document describing the result of processing part of the request.
 void buildSessionDetails(Session session)
          Assembles the part of the response document identifying the session that the request was joined to.
 org.w3c.dom.Document getResponseDocument()
          Gets the assembled response document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
Copyright statement.

See Also:
Constant Field Values

LOG

private static final DAILogger LOG
Logger object for logging in this class.


mResponse

final org.w3c.dom.Document mResponse
The response document that is being built.


mRootElement

final org.w3c.dom.Element mRootElement
Reference to the response document's root element for convenience.

Constructor Detail

ResponseDocumentBuilder

public ResponseDocumentBuilder()
Constructor - creates a skeleton response document.

Method Detail

buildResult

public void buildResult(java.lang.String name,
                        ProcessingStatus status,
                        byte[] data)
Description copied from interface: ResponseBuilder
Assembles part of the response document describing the result of processing part of the request.

Specified by:
buildResult in interface ResponseBuilder
Parameters:
name - The name associated with the result
status - The status of the result.
data - The result data. This may be null or an empty String if the result contains no result data.

buildResult

public void buildResult(java.lang.String name,
                        Status status,
                        byte[] data)
Description copied from interface: ResponseBuilder
Assembles part of the response document describing the result of processing part of the request.

Specified by:
buildResult in interface ResponseBuilder
Parameters:
name - The name associated with the result
status - The status of the result.
data - The result data. This may be null or an empty array if the result contains no result data.

buildError

public void buildError(java.lang.String name,
                       java.lang.Throwable cause)
Description copied from interface: ResponseBuilder
Assembles part of the response document describing an error that has occurred while processing part of a request.

Specified by:
buildError in interface ResponseBuilder
Parameters:
name - The name associated with the result
cause - Cause of the error.

buildRequestStatus

public void buildRequestStatus(ProcessingStatus status)
Description copied from interface: ResponseBuilder
Assembles the part of the response document describing the status of the request.

Specified by:
buildRequestStatus in interface ResponseBuilder
Parameters:
status - Request status.

buildRequestError

public void buildRequestError(java.lang.String cause)
Description copied from interface: ResponseBuilder
Assembles the part of the response document describing the status of a request that has failed due to an error.

Specified by:
buildRequestError in interface ResponseBuilder
Parameters:
cause - Name of the cause of the failue e.g. an activity name.

buildSessionDetails

public void buildSessionDetails(Session session)
Description copied from interface: ResponseBuilder
Assembles the part of the response document identifying the session that the request was joined to.

Specified by:
buildSessionDetails in interface ResponseBuilder
Parameters:
session - Session the request was joined to

getResponseDocument

public org.w3c.dom.Document getResponseDocument()
Gets the assembled response document. This should be invoked after the building process has been completed.

Returns:
the response Document

addClientException

private void addClientException(org.w3c.dom.Document doc,
                                org.w3c.dom.Element parent,
                                java.lang.Throwable exception)
This method adds information about an exception arising due to information provided by a client, to an XML document.

The information is in the form of an XML fragment:

 <ns1:activityFault 
   xmlns:ns1="http://ogsadai.org.uk/namespaces/2005/10/types">
   <ns1:reason>
     <ns1:errorID>ID</ns1:errorID>
     <ns1:msg>MESSAGE</ns1:msg>
     <ns1:params>PARAM-ONE</ns1:params>
     <ns1:params>PARAM-TWO</ns1:params>
   </ns1:reason>
   <ns1:reason>
     <ns1:errorID>ID</ns1:errorID>
     <ns1:msg>MESSAGE</ns1:msg>
     <ns1:params>PARAM-ONE</ns1:params>
     <ns1:params>PARAM-TWO</ns1:params>
   </ns1:reason>
   <ns1:reason>
     <ns1:errorID>ID</ns1:errorID>
     <ns1:msg>MESSAGE</ns1:msg>
     <ns1:params>PARAM-ONE</ns1:params>
     <ns1:params>PARAM-TWO</ns1:params>
   </ns1:reason>
 </ns1:activityFault>
 

The exception traverses all exceptions in the given train until either the bottom of the chain is reached or a DAIAuthorizationException is reached (in which case it is not appropriate to give further information).

Parameters:
doc - XML document to which the information is to be added.
parent - XML element to which the information is to be added, as a child.
exception - Exception for which the information is to be created.

addClientExceptionDetail

private void addClientExceptionDetail(org.w3c.dom.Document doc,
                                      org.w3c.dom.Element parent,
                                      java.lang.Throwable exception)
This method adds information about an exception arising due to information provided by a client, to an XML document.

The information is in the form of an XML fragment:

   <ns1:errorID>ID</ns1:errorID>
   <ns1:msg>MESSAGE</ns1:msg>
   <ns1:params>PARAM-ONE</ns1:params>
   <ns1:params>PARAM-TWO</ns1:params>
 

Parameters:
doc - XML document to which the information is to be added.
parent - XML element to which the information is to be added, as a child.
exception - Exception for which the information is to be created.

addClientExceptionAuthz

private void addClientExceptionAuthz(org.w3c.dom.Document doc,
                                     org.w3c.dom.Element parent,
                                     DAIAuthorizationException exception)
This method adds information about an authorization exception, to an XML document.

The information is in the form of an XML fragment:

 <ns1:errorID>
   uk.org.ogsadai.AUTHORISATION_FAULT
 </ns1:errorID>
 <ns1:msg>
   Authorisation fault. Consult the OGSA-DAI Service Provider
   with ID UNIQUE-SERVER-SIDE-ID.
 </ns1:msg>
 <ns1:params>UNIQUE-SERVER-SIDE-ID>/ns1:params>
 

Parameters:
doc - XML document to which the information is to be added.
parent - XML element to which the information is to be added, as a child.
exception - Exception for which the information is to be created.

addServerException

private void addServerException(org.w3c.dom.Document doc,
                                org.w3c.dom.Element parent,
                                java.lang.Throwable exception)
This method adds information about an internal server-side exception, details of which should not be exposed to a client, to an XML document.

The information is in the form of an XML fragment:

 <ns1:activityFault
   xmlns:ns1="http://ogsadai.org.uk/namespaces/2005/10/types">
   <ns1:reason>
     <ns1:errorID>uk.org.ogsadai.INTERNAL_FAULT</ns1:errorID>
     <ns1:msg>
       Internal fault. Consult the OGSA-DAI Service Provider with
       ID UNIQUE-SERVER-SIDE-ID.
     </ns1:msg>
     <ns1:params>UNIQUE-SERVER-SIDE-ID>/ns1:params>
   </ns1:reason>
 </ns1:activityFault>
 

Parameters:
doc - XML document to which the information is to be added.
parent - XML element to which the information is to be added, as a child.
exception - Exception for which the information is to be created.