1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.graph.connector.path;
25
26 import java.util.HashMap;
27 import java.util.Map;
28 import java.util.UUID;
29 import org.modeshape.graph.ExecutionContext;
30 import org.modeshape.graph.NodeConflictBehavior;
31 import org.modeshape.graph.connector.LockFailedException;
32 import org.modeshape.graph.property.Name;
33 import org.modeshape.graph.property.Path;
34 import org.modeshape.graph.property.PathFactory;
35 import org.modeshape.graph.property.Property;
36 import org.modeshape.graph.property.Path.Segment;
37 import org.modeshape.graph.query.QueryResults;
38 import org.modeshape.graph.request.AccessQueryRequest;
39 import org.modeshape.graph.request.LockBranchRequest.LockScope;
40
41
42
43
44
45 public abstract class AbstractWritablePathWorkspace implements WritablePathWorkspace {
46
47 private final String name;
48 protected final UUID rootNodeUuid;
49
50 public AbstractWritablePathWorkspace( String name,
51 UUID rootNodeUuid ) {
52 super();
53 this.name = name;
54 this.rootNodeUuid = rootNodeUuid;
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public PathNode copyNode( ExecutionContext context,
70 PathNode original,
71 PathWorkspace originalWorkspace,
72 PathNode newParent,
73 Name desiredName,
74 boolean recursive ) {
75 PathFactory pathFactory = context.getValueFactories().getPathFactory();
76 PathNode copy = createNode(context, newParent, desiredName, original.getProperties(), NodeConflictBehavior.REPLACE);
77
78 if (recursive) {
79 Path originalPath = original.getPath();
80
81 for (Segment childSegment : original.getChildSegments()) {
82 Path childPath = pathFactory.create(originalPath, childSegment);
83 PathNode childNode = originalWorkspace.getNode(childPath);
84 copyNode(context, childNode, originalWorkspace, copy, childSegment.getName(), true);
85 }
86 }
87 return copy;
88 }
89
90 public PathNode createNode( ExecutionContext context,
91 String pathToNewNode,
92 Map<Name, Property> properties,
93 NodeConflictBehavior conflictBehavior ) {
94 PathFactory pathFactory = context.getValueFactories().getPathFactory();
95 Path newPath = pathFactory.create(pathToNewNode);
96
97 return createNode(context, getNode(newPath.getParent()), newPath.getLastSegment().getName(), properties, conflictBehavior);
98 }
99
100 public PathNode moveNode( ExecutionContext context,
101 PathNode node,
102 Name desiredNewName,
103 WritablePathWorkspace originalWorkspace,
104 PathNode newParent,
105 PathNode beforeNode ) {
106 if (desiredNewName == null) {
107 assert !node.getPath().isRoot();
108 desiredNewName = node.getPath().getLastSegment().getName();
109 }
110
111 PathNode newCopy = copyNode(context, node, originalWorkspace, newParent, desiredNewName, true);
112 originalWorkspace.removeNode(context, node.getPath());
113 return newCopy;
114 }
115
116 public PathNode removeProperties( ExecutionContext context,
117 Path nodePath,
118 Iterable<Name> propertyNames ) {
119 Map<Name, Property> properties = new HashMap<Name, Property>();
120 for (Name propertyName : propertyNames) {
121 properties.put(propertyName, null);
122 }
123
124 return setProperties(context, nodePath, properties);
125 }
126
127 public QueryResults query( ExecutionContext context,
128 AccessQueryRequest accessQuery ) {
129 return null;
130 }
131
132 public QueryResults search( ExecutionContext context,
133 String fullTextSearchExpression ) {
134 return null;
135 }
136
137 public String getName() {
138 return this.name;
139 }
140
141 public void lockNode( PathNode node,
142 LockScope lockScope,
143 long lockTimeoutInMillis ) throws LockFailedException {
144 }
145
146 public void unlockNode( PathNode node ) {
147 }
148
149 }