KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > util > AbstractNodeManager


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
11 package org.mmbase.bridge.util;
12 import javax.servlet.*;
13 import java.util.*;
14 import java.io.*;
15
16 import org.mmbase.bridge.*;
17 import org.mmbase.bridge.implementation.BasicFieldList;
18 import org.mmbase.util.logging.*;
19 import org.mmbase.util.*;
20
21 /**
22  * Abstract implementation of NodeManager, to minimalize the implementation of a virtual one. Must
23  * methods throw UnsupportOperationException (like in {@link
24  * org.mmbase.bridge.implementation.VirtualNodeManager}.
25  *
26  * @author Michiel Meeuwissen
27  * @version $Id: AbstractNodeManager.java,v 1.2 2006/02/14 22:31:46 michiel Exp $
28  * @see org.mmbase.bridge.NodeManager
29  * @since MMBase-1.8
30  */

31 public abstract class AbstractNodeManager extends AbstractNode implements NodeManager {
32     private static final Logger log = Logging.getLoggerInstance(AbstractNodeManager.class);
33
34
35     protected Map values = new HashMap();
36     protected final Cloud cloud;
37     protected AbstractNodeManager(Cloud c) {
38         cloud = c;
39     }
40
41     protected void setValueWithoutChecks(String JavaDoc fieldName, Object JavaDoc value) {
42         values.put(fieldName, value);
43     }
44     public Object JavaDoc getValueWithoutProcess(String JavaDoc fieldName) {
45         return values.get(fieldName);
46     }
47     protected void edit(int action) {
48         // go ahead
49
}
50
51     protected void setSize(String JavaDoc fieldName, long size) {
52         // never mind
53
}
54     public long getSize(String JavaDoc fieldName) {
55         // never mind
56
return 2;
57     }
58     public NodeManager getNodeManager() {
59         return cloud.getNodeManager("typedef");
60     }
61     public Cloud getCloud() {
62         return cloud;
63     }
64
65
66     public Node createNode() { throw new UnsupportedOperationException JavaDoc();}
67     public NodeList getList(String JavaDoc where, String JavaDoc sorted, boolean direction) { throw new UnsupportedOperationException JavaDoc(); }
68     public NodeList getList(String JavaDoc where, String JavaDoc sorted, String JavaDoc direction) { throw new UnsupportedOperationException JavaDoc(); }
69
70
71     public FieldList createFieldList() {
72         return new BasicFieldList(Collections.EMPTY_LIST, this);
73     }
74
75     public NodeList createNodeList() {
76         return new CollectionNodeList(Collections.EMPTY_LIST, this);
77     }
78
79     public RelationList createRelationList() {
80         return new CollectionRelationList(Collections.EMPTY_LIST, this);
81     }
82
83     public boolean mayCreateNode() {
84         return false;
85     }
86
87     public NodeList getList(NodeQuery query) { throw new UnsupportedOperationException JavaDoc(); }
88
89     public NodeQuery createQuery() { throw new UnsupportedOperationException JavaDoc(); }
90     public NodeList getList(String JavaDoc command, Map parameters, ServletRequest req, ServletResponse resp){ throw new UnsupportedOperationException JavaDoc();}
91
92     public NodeList getList(String JavaDoc command, Map parameters){ throw new UnsupportedOperationException JavaDoc();}
93
94
95     public RelationManagerList getAllowedRelations() { return BridgeCollections.EMPTY_RELATIONMANAGERLIST; }
96     public RelationManagerList getAllowedRelations(String JavaDoc nodeManager, String JavaDoc role, String JavaDoc direction) { return BridgeCollections.EMPTY_RELATIONMANAGERLIST; }
97
98     public RelationManagerList getAllowedRelations(NodeManager nodeManager, String JavaDoc role, String JavaDoc direction) { return BridgeCollections.EMPTY_RELATIONMANAGERLIST; }
99
100     public String JavaDoc getInfo(String JavaDoc command) { return getInfo(command, null,null);}
101
102     public String JavaDoc getInfo(String JavaDoc command, ServletRequest req, ServletResponse resp){ throw new UnsupportedOperationException JavaDoc();}
103
104
105     protected abstract Map getFieldTypes();
106
107
108     public final boolean hasField(String JavaDoc fieldName) {
109         Map fieldTypes = getFieldTypes();
110         return fieldTypes.isEmpty() || fieldTypes.containsKey(fieldName);
111     }
112
113     public final FieldList getFields() {
114         return getFields(NodeManager.ORDER_NONE);
115     }
116
117     public final FieldList getFields(int order) {
118         return new BasicFieldList(getFieldTypes().values(), this);
119     }
120
121     public final Field getField(String JavaDoc fieldName) throws NotFoundException {
122         Field f = (Field) getFieldTypes().get(fieldName);
123         if (f == null) throw new NotFoundException("Field '" + fieldName + "' does not exist in NodeManager '" + getName() + "'.(" + getFieldTypes() + ")");
124         return f;
125     }
126
127     public String JavaDoc getGUIName() {
128         return getGUIName(NodeManager.GUI_SINGULAR);
129     }
130
131     public String JavaDoc getGUIName(int plurality) {
132         return getGUIName(plurality, null);
133     }
134
135     public String JavaDoc getGUIName(int plurality, Locale locale) {
136         return getName();
137     }
138
139     public String JavaDoc getName() {
140         return "virtual_manager";
141     }
142     public String JavaDoc getDescription() {
143         return getDescription(null);
144     }
145
146     public String JavaDoc getDescription(Locale locale) {
147         return "";
148     }
149
150     public NodeManager getParent() {
151         return null;
152     }
153     
154     
155     public String JavaDoc getProperty(String JavaDoc name) {
156         return null;
157     }
158     public Map getProperties() {
159         return Collections.EMPTY_MAP;
160     }
161
162     public NodeManagerList getDescendants() {
163         return BridgeCollections.EMPTY_NODEMANAGERLIST;
164     }
165
166     public Collection getFunctions() {
167         return Collections.EMPTY_LIST;
168     }
169
170 }
171
Popular Tags