org.mmbase.applications.editwizard
Class WizardDatabaseConnector

java.lang.Object
  extended byorg.mmbase.applications.editwizard.WizardDatabaseConnector

public class WizardDatabaseConnector
extends java.lang.Object

This class handles all communition 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,v 1.40.2.1 2004/04/15 11:28:42 michiel Exp $
Author:
Kars Veling, Michiel Meeuwissen, Pierre van Rooden
Warning: No Java Documentation Available.

Constructor Summary
WizardDatabaseConnector()
          Constructor: Creates the connector.
 
Method Summary
 void cloneOneDeep(org.w3c.dom.Node sourcenode, org.w3c.dom.Node targetParentNode, java.lang.String allowedChildrenXpath)
          This method can clone an object node one deep.
 org.w3c.dom.Node createObject(org.w3c.dom.Document data, org.w3c.dom.Node targetParentNode, org.w3c.dom.Node objectDef, java.util.Map params)
          This method can create a object (or a tree of objects and relations)
 org.w3c.dom.Node createObject(org.w3c.dom.Document data, org.w3c.dom.Node targetParentNode, org.w3c.dom.Node objectDef, java.util.Map params, int createorder)
          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.
 org.w3c.dom.Node getConstraints(java.lang.String objecttype)
          This method gets constraint information from mmbase about a specific objecttype.
 org.w3c.dom.Node getData(org.w3c.dom.Node targetNode, java.lang.String objectnumber)
          This method retrieves data (objectdata) from mmbase.
 org.w3c.dom.Node getData(org.w3c.dom.Node targetNode, java.lang.String objectnumber, org.w3c.dom.NodeList restrictions)
          This method retrieves data (objectdata) from mmbase.
 org.w3c.dom.Node getDataNode(org.w3c.dom.Document document, java.lang.String objectnumber, org.w3c.dom.NodeList restrictions)
          This method retrieves data (objectdata) from mmbase.
 org.w3c.dom.Node getList(org.w3c.dom.Node query)
          This method retrieves a list from mmbase.
 org.w3c.dom.Node getNew(org.w3c.dom.Node targetNode, java.lang.String objecttype)
          This method gets a new temporarily object of the given type.
 org.w3c.dom.Node getNewRelation(org.w3c.dom.Node targetNode, java.lang.String role, java.lang.String sourceObjectNumber, java.lang.String sourceType, java.lang.String destinationObjectNumber, java.lang.String destinationType, java.lang.String createDir)
          This method creates a new temporarily relation.
 org.w3c.dom.Node getPutData(org.w3c.dom.Document originalData, org.w3c.dom.Document newData)
          This method constructs a update transaction ready for mmbase.
 void getRelations(org.w3c.dom.Node targetNode, java.lang.String objectnumber)
          This method gets relation information from mmbase.
 java.util.Collection getRelations(org.w3c.dom.Node targetNode, java.lang.String objectNumber, org.w3c.dom.NodeList queryRelations)
          This method gets relation information from mmbase.
 boolean isDifferent(org.w3c.dom.Node node1, org.w3c.dom.Node node2)
          This method compares two xml nodes and checks them for identity.
 org.w3c.dom.Document load(org.w3c.dom.Node schema, java.lang.String objectNumber)
          This method loads an object and the necessary relations and fields, according to the given schema.
 void makeFlat(org.w3c.dom.Node sourcenode, org.w3c.dom.Node targetParentNode, java.lang.String xpath, java.lang.String allowedChildrenXpath)
          This method makes the object data tree flat, so that Dove can construct a transaction from it.
 org.w3c.dom.Element put(org.w3c.dom.Document originalData, org.w3c.dom.Document newData, java.util.Map binaries)
          This method can fire a Put command to Dove.
 void setUserInfo(Cloud cloud)
          Sets the right cloud for the user info.
 void tagDataNode(org.w3c.dom.Node node)
          This method tags datanodes starting from the current node.
 void tagDataNodes(org.w3c.dom.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
 

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.

tagDataNodes

public void tagDataNodes(org.w3c.dom.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.

tagDataNode

public void tagDataNode(org.w3c.dom.Node node)
This method tags datanodes starting from the current node. A internal counter is used to make sure identifiers are still unique.


load

public org.w3c.dom.Document load(org.w3c.dom.Node schema,
                                 java.lang.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.
Returns:
The resulting data document.
Throws:
WizardException - if loading the schema fails
Since:
MMBase-1.7

getConstraints

public org.w3c.dom.Node getConstraints(java.lang.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 org.w3c.dom.Node getList(org.w3c.dom.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

getData

public org.w3c.dom.Node getData(org.w3c.dom.Node targetNode,
                                java.lang.String objectnumber)
                         throws WizardException
This method retrieves data (objectdata) from mmbase.

Parameters:
targetNode - Results are appended to this targetNode.
objectnumber - The number of the object to load.
Returns:
The resulting node with the objectdata.
Throws:
WizardException - if loading the object fails

getData

public org.w3c.dom.Node getData(org.w3c.dom.Node targetNode,
                                java.lang.String objectnumber,
                                org.w3c.dom.NodeList restrictions)
                         throws WizardException
This method retrieves data (objectdata) from mmbase.

Parameters:
targetNode - Results are appended to this targetNode.
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

getDataNode

public org.w3c.dom.Node getDataNode(org.w3c.dom.Document document,
                                    java.lang.String objectnumber,
                                    org.w3c.dom.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

getRelations

public void getRelations(org.w3c.dom.Node targetNode,
                         java.lang.String objectnumber)
                  throws WizardException
This method gets relation information from mmbase.

Parameters:
targetNode - The targetnode where the results should be appended.
objectnumber - The objectnumber of the parent object from where the relations originate.
Throws:
WizardException - if the relations could not be obtained

getRelations

public java.util.Collection getRelations(org.w3c.dom.Node targetNode,
                                         java.lang.String objectNumber,
                                         org.w3c.dom.NodeList queryRelations)
                                  throws WizardException
This method gets relation information from mmbase.

Parameters:
targetNode - The targetnode where the results should be appended.
objectNumber - The objectnumber of the parent object from where the relations originate.
queryRelations - A list of 'relation' DOM-nodes, defining the relations which must be fetched.
Throws:
WizardException - if the relations could not be obtained

getNew

public org.w3c.dom.Node getNew(org.w3c.dom.Node targetNode,
                               java.lang.String objecttype)
                        throws WizardException
This method gets a new temporarily object of the given type.

Parameters:
targetNode - The place where the results should be appended.
objecttype - The objecttype which should be created.
Returns:
The resulting object node.
Throws:
WizardException - if the node could not be created

getNewRelation

public org.w3c.dom.Node getNewRelation(org.w3c.dom.Node targetNode,
                                       java.lang.String role,
                                       java.lang.String sourceObjectNumber,
                                       java.lang.String sourceType,
                                       java.lang.String destinationObjectNumber,
                                       java.lang.String destinationType,
                                       java.lang.String createDir)
                                throws WizardException
This method creates a new temporarily relation.

Parameters:
targetNode - The place where the results should be appended.
role - The name of the role the new relation should have.
sourceObjectNumber - the number of the sourceobject
sourceType - the type of the sourceobject
destinationObjectNumber - the number of the destination object
destinationType - the type of the destination object
Returns:
The resulting relation node.
Throws:
WizardException - if the relation could not be created

createObject

public org.w3c.dom.Node createObject(org.w3c.dom.Document data,
                                     org.w3c.dom.Node targetParentNode,
                                     org.w3c.dom.Node objectDef,
                                     java.util.Map params)
                              throws WizardException
This method can create a object (or a tree of objects and relations)

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

createObject

public org.w3c.dom.Node createObject(org.w3c.dom.Document data,
                                     org.w3c.dom.Node targetParentNode,
                                     org.w3c.dom.Node objectDef,
                                     java.util.Map params,
                                     int createorder)
                              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:
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
Returns:
The resulting object(tree) node.
Throws:
WizardException - if the object cannot be created

put

public org.w3c.dom.Element put(org.w3c.dom.Document originalData,
                               org.w3c.dom.Document newData,
                               java.util.Map 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.
binaries - A hashmap with the uploaded binaries.
Returns:
The element containing the results of the put transaction.
Throws:
WizardException

getPutData

public org.w3c.dom.Node getPutData(org.w3c.dom.Document originalData,
                                   org.w3c.dom.Document newData)
                            throws WizardException
This method constructs a update transaction ready for mmbase. The differences between the original and the new data define the transaction.

Parameters:
originalData - The original data.
newData - The new data.
Throws:
WizardException

makeFlat

public void makeFlat(org.w3c.dom.Node sourcenode,
                     org.w3c.dom.Node targetParentNode,
                     java.lang.String xpath,
                     java.lang.String allowedChildrenXpath)
This method makes the object data tree flat, so that Dove can construct a transaction from it.

Parameters:
sourcenode - The sourcenode from which should be flattened.
targetParentNode - The targetParentNode where the results should be appended.

cloneOneDeep

public void cloneOneDeep(org.w3c.dom.Node sourcenode,
                         org.w3c.dom.Node targetParentNode,
                         java.lang.String allowedChildrenXpath)
This method can clone an object node one deep. So, only the first level children will be copied.

Parameters:
sourcenode - The sourcenode from where the flattening should start.
targetParentNode - The parent on which the results should be appended.
allowedChildrenXpath - The xpath describing what children may be copied.

isDifferent

public boolean isDifferent(org.w3c.dom.Node node1,
                           org.w3c.dom.Node node2)
This method compares two xml nodes and checks them for identity.

Parameters:
node1 - The first node to check
node2 - Compare with thisone.
Returns:
True if they are different, False if they are similar.


MMBase build 1.7.1.20041002