load();
// Figure out the name and SNS of the new copy ...
List<Node<Payload, PropertyPayload>> currentChildren = childrenByName.get(name);
Path newPath = cache.pathFactory.create(path, name, currentChildren.size() + 1);
Location newChild = idProperties != null && !idProperties.isEmpty() ? Location.create(newPath, idProperties) : Location.create(newPath);
// Create the properties ...
Map<Name, PropertyInfo<PropertyPayload>> newProperties = new HashMap<Name, PropertyInfo<PropertyPayload>>();
if (idProperties != null) {
for (Property idProp : idProperties) {
PropertyInfo<PropertyPayload> info = new PropertyInfo<PropertyPayload>(idProp, idProp.isMultiple(),
Status.NEW, null);
newProperties.put(info.getName(), info);
}
}
if (remainingProperties != null) {
for (Property property : remainingProperties) {
PropertyInfo<PropertyPayload> info2 = new PropertyInfo<PropertyPayload>(property, property.isMultiple(),
Status.NEW, null);
newProperties.put(info2.getName(), info2);
}
}
// Notify before the addition ...
cache.nodeOperations.preCreateChild(this, newPath.getLastSegment(), newProperties);
// Record the current state before any changes ...
Status statusBefore = this.status;
boolean changedBelowBefore = this.changedBelow;
// Add the child to the parent ...
Node<Payload, PropertyPayload> child = cache.createNode(this, cache.idFactory.create(), newChild);
child.markAsNew(); // marks parent as changed
if (childrenByName == cache.NO_CHILDREN) {
childrenByName = Multimaps.newLinkedListMultimap();
}
childrenByName.put(name, child);
// Set the properties on the new node, but in a private backdoor way ...
assert child.properties == null;
child.properties = newProperties;
child.childrenByName = cache.NO_CHILDREN;
try {
// The node has been changed, so try notifying before we record the creation (which can't be undone) ...
cache.nodeOperations.postCreateChild(this, child, child.properties);
// Notification was fine, so now do the create ...
Graph.Create<Graph.Batch> create = cache.operations.create(newChild.getPath());
if (!child.properties.isEmpty()) {
// Process the property infos (in case some were added during the pre- or post- operations ...
for (PropertyInfo<PropertyPayload> property : child.properties.values()) {
create.with(property.getProperty());
}