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.jcr;
25
26 import javax.jcr.AccessDeniedException;
27 import javax.jcr.ItemNotFoundException;
28 import javax.jcr.Node;
29 import javax.jcr.RepositoryException;
30 import javax.jcr.lock.Lock;
31 import javax.jcr.lock.LockException;
32 import javax.jcr.nodetype.ConstraintViolationException;
33 import javax.jcr.version.VersionException;
34 import net.jcip.annotations.NotThreadSafe;
35 import org.modeshape.graph.Location;
36 import org.modeshape.graph.session.GraphSession.NodeId;
37
38
39
40
41
42
43
44 @NotThreadSafe
45 class JcrNode extends AbstractJcrNode {
46
47 JcrNode( SessionCache cache,
48 NodeId nodeId,
49 Location location ) {
50 super(cache, nodeId, location);
51 }
52
53
54
55
56
57
58 @Override
59 final boolean isRoot() {
60 return false;
61 }
62
63
64
65
66
67
68 public int getIndex() throws RepositoryException {
69 return segment().getIndex();
70 }
71
72
73
74
75
76
77 public String getName() throws RepositoryException {
78 return segment().getName().getString(namespaces());
79 }
80
81
82
83
84
85
86 @Override
87 public AbstractJcrNode getParent() throws ItemNotFoundException, RepositoryException {
88 checkSession();
89 return parentNodeInfo().getPayload().getJcrNode();
90 }
91
92
93
94
95
96
97 public String getPath() throws RepositoryException {
98
99 return path().getString(namespaces());
100 }
101
102
103
104
105
106
107 @Override
108 protected void doRemove() throws RepositoryException, LockException {
109 Node parentNode = getParent();
110 if (parentNode.isLocked()) {
111 Lock parentLock = lockManager().getLock(this);
112 if (parentLock != null && !parentLock.isLockOwningSession()) {
113 throw new LockException(JcrI18n.lockTokenNotHeld.text(this.location));
114 }
115 }
116
117 if (!parentNode.isCheckedOut()) {
118 throw new VersionException(JcrI18n.nodeIsCheckedIn.text(parentNode.getPath()));
119 }
120
121 JcrNodeDefinition nodeDefn = cache.nodeTypes().getNodeDefinition(nodeInfo().getPayload().getDefinitionId());
122
123 if (nodeDefn.isProtected()) {
124 throw new ConstraintViolationException(JcrI18n.cannotRemoveItemWithProtectedDefinition.text(getPath()));
125 }
126 session().recordRemoval(locationToDestroy());
127 doDestroy();
128 }
129
130 protected Location locationToDestroy() {
131 return location;
132 }
133
134 protected void doDestroy() throws AccessDeniedException, RepositoryException {
135 editor().destroy();
136 }
137
138 }