1 56 package org.objectstyle.cayenne.service; 57 58 import org.objectstyle.cayenne.CayenneRuntimeException; 59 import org.objectstyle.cayenne.ObjectId; 60 import org.objectstyle.cayenne.distribution.GlobalID; 61 import org.objectstyle.cayenne.graph.CompoundDiff; 62 import org.objectstyle.cayenne.graph.GraphChangeHandler; 63 import org.objectstyle.cayenne.graph.GraphDiff; 64 import org.objectstyle.cayenne.graph.NodeIdChangeOperation; 65 import org.objectstyle.cayenne.map.EntityResolver; 66 67 74 class ServerToClientDiffConverter implements GraphChangeHandler { 77 78 EntityResolver resolver; 79 CompoundDiff clientDiff; 80 81 ServerToClientDiffConverter(EntityResolver resolver) { 82 this.resolver = resolver; 83 this.clientDiff = new CompoundDiff(); 84 } 85 86 GraphDiff getClientDiff() { 87 return clientDiff; 88 } 89 90 public void nodeIdChanged(Object nodeId, Object newId) { 91 GlobalID nodeGlobalID = toGlobalID(nodeId); 92 GlobalID newGlobalID = toGlobalID(newId); 93 clientDiff.add(new NodeIdChangeOperation(nodeGlobalID, newGlobalID)); 94 } 95 96 public void nodeCreated(Object nodeId) { 97 throw new CayenneRuntimeException("Unimplemented..."); 98 } 99 100 public void nodeRemoved(Object nodeId) { 101 throw new CayenneRuntimeException("Unimplemented..."); 102 } 103 104 public void nodePropertyChanged( 105 Object nodeId, 106 String property, 107 Object oldValue, 108 Object newValue) { 109 throw new CayenneRuntimeException("Unimplemented..."); 110 } 111 112 public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) { 113 throw new CayenneRuntimeException("Unimplemented..."); 114 } 115 116 public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) { 117 throw new CayenneRuntimeException("Unimplemented..."); 118 } 119 120 GlobalID toGlobalID(Object nodeId) { 121 if (nodeId instanceof ObjectId) { 122 return resolver.convertToGlobalID((ObjectId) nodeId); 123 } 124 else if (nodeId instanceof GlobalID) { 125 return (GlobalID) nodeId; 126 } 127 else if (nodeId == null) { 128 throw new NullPointerException ("Null ObjectId"); 129 } 130 else { 131 throw new CayenneRuntimeException( 132 "Server object identifier is expected to be ObjectId, got: " + nodeId); 133 } 134 } 135 } 136 | Popular Tags |