001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase.module.core;
011:
012: import java.util.*;
013:
014: /**
015: * VirtualNode is a representation of a virtual objectnode.
016: * Virtual Object nodes are nodes that are not stored in a databasetable.
017: * Note that a temporary node is not virtual.
018: * This class captures a number of methods that would normally require datbase
019: * access, such as obtaining relations or determining age of a node.
020: *
021: * @author Pierre van Rooden
022: * @version $Id: VirtualNode.java,v 1.15 2007/02/11 19:21:11 nklasens Exp $
023: */
024: public class VirtualNode extends MMObjectNode {
025:
026: /**
027: * Main constructor.
028: * @param parent the node's parent
029: */
030: public VirtualNode(MMObjectBuilder parent) {
031: super (parent, false);
032: }
033:
034: /**
035: * Alternate constructor, to create a node with the values given.
036: */
037: public VirtualNode(Map<String, Object> values) {
038: super (new VirtualBuilder(MMBase.getMMBase()), values);
039: }
040:
041: public boolean isVirtual() {
042: return true;
043: }
044:
045: /**
046: * Overrides to no throw exception on non-existing fields
047: */
048: protected boolean checkFieldExistance(String fieldName) {
049: return true;
050: }
051:
052: /**
053: * commit : commits the node to the database or other storage system.
054: * Generally, commiting a virtual node has no effect, so the basic
055: * implementation returns false.
056: * @return <code>false</code>
057: */
058: public boolean commit() {
059: return false;
060: }
061:
062: /**
063: * Insert is not implemented on a virtual node.
064: * @return nothing, throws an exception
065: * @throws UnsupportedOperationException
066: */
067: public int insert(String userName) {
068: throw new UnsupportedOperationException(
069: "Method insert is not implemented on a virtual node.");
070: }
071:
072: /**
073: * {@inheritDoc}
074: * A virtual node never has relations.
075: * @return <code>false</code>
076: */
077: public boolean hasRelations() {
078: return false;
079: }
080:
081: /**
082: * {@inheritDoc}
083: * A virtual node never has relations.
084: * @return empty <code>Enumeration</code>
085: */
086: public Enumeration<MMObjectNode> getRelations() {
087: return new java.util.Vector<MMObjectNode>(0).elements();
088: }
089:
090: /**
091: * {@inheritDoc}
092: * A virtual node never has relations.
093: * @return 0, because Virtual nodes have no relations.
094: */
095: public int getRelationCount() {
096: return 0;
097: }
098:
099: /**
100: * {@inheritDoc}
101: * A virtual node never has relations.
102: * @param wantedtype the 'type' of related nodes (NOT the relations!).
103: * @return 0, because Virtual nodes have no relations.
104: */
105: public int getRelationCount(String wantedtype) {
106: return 0;
107: }
108:
109: /**
110: * Returns the node's age
111: * A virtual node is always new (0)
112: * @return the age in days (0)
113: */
114: public int getAge() {
115: return 0;
116: }
117:
118: public int getOType() {
119: return -1;
120: }
121:
122: }
|