View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6   * See the AUTHORS.txt file in the distribution for a full listing of 
7   * individual contributors.
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   *
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.graph.connector.path;
25  
26  import java.util.Map;
27  import org.modeshape.graph.ExecutionContext;
28  import org.modeshape.graph.NodeConflictBehavior;
29  import org.modeshape.graph.property.Name;
30  import org.modeshape.graph.property.Path;
31  import org.modeshape.graph.property.Property;
32  import org.modeshape.graph.property.Path.Segment;
33  
34  /**
35   * Extension of {@link PathWorkspace} for repositories that support modification of nodes as well as access to the nodes.
36   */
37  public interface WritablePathWorkspace extends PathWorkspace {
38  
39      /**
40       * Create a node at the supplied path. The parent of the new node must already exist.
41       * 
42       * @param context the environment; may not be null
43       * @param pathToNewNode the path to the new node; may not be null
44       * @param properties the properties for the new node
45       * @param conflictBehavior the expected behavior if an equivalently-named child already exists at the location
46       * @return the new node (or root if the path specified the root)
47       */
48      PathNode createNode( ExecutionContext context,
49                           String pathToNewNode,
50                           Map<Name, Property> properties,
51                           NodeConflictBehavior conflictBehavior );
52  
53      /**
54       * Create a new node with the supplied name, as a child of the supplied parent.
55       * 
56       * @param context the execution context
57       * @param parentNode the parent node; may not be null
58       * @param name the name; may not be null
59       * @param properties the properties for the new node
60       * @param conflictBehavior the expected behavior if an equivalently-named child already exists at the location
61       * @return the new node
62       */
63      PathNode createNode( ExecutionContext context,
64                           PathNode parentNode,
65                           Name name,
66                           Map<Name, Property> properties,
67                           NodeConflictBehavior conflictBehavior );
68  
69      /**
70       * Move the supplied node to the new parent within this workspace. This method automatically removes the node from its
71       * existing parent, and also correctly adjusts the {@link Segment#getIndex() index} to be correct in the new parent.
72       * 
73       * @param context
74       * @param node the node to be moved; may not be the workspace root node
75       * @param desiredNewName the new name for the node, if it is to be changed; may be null
76       * @param originalWorkspace the workspace containing the node to be moved
77       * @param newParent the new parent; may not be the workspace root node
78       * @param beforeNode the node before which this new node should be placed
79       * @return a new copy of {@code node} that reflects the new location
80       */
81      public PathNode moveNode( ExecutionContext context,
82                                PathNode node,
83                                Name desiredNewName,
84                                WritablePathWorkspace originalWorkspace,
85                                PathNode newParent,
86                                PathNode beforeNode );
87  
88      /**
89       * Copy the subgraph given by the original node and place the new copy under the supplied new parent. Note that internal
90       * references between nodes within the original subgraph must be reflected as internal nodes within the new subgraph.
91       * 
92       * @param context the context; may not be null
93       * @param original the node to be copied; may not be null
94       * @param originalWorkspace the workspace containing the original parent node; may not be null
95       * @param newParent the parent where the copy is to be placed; may not be null
96       * @param desiredName the desired name for the node; if null, the name will be obtained from the original node
97       * @param recursive true if the copy should be recursive
98       * @return the new node, which is the top of the new subgraph
99       */
100     PathNode copyNode( ExecutionContext context,
101                        PathNode original,
102                        PathWorkspace originalWorkspace,
103                        PathNode newParent,
104                        Name desiredName,
105                        boolean recursive );
106 
107     /**
108      * Inserts the specified child at the specified position in the list of children. Shifts the child currently at that position
109      * (if any) and any subsequent children to the right (adds one to their indices).
110      * 
111      * @param index index at which the specified child is to be inserted
112      * @param child the child to be inserted
113      */
114     // public void addChild( int index,
115     // PathNode child );
116     /**
117      * Removes the node at the given path
118      * 
119      * @param context the context; may not be null
120      * @param nodePath the path of the node to be removed
121      * @return true if the node existed (and was removed); false otherwise
122      */
123     public boolean removeNode( ExecutionContext context,
124                                Path nodePath );
125 
126     /**
127      * Sets the given properties in a single operation, overwriting any previous properties for the same name. This bulk mutator
128      * should be used when multiple properties are being set in order to allow underlying implementations to optimize their access
129      * to their respective persistent storage mechanism.
130      * 
131      * @param context the context; may not be null
132      * @param nodePath the path to the node on which the properties should be set
133      * @param properties the properties to set
134      * @return this map node
135      */
136     public PathNode setProperties( ExecutionContext context,
137                                    Path nodePath,
138                                    Map<Name, Property> properties );
139 
140     /**
141      * Removes the properties with the given names
142      * 
143      * @param context the context; may not be null
144      * @param nodePath the path to the node from which the properties should be removed
145      * @param propertyNames the name of the properties to remove
146      * @return this map node
147      */
148     public PathNode removeProperties( ExecutionContext context,
149                                       Path nodePath,
150                                       Iterable<Name> propertyNames );
151 
152 }