org.mmbase.applications.dove
Class AbstractDove

java.lang.Object
  extended by org.mmbase.applications.dove.AbstractDove
Direct Known Subclasses:
Dove

public abstract class AbstractDove
extends Object

This class handles Remote Procedure Calls described using a DOM model. The original data is received in xml, likely through a specialized servlet such as the DoveServlet (but this is not required. it may, for instance, be possible to use this class in conjunction with SOAP or even outside a servlet context). The call should result in a new DOM tree (see the EditWizard API for details).
XXX: Currently, this class performs some type of validation on the xml received. If errors occur, they are included in the response, at the place where they occur. This means that the <error > tag can occur anywhere in the response, which is not very neat.
Errors have three types:
parser : the xml given is invalid or does not follow the grammar. This likely means there is a bug in the client code.
server : the code invoked is either not yet implemented or another, server-related, error occurred (such as no memory, bad configuration, etc.). Server errors entirely fail a request.
client : The data requested could not be retrieved or values specified were invalid. I.e. a requested node does not exist (any more), or a put failed due to locking or invalid data.

This is ONLY for debugging purposes! XML validation should occur at the parser and be captured early. If we reach consensus that we must always validate, the xml-checking can be left out, as we can then assumes a correct model. This will optimize processing.

Since:
MMBase-1.5
Version:
$Id: AbstractDove.java 35335 2009-05-21 08:14:41Z michiel $
Author:
Pierre van Rooden

Field Summary
static String DESCENDANT
           
static String DESCENDANTS
           
static String DESCRIPTION
           
protected  Document doc
          The document that is being constructed.
static String DOCTYPE_REQUEST
           
static String DOCTYPE_RESPONSE
           
static String ELM_CONTEXT
           
static String ELM_CREATEDIR
           
static String ELM_DESTINATION
           
static String ELM_DESTINATIONTYPE
           
static String ELM_DIRECTIONS
           
static String ELM_ENCODING
           
static String ELM_HREF
           
static String ELM_ID
           
static String ELM_LANG
           
static String ELM_MAYDELETE
           
static String ELM_MAYWRITE
           
static String ELM_NAME
           
static String ELM_NUMBER
           
static String ELM_OLDNUMBER
           
static String ELM_ORDERBY
           
static String ELM_ROLE
           
static String ELM_SEARCHDIR
           
static String ELM_SEARCHTYPE
           
static String ELM_SIZE
           
static String ELM_SOURCE
           
static String ELM_SOURCETYPE
           
static String ELM_STATUS
           
static String ELM_TYPE
           
static String ELM_WHERE
           
static String ELM_XPATH
           
static String ERROR
           
static String FIELD
           
static String FIELDS
           
static String GETCONSTRAINTS
           
static String GETDATA
           
static String GETLIST
           
static String GETNEW
           
static String GETNEWRELATION
           
static String GETRELATIONS
           
static String GUINAME
           
static String GUITYPE
           
static String IS_CLIENT
           
static String IS_FALSE
           
static String IS_PARSER
           
static String IS_SERVER
           
static String IS_TRUE
           
static String MAXLENGTH
           
static String NEW
           
static String OBJECT
           
static String ORIGINAL
           
static String PARENT
           
static String PLURALNAME
           
static String PUT
           
static String QUERY
           
static String RELATION
           
static String RELATIONS
           
static String REQUEST
           
static String REQUIRED
           
static String RESPONSE
           
static String SECURITY
           
static String SECURITY_CLOUD
           
static String SECURITY_METHOD
           
static String SECURITY_NAME
           
static String SECURITY_PASSWORD
           
static String SINGULARNAME
           
protected static String[] TYPE_DESCRIPTIONS
           
 
Constructor Summary
AbstractDove(Document doc)
          Constructor
 
Method Summary
protected  Element addContentElement(String tagname, String content, Element out)
          Creates a DOM element which contains a Text Node, and adds it to the specified node as a child.
 void doRequest(Element in, Element out)
          Handles a request running one or more RPCs.
abstract  void doRequest(Element in, Element out, Cloud cloud, Map<String,byte[]> repository)
          Handles a request running one or more RPCs.
 Element executeRequest(Element in)
          This method executes the request from the editors, it can be invoked directly
 Element executeRequest(Element in, Cloud cloud, Map<String,byte[]> repository)
          This method executes the request from the editors, it can be invoked directly
protected  Element getFirstElement(Node item)
          Retrieves the first child node of an element that is itself an element.
protected  Element getFirstElement(Node item, String tagname)
          Retrieves the first child node of an element that is itself an element, and has the specified tagname.
protected  Element getNextElement(Node item)
          Retrieves the next sibling of an element that is itself an element.
protected  Element getNextElement(Node item, String tagname)
          Retrieves the the next sibling of an element that is itself an element, and has the specified tagname.
protected  String getTypeDescription(int type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOCTYPE_REQUEST

public static final String DOCTYPE_REQUEST
See Also:
Constant Field Values

DOCTYPE_RESPONSE

public static final String DOCTYPE_RESPONSE
See Also:
Constant Field Values

REQUEST

public static final String REQUEST
See Also:
Constant Field Values

RESPONSE

public static final String RESPONSE
See Also:
Constant Field Values

SECURITY

public static final String SECURITY
See Also:
Constant Field Values

GETDATA

public static final String GETDATA
See Also:
Constant Field Values

GETNEW

public static final String GETNEW
See Also:
Constant Field Values

GETNEWRELATION

public static final String GETNEWRELATION
See Also:
Constant Field Values

GETRELATIONS

public static final String GETRELATIONS
See Also:
Constant Field Values

GETCONSTRAINTS

public static final String GETCONSTRAINTS
See Also:
Constant Field Values

GETLIST

public static final String GETLIST
See Also:
Constant Field Values

PUT

public static final String PUT
See Also:
Constant Field Values

SECURITY_NAME

public static final String SECURITY_NAME
See Also:
Constant Field Values

SECURITY_PASSWORD

public static final String SECURITY_PASSWORD
See Also:
Constant Field Values

SECURITY_CLOUD

public static final String SECURITY_CLOUD
See Also:
Constant Field Values

SECURITY_METHOD

public static final String SECURITY_METHOD
See Also:
Constant Field Values

OBJECT

public static final String OBJECT
See Also:
Constant Field Values

FIELD

public static final String FIELD
See Also:
Constant Field Values

ORIGINAL

public static final String ORIGINAL
See Also:
Constant Field Values

NEW

public static final String NEW
See Also:
Constant Field Values

RELATIONS

public static final String RELATIONS
See Also:
Constant Field Values

RELATION

public static final String RELATION
See Also:
Constant Field Values

ERROR

public static final String ERROR
See Also:
Constant Field Values

QUERY

public static final String QUERY
See Also:
Constant Field Values

PARENT

public static final String PARENT
See Also:
Constant Field Values

DESCENDANTS

public static final String DESCENDANTS
See Also:
Constant Field Values

DESCENDANT

public static final String DESCENDANT
See Also:
Constant Field Values

SINGULARNAME

public static final String SINGULARNAME
See Also:
Constant Field Values

PLURALNAME

public static final String PLURALNAME
See Also:
Constant Field Values

DESCRIPTION

public static final String DESCRIPTION
See Also:
Constant Field Values

FIELDS

public static final String FIELDS
See Also:
Constant Field Values

GUINAME

public static final String GUINAME
See Also:
Constant Field Values

GUITYPE

public static final String GUITYPE
See Also:
Constant Field Values

MAXLENGTH

public static final String MAXLENGTH
See Also:
Constant Field Values

REQUIRED

public static final String REQUIRED
See Also:
Constant Field Values

ELM_ID

public static final String ELM_ID
See Also:
Constant Field Values

ELM_NUMBER

public static final String ELM_NUMBER
See Also:
Constant Field Values

ELM_OLDNUMBER

public static final String ELM_OLDNUMBER
See Also:
Constant Field Values

ELM_TYPE

public static final String ELM_TYPE
See Also:
Constant Field Values

ELM_SEARCHTYPE

public static final String ELM_SEARCHTYPE
See Also:
Constant Field Values

ELM_STATUS

public static final String ELM_STATUS
See Also:
Constant Field Values

ELM_NAME

public static final String ELM_NAME
See Also:
Constant Field Values

ELM_ROLE

public static final String ELM_ROLE
See Also:
Constant Field Values

ELM_DESTINATION

public static final String ELM_DESTINATION
See Also:
Constant Field Values

ELM_DESTINATIONTYPE

public static final String ELM_DESTINATIONTYPE
See Also:
Constant Field Values

ELM_SOURCETYPE

public static final String ELM_SOURCETYPE
See Also:
Constant Field Values

ELM_SEARCHDIR

public static final String ELM_SEARCHDIR
See Also:
Constant Field Values

ELM_CREATEDIR

public static final String ELM_CREATEDIR
See Also:
Constant Field Values

ELM_LANG

public static final String ELM_LANG
See Also:
Constant Field Values

ELM_XPATH

public static final String ELM_XPATH
See Also:
Constant Field Values

ELM_WHERE

public static final String ELM_WHERE
See Also:
Constant Field Values

ELM_ORDERBY

public static final String ELM_ORDERBY
See Also:
Constant Field Values

ELM_DIRECTIONS

public static final String ELM_DIRECTIONS
See Also:
Constant Field Values

ELM_SOURCE

public static final String ELM_SOURCE
See Also:
Constant Field Values

ELM_HREF

public static final String ELM_HREF
See Also:
Constant Field Values

ELM_MAYWRITE

public static final String ELM_MAYWRITE
See Also:
Constant Field Values

ELM_MAYDELETE

public static final String ELM_MAYDELETE
See Also:
Constant Field Values

ELM_CONTEXT

public static final String ELM_CONTEXT
See Also:
Constant Field Values

ELM_SIZE

public static final String ELM_SIZE
See Also:
Constant Field Values

ELM_ENCODING

public static final String ELM_ENCODING
See Also:
Constant Field Values

IS_PARSER

public static final String IS_PARSER
See Also:
Constant Field Values

IS_SERVER

public static final String IS_SERVER
See Also:
Constant Field Values

IS_CLIENT

public static final String IS_CLIENT
See Also:
Constant Field Values

IS_TRUE

public static final String IS_TRUE
See Also:
Constant Field Values

IS_FALSE

public static final String IS_FALSE
See Also:
Constant Field Values

TYPE_DESCRIPTIONS

protected static final String[] TYPE_DESCRIPTIONS

doc

protected final Document doc
The document that is being constructed. This should be used to construct new DOM elements.

Constructor Detail

AbstractDove

public AbstractDove(Document doc)
Constructor

Parameters:
doc - the Document that is constructed. This should only be used to construct new DOM elements. New (child) nodes should not be added to this document, but to the out element.
Method Detail

getTypeDescription

protected String getTypeDescription(int type)

addContentElement

protected Element addContentElement(String tagname,
                                    String content,
                                    Element out)
Creates a DOM element which contains a Text Node, and adds it to the specified node as a child. Used for creating field and error tags.

Parameters:
tagname - name of the new element
content - content of the new element as a string
out - the element to which to add the new Element.
Returns:
the newly created element

getFirstElement

protected Element getFirstElement(Node item)
Retrieves the first child node of an element that is itself an element. If none exist, it returns null.

Parameters:
item - the element to find the first child element of
Returns:
the first child element, or null.

getFirstElement

protected Element getFirstElement(Node item,
                                  String tagname)
Retrieves the first child node of an element that is itself an element, and has the specified tagname. If none exist, it returns null.

Parameters:
item - the element to find the first child element of
tagname - the tagname of the element desired
Returns:
the first child element, or null.

getNextElement

protected Element getNextElement(Node item)
Retrieves the next sibling of an element that is itself an element. If none exist, it returns null.

Parameters:
item - the element to find the sibling element of
Returns:
the sibling element, or null.

getNextElement

protected Element getNextElement(Node item,
                                 String tagname)
Retrieves the the next sibling of an element that is itself an element, and has the specified tagname. If none exist, it returns null.

Parameters:
item - the element to find the sibling element of
tagname - the tagname of the element desired
Returns:
the first child element, or null.

doRequest

public abstract void doRequest(Element in,
                               Element out,
                               Cloud cloud,
                               Map<String,byte[]> repository)
Handles a request running one or more RPCs. This method accepts a root DOM element, which should contain as it child nodes elements describing the call(s) to perform. Each element is an xml element with as the tagname the name of the call to run. Valid calls are getdata, getrelations, getlist, getconstraints, getnew, and put. The calls are redirected to the appropriate encapsulating method in this class. The end result of each call should be a DOM tree, built using the given parameters, which is then appended to the out element.
XXX:This method runs all commands in order of entrance. It does not currently check whether all child nodes refer to the same call. This means that it is possible to mix 'getdata' and 'getrelations' calls in one request. Ina dditon, it ignores calls it does not know how to handle. as described above, this should be handled by the xml parser. Note also that if no id was given for a call, a NullPointer exception is thrown.

Parameters:
in - the element that described the request (or input). The childnodes should describe the calls to perform.
out - the element that described the response (or return value). Results of calls should be added as childs to this element.
cloud - the MMCI cloud to use, if applicable.
repository - Repository that contains the blobs

doRequest

public void doRequest(Element in,
                      Element out)
Handles a request running one or more RPCs.

Parameters:
in - the element that described the request (or input). The childnodes should describe the calls to perform.
out - the element that described the response (or return value). Results of calls should be added as childs to this element.

executeRequest

public Element executeRequest(Element in,
                              Cloud cloud,
                              Map<String,byte[]> repository)
This method executes the request from the editors, it can be invoked directly

Parameters:
in - the element that described the request (or input). The childnodes should describe the calls to perform.
cloud - the MMCI cloud to use, if applicable.
repository - Repository that contains the blobs
Returns:
the element that described the response (or return value). Results of calls should be added as childs to this element.

executeRequest

public Element executeRequest(Element in)
This method executes the request from the editors, it can be invoked directly

Parameters:
in - the element that described the request (or input). The childnodes should describe the calls to perform.
Returns:
the element that described the response (or return value). Results of calls should be added as childs to this element.


MMBase 2.0-SNAPSHOT - null