org.mmbase.util.xml.applicationdata
Class ContextDepthDataWriter

java.lang.Object
  extended by org.mmbase.util.xml.applicationdata.ContextDepthDataWriter

public class ContextDepthDataWriter
extends Object

This class is used to write (export) a selection of nodes to xml format. The nodes to export are read from a XML context file, which specifies the startnode and depth to which to parse. The current version of this class combines a number of methods which we want to split - or at least share - with a seperate class for handling contexts. Note that because of it's static nature, no object instance need be made (in fact, none CAN be made) of this class.

Since:
MMBase-1.8
Version:
$Id: ContextDepthDataWriter.java 34900 2009-05-01 16:29:42Z michiel $
Author:
Daniel Ockeloen, Jacco de Groot, Pierre van Rooden

Constructor Summary
ContextDepthDataWriter()
           
 
Method Summary
(package private) static HashSet<Integer> getFilterBuilders(List<Map<String,String>> filter, TypeDef bul)
          Retrieves the builders used for filtering the nodes for this application
(package private) static int getRelatedNode(int nodeNumber, MMObjectNode relationNode)
          Determines the number of the node referenced by another node.
(package private) static int getStartNode(ContextDepthDataReader capp, MMBase mmb)
          Retrieves the number of the startnode referenced by the context configuration file..
(package private) static void getSubNodes(int startnodenr, int maxdepth, HashSet<Integer> fb, HashSet<Integer> nodesdoneSet, HashSet<Integer> relationnodesSet, MMBase mmb)
          Searches the MMBase cloud, colelcting all nodes (and corresponmding relation nodes) that belong to a specific type, and which can be traced up to a certain depth of nodes to a starting node.
(package private) static boolean saveFile(String filename, byte[] value)
          Saves an array of byte to a file.
(package private) static boolean saveFile(String filename, String value)
          Saves a string value to a file.
static boolean writeContext(ApplicationReader app, ContextDepthDataReader capp, String targetpath, MMBase mmb, Logger logger)
          Writes an application's nodes, according to that application's contexts, to a path.
static boolean writeContextXML(ContextDepthDataReader capp, String filename)
          Writes the context file, based on what was supplied by the application
(package private) static void writeDataSources(ApplicationReader app, HashSet<Integer> nodes, String targetpath, MMBase mmb, Logger logger)
          Writes the required datasources to their corresponding xml files by calling writeNodes()
(package private) static void writeNodes(ApplicationReader app, HashSet<Integer> nodes, String targetpath, MMBase mmb, Logger logger, boolean isRelation)
          Writes the nodes to their corresponding xml files
(package private) static void writeRelationSources(ApplicationReader app, HashSet<Integer> nodes, String targetpath, MMBase mmb, Logger logger)
          Writes the required relation sources to their corresponding xml files by calling writeNodes()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextDepthDataWriter

public ContextDepthDataWriter()
Method Detail

writeContext

public static boolean writeContext(ApplicationReader app,
                                   ContextDepthDataReader capp,
                                   String targetpath,
                                   MMBase mmb,
                                   Logger logger)
Writes an application's nodes, according to that application's contexts, to a path. The files written are stored in a subdirectory (named after the application), and contain the datasource (xml) files for both datanodes and relation nodes.

Parameters:
app - A ApplicationReader initialised to read the application's description (xml) file This object is used to retrieve what builder and relations are needed, and in which files data should be stored.
capp - A ContextDepthDataReader initialised to read the application's context file This object is used to retrieve information regarding search depth and starting nodes for the search tree whoch determines what nodes are part of this application.
targetpath - The path where to save the application
mmb - Reference to the MMbase processormodule. Used to retrieve the nodes to write.
logger - Storage for messages which can be displayed to the user.
Returns:
Returns true if succesful, false if no valid depth or startnode could be found Failure of the export itself is not detected, though may be visible in the messages returned.
Throws:
IOException - if one or more files could not be written

writeDataSources

static void writeDataSources(ApplicationReader app,
                             HashSet<Integer> nodes,
                             String targetpath,
                             MMBase mmb,
                             Logger logger)
Writes the required datasources to their corresponding xml files by calling writeNodes()

Parameters:
app - The ApplicationReader object, which is used to retrieve what datasources to write (and to what file).
nodes - The nodes that are part of the application. Those that are of a type compatible with the datasources are exported.
targetpath - Path where the xml files are written
mmb - MMBase object used to retrieve builder information
logger - Used to store messages that can be showmn to the user

writeRelationSources

static void writeRelationSources(ApplicationReader app,
                                 HashSet<Integer> nodes,
                                 String targetpath,
                                 MMBase mmb,
                                 Logger logger)
Writes the required relation sources to their corresponding xml files by calling writeNodes()

Parameters:
app - The ApplicationReader object, which is used to retrieve what relationsources to write (and to what file).
nodes - The relation nodes that are part of the application. Those that are of a type compatible with the relationsources are exported.
targetpath - Path where the xml files are written
mmb - MMBase object used to retrieve builder information
logger - Used to store messages that can be showmn to the user

writeNodes

static void writeNodes(ApplicationReader app,
                       HashSet<Integer> nodes,
                       String targetpath,
                       MMBase mmb,
                       Logger logger,
                       boolean isRelation)
Writes the nodes to their corresponding xml files

Parameters:
app - The ApplicationReader object, which is used to retrieve what sources to write (and to what file).
nodes - The nodes that are part of the application. Those that are of a type compatible with the sources are exported.
targetpath - Path where the xml files are written
mmb - MMBase object used to retrieve builder information
logger - Used to store messages that can be showmn to the user
isRelation - Indicates whether the nodes to write are data (false) or relation (true) nodes

getRelatedNode

static int getRelatedNode(int nodeNumber,
                          MMObjectNode relationNode)
Determines the number of the node referenced by another node.

Parameters:
nodeNumber - number of the referencing node
relationNode - node from the relationtable containing the relation data

getSubNodes

static void getSubNodes(int startnodenr,
                        int maxdepth,
                        HashSet<Integer> fb,
                        HashSet<Integer> nodesdoneSet,
                        HashSet<Integer> relationnodesSet,
                        MMBase mmb)
Searches the MMBase cloud, colelcting all nodes (and corresponmding relation nodes) that belong to a specific type, and which can be traced up to a certain depth of nodes to a starting node.

Parameters:
startnodenr - the number of the node to start with
maxdeoth - the maximum depth a tree is traversed. A depth of 0 or less means only the sdtartnode is added. A depth of one includes all teh nodes refernced by the startnode, etc. Relation nodes are not counted when determining 'depth'.
fb - a HashSet containing the set of types that are allowed for export
nodesdoneSet - A HashSet which holds all nodes that are already 'done' or 'almost done'. this set is expanded in the method nodes already in this set are skipped (optimization). After return, the set has been expanded with all nodes found while traversing the cloud
mmb - MMBase object used to retrieve builder information

getFilterBuilders

static HashSet<Integer> getFilterBuilders(List<Map<String,String>> filter,
                                          TypeDef bul)
Retrieves the builders used for filtering the nodes for this application

Parameters:
filter - Vector containign all the buildernames that are part of this application Note that being part of an application does not mean that they are exported!
bul - reference to the TypeDef builder, used for rertrieving builder types
Returns:
a HashSet, containing the types (Integer) of all builders part of this application.

getStartNode

static int getStartNode(ContextDepthDataReader capp,
                        MMBase mmb)
Retrieves the number of the startnode referenced by the context configuration file.. Returns always only one node (should be changed?)

Parameters:
capp - ContextDepthDataReader object for retrieving data from the context
mmb - reference to the MMBase object, used for retrieving aliases and builders
Returns:
An integer, the number of the startnode if succesful, -1 otherwise.

saveFile

static boolean saveFile(String filename,
                        String value)
Saves a string value to a file.

Parameters:
filename - Name of the file to save.
value - string to store in the file
Returns:
True if succesfull, false if an error occurred.

saveFile

static boolean saveFile(String filename,
                        byte[] value)
Saves an array of byte to a file.

Parameters:
filename - Name of the file to save.
value - array to stiore in the file
Returns:
True if succesfull, false if an error occurred.

writeContextXML

public static boolean writeContextXML(ContextDepthDataReader capp,
                                      String filename)
Writes the context file, based on what was supplied by the application

Parameters:
capp - ContextDepthDataReader providing original context data
filename - Name of the xml file to save.
Returns:
always true


MMBase 2.0-SNAPSHOT - null