org.mmbase.applications.editwizard
Class WizardDatabaseConnector

java.lang.Object
  extended by org.mmbase.applications.editwizard.WizardDatabaseConnector
All Implemented Interfaces:
Serializable

public class WizardDatabaseConnector
extends Object
implements Serializable

This class handles all communication with mmbase. It uses the MMBase-Dove code to do the transactions and get the information needed for rendering the wizard screens. The WizardDatabaseConnector can connect to MMBase and get data, relations, constraints, lists. It can also store changes, create new objects and relations. The connector can be instantiated without the wizard class, but will usually be called from the Wizard class itself. EditWizard

Since:
MMBase-1.6
Version:
$Id: WizardDatabaseConnector.java 35335 2009-05-21 08:14:41Z michiel $
Author:
Kars Veling, Michiel Meeuwissen, Pierre van Rooden
See Also:
Serialized Form
Javadoc:

Field Summary
(package private)  int didcounter
           
 
Constructor Summary
WizardDatabaseConnector()
          Constructor: Creates the connector.
 
Method Summary
protected static void convertBooleanToInt(Node rootNode)
          Booleans in MMBase are represented by a boolean value.
protected  void convertDateTimeToInt(Node rootNode)
          The editwizard uses integer values to represent dates.
protected  void convertIntToBoolean(Node rootNode)
          Booleans in MMBase are represented by a boolean value.
protected  void convertIntToDateTime(Node rootNode)
          The editwizard uses integer values to represent dates.
 Node createObject(Document data, Node targetParentNode, Node objectDef, Map<String,Object> params, Document loadedData)
          This method can create a object (or a tree of objects and relations)
 Node createObject(Document data, Node targetParentNode, Node objectDef, Map<String,Object> params, int createorder, Document loadedData)
          This method can create a object (or a tree of objects and relations) this method should be called from the wizard if it needs to create a new combination of fields, objects and relations.
 Node getConstraints(String objecttype)
          This method gets constraint information from mmbase about a specific objecttype.
 Node getDataNode(Document document, String objectnumber, NodeList restrictions)
          This method retrieves data (objectdata) from mmbase.
 Node getList(Node query)
          This method retrieves a list from mmbase.
 Document load(Node schema, String objectNumber)
          This method loads an object and the necessary relations and fields, according to the given schema.
(package private)  Collection<Node> loadRelations(Node object, String objectNumber, Node loadAction)
          This method loads relations from MMBase and stores the result in the given object node.
 Element put(Document originalData, Document loadedData, Document newData, Map<String,byte[]> binaries)
          This method can fire a Put command to Dove.
 void setUserInfo(Cloud cloud)
          Sets the right cloud for the user info.
 void tagDataNodesWithoutDataID(Document data)
          This method tags the datanodes in the given document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

didcounter

int didcounter
Constructor Detail

WizardDatabaseConnector

public WizardDatabaseConnector()
Constructor: Creates the connector. Call #init also.

Method Detail

setUserInfo

public void setUserInfo(Cloud cloud)
Sets the right cloud for the user info.

Parameters:
cloud - The cloud from which the userinfo should be set.

tagDataNodesWithoutDataID

public void tagDataNodesWithoutDataID(Document data)
This method tags the datanodes in the given document. The wizards use the tagged datanodes so that each datanode can be identified.

Parameters:
data - The data document which should be tagged.

loadRelations

Collection<Node> loadRelations(Node object,
                               String objectNumber,
                               Node loadAction)
                         throws WizardException
This method loads relations from MMBase and stores the result in the given object node.

Parameters:
object - The objectNode where the results should be appended to.
objectNumber - The objectnumber of the parentobject from where the relations should originate.
loadAction - The node with loadaction data. Has inforation about what relations should be loaded and what fields should be retrieved.
Returns:
The new relations (in the data object), or null if none.
Throws:
WizardException - if loading the relations fails

load

public Document load(Node schema,
                     String objectNumber)
              throws WizardException
This method loads an object and the necessary relations and fields, according to the given schema.

Parameters:
schema - The schema carrying all the information needed for loading the proper object and related fields and objects.
objectNumber - The objectnumber of the object to start with.
Returns:
The resulting data document.
Throws:
WizardException - if loading the schema fails
Since:
MMBase-1.7

getConstraints

public Node getConstraints(String objecttype)
                    throws WizardException
This method gets constraint information from mmbase about a specific objecttype.

Parameters:
objecttype - the objecttype where you want constraint information from.
Returns:
the constraintsnode as received from mmbase (Dove)
Throws:
WizardException - if the constraints could not be obtained

getList

public Node getList(Node query)
             throws WizardException
This method retrieves a list from mmbase. It uses a query which is sent to mmbase.

Parameters:
query - the node containign the query to run
Returns:
a node containing as its childnodes the list of nodes queried
Throws:
WizardException - if the constraints could not be obtained

getDataNode

public Node getDataNode(Document document,
                        String objectnumber,
                        NodeList restrictions)
                 throws WizardException
This method retrieves data (objectdata) from mmbase.

Parameters:
document - Results are imported in this document
objectnumber - The number of the object to load.
restrictions - These restrictions will restrict the load action. So that not too large or too many fields are retrieved.
Returns:
The resulting node with the objectdata.
Throws:
WizardException - if the object could not be retrieved

createObject

public Node createObject(Document data,
                         Node targetParentNode,
                         Node objectDef,
                         Map<String,Object> params,
                         Document loadedData)
                  throws WizardException
This method can create a object (or a tree of objects and relations)

Parameters:
data - data of current wizard
targetParentNode - The place where the results should be appended.
objectDef - The objectdefinition.
params - The params to use when creating the objects and relations.
loadedData -
Returns:
The resulting object(tree) node.
Throws:
WizardException - if the object cannot be created

createObject

public Node createObject(Document data,
                         Node targetParentNode,
                         Node objectDef,
                         Map<String,Object> params,
                         int createorder,
                         Document loadedData)
                  throws WizardException
This method can create a object (or a tree of objects and relations) this method should be called from the wizard if it needs to create a new combination of fields, objects and relations. See further documentation or the samples for the definition of the action in global: the Action node looks like this: (Note: this function expects the $lt;object/> node, not the action node.
 $lt;action type="create"$gt;
   $lt;object type="authors"$gt;
     $lt;field name="name"$gt;Enter name here$lt;/field$gt;
     $lt;relation role="related" [destination="234" *]$gt;
       $lt;object type="locations"$gt;
         $lt;field name="street"$gt;Enter street$lt;/field$gt;
       $lt;/object$gt;
     $lt;/relation$gt;
   $lt;/object$gt;
 $lt;/action$gt;
 
*) if dnumber is supplied, no new object is created (shouldn't be included in the relation node either), but the relation will be created and directly linked to an object with number "dnumber".

Parameters:
data - data of current wizard
targetParentNode - The place where the results should be appended.
objectDef - The objectdefinition.
params - The params to use when creating the objects and relations.
createorder - ordernr under which this object is added (i.e. when added to a list) The first ordernr in a list is 1
loadedData -
Returns:
The resulting object(tree) node.
Throws:
WizardException - if the object cannot be created

put

public Element put(Document originalData,
                   Document loadedData,
                   Document newData,
                   Map<String,byte[]> binaries)
            throws WizardException
This method can fire a Put command to Dove. It uses #getPutData to construct the transaction.

Parameters:
originalData - The original data object tree.
newData - The new and manipulated data. According to differences between the original and the new data, the transaction is constructed.
loadedData - The data loaded by actions on the wizard
binaries - A hashmap with the uploaded binaries.
Returns:
The element containing the results of the put transaction.
Throws:
WizardException - if the data could not be stored

convertIntToDateTime

protected void convertIntToDateTime(Node rootNode)
The editwizard uses integer values to represent dates. This method convert the integer values of date fields (seconds per 1/1/1970) to the MMBase string representation of a date value before sending the data to MMBase.

Parameters:
rootNode - the node whose field sub nodes should be converted
Since:
MMBase 1.8

convertIntToBoolean

protected void convertIntToBoolean(Node rootNode)
Booleans in MMBase are represented by a boolean value. The editwizard uses integer values to represent true/false. This method convert the integer values of boolean fields to as boolean string value (true or false) before sending the data to MMBase.

Parameters:
rootNode - the node whose field sub nodes should be converted
Since:
MMBase 1.8

convertDateTimeToInt

protected void convertDateTimeToInt(Node rootNode)
The editwizard uses integer values to represent dates. This method converts the MMBase string representation of a date field's value to this integer value (seconds per 1/1/1970) after reading the data from MMBase.

Parameters:
rootNode - the node whose field sub nodes should be converted
Since:
MMBase 1.8

convertBooleanToInt

protected static void convertBooleanToInt(Node rootNode)
Booleans in MMBase are represented by a boolean value. The editwizard uses integer values to represent true/false. This method convert the boolean values of boolean fields to an integer value (0 or 1) after reading the data from MMBase.

Parameters:
rootNode - the node whose field sub nodes should be converted
Since:
MMBase 1.8


MMBase 2.0-SNAPSHOT - null