KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > core > VirtualNode


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.module.core;
11
12 import java.util.*;
13
14 /**
15  * VirtualNode is a representation of a virtual objectnode.
16  * Virtual Object nodes are nodes that are not stored in a databasetable.
17  * Note that a temporary node is not virtual.
18  * This class captures a number of methods that would normally require datbase
19  * access, such as obtaining relations or determining age of a node.
20  *
21  * @author Pierre van Rooden
22  * @version $Id: VirtualNode.java,v 1.12.2.1 2006/11/28 13:48:45 johannes Exp $
23  */

24 public class VirtualNode extends MMObjectNode {
25
26     /**
27      * Main constructor.
28      * @param parent the node's parent
29      */

30     public VirtualNode(MMObjectBuilder parent) {
31         super(parent, false);
32     }
33
34     /**
35      * Alternate constructor, to create a node with the values given.
36      */

37     public VirtualNode(Map values) {
38         super(new VirtualBuilder(MMBase.getMMBase()), values);
39     }
40
41     public boolean isVirtual() {
42         return true;
43     }
44
45     /**
46      * Overrides to no throw exception on non-existing fields
47      */

48     protected boolean checkFieldExistance(String JavaDoc fieldName) {
49         return true;
50     }
51
52      /**
53       * commit : commits the node to the database or other storage system.
54       * Generally, commiting a virtual node has no effect, so the basic
55       * implementation returns false.
56       * @return <code>false</code>
57       */

58     public boolean commit() {
59       return false;
60     }
61
62     /**
63      * Insert is not implemented on a virtual node.
64      * @return nothing, throws an exception
65      * @throws UnsupportedOperationException
66      */

67     public int insert(String JavaDoc userName) {
68         throw new UnsupportedOperationException JavaDoc("Method insert is not implemented on a virtual node.");
69     }
70
71     /**
72      * {@inheritDoc}
73      * A virtual node never has relations.
74      * @return <code>false</code>
75      */

76     public boolean hasRelations() {
77         return false;
78     }
79
80     /**
81      * {@inheritDoc}
82      * A virtual node never has relations.
83      * @return empty <code>Enumeration</code>
84      */

85     public Enumeration getRelations() {
86         return new java.util.Vector JavaDoc(0).elements();
87     }
88
89     /**
90      * {@inheritDoc}
91      * A virtual node never has relations.
92      * @return 0, because Virtual nodes have no relations.
93      */

94     public int getRelationCount() {
95         return 0;
96     }
97
98     /**
99      * {@inheritDoc}
100      * A virtual node never has relations.
101      * @param wantedtype the 'type' of related nodes (NOT the relations!).
102      * @return 0, because Virtual nodes have no relations.
103      */

104     public int getRelationCount(String JavaDoc wantedtype) {
105         return 0;
106     }
107
108     /**
109      * Returns the node's age
110      * A virtual node is always new (0)
111      * @return the age in days (0)
112      */

113     public int getAge() {
114         return 0;
115     }
116
117     public int getOType() {
118         return -1;
119     }
120
121 }
122
Popular Tags