org.mmbase.module.corebuilders
Class TypeRel

java.lang.Object
  extended by org.mmbase.util.functions.FunctionProvider
      extended by org.mmbase.module.core.MMTable
          extended by org.mmbase.module.core.MMObjectBuilder
              extended by org.mmbase.module.corebuilders.TypeRel
All Implemented Interfaces:
EventListener, NodeEventListener, RelationEventListener, SystemEventListener
Direct Known Subclasses:
TypeRel.VirtualTypeRel

public class TypeRel
extends MMObjectBuilder
implements SystemEventListener

TypeRel defines the allowed relations between two object types. Every relations also specifies a 'role', which is a reference to the RelDef table. Relations do principally have a 'source' and a 'destination' object type, but most functions of this class do ignore this distinction. TypeRel is a 'core' MMBase builder. You can get a reference to it via the MMBase instance.

Version:
$Id: TypeRel.java 41988 2010-04-20 16:22:11Z michiel $
Author:
Daniel Ockeloen, Pierre van Rooden, Michiel Meeuwissen
See Also:
RelDef, InsRel, MMBase

Nested Class Summary
protected  class TypeRel.InverseTypeRelSet
          An InverseTypeRelSet is a Set of typerel nodes.
protected  class TypeRel.TypeRelSet
          A TypeRelSet is a Set of typerel nodes.
(package private) static class TypeRel.VirtualTypeRel
          Of course, virtual typerel nodes need a virtual typerel builder.
protected  class TypeRel.VirtualTypeRelNode
          A VirtualTypeRelNode is a MMObjectNode which is added to the typerelset with extensions of the actual builders specified.
 
Field Summary
static int INCLUDE_DESCENDANTS
          Constant for contains(int, int, int): return typerels where source/destination match with a builder or its descendants
static int INCLUDE_PARENTS
          Constant for contains(int, int, int): return typerels where source/destination match with a builder or its parents
static int INCLUDE_PARENTS_AND_DESCENDANTS
          Constant for contains(int, int, int): return typerels where source/destination match with a builder, its descendants, or its parents
 TypeRel.InverseTypeRelSet inverseTypeRelNodes
           
protected  TypeRel.TypeRelSet parentTypeRelNodes
           
static int STRICT
          Constant for contains(int, int, int): return only typerels that exactly match.
protected  TypeRel.TypeRelSet typeRelNodes
          TypeRel should contain only a limited amount of nodes, so we can simply cache them all, and avoid all further querying.
 
Fields inherited from class org.mmbase.module.core.MMObjectBuilder
AGE_PARAMETERS, broadCastChanges, DEFAULT_ALINEA, DEFAULT_EOL, description, descriptions, EVENT_TYPE_LOCAL, EVENT_TYPE_REMOTE, FIELD_NUMBER, FIELD_OBJECT_TYPE, FIELD_OWNER, fields, genericBlobCache, getFunctions, GUI_INDICATOR, GUI_PARAMETERS, guiFunction, infoFunction, internalVersion, nodeCache, oType, pluralNames, searchAge, singularNames, SYSTEM_OWNER, TEMPNODE_DEFAULT_SIZE, TMP_FIELD_EXISTS, TMP_FIELD_NUMBER, virtual, WRAP_PARAMETERS, wrapFunction
 
Fields inherited from class org.mmbase.module.core.MMTable
maxNodesFromQuery, mmb, storageConnector, tableName
 
Fields inherited from class org.mmbase.util.functions.FunctionProvider
functions
 
Constructor Summary
TypeRel()
           
 
Method Summary
protected  TypeRel.TypeRelSet addCacheEntry(MMObjectNode typeRel, boolean buildersInitialized)
          Addes one typerel cache entries, plus inherited relations (if builder are initialized)
 boolean contains(int n1, int n2, int r)
          Tests if a specific relation type is defined.
 boolean contains(int n1, int n2, int r, int restriction)
          Tests if a specific relation type is defined.
 boolean equals(MMObjectNode o1, MMObjectNode o2)
          Implements equals for a typerel node.
 Enumeration<MMObjectNode> getAllowedRelations(int otype)
           
 Enumeration<MMObjectNode> getAllowedRelations(int builder1, int builder2)
          An enumeration of all allowed relations between two builders.
 Set<MMObjectNode> getAllowedRelations(int builder1, int builder2, int role)
          A Set of all allowed relations of a certain role between two builders.
 Set<MMObjectNode> getAllowedRelations(int builder1, int builder2, int role, int directionality)
          A Set of all allowed relations of a certain role between two builders.
 Enumeration<MMObjectNode> getAllowedRelations(MMObjectNode node)
          Retrieves all relations which are 'allowed' for a specified node, that is, where the node is either allowed to be the source, or to be the destination (but where the corresponing relation definition is bidirectional).
 Enumeration<MMObjectNode> getAllowedRelations(MMObjectNode node1, MMObjectNode node2)
          Retrieves all relations which are 'allowed' between two specified nodes.
protected  Vector<String> getAllowedRelationsNames(int snum, int dnum)
          Retrieves all relations which are 'allowed' between two specified nodes.
 int getAllowedRelationType(int snum, int dnum)
          Retrieves the identifying number of the relation definition that is 'allowed' between two specified node types.
 String getGUIIndicator(MMObjectNode node)
          Returns the display string for this node It returns a commbination of objecttypes and rolename : "source->destination (role)".
 String getGUIIndicator(String field, MMObjectNode node)
          Returns the display string for a specified field.
 Vector<String> getList(PageInfo sp, StringTagger tagger, StringTokenizer tok)
          Processes the BUILDER-typerel-ALLOWEDRELATIONSNAMES in the LIST command, and (possibly) returns a Vector containing requested data (based on the content of TYPE and NODE, which can be retrieved through tagger).
 int hashCode(MMObjectNode o)
          Implements for MMObjectNode
 boolean init()
          Initializes this builder The property 'mmb' needs to be set for the builder before this method can be called.
 int insert(String owner, MMObjectNode node)
          Insert a new object (content provided) in the cloud, including an entry for the object alias (if provided).
 void notify(NodeEvent event)
          Watch for changes on relation types and adjust our memory table accordingly
 void notify(SystemEvent se)
           
 boolean optimizeRelationStep(BasicRelationStep relationStep, int sourceType, int destinationType, int roleInt, int searchDir)
          Optimize as relation step by considering restrictions of TypeRel.
 void readCache()
          The TypeRel cache contains all TypeRels MMObjectNodes.
 boolean reldefCorrect(int n1, int n2, int r)
          Deprecated. use contains(int, int, int)instead
 void removeNode(MMObjectNode node)
          Remove a node from the cloud.
 String toString(MMObjectNode n)
          Implements for MMObjectNode
 
Methods inherited from class org.mmbase.module.core.MMObjectBuilder
addEventListener, addField, addLocalObserver, addRemoteObserver, broadcastChanges, checkAddTmpField, clearBlobCache, commit, create, createAlias, createAlias, delete, equals, executeFunction, executeFunction, fieldLocalChanged, getAncestors, getBlobCache, getClassName, getConfigFile, getConfigResource, getDataTypeCollector, getDBState, getDBType, getDefaultTeaser, getDefaultUrl, getDescendants, getDescription, getDescription, getDescriptions, getEmptyNode, getField, getFieldNames, getFields, getFields, getFunction, getFunctionParameters, getFunctions, getGUIIndicator, getHTML, getInitParameter, getInitParameters, getInitParameters, getInternalVersion, getLocaleGUIIndicator, getLocaleGUIIndicator, getMachineName, getMaintainer, getNewNode, getNewTmpNode, getNextField, getNextField, getNode, getNode, getNode, getNodeFromCache, getNodeGUIIndicator, getNumber, getObjectType, getObjectValue, getParentBuilder, getPluralName, getPluralName, getPluralNames, getRelations_main, getSearchAge, getShort, getShortedByte, getShortedInputStream, getShortedText, getSingularName, getSingularName, getSingularNames, getSmartPath, getTmpNode, getURLEncode, getValue, getVersion, getWAP, getXMLPath, hasField, hashCode, hostname_function, insert, isExtensionOf, isNodeCached, isNull, isVirtual, loadInitParameters, newFunctionInstance, nodeLocalChanged, nodeRemoteChanged, notify, preCommit, process, removeEventListener, removeField, removeLocalObserver, removeRelations, removeRemoteObserver, removeSyncNodes, replace, safeCache, sendFieldChangeSignal, setDefaults, setDescription, setDescriptions, setFields, setInitParameter, setMaintainer, setPluralNames, setSearchAge, setSingularNames, setUniqueValue, setUniqueValue, setValue, setValue, setVersion, setXMLPath, shutdown, testValidData, toString, update, updateFields, wrap
 
Methods inherited from class org.mmbase.module.core.MMTable
count, count, created, getFullTableName, getMMBase, getNode, getNodes, getNodes, getNodes, getNodeType, getStorageConnector, getTableName, search, searchVector, setMMBase, setTableName, size
 
Methods inherited from class org.mmbase.util.functions.FunctionProvider
addFunction, createParameters, getFunction, getFunctions, getFunctionValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

STRICT

public static final int STRICT
Constant for contains(int, int, int): return only typerels that exactly match.

See Also:
Constant Field Values

INCLUDE_DESCENDANTS

public static final int INCLUDE_DESCENDANTS
Constant for contains(int, int, int): return typerels where source/destination match with a builder or its descendants

See Also:
Constant Field Values

INCLUDE_PARENTS

public static final int INCLUDE_PARENTS
Constant for contains(int, int, int): return typerels where source/destination match with a builder or its parents

See Also:
Constant Field Values

INCLUDE_PARENTS_AND_DESCENDANTS

public static final int INCLUDE_PARENTS_AND_DESCENDANTS
Constant for contains(int, int, int): return typerels where source/destination match with a builder, its descendants, or its parents

See Also:
Constant Field Values

typeRelNodes

protected TypeRel.TypeRelSet typeRelNodes
TypeRel should contain only a limited amount of nodes, so we can simply cache them all, and avoid all further querying.


parentTypeRelNodes

protected TypeRel.TypeRelSet parentTypeRelNodes

inverseTypeRelNodes

public TypeRel.InverseTypeRelSet inverseTypeRelNodes
Constructor Detail

TypeRel

public TypeRel()
Method Detail

init

public boolean init()
Description copied from class: MMObjectBuilder
Initializes this builder The property 'mmb' needs to be set for the builder before this method can be called. The method retrieves data from the TypeDef builder, or adds data to that builder if the current builder is not yet registered.

Overrides:
init in class MMObjectBuilder
Returns:
true if init was completed, false if uncompleted.
See Also:
MMObjectBuilder.create()

notify

public void notify(SystemEvent se)
Specified by:
notify in interface SystemEventListener

readCache

public void readCache()
The TypeRel cache contains all TypeRels MMObjectNodes. Called after init by MMBase, and when something changes.

Since:
MMBase-1.6.2

addCacheEntry

protected TypeRel.TypeRelSet addCacheEntry(MMObjectNode typeRel,
                                           boolean buildersInitialized)
Addes one typerel cache entries, plus inherited relations (if builder are initialized)

Returns:
A Set with the added entries, which can be used for logging or so, or can be disregarded
Since:
MMBase-1.6.2

insert

public int insert(String owner,
                  MMObjectNode node)
Insert a new object (content provided) in the cloud, including an entry for the object alias (if provided). This method indirectly calls MMObjectBuilder.preCommit(org.mmbase.module.core.MMObjectNode). If the typerel node specified already exists (i.e. same snumber, dnumber,a nd rnumber fielfds), the typerel creation fails and returns -1.

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.

removeNode

public void removeNode(MMObjectNode node)
Remove a node from the cloud.

Overrides:
removeNode in class MMObjectBuilder
Parameters:
node - The node to remove.

getAllowedRelations

public Enumeration<MMObjectNode> getAllowedRelations(MMObjectNode node)
Retrieves all relations which are 'allowed' for a specified node, that is, where the node is either allowed to be the source, or to be the destination (but where the corresponing relation definition is bidirectional). The allowed relations are determined by the type of the node

Parameters:
node - The node to retrieve the allowed relations of.
Returns:
An Enumeration of nodes containing the typerel relation data

getAllowedRelations

public Enumeration<MMObjectNode> getAllowedRelations(int otype)

getAllowedRelations

public Enumeration<MMObjectNode> getAllowedRelations(MMObjectNode node1,
                                                     MMObjectNode node2)
Retrieves all relations which are 'allowed' between two specified nodes. No distinction between source / destination.

Parameters:
node1 - The first objectnode
node2 - The second objectnode
Returns:
An Enumeration of nodes containing the typerel relation data

getAllowedRelations

public Enumeration<MMObjectNode> getAllowedRelations(int builder1,
                                                     int builder2)
An enumeration of all allowed relations between two builders. No distinction is made between source and destination.


getAllowedRelations

public Set<MMObjectNode> getAllowedRelations(int builder1,
                                             int builder2,
                                             int role)
A Set of all allowed relations of a certain role between two builders. No distinction between source and destination.

Since:
MMBase-1.6.2

getAllowedRelations

public Set<MMObjectNode> getAllowedRelations(int builder1,
                                             int builder2,
                                             int role,
                                             int directionality)
A Set of all allowed relations of a certain role between two builders. Distinction is made between source and destination depending on passed directionality.

Since:
MMBase-1.6.2

getAllowedRelationsNames

protected Vector<String> getAllowedRelationsNames(int snum,
                                                  int dnum)
Retrieves all relations which are 'allowed' between two specified nodes.

Parameters:
snum - The first objectnode type (the source)
dnum - The second objectnode type (the destination)
Returns:
An Enumeration of nodes containing the reldef (not typerel!) sname field

getAllowedRelationType

public int getAllowedRelationType(int snum,
                                  int dnum)
Retrieves the identifying number of the relation definition that is 'allowed' between two specified node types. The results are dependent on there being only one type of relation between two node types (not enforced, thus unpredictable). Makes use of a typeRelNodes.

Parameters:
snum - The first objectnode type (the source)
dnum - The second objectnode type (the destination)
Returns:
the number of the found relation, or -1 if either no relation was found, or more than one was found.

getGUIIndicator

public String getGUIIndicator(MMObjectNode node)
Returns the display string for this node It returns a commbination of objecttypes and rolename : "source->destination (role)".

Overrides:
getGUIIndicator in class MMObjectBuilder
Parameters:
node - Node from which to retrieve the data
Returns:
A String describing the content of the node

getGUIIndicator

public String getGUIIndicator(String field,
                              MMObjectNode node)
Returns the display string for a specified field. Returns, for snumber and dnumber, the name of the objecttype they represent, and for rnumber the display (GUI) string for the indicated relation definition.

Overrides:
getGUIIndicator in class MMObjectBuilder
Parameters:
field - The name of the field to retrieve
node - Node from which to retrieve the data
Returns:
A String describing the content of the field

getList

public Vector<String> getList(PageInfo sp,
                              StringTagger tagger,
                              StringTokenizer tok)
Processes the BUILDER-typerel-ALLOWEDRELATIONSNAMES in the LIST command, and (possibly) returns a Vector containing requested data (based on the content of TYPE and NODE, which can be retrieved through tagger).

Overrides:
getList in class MMObjectBuilder
Parameters:
sp - The PageInfo (containing http and user info) that calls the function
tagger - a Hashtable of parameters (name-value pairs) for the command
tok - a list of strings that describe the (sub)command to execute
Returns:
a Vector containing the result values as a String
Javadoc:
parameters

reldefCorrect

public boolean reldefCorrect(int n1,
                             int n2,
                             int r)
Deprecated. use contains(int, int, int)instead

Tests if a specific relation type is defined.

Note that this routine returns false both when a snumber/dnumber are swapped, and when a typecombo does not exist - it is not possible to derive whether one or the other has occurred.

Parameters:
n1 - The source type number.
n2 - The destination type number.
r - The relation definition (role) number, or -1 if the role does not matter
Returns:
true when the relation exists, false otherwise.

contains

public boolean contains(int n1,
                        int n2,
                        int r)
Tests if a specific relation type is defined. The method also returns true if the typerel occurs as a virtual (derived) node.

Note that this routine returns false both when a snumber/dnumber are swapped, and when a typecombo does not exist - it is not possible to derive whether one or the other has occurred.

Parameters:
n1 - The source type number.
n2 - The destination type number.
r - The relation definition (role) number, or -1 if the role does not matter
Returns:
true when the relation exists, false otherwise.
Since:
MMBase-1.6.2

contains

public boolean contains(int n1,
                        int n2,
                        int r,
                        int restriction)
Tests if a specific relation type is defined.

Note that this routine returns false both when a snumber/dnumber are swapped, and when a typecombo does not exist - it is not possible to derive whether one or the other has occurred.

Parameters:
n1 - The source type number.
n2 - The destination type number.
r - The relation definition (role) number, or -1 if the role does not matter r can only be -1 if virtual is true
restriction - if STRICT, contains only returns true if the typerel occurs as-is in the database. if INCLUDE_DESCENDANTS, contains returns true if the typerel occurs as a virtual (derived) node, where source or destination may also be descendants of the specified type. if INCLUDE_PARENTS, contains returns true if the typerel occurs as a virtual (derived) node, where source or destination may also be parents of the specified type. if INCLUDE_PARENTS_AND_DESCENDANTS, contains returns true if the typerel occurs as a virtual (derived) node, where source or destination may also be descendants or parents of the specified type.
Returns:
true when the relation exists, false otherwise.
Since:
MMBase-1.6.2

notify

public void notify(NodeEvent event)
Watch for changes on relation types and adjust our memory table accordingly

Specified by:
notify in interface NodeEventListener
Overrides:
notify in class MMObjectBuilder
See Also:
here we handle all the backward compatibility stuff. this method covers for both node and relation events.
To Do:
Should update artCache en relDefCorrectCache as wel

optimizeRelationStep

public boolean optimizeRelationStep(BasicRelationStep relationStep,
                                    int sourceType,
                                    int destinationType,
                                    int roleInt,
                                    int searchDir)
Optimize as relation step by considering restrictions of TypeRel. TypeRel defines which type of relations may be created, ergo can exist.

Since:
MMBase-1.7

equals

public boolean equals(MMObjectNode o1,
                      MMObjectNode o2)
Implements equals for a typerel node. Two nodes are equal if the snumber and dnumber fields are the same, and the rnumber fields are the same, or one of these is '-1' (don't care).

Overrides:
equals in class MMObjectBuilder
Since:
MMBase-1.6.2

hashCode

public int hashCode(MMObjectNode o)
Implements for MMObjectNode

Overrides:
hashCode in class MMObjectBuilder
Since:
MMBase-1.6.2

toString

public String toString(MMObjectNode n)
Description copied from class: MMObjectBuilder
Implements for MMObjectNode

Overrides:
toString in class MMObjectBuilder


MMBase 2.0-SNAPSHOT - null