de.knipp.rritoolkit
Class DefaultResponseFactory

java.lang.Object
  extended by de.knipp.rritoolkit.DefaultResponseFactory
All Implemented Interfaces:
ResponseFactory

public class DefaultResponseFactory
extends java.lang.Object
implements ResponseFactory

default implementation of the response factory

Version:
$Revision: 14936 $
Author:
Klaus Malorny

Nested Class Summary
protected  class DefaultResponseFactory.ClassRule
          rule that uses the request for the selection of the suitable response
protected static class DefaultResponseFactory.KeyRule
          rule that tests for the existance of certain keys
protected static class DefaultResponseFactory.ListRule
          small class that describes a rule for choosing a specific subclass
 
Field Summary
private  java.lang.Class<? extends Response> defaultClass
          the default class
private  java.util.SortedSet<DefaultResponseFactory.ListRule> rules
          the set of rules
private static DefaultResponseFactory singleton
          singleton instance with default settings
private  java.util.Map<javax.xml.namespace.QName,java.lang.Class<? extends Response>> xmlMap
          map from the name of the first element to the class
 
Constructor Summary
protected DefaultResponseFactory()
          constructor.
 
Method Summary
protected  void addRule(DefaultResponseFactory.ListRule rule)
          add a list rule
protected  void addXmlMapping(javax.xml.namespace.QName qName, java.lang.Class<? extends Response> cls)
          add an XML mapping
protected  void addXmlMapping(java.lang.String uri, java.lang.String localName, java.lang.Class<? extends Response> cls)
          add an XML mapping
protected  void createDefaults()
          create the default entries
protected  Response createInstance(java.lang.Class<? extends Response> cls)
          create an instance of the given class, mapping the special exceptions to RuntimeExceptions
 Response createResponse(org.w3c.dom.Document doc, Request request)
          create an instance based on the given XML document.
 Response createResponse(KVMultiList list, Request request)
          create an instance based on the given key-value pair list.
static ResponseFactory getFactory()
          return the default factory
protected  void setDefaultClass(java.lang.Class<? extends Response> cls)
          set the default class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xmlMap

private java.util.Map<javax.xml.namespace.QName,java.lang.Class<? extends Response>> xmlMap
map from the name of the first element to the class


rules

private java.util.SortedSet<DefaultResponseFactory.ListRule> rules
the set of rules


defaultClass

private java.lang.Class<? extends Response> defaultClass
the default class


singleton

private static DefaultResponseFactory singleton
singleton instance with default settings

Constructor Detail

DefaultResponseFactory

protected DefaultResponseFactory()
constructor. Protected to avoid direct instantiation, but allowing subclassing. For defaults to be added, createDefaults needs to be called.

Method Detail

setDefaultClass

protected void setDefaultClass(java.lang.Class<? extends Response> cls)
set the default class

Parameters:
cls - the default class

addXmlMapping

protected void addXmlMapping(javax.xml.namespace.QName qName,
                             java.lang.Class<? extends Response> cls)
add an XML mapping

Parameters:
qName - the name of the XML element
cls - the class

addXmlMapping

protected void addXmlMapping(java.lang.String uri,
                             java.lang.String localName,
                             java.lang.Class<? extends Response> cls)
add an XML mapping

Parameters:
uri - the namespace URI
localName - the local name
cls - the class

addRule

protected void addRule(DefaultResponseFactory.ListRule rule)
add a list rule

Parameters:
rule - the rule

createDefaults

protected void createDefaults()
create the default entries


getFactory

public static ResponseFactory getFactory()
return the default factory

Returns:
the factory

createInstance

protected Response createInstance(java.lang.Class<? extends Response> cls)
create an instance of the given class, mapping the special exceptions to RuntimeExceptions

Parameters:
cls - the class to instantiate
Returns:
the instance

createResponse

public Response createResponse(org.w3c.dom.Document doc,
                               Request request)
                        throws org.w3c.dom.DOMException,
                               ResponseParseException
create an instance based on the given XML document. Since the content of the list is not necessarily self-describing in respect to the type of response, the request can be supplied to ease the selection of the correct subclass.

Specified by:
createResponse in interface ResponseFactory
Parameters:
doc - the document
request - the request, may be null
Returns:
the new instance
Throws:
org.w3c.dom.DOMException - on DOM exceptions
ResponseParseException - if the type could not be determined

createResponse

public Response createResponse(KVMultiList list,
                               Request request)
                        throws ResponseParseException
create an instance based on the given key-value pair list. Since the content of the list is not necessarily self-describing in respect to the type of response, the request can be supplied to ease the selection of the correct subclass.

Specified by:
createResponse in interface ResponseFactory
Parameters:
list - the list
request - the request, may be null
Returns:
the created response
Throws:
ResponseParseException - if the type could not be determined


Copyright © 2005-2011 Knipp Medien und Kommunikation GmbH