1 10 11 package org.mmbase.bridge.implementation; 12 13 import java.io.InputStream ; 14 import java.util.*; 15 16 import org.mmbase.bridge.*; 17 import org.mmbase.bridge.util.*; 18 import org.mmbase.module.core.MMObjectBuilder; 19 import org.mmbase.module.core.VirtualBuilder; 20 import org.mmbase.module.core.MMObjectNode; 21 import org.mmbase.module.core.MMBase; 22 import org.mmbase.core.util.Fields; 23 import org.mmbase.core.CoreField; 24 import org.mmbase.util.functions.*; 25 import org.mmbase.util.logging.Logger; 26 import org.mmbase.util.logging.Logging; 27 import org.w3c.dom.Document ; 28 import org.w3c.dom.Element ; 29 30 41 public class VirtualNode extends AbstractNode implements Node { 42 43 private static final Logger log = Logging.getLoggerInstance(VirtualNode.class); 44 45 final protected org.mmbase.module.core.VirtualNode noderef; 46 47 51 final protected NodeManager nodeManager; 52 final protected Cloud cloud; 53 54 55 protected VirtualNode(Cloud cloud, org.mmbase.module.core.VirtualNode node, NodeManager nm) { 56 this.cloud = cloud; 57 this.noderef = node; 58 nodeManager = nm; 59 60 } 61 62 public VirtualNode(org.mmbase.module.core.VirtualNode node, Cloud cloud) { 63 this(cloud, node, new VirtualNodeManager(node, cloud)); 64 } 65 66 70 public VirtualNode(Map values, Cloud cloud) { 71 this(getVirtualNode(values), cloud); 72 } 73 74 public String toString() { 75 return "BridgeVirtualNode " + noderef; 76 } 77 78 protected static org.mmbase.module.core.VirtualNode getVirtualNode(Map values) { 79 VirtualBuilder builder = new VirtualBuilder(MMBase.getMMBase()); 80 org.mmbase.module.core.VirtualNode node = new org.mmbase.module.core.VirtualNode(builder); 81 Iterator i = values.entrySet().iterator(); 82 while (i.hasNext()) { 83 Map.Entry entry = (Map.Entry) i.next(); 84 String name = entry.getKey().toString(); 85 Object value = entry.getValue(); 86 node.storeValue(name, value); 87 } 88 return node; 89 } 90 91 94 public org.mmbase.module.core.VirtualNode getNodeRef() { 95 return noderef; 96 } 97 98 99 public boolean isRelation() { 100 return false; 101 } 102 103 public Relation toRelation() { 104 return (Relation)this; 105 } 106 107 public boolean isNodeManager() { 108 return false; 109 } 110 111 public NodeManager toNodeManager() { 112 return (NodeManager)this; 113 } 114 115 public boolean isRelationManager() { 116 return false; 117 } 118 119 public RelationManager toRelationManager() { 120 return (RelationManager)this; 121 } 122 123 130 protected final MMObjectNode getNode() { 131 return noderef; 132 } 133 134 135 public Cloud getCloud() { 136 return cloud; 137 } 138 139 public NodeManager getNodeManager() { 140 return nodeManager; 141 } 142 143 public int getNumber() { 144 return noderef.getNumber(); 145 } 146 147 148 protected void edit(int action) { 149 throw new UnsupportedOperationException ("Cannot edit virtual node"); 150 } 151 152 public boolean isNull(String fieldName) { 153 return noderef.isNull(fieldName); 154 } 155 156 public void setSize(String fieldName, long size) { 157 noderef.setSize(fieldName, size); 158 } 159 public long getSize(String fieldName) { 160 return noderef.getSize(fieldName); 161 } 162 163 protected void setValueWithoutChecks(String fieldName, Object value) { 164 getNode().setValue(fieldName, value); 167 } 168 169 public Object getValueWithoutProcess(String fieldName) { 170 Object result = getNode().getValue(fieldName); 171 return result; 172 } 173 174 public boolean getBooleanValue(String fieldName) { 175 Boolean result = Boolean.valueOf(noderef.getBooleanValue(fieldName)); 176 return result.booleanValue(); 177 } 178 179 public Date getDateValue(String fieldName) { 180 Date result = noderef.getDateValue(fieldName); 181 return result; 182 } 183 184 public List getListValue(String fieldName) { 185 List result = noderef.getListValue(fieldName); 186 return result; 187 } 188 189 190 194 public Node getNodeValue(String fieldName) { 195 if (fieldName == null || fieldName.equals("number")) { 196 return this; 197 } 198 Node result = null; 199 MMObjectNode mmobjectNode = getNode().getNodeValue(fieldName); 200 if (mmobjectNode != null) { 201 MMObjectBuilder builder = mmobjectNode.getBuilder(); 202 if (builder instanceof VirtualBuilder) { 203 return new VirtualNode((org.mmbase.module.core.VirtualNode)mmobjectNode, cloud); 204 } 205 206 try { 207 result = cloud.getNode(mmobjectNode.getNumber()); 208 } catch (NotFoundException nfe) { 209 log.debug(nfe.getMessage()); 211 return null; 212 } 213 } 214 return result; 215 } 216 217 public int getIntValue(String fieldName) { 218 Integer result = new Integer (getNode().getIntValue(fieldName)); 219 return result.intValue(); 220 221 } 222 223 public float getFloatValue(String fieldName) { 224 Float result = new Float (getNode().getFloatValue(fieldName)); 225 return result.floatValue(); 226 } 227 228 public long getLongValue(String fieldName) { 229 Long result = new Long (getNode().getLongValue(fieldName)); 230 return result.longValue(); 231 } 232 233 public double getDoubleValue(String fieldName) { 234 Double result = new Double (getNode().getDoubleValue(fieldName)); 235 return result.doubleValue(); 236 } 237 238 public byte[] getByteValue(String fieldName) { 239 byte[] result = getNode().getByteValue(fieldName); 240 return result; 241 } 242 public java.io.InputStream getInputStreamValue(String fieldName) { 243 java.io.InputStream result = getNode().getInputStreamValue(fieldName); 244 return result; 245 } 246 247 public String getStringValue(String fieldName) { 248 String result = getNode().getStringValue(fieldName); 249 return result; 250 } 251 252 public Document getXMLValue(String fieldName) { 253 Document result = getNode().getXMLValue(fieldName); 254 return result; 255 } 256 257 258 public Collection getFunctions() { 259 return getNode().getFunctions(); 260 } 261 262 protected Function getNodeFunction(String functionName) { 263 return getNode().getFunction(functionName); 264 } 265 266 public Parameters createParameters(String functionName) { 267 return getNode().getFunction(functionName).createParameters(); 268 } 269 270 protected FieldValue createFunctionValue(Object result) { 271 return new BasicFunctionValue(getCloud(), result); 272 } 273 274 } 275 | Popular Tags |