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:
011: package org.mmbase.bridge.util;
012:
013: import java.util.*;
014:
015: import javax.servlet.ServletRequest;
016: import javax.servlet.ServletResponse;
017:
018: import org.mmbase.bridge.*;
019: import org.mmbase.bridge.implementation.BasicFieldList;
020: import org.mmbase.util.functions.Function;
021:
022: /**
023: * Abstract implementation of NodeManager, to minimalize the implementation of a virtual one. Must
024: * methods throw UnsupportOperationException (like in {@link
025: * org.mmbase.bridge.implementation.VirtualNodeManager}.
026: *
027: * @author Michiel Meeuwissen
028: * @version $Id: AbstractNodeManager.java,v 1.9 2008/02/03 17:33:56 nklasens Exp $
029: * @see org.mmbase.bridge.NodeManager
030: * @since MMBase-1.8
031: */
032: public abstract class AbstractNodeManager extends AbstractNode
033: implements NodeManager {
034:
035: protected Map<String, Object> values = new HashMap<String, Object>();
036: protected final Cloud cloud;
037:
038: protected AbstractNodeManager(Cloud c) {
039: cloud = c;
040: }
041:
042: @Override
043: protected void setValueWithoutChecks(String fieldName, Object value) {
044: values.put(fieldName, value);
045: }
046:
047: public Object getValueWithoutProcess(String fieldName) {
048: return values.get(fieldName);
049: }
050:
051: protected void edit(int action) {
052: // go ahead
053: }
054:
055: @Override
056: protected void setSize(String fieldName, long size) {
057: // never mind
058: }
059:
060: public long getSize(String fieldName) {
061: // never mind
062: return 2;
063: }
064:
065: public NodeManager getNodeManager() {
066: return cloud.getNodeManager("typedef");
067: }
068:
069: public Cloud getCloud() {
070: return cloud;
071: }
072:
073: public Node createNode() {
074: throw new UnsupportedOperationException();
075: }
076:
077: public NodeList getList(String where, String sorted,
078: boolean direction) {
079: throw new UnsupportedOperationException();
080: }
081:
082: public NodeList getList(String where, String sorted,
083: String direction) {
084: throw new UnsupportedOperationException();
085: }
086:
087: public FieldList createFieldList() {
088: return new BasicFieldList(Collections.emptyList(), this );
089: }
090:
091: public NodeList createNodeList() {
092: return new CollectionNodeList(Collections.emptyList(), this );
093: }
094:
095: public RelationList createRelationList() {
096: return new CollectionRelationList(Collections.emptyList(), this );
097: }
098:
099: public boolean mayCreateNode() {
100: return false;
101: }
102:
103: public NodeList getList(NodeQuery query) {
104: throw new UnsupportedOperationException();
105: }
106:
107: public NodeQuery createQuery() {
108: throw new UnsupportedOperationException();
109: }
110:
111: public NodeList getList(String command, Map parameters,
112: ServletRequest req, ServletResponse resp) {
113: throw new UnsupportedOperationException();
114: }
115:
116: public NodeList getList(String command, Map parameters) {
117: throw new UnsupportedOperationException();
118: }
119:
120: public RelationManagerList getAllowedRelations() {
121: return BridgeCollections.EMPTY_RELATIONMANAGERLIST;
122: }
123:
124: public RelationManagerList getAllowedRelations(String nodeManager,
125: String role, String direction) {
126: return BridgeCollections.EMPTY_RELATIONMANAGERLIST;
127: }
128:
129: public RelationManagerList getAllowedRelations(
130: NodeManager nodeManager, String role, String direction) {
131: return BridgeCollections.EMPTY_RELATIONMANAGERLIST;
132: }
133:
134: public String getInfo(String command) {
135: return getInfo(command, null, null);
136: }
137:
138: public String getInfo(String command, ServletRequest req,
139: ServletResponse resp) {
140: throw new UnsupportedOperationException();
141: }
142:
143: protected abstract Map<String, Field> getFieldTypes();
144:
145: public boolean hasField(String fieldName) {
146: Map fieldTypes = getFieldTypes();
147: return fieldTypes.isEmpty()
148: || fieldTypes.containsKey(fieldName);
149: }
150:
151: public final FieldList getFields() {
152: return getFields(NodeManager.ORDER_NONE);
153: }
154:
155: public final FieldList getFields(int order) {
156: return new BasicFieldList(getFieldTypes().values(), this );
157: }
158:
159: public Field getField(String fieldName) throws NotFoundException {
160: Field f = getFieldTypes().get(fieldName);
161: if (f == null)
162: throw new NotFoundException("Field '" + fieldName
163: + "' does not exist in NodeManager '" + getName()
164: + "'.(" + getFieldTypes() + ")");
165: return f;
166: }
167:
168: public String getGUIName() {
169: return getGUIName(NodeManager.GUI_SINGULAR);
170: }
171:
172: public String getGUIName(int plurality) {
173: return getGUIName(plurality, null);
174: }
175:
176: public String getGUIName(int plurality, Locale locale) {
177: return getName();
178: }
179:
180: public String getName() {
181: return "virtual_manager";
182: }
183:
184: public String getDescription() {
185: return getDescription(null);
186: }
187:
188: public String getDescription(Locale locale) {
189: return "";
190: }
191:
192: public NodeManager getParent() {
193: return null;
194: }
195:
196: public String getProperty(String name) {
197: return null;
198: }
199:
200: public Map<String, String> getProperties() {
201: return Collections.emptyMap();
202: }
203:
204: public NodeManagerList getDescendants() {
205: return BridgeCollections.EMPTY_NODEMANAGERLIST;
206: }
207:
208: public Collection<Function<?>> getFunctions() {
209: return Collections.emptyList();
210: }
211:
212: }
|