org.mmbase.module.corebuilders
Class RelDef

java.lang.Object
  |
  +--org.mmbase.module.core.MMTable
        |
        +--org.mmbase.module.core.MMObjectBuilder
              |
              +--org.mmbase.module.corebuilders.RelDef

public class RelDef
extends MMObjectBuilder

RelDef ,one of the meta stucture nodes, is used to define the possible relation types.

A Relation Definition consists of a source and destination, and a descriptor (direction) for it's use (unidirectional or bidirectional).

Relations are mapped to a builder.
This is so that additonal functionality can be added by means of a builder (i.e. AuthRel)
The old system mapped the relations to a builder by name. Unfortunately, this means that some care need be taken when naming relations, as unintentionally naming a relation to a builder can give bad (if not disastrous) results.
Relations that are not directly mapped to a builder are mapped (internally) to the InsRel builder instead.

The new system uses an additional field to map to a builder. This 'builder' field contains a reference (otype) to teh builder to be used. If null or 0, the builder is assumed to refer to the InsRel builder. sname is now the name of the relation and serves no function.

This patched version of RelDef can make use of either direct builder references (through the builder field), or the old system of using names. The system used is determined by examining whether the builder field has been defined in the builder's configuration (xml) file. See the documentation of the relations project at http://www.mmbase.org for more info.

Version:
3 jan 2001
Author:
Daniel Ockeloen, Pierre van Rooden

Field Summary
static boolean usesbuilder
          Indicates whether the relationdefinitions use the 'builder' field (that is, whether the field has been defined in the xml file).
 
Fields inherited from class org.mmbase.module.core.MMObjectBuilder
broadcastChanges, className, database, debug, description, descriptions, fields, NODE_MAX_SIZE, nodeCache, obj2type, OBJ2TYPE_MAX_SIZE, oType, replaceCache, searchAge, sortedDBLayout, TEMPNODE_DEFAULT_SIZE, TemporaryNodes, virtual
 
Fields inherited from class org.mmbase.module.core.MMTable
mmb, tableName
 
Constructor Summary
RelDef()
          Contruct the builder
 
Method Summary
 boolean commit(MMObjectNode node)
          Commit changes to this node and updated the cache.
 InsRel getBuilder(int rnumber)
          Returns the builder of a relation definition.
 InsRel getBuilder(MMObjectNode node)
          Returns the builder of a relation definition.
 java.lang.String getBuilderName(MMObjectNode node)
          Returns the builder name of a relation definition.
 MMObjectNode getDefaultForBuilder(InsRel relBuilder)
          Returns the first occurrence of a reldef node of a relation definition.
 int getGuessedByName(java.lang.String name)
          Deprecated. use getNumberByName(java.lang.String) instead
 int getGuessedNumber(java.lang.String name)
          Deprecated. renamed to getNumberByName(java.lang.String) which better explains its use
 java.lang.String getGUIIndicator(MMObjectNode node)
          Returns a GUI description of a relation definition.
 java.lang.String getGUIIndicator(java.lang.String field, MMObjectNode node)
          Retrieve descriptors for a relation definition's fields, specifically a descriptive text for the relation's direction (dir)
 int getNumberByName(java.lang.String role)
          Search the relation definition table for the identifying number of a relationdefinition, by name of the role to use.
 java.util.Enumeration getRelationBuilders()
          Returns a list of builders currently implementing a relation node.
 int getRelNrByName(java.lang.String sname, java.lang.String dname)
          Deprecated. use getNumberByName(java.lang.String) instead
 boolean init()
          Initializes the builder by reading the cache.
 int insert(java.lang.String owner, MMObjectNode node)
          Insert a new object, and updated the cache after an insert.
 boolean isRelationBuilder(int number)
          Checks to see if a given builder (otype) is known to be a relation builder.
 boolean isRelationTable(java.lang.String name)
          Checks to see if a given relation definition is stored in the cache.
 void removeNode(MMObjectNode node)
          Remove a node from the cloud.
 void setDefaults(MMObjectNode node)
          Sets defaults for a new relation definition.
 void testValidData(MMObjectNode node)
          Tests whether the data in a node is valid (throws an exception if this is not the case).
 
Methods inherited from class org.mmbase.module.core.MMObjectBuilder
addField, addLocalObserver, addRemoteObserver, buildSet, checkAddTmpField, convertMMNode2SQL, count, create, createAlias, created, debug, deleteNodeCache, executeFunction, fieldLocalChanged, getAge, getAliasedNode, getCacheNumbers, getCacheSize, getCacheSize, getClassName, getDBByte, getDBKey, getDBState, getDBText, getDBType, getDefaultTeaser, getDefaultUrl, getDescription, getDescriptions, getDutchSName, getEditFields, getField, getFieldNames, getFields, getFullTableName, getFunctionParameters, getHardNode, getHardNode, getHTML, getInitParameter, getInitParameters, getList, getMachineName, getMaintainer, getNewNode, getNewTmpNode, getNextField, getNode, getNode, getNode, getNode, getNodeType, getNumberFromName, getPluralName, getPluralName, getPluralNames, getRelations_main, getSearchAge, getShort, getShortedByte, getShortedText, getSingularName, getSingularName, getSingularNames, getSmartPath, getSortedFields, getSortedListFields, getTableName, getTmpNode, getURLEncode, getValue, getVersion, getWAP, getXMLPath, getXMLSetup, hostname_function, init_obj2type, insert, insertDone, isNodeCached, isVirtual, isXMLConfig, nodeLocalChanged, nodeRemoteChanged, preCommit, preEdit, process, putTmpNode, readSearchResults, removeField, removeRelations, removeTmpNode, replace, safeCache, safeCommit, safeInsert, search, search, search, searchIn, searchIn, searchIn, searchNumbers, searchVector, searchVector, searchVector, searchVector, searchVectorIn, searchVectorIn, searchVectorIn, searchVectorIn, searchWithWhere, sendFieldChangeSignal, setClassName, setDBLayout_xml, setDBLayout, setDebug, setDescription, setDescriptions, setDutchSName, setInitParameter, setMaintainer, setMMBase, setPluralNames, setSearchAge, setSingularNames, setTableName, setValue, setValue, setVersion, setXmlConfig, setXMLPath, setXMLValues, signalNewObject, toXML, waitUntilNodeChanged, wrap
 
Methods inherited from class org.mmbase.module.core.MMTable
size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

usesbuilder

public static boolean usesbuilder
Indicates whether the relationdefinitions use the 'builder' field (that is, whether the field has been defined in the xml file). Used for backward compatibility.
Constructor Detail

RelDef

public RelDef()
Contruct the builder
Method Detail

init

public boolean init()
Initializes the builder by reading the cache. Also determines whether the 'builder' field is used.
Overrides:
init in class MMObjectBuilder
Returns:
A boolean value, always success (true), as any exceptions are caught and logged.

getGUIIndicator

public java.lang.String getGUIIndicator(MMObjectNode node)
Returns a GUI description of a relation definition. The description is dependent on the direction (uni/bi) of the relation
Overrides:
getGUIIndicator in class MMObjectBuilder
Parameters:
node - Relation definition to describe
Returns:
A String of descriptive text

getBuilderName

public java.lang.String getBuilderName(MMObjectNode node)
Returns the builder name of a relation definition. If the buildername cannot be accurately determined, the sname field will be returned instead.
Returns:
the builder name

getBuilder

public InsRel getBuilder(int rnumber)
Returns the builder of a relation definition.
Returns:
the builder

getBuilder

public InsRel getBuilder(MMObjectNode node)
Returns the builder of a relation definition.
Returns:
the builder

getDefaultForBuilder

public MMObjectNode getDefaultForBuilder(InsRel relBuilder)
Returns the first occurrence of a reldef node of a relation definition. used to set the default reldef for a specific builder.

testValidData

public void testValidData(MMObjectNode node)
                   throws InvalidDataException
Tests whether the data in a node is valid (throws an exception if this is not the case).
Overrides:
testValidData in class MMObjectBuilder
Parameters:
node - The node whose data to check

insert

public int insert(java.lang.String owner,
                  MMObjectNode node)
Insert a new object, and updated the cache after an insert. This method indirectly calls MMObjectBuilder.preCommit(org.mmbase.module.core.MMObjectNode).
Overrides:
insert in class MMObjectBuilder
Parameters:
owner - The administrator creating the node
node - The object to insert. The object need be of the same type as the current builder.
Returns:
An int value which is the new object's unique number, -1 if the insert failed.

commit

public boolean commit(MMObjectNode node)
Commit changes to this node and updated the cache. This method indirectly calls MMObjectBuilder.preCommit(org.mmbase.module.core.MMObjectNode). This method does not remove names from the cache, as currently, unique names are not enforced.
Overrides:
commit in class MMObjectBuilder
Parameters:
node - The node to be committed
Returns:
a boolean indicating success

removeNode

public void removeNode(MMObjectNode node)
Remove a node from the cloud.
Overrides:
removeNode in class MMObjectBuilder
Parameters:
node - The node to remove.

setDefaults

public void setDefaults(MMObjectNode node)
Sets defaults for a new relation definition. Initializes a relation to be bidirectional, and, if applicable, to use the 'insrel' builder.
Overrides:
setDefaults in class MMObjectBuilder
Parameters:
node - Node to be initialized

getGUIIndicator

public java.lang.String getGUIIndicator(java.lang.String field,
                                        MMObjectNode node)
Retrieve descriptors for a relation definition's fields, specifically a descriptive text for the relation's direction (dir)
Overrides:
getGUIIndicator in class MMObjectBuilder
Parameters:
field - Name of the field whose description should be returned. valid values : 'dir'
node - Relation definition containing the field's information
Returns:
A descriptive text for the field's contents, or null if no description could be generated

isRelationTable

public boolean isRelationTable(java.lang.String name)
Checks to see if a given relation definition is stored in the cache.
Parameters:
name - A String of the relation definitions' name

isRelationBuilder

public boolean isRelationBuilder(int number)
Checks to see if a given builder (otype) is known to be a relation builder.
Parameters:
number - The otype of the builder

getRelationBuilders

public java.util.Enumeration getRelationBuilders()
Returns a list of builders currently implementing a relation node.

getGuessedNumber

public int getGuessedNumber(java.lang.String name)
Deprecated. renamed to getNumberByName(java.lang.String) which better explains its use

Search the relation definition table for the identifying number of a relation, by name of the relation to use Similar to getGuessedByName(java.lang.String) (but does not make use of dname) Not very suitable to use, as success is dependent on the uniqueness of the builder in the table (not enforced, so unpredictable).

getNumberByName

public int getNumberByName(java.lang.String role)
Search the relation definition table for the identifying number of a relationdefinition, by name of the role to use. The name should be either the primary identifying role name (sname), or a combination of sname and dname separated by a slash ("/").

getGuessedByName

public int getGuessedByName(java.lang.String name)
Deprecated. use getNumberByName(java.lang.String) instead

Search the relation definition table for the identifying number of a relation, by name of the relation to use This function is used by descendants of Insrel to determine a default reference to a 'relation definition' (reldef entry). The 'default' is the relation with the same name as the builder. If no such relation exists, there is no default.

getRelNrByName

public int getRelNrByName(java.lang.String sname,
                          java.lang.String dname)
Deprecated. use getNumberByName(java.lang.String) instead

Searches for the relation number on the combination of sname and dname. When there's no match found in this order a search with a swapped sname and dname will be done. Note that there is no real assurance that an sname/dname combination must be unique.


MMBase 2002