Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
<+>/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements. See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with\n * the License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.apache.jackrabbit.oak.jcr;\n\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Locale;\nimport java.util.Map;\nimport java.util.Set;\n\nimport javax.annotation.Nonnull;\nimport javax.jcr.AccessDeniedException;\nimport javax.jcr.Credentials;\nimport javax.jcr.Item;\nimport javax.jcr.ItemNotFoundException;\nimport javax.jcr.NamespaceException;\nimport javax.jcr.Node;\nimport javax.jcr.PathNotFoundException;\nimport javax.jcr.Property;\nimport javax.jcr.Repository;\nimport javax.jcr.RepositoryException;\nimport javax.jcr.Session;\nimport javax.jcr.UnsupportedRepositoryOperationException;\nimport javax.jcr.ValueFactory;\nimport javax.jcr.Workspace;\nimport javax.jcr.retention.RetentionManager;\nimport javax.jcr.security.AccessControlException;\nimport javax.jcr.security.AccessControlManager;\nimport javax.jcr.security.AccessControlPolicy;\nimport javax.jcr.security.AccessControlPolicyIterator;\nimport javax.jcr.security.Privilege;\n\nimport org.apache.jackrabbit.api.JackrabbitSession;\nimport org.apache.jackrabbit.api.security.principal.PrincipalManager;\nimport org.apache.jackrabbit.api.security.user.UserManager;\nimport org.apache.jackrabbit.commons.AbstractSession;\nimport org.apache.jackrabbit.commons.iterator.AccessControlPolicyIteratorAdapter;\nimport org.apache.jackrabbit.oak.api.TreeLocation;\nimport org.apache.jackrabbit.oak.commons.PathUtils;\nimport org.apache.jackrabbit.oak.jcr.xml.XmlImportHandler;\nimport org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials;\nimport org.apache.jackrabbit.oak.util.TODO;\nimport org.apache.jackrabbit.util.Text;\nimport org.apache.jackrabbit.util.XMLChar;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.xml.sax.ContentHandler;\n\n/**\n * TODO document\n */\npublic class SessionImpl extends AbstractSession implements JackrabbitSession {\n\n /**\n * logger instance\n */\n private static final Logger log = LoggerFactory.getLogger(SessionImpl.class);\n\n private final SessionDelegate dlg;\n\n /**\n * Local namespace remappings. Prefixes as keys and namespace URIs as values.\n *
\n * This map is only accessed from synchronized methods (see\n * JCR-1793).\n */\n private final Map namespaces;\n\n SessionImpl(SessionDelegate dlg, Map namespaces) {\n this.dlg = dlg;\n this.namespaces = namespaces;\n }\n\n //------------------------------------------------------------< Session >---\n\n @Override\n @Nonnull\n public Repository getRepository() {\n return dlg.getRepository();\n }\n\n @Override\n public String getUserID() {\n return dlg.getAuthInfo().getUserID();\n }\n\n @Override\n public String[] getAttributeNames() {\n return dlg.getAuthInfo().getAttributeNames();\n }\n\n @Override\n public Object getAttribute(String name) {\n return dlg.getAuthInfo().getAttribute(name);\n }\n\n @Override\n @Nonnull\n public Workspace getWorkspace() {\n return dlg.getWorkspace();\n }\n\n @Override\n @Nonnull\n public Session impersonate(Credentials credentials) throws RepositoryException {\n ensureIsAlive();\n\n ImpersonationCredentials impCreds = new ImpersonationCredentials(credentials, dlg.getAuthInfo());\n return getRepository().login(impCreds, dlg.getWorkspaceName());\n }\n\n @Override\n @Nonnull\n public ValueFactory getValueFactory() throws RepositoryException {\n ensureIsAlive();\n return dlg.getValueFactory();\n }\n\n @Override\n @Nonnull\n public Node getRootNode() throws RepositoryException {\n ensureIsAlive();\n\n return dlg.perform(new SessionOperation() {\n @Override\n public NodeImpl perform() throws AccessDeniedException {\n NodeDelegate nd = dlg.getRootNode();\n if (nd == null) {\n throw new AccessDeniedException(\"Root node is not accessible.\");\n } else {\n return new NodeImpl(nd);\n }\n }\n });\n }\n\n @Override\n @Nonnull\n public Node getNodeByUUID(String uuid) throws RepositoryException {\n return getNodeByIdentifier(uuid);\n }\n\n @Override\n @Nonnull\n public Node getNodeByIdentifier(final String id) throws RepositoryException {\n ensureIsAlive();\n\n return dlg.perform(new SessionOperation() {\n @Override\n public NodeImpl perform() throws RepositoryException {\n NodeDelegate d = dlg.getNodeByIdentifier(id);\n if (d == null) {\n throw new ItemNotFoundException(\"Node with id \" + id + \" does not exist.\");\n }\n return new NodeImpl(d);\n }\n });\n }\n\n @Override\n public Item getItem(String absPath) throws RepositoryException {\n if (nodeExists(absPath)) {\n return getNode(absPath);\n } else {\n return getProperty(absPath);\n }\n }\n\n @Override\n public boolean itemExists(String absPath) throws RepositoryException {\n return nodeExists(absPath) || propertyExists(absPath);\n }\n\n @Override\n public Node getNode(final String absPath) throws RepositoryException {\n ensureIsAlive();\n\n return dlg.perform(new SessionOperation() {\n @Override\n public NodeImpl perform() throws RepositoryException {\n String oakPath = dlg.getOakPathOrThrow(absPath);\n NodeDelegate d = dlg.getNode(oakPath);\n if (d == null) {\n throw new PathNotFoundException(\"Node with path \" + absPath + \" does not exist.\");\n }\n return new NodeImpl(d);\n }\n });\n }\n\n @Override\n public boolean nodeExists(final String absPath) throws RepositoryException {\n ensureIsAlive();\n\n return dlg.perform(new SessionOperation() {\n @Override\n public Boolean perform() throws RepositoryException {\n String oakPath = dlg.getOakPathOrThrow(absPath);\n return dlg.getNode(oakPath) != null;\n }\n });\n }\n\n @Override\n public Property getProperty(final String absPath) throws RepositoryException {\n if (absPath.equals(\"/\")) {\n throw new RepositoryException(\"The root node is not a property\");\n } else {\n return dlg.perform(new SessionOperation() {\n @Override\n public PropertyImpl perform() throws RepositoryException {\n String oakPath = dlg.getOakPathOrThrowNotFound(absPath);\n TreeLocation loc = dlg.getLocation(oakPath);\n if (loc.getProperty() == null) {\n throw new PathNotFoundException(absPath);\n }\n else {\n return new PropertyImpl(new PropertyDelegate(dlg, loc));\n }\n }\n });\n }\n }\n\n @Override\n public boolean propertyExists(final String absPath) throws RepositoryException {\n if (absPath.equals(\"/\")) {\n throw new RepositoryException(\"The root node is not a property\");\n } else {\n return dlg.perform(new SessionOperation() {\n @Override\n public Boolean perform() throws RepositoryException {\n String oakPath = dlg.getOakPathOrThrowNotFound(absPath);\n TreeLocation loc = dlg.getLocation(oakPath);\n return loc.getProperty() != null;\n }\n });\n }\n }\n\n @Override\n public void move(final String srcAbsPath, final String destAbsPath) throws RepositoryException {\n ensureIsAlive();\n\n dlg.perform(new SessionOperation() {\n @Override\n public Void perform() throws RepositoryException {\n dlg.checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath, 1));\n String oakPath = dlg.getOakPathKeepIndexOrThrowNotFound(destAbsPath);\n String oakName = PathUtils.getName(oakPath);\n // handle index\n if (oakName.contains(\"[\")) {\n throw new RepositoryException(\"Cannot create a new node using a name including an index\");\n }\n\n dlg.move(\n dlg.getOakPathOrThrowNotFound(srcAbsPath),\n dlg.getOakPathOrThrowNotFound(oakPath),\n true);\n\n return null;\n }\n });\n }\n\n @Override\n public void save() throws RepositoryException {\n ensureIsAlive();\n dlg.save();\n }\n\n @Override\n public void refresh(boolean keepChanges) throws RepositoryException {\n ensureIsAlive();\n dlg.refresh(keepChanges);\n }\n\n @Override\n public boolean hasPendingChanges() throws RepositoryException {\n ensureIsAlive();\n return dlg.hasPendingChanges();\n }\n\n @Override\n public boolean isLive() {\n return dlg.isAlive();\n }\n\n\n @Override\n public void logout() {\n dlg.logout();\n synchronized (namespaces) {\n namespaces.clear();\n }\n }\n\n @Override\n @Nonnull\n public ContentHandler getImportContentHandler(\n String parentAbsPath, int uuidBehavior) throws RepositoryException {\n final Node parent = getNode(parentAbsPath);\n return new XmlImportHandler(parent, uuidBehavior);\n }\n\n /**\n * @see javax.jcr.Session#addLockToken(String)\n */\n @Override\n public void addLockToken(String lt) {\n try {\n dlg.getLockManager().addLockToken(lt);\n } catch (RepositoryException e) {\n log.warn(\"Unable to add lock token '{}' to this session: {}\", lt, e.getMessage());\n }\n }\n\n /**\n * @see javax.jcr.Session#getLockTokens()\n */\n @Override\n @Nonnull\n public String[] getLockTokens() {\n try {\n return dlg.getLockManager().getLockTokens();\n } catch (RepositoryException e) {\n log.warn(\"Unable to retrieve lock tokens for this session: {}\", e.getMessage());\n return new String[0]; }\n }\n\n /**\n * @see javax.jcr.Session#removeLockToken(String)\n */\n @Override\n public void removeLockToken(String lt) {\n try {\n dlg.getLockManager().addLockToken(lt);\n } catch (RepositoryException e) {\n log.warn(\"Unable to add lock token '{}' to this session: {}\", lt, e.getMessage());\n }\n }\n\n @Override\n public boolean hasPermission(String absPath, String actions) throws RepositoryException {\n ensureIsAlive();\n\n String oakPath = dlg.getOakPathOrNull(absPath);\n if (oakPath == null) {\n // TODO should we throw an exception here?\n return TODO.unimplemented().returnValue(false);\n }\n\n // TODO implement hasPermission\n return TODO.unimplemented().returnValue(true);\n }\n\n /**\n * @see javax.jcr.Session#checkPermission(String, String)\n */\n @Override\n public void checkPermission(String absPath, String actions) throws AccessControlException, RepositoryException {\n if (!hasPermission(absPath, actions)) {\n throw new AccessControlException(\"Access control violation: path = \" + absPath + \", actions = \" + actions);\n }\n }\n\n @Override\n public boolean hasCapability(String methodName, Object target, Object[] arguments) throws RepositoryException {\n ensureIsAlive();\n\n // TODO\n return TODO.unimplemented().returnValue(false);\n }\n\n @Override\n @Nonnull\n public AccessControlManager getAccessControlManager()\n throws RepositoryException {\n return TODO.unimplemented().returnValue(new AccessControlManager() {\n @Override\n public void setPolicy(String absPath, AccessControlPolicy policy) throws AccessControlException {\n throw new AccessControlException(policy.toString());\n }\n @Override\n public void removePolicy(String absPath, AccessControlPolicy policy) throws AccessControlException {\n throw new AccessControlException(policy.toString());\n }\n @Override\n public Privilege privilegeFromName(String privilegeName)\n throws AccessControlException, RepositoryException {\n return dlg.getPrivilegeManager().getPrivilege(privilegeName);\n }\n @Override\n public boolean hasPrivileges(String absPath, Privilege[] privileges) {\n return true;\n }\n @Override\n public Privilege[] getSupportedPrivileges(String absPath) {\n return new Privilege[0];\n }\n @Override\n public Privilege[] getPrivileges(String absPath) {\n return new Privilege[0];\n }\n @Override\n public AccessControlPolicy[] getPolicies(String absPath) {\n return new AccessControlPolicy[0];\n }\n @Override\n public AccessControlPolicy[] getEffectivePolicies(String absPath) {\n return new AccessControlPolicy[0];\n }\n @Override\n public AccessControlPolicyIterator getApplicablePolicies(String absPath) {\n return AccessControlPolicyIteratorAdapter.EMPTY;\n }\n });\n }\n\n /**\n * @see javax.jcr.Session#getRetentionManager()\n */\n @Override\n @Nonnull\n public RetentionManager getRetentionManager() throws RepositoryException {\n throw new UnsupportedRepositoryOperationException(\"Retention Management is not supported.\");\n }\n\n //---------------------------------------------------------< Namespaces >---\n // The code below was initially copied from JCR Commons AbstractSession, but\n // provides information the \"hasRemappings\" information\n\n @Override\n public void setNamespacePrefix(String prefix, String uri) throws RepositoryException {\n if (prefix == null) {\n throw new IllegalArgumentException(\"Prefix must not be null\");\n } else if (uri == null) {\n throw new IllegalArgumentException(\"Namespace must not be null\");\n } else if (prefix.isEmpty()) {\n throw new NamespaceException(\n \"Empty prefix is reserved and can not be remapped\");\n } else if (uri.isEmpty()) {\n throw new NamespaceException(\n \"Default namespace is reserved and can not be remapped\");\n } else if (prefix.toLowerCase(Locale.ENGLISH).startsWith(\"xml\")) {\n throw new NamespaceException(\n \"XML prefixes are reserved: \" + prefix);\n } else if (!XMLChar.isValidNCName(prefix)) {\n throw new NamespaceException(\n \"Prefix is not a valid XML NCName: \" + prefix);\n }\n\n synchronized (namespaces) {\n // Remove existing mapping for the given prefix\n namespaces.remove(prefix);\n\n // Remove existing mapping(s) for the given URI\n Set prefixes = new HashSet();\n for (Map.Entry entry : namespaces.entrySet()) {\n if (entry.getValue().equals(uri)) {\n prefixes.add(entry.getKey());\n }\n }\n namespaces.keySet().removeAll(prefixes);\n\n // Add the new mapping\n namespaces.put(prefix, uri);\n }\n }\n\n @Override\n public String[] getNamespacePrefixes() throws RepositoryException {\n Set uris = new HashSet();\n uris.addAll(Arrays.asList(getWorkspace().getNamespaceRegistry().getURIs()));\n synchronized (namespaces) {\n // Add namespace uris only visible to session\n uris.addAll(namespaces.values());\n }\n Set prefixes = new HashSet();\n for (String uri : uris) {\n prefixes.add(getNamespacePrefix(uri));\n }\n return prefixes.toArray(new String[prefixes.size()]);\n }\n\n @Override\n public String getNamespaceURI(String prefix) throws RepositoryException {\n synchronized (namespaces) {\n String uri = namespaces.get(prefix);\n\n if (uri == null) {\n // Not in local mappings, try the global ones\n uri = getWorkspace().getNamespaceRegistry().getURI(prefix);\n if (namespaces.containsValue(uri)) {\n // The global URI is locally mapped to some other prefix,\n // so there are no mappings for this prefix\n throw new NamespaceException(\"Namespace not found: \" + prefix);\n }\n }\n\n return uri;\n }\n }\n\n @Override\n public String getNamespacePrefix(String uri) throws RepositoryException {\n synchronized (namespaces) {\n for (Map.Entry entry : namespaces.entrySet()) {\n if (entry.getValue().equals(uri)) {\n return entry.getKey();\n }\n }\n\n // The following throws an exception if the URI is not found, that's OK\n String prefix = getWorkspace().getNamespaceRegistry().getPrefix(uri);\n\n // Generate a new prefix if the global mapping is already taken\n String base = prefix;\n for (int i = 2; namespaces.containsKey(prefix); i++) {\n prefix = base + i;\n }\n\n if (!base.equals(prefix)) {\n namespaces.put(prefix, uri);\n }\n return prefix;\n }\n }\n\n //--------------------------------------------------< JackrabbitSession >---\n\n @Override\n @Nonnull\n public PrincipalManager getPrincipalManager() throws RepositoryException {\n return dlg.getPrincipalManager();\n }\n\n @Override\n @Nonnull\n public UserManager getUserManager() throws RepositoryException {\n return dlg.getUserManager();\n }\n\n //------------------------------------------------------------< private >---\n\n /**\n * Ensure that this session is alive and throw an exception otherwise.\n *\n * @throws RepositoryException if this session has been rendered invalid\n * for some reason (e.g. if this session has been closed explicitly by logout)\n */\n private void ensureIsAlive() throws RepositoryException {\n // check session status\n if (!dlg.isAlive()) {\n throw new RepositoryException(\"This session has been closed.\");\n }\n }\n}
===================================================================
--- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java (revision 5fdaf7a63b9a1f0a11099754834c910a50348461)
+++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java (revision )
@@ -192,7 +192,7 @@
return dlg.perform(new SessionOperation() {
@Override
public NodeImpl perform() throws RepositoryException {
- String oakPath = dlg.getOakPathOrThrow(absPath);
+ String oakPath = dlg.getOakPath(absPath);
NodeDelegate d = dlg.getNode(oakPath);
if (d == null) {
throw new PathNotFoundException("Node with path " + absPath + " does not exist.");
@@ -209,7 +209,7 @@
return dlg.perform(new SessionOperation() {
@Override
public Boolean perform() throws RepositoryException {
- String oakPath = dlg.getOakPathOrThrow(absPath);
+ String oakPath = dlg.getOakPath(absPath);
return dlg.getNode(oakPath) != null;
}
});
@@ -223,7 +223,7 @@
return dlg.perform(new SessionOperation() {
@Override
public PropertyImpl perform() throws RepositoryException {
- String oakPath = dlg.getOakPathOrThrowNotFound(absPath);
+ String oakPath = dlg.getOakPath(absPath);
TreeLocation loc = dlg.getLocation(oakPath);
if (loc.getProperty() == null) {
throw new PathNotFoundException(absPath);
@@ -244,7 +244,7 @@
return dlg.perform(new SessionOperation() {
@Override
public Boolean perform() throws RepositoryException {
- String oakPath = dlg.getOakPathOrThrowNotFound(absPath);
+ String oakPath = dlg.getOakPath(absPath);
TreeLocation loc = dlg.getLocation(oakPath);
return loc.getProperty() != null;
}
@@ -260,7 +260,7 @@
@Override
public Void perform() throws RepositoryException {
dlg.checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath, 1));
- String oakPath = dlg.getOakPathKeepIndexOrThrowNotFound(destAbsPath);
+ String oakPath = dlg.getOakPathKeepIndex(destAbsPath);
String oakName = PathUtils.getName(oakPath);
// handle index
if (oakName.contains("[")) {
@@ -268,8 +268,8 @@
}
dlg.move(
- dlg.getOakPathOrThrowNotFound(srcAbsPath),
- dlg.getOakPathOrThrowNotFound(oakPath),
+ dlg.getOakPath(srcAbsPath),
+ dlg.getOakPath(oakPath),
true);
return null;
\ No newline at end of file
Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
<+>/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements. See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with\n * the License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.apache.jackrabbit.oak.jcr;\n\nimport java.io.InputStream;\nimport java.math.BigDecimal;\nimport java.util.Arrays;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Set;\n\nimport javax.annotation.CheckForNull;\nimport javax.annotation.Nonnull;\nimport javax.jcr.AccessDeniedException;\nimport javax.jcr.Binary;\nimport javax.jcr.InvalidItemStateException;\nimport javax.jcr.Item;\nimport javax.jcr.ItemExistsException;\nimport javax.jcr.ItemNotFoundException;\nimport javax.jcr.ItemVisitor;\nimport javax.jcr.NoSuchWorkspaceException;\nimport javax.jcr.Node;\nimport javax.jcr.NodeIterator;\nimport javax.jcr.PathNotFoundException;\nimport javax.jcr.Property;\nimport javax.jcr.PropertyIterator;\nimport javax.jcr.PropertyType;\nimport javax.jcr.RepositoryException;\nimport javax.jcr.UnsupportedRepositoryOperationException;\nimport javax.jcr.Value;\nimport javax.jcr.ValueFormatException;\nimport javax.jcr.lock.Lock;\nimport javax.jcr.nodetype.ConstraintViolationException;\nimport javax.jcr.nodetype.NoSuchNodeTypeException;\nimport javax.jcr.nodetype.NodeDefinition;\nimport javax.jcr.nodetype.NodeType;\nimport javax.jcr.nodetype.NodeTypeManager;\nimport javax.jcr.nodetype.PropertyDefinition;\nimport javax.jcr.version.Version;\nimport javax.jcr.version.VersionException;\nimport javax.jcr.version.VersionHistory;\n\nimport com.google.common.base.Function;\nimport com.google.common.base.Predicate;\nimport com.google.common.base.Predicates;\nimport com.google.common.collect.Iterables;\nimport com.google.common.collect.Iterators;\nimport com.google.common.collect.Lists;\n\nimport org.apache.jackrabbit.JcrConstants;\nimport org.apache.jackrabbit.commons.ItemNameMatcher;\nimport org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;\nimport org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;\nimport org.apache.jackrabbit.oak.api.CommitFailedException;\nimport org.apache.jackrabbit.oak.api.ContentSession;\nimport org.apache.jackrabbit.oak.api.Root;\nimport org.apache.jackrabbit.oak.api.Tree;\nimport org.apache.jackrabbit.oak.api.Tree.Status;\nimport org.apache.jackrabbit.oak.commons.PathUtils;\nimport org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;\nimport org.apache.jackrabbit.oak.plugins.nodetype.DefinitionProvider;\nimport org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeType;\nimport org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;\nimport org.apache.jackrabbit.oak.util.TODO;\nimport org.apache.jackrabbit.value.ValueHelper;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\n\nimport static javax.jcr.Property.JCR_LOCK_IS_DEEP;\nimport static javax.jcr.Property.JCR_LOCK_OWNER;\n\n/**\n * TODO document\n * \n * @param the delegate type\n */\npublic class NodeImpl extends ItemImpl implements Node {\n\n /**\n * logger instance\n */\n private static final Logger log = LoggerFactory.getLogger(NodeImpl.class);\n\n public NodeImpl(T dlg) {\n super(dlg.getSessionDelegate(), dlg);\n }\n\n //---------------------------------------------------------------< Item >---\n\n /**\n * @see javax.jcr.Item#isNode()\n */\n @Override\n public boolean isNode() {\n return true;\n }\n\n /**\n * @see javax.jcr.Item#getParent()\n */\n @Override\n @Nonnull\n public Node getParent() throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation>() {\n @Override\n public NodeImpl perform() throws RepositoryException {\n if (dlg.isRoot()) {\n throw new ItemNotFoundException(\"Root has no parent\");\n } else {\n NodeDelegate parent = dlg.getParent();\n if (parent == null) {\n throw new AccessDeniedException();\n }\n return new NodeImpl(parent);\n }\n }\n });\n }\n\n /**\n * @see javax.jcr.Item#isNew()\n */\n @Override\n public boolean isNew() {\n try {\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Boolean perform() throws InvalidItemStateException {\n return !dlg.isStale() && dlg.getStatus() == Status.NEW;\n }\n });\n }\n catch (RepositoryException e) {\n return false;\n }\n }\n\n /**\n * @see javax.jcr.Item#isModified()\n */\n @Override\n public boolean isModified() {\n try {\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Boolean perform() throws InvalidItemStateException {\n return !dlg.isStale() && dlg.getStatus() == Status.MODIFIED;\n }\n });\n }\n catch (RepositoryException e) {\n return false;\n }\n }\n\n /**\n * @see javax.jcr.Item#remove()\n */\n @Override\n public void remove() throws RepositoryException {\n checkStatus();\n checkProtected();\n\n sessionDelegate.perform(new SessionOperation() {\n @Override\n public Void perform() throws RepositoryException {\n if (dlg.isRoot()) {\n throw new RepositoryException(\"Cannot remove the root node\");\n }\n\n dlg.remove();\n return null;\n }\n });\n }\n\n /**\n * @see Item#accept(javax.jcr.ItemVisitor)\n */\n @Override\n public void accept(ItemVisitor visitor) throws RepositoryException {\n checkStatus();\n visitor.visit(this);\n }\n\n //---------------------------------------------------------------< Node >---\n /**\n * @see Node#addNode(String)\n */\n @Override\n @Nonnull\n public Node addNode(String relPath) throws RepositoryException {\n checkStatus();\n return addNode(relPath, null);\n }\n\n @Override\n @Nonnull\n public Node addNode(final String relPath, final String primaryNodeTypeName) throws RepositoryException {\n checkStatus();\n checkProtected();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Node perform() throws RepositoryException {\n String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(relPath);\n String oakName = PathUtils.getName(oakPath);\n String parentPath = sessionDelegate.getOakPathOrThrow(PathUtils.getParentPath(oakPath));\n\n // handle index\n if (oakName.contains(\"[\")) {\n throw new RepositoryException(\"Cannot create a new node using a name including an index\");\n }\n\n NodeDelegate parent = dlg.getChild(parentPath);\n if (parent == null) {\n // is it a property?\n String grandParentPath = PathUtils.getParentPath(parentPath);\n NodeDelegate grandParent = dlg.getChild(grandParentPath);\n if (grandParent != null) {\n String propName = PathUtils.getName(parentPath);\n if (grandParent.getProperty(propName) != null) {\n throw new ConstraintViolationException(\"Can't add new node to property.\");\n }\n }\n\n throw new PathNotFoundException(relPath);\n }\n\n if (parent.getChild(oakName) != null) {\n throw new ItemExistsException(relPath);\n }\n\n String ntName = primaryNodeTypeName;\n if (ntName == null) {\n DefinitionProvider dp = sessionDelegate.getDefinitionProvider();\n try {\n String childName = sessionDelegate.getOakName(PathUtils.getName(relPath));\n NodeDefinition def = dp.getDefinition(new NodeImpl(parent), childName);\n ntName = def.getDefaultPrimaryTypeName();\n } catch (RepositoryException e) {\n throw new ConstraintViolationException(\n \"no matching child node definition found for \" + relPath);\n }\n }\n\n // TODO: figure out the right place for this check\n NodeTypeManager ntm = sessionDelegate.getNodeTypeManager();\n NodeType nt = ntm.getNodeType(ntName); // throws on not found\n if (nt.isAbstract() || nt.isMixin()) {\n throw new ConstraintViolationException();\n }\n // TODO: END\n\n NodeDelegate added = parent.addChild(oakName);\n if (added == null) {\n throw new ItemExistsException();\n }\n\n NodeImpl childNode = new NodeImpl(added);\n childNode.internalSetPrimaryType(ntName);\n childNode.autoCreateItems();\n return childNode;\n }\n });\n }\n\n @Override\n public void orderBefore(final String srcChildRelPath, final String destChildRelPath) throws RepositoryException {\n checkStatus();\n checkProtected();\n\n sessionDelegate.perform(new SessionOperation() {\n @Override\n public Void perform() throws RepositoryException {\n String oakSrcChildRelPath =\n sessionDelegate.getOakPathOrThrowNotFound(srcChildRelPath);\n String oakDestChildRelPath = null;\n if (destChildRelPath != null) {\n oakDestChildRelPath =\n sessionDelegate.getOakPathOrThrowNotFound(destChildRelPath);\n }\n dlg.orderBefore(oakSrcChildRelPath, oakDestChildRelPath);\n return null;\n }\n });\n }\n\n /**\n * @see Node#setProperty(String, javax.jcr.Value)\n */\n @Override\n @CheckForNull\n public Property setProperty(String name, Value value) throws RepositoryException {\n int type = PropertyType.UNDEFINED;\n if (value != null) {\n type = value.getType();\n }\n return internalSetProperty(name, value, type, false);\n }\n\n /**\n * @see Node#setProperty(String, javax.jcr.Value, int)\n */\n @Override\n @Nonnull\n public Property setProperty(String name, Value value, int type)\n throws RepositoryException {\n return internalSetProperty(name, value, type, type != PropertyType.UNDEFINED);\n }\n\n /**\n * @see Node#setProperty(String, javax.jcr.Value[])\n */\n @Override\n @Nonnull\n public Property setProperty(String name, Value[] values) throws RepositoryException {\n int type;\n if (values == null || values.length == 0 || values[0] == null) {\n type = PropertyType.UNDEFINED;\n } else {\n type = values[0].getType();\n }\n return internalSetProperty(name, values, type, false);\n }\n\n @Override\n @Nonnull\n public Property setProperty(String jcrName, Value[] values, int type) throws RepositoryException {\n return internalSetProperty(jcrName, values, type, true);\n }\n\n /**\n * @see Node#setProperty(String, String[])\n */\n @Override\n @Nonnull\n public Property setProperty(String name, String[] values) throws RepositoryException {\n return setProperty(name, values, PropertyType.UNDEFINED);\n }\n\n /**\n * @see Node#setProperty(String, String[], int)\n */\n @Override\n @Nonnull\n public Property setProperty(String name, String[] values, int type) throws RepositoryException {\n Value[] vs;\n if (type == PropertyType.UNDEFINED) {\n vs = ValueHelper.convert(values, PropertyType.STRING, getValueFactory());\n } else {\n vs = ValueHelper.convert(values, type, getValueFactory());\n }\n return internalSetProperty(name, vs, type, (type != PropertyType.UNDEFINED));\n }\n\n /**\n * @see Node#setProperty(String, String)\n */\n @Override\n @CheckForNull\n public Property setProperty(String name, String value) throws RepositoryException {\n Value v = (value == null) ? null : getValueFactory().createValue(value, PropertyType.STRING);\n return internalSetProperty(name, v, PropertyType.UNDEFINED, false);\n }\n\n /**\n * @see Node#setProperty(String, String, int)\n */\n @Override\n @CheckForNull\n public Property setProperty(String name, String value, int type) throws RepositoryException {\n Value v = (value == null) ? null : getValueFactory().createValue(value, type);\n return internalSetProperty(name, v, type, true);\n }\n\n /**\n * @see Node#setProperty(String, InputStream)\n */\n @SuppressWarnings(\"deprecation\")\n @Override\n @CheckForNull\n public Property setProperty(String name, InputStream value) throws RepositoryException {\n Value v = (value == null ? null : getValueFactory().createValue(value));\n return setProperty(name, v, PropertyType.BINARY);\n }\n\n /**\n * @see Node#setProperty(String, Binary)\n */\n @Override\n @CheckForNull\n public Property setProperty(String name, Binary value) throws RepositoryException {\n Value v = (value == null ? null : getValueFactory().createValue(value));\n return setProperty(name, v, PropertyType.BINARY);\n }\n\n /**\n * @see Node#setProperty(String, boolean)\n */\n @Override\n @Nonnull\n public Property setProperty(String name, boolean value) throws RepositoryException {\n return setProperty(name, getValueFactory().createValue(value), PropertyType.BOOLEAN);\n }\n\n /**\n * @see Node#setProperty(String, double)\n */\n @Override\n @Nonnull\n public Property setProperty(String name, double value) throws RepositoryException {\n return setProperty(name, getValueFactory().createValue(value), PropertyType.DOUBLE);\n }\n\n /**\n * @see Node#setProperty(String, BigDecimal)\n */\n @Override\n @CheckForNull\n public Property setProperty(String name, BigDecimal value) throws RepositoryException {\n Value v = (value == null ? null : getValueFactory().createValue(value));\n return setProperty(name, v, PropertyType.DECIMAL);\n }\n\n /**\n * @see Node#setProperty(String, long)\n */\n @Override\n @Nonnull\n public Property setProperty(String name, long value) throws RepositoryException {\n return setProperty(name, getValueFactory().createValue(value), PropertyType.LONG);\n }\n\n /**\n * @see Node#setProperty(String, Calendar)\n */\n @Override\n @CheckForNull\n public Property setProperty(String name, Calendar value) throws RepositoryException {\n Value v = (value == null ? null : getValueFactory().createValue(value));\n return setProperty(name, v, PropertyType.DATE);\n }\n\n /**\n * @see Node#setProperty(String, Node)\n */\n @Override\n @CheckForNull\n public Property setProperty(String name, Node value) throws RepositoryException {\n Value v = (value == null) ? null : getValueFactory().createValue(value);\n return setProperty(name, v, PropertyType.REFERENCE);\n }\n\n @Override\n @Nonnull\n public Node getNode(final String relPath) throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public NodeImpl perform() throws RepositoryException {\n String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);\n\n NodeDelegate nd = dlg.getChild(oakPath);\n if (nd == null) {\n throw new PathNotFoundException(relPath);\n } else {\n return new NodeImpl(nd);\n }\n }\n });\n }\n\n @Override\n @Nonnull\n public NodeIterator getNodes() throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public NodeIterator perform() throws RepositoryException {\n Iterator children = dlg.getChildren();\n long size = dlg.getChildCount();\n return new NodeIteratorAdapter(nodeIterator(children), size);\n }\n });\n }\n\n @Override\n @Nonnull\n public NodeIterator getNodes(final String namePattern)\n throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public NodeIterator perform() throws RepositoryException {\n Iterator children = Iterators.filter(dlg.getChildren(),\n new Predicate() {\n @Override\n public boolean apply(NodeDelegate state) {\n try {\n return ItemNameMatcher.matches(toJcrPath(state.getName()), namePattern);\n } catch (InvalidItemStateException e) {\n return false;\n }\n }\n });\n\n return new NodeIteratorAdapter(nodeIterator(children));\n }\n });\n }\n\n @Override\n @Nonnull\n public NodeIterator getNodes(final String[] nameGlobs) throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public NodeIterator perform() throws RepositoryException {\n Iterator children = Iterators.filter(dlg.getChildren(),\n new Predicate() {\n @Override\n public boolean apply(NodeDelegate state) {\n try {\n return ItemNameMatcher.matches(toJcrPath(state.getName()), nameGlobs);\n } catch (InvalidItemStateException e) {\n return false;\n }\n }\n });\n\n return new NodeIteratorAdapter(nodeIterator(children));\n }\n });\n }\n\n @Override\n @Nonnull\n public Property getProperty(final String relPath) throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public PropertyImpl perform() throws RepositoryException {\n String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);\n PropertyDelegate pd = dlg.getProperty(oakPath);\n if (pd == null) {\n throw new PathNotFoundException(relPath + \" not found on \" + getPath());\n } else {\n return new PropertyImpl(pd);\n }\n }\n });\n }\n\n @Override\n @Nonnull\n public PropertyIterator getProperties() throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public PropertyIterator perform() throws RepositoryException {\n Iterator properties = dlg.getProperties();\n long size = dlg.getPropertyCount();\n return new PropertyIteratorAdapter(propertyIterator(properties), size);\n }\n });\n }\n\n @Override\n @Nonnull\n public PropertyIterator getProperties(final String namePattern) throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public PropertyIterator perform() throws RepositoryException {\n Iterator properties = Iterators.filter(dlg.getProperties(),\n new Predicate() {\n @Override\n public boolean apply(PropertyDelegate entry) {\n try {\n return ItemNameMatcher.matches(toJcrPath(entry.getName()), namePattern);\n } catch (InvalidItemStateException e) {\n return false;\n }\n }\n });\n\n return new PropertyIteratorAdapter(propertyIterator(properties));\n }\n });\n }\n\n @Override\n @Nonnull\n public PropertyIterator getProperties(final String[] nameGlobs) throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public PropertyIterator perform() throws RepositoryException {\n Iterator propertyNames = Iterators.filter(dlg.getProperties(),\n new Predicate() {\n @Override\n public boolean apply(PropertyDelegate entry) {\n try {\n return ItemNameMatcher.matches(toJcrPath(entry.getName()), nameGlobs);\n } catch (InvalidItemStateException e) {\n return false;\n }\n }\n });\n\n return new PropertyIteratorAdapter(propertyIterator(propertyNames));\n }\n });\n }\n\n /**\n * @see javax.jcr.Node#getPrimaryItem()\n */\n @Override\n @Nonnull\n public Item getPrimaryItem() throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation- () {\n @Override\n public Item perform() throws RepositoryException {\n String name = getPrimaryNodeType().getPrimaryItemName();\n if (name == null) {\n throw new ItemNotFoundException(\"No primary item present on node \" + this);\n }\n if (hasProperty(name)) {\n return getProperty(name);\n } else if (hasNode(name)) {\n return getNode(name);\n } else {\n throw new ItemNotFoundException(\"Primary item \" + name + \" does not exist on node \" + this);\n }\n }\n });\n }\n\n /**\n * @see javax.jcr.Node#getUUID()\n */\n @Override\n @Nonnull\n public String getUUID() throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public String perform() throws RepositoryException {\n if (isNodeType(NodeType.MIX_REFERENCEABLE)) {\n return getIdentifier();\n }\n\n throw new UnsupportedRepositoryOperationException(\"Node is not referenceable.\");\n }\n });\n }\n\n @Override\n @Nonnull\n public String getIdentifier() throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public String perform() throws RepositoryException {\n return dlg.getIdentifier();\n }\n });\n }\n\n @Override\n public int getIndex() throws RepositoryException {\n // as long as we do not support same name siblings, index always is 1\n return 1;\n }\n\n /**\n * @see javax.jcr.Node#getReferences()\n */\n @Override\n @Nonnull\n public PropertyIterator getReferences() throws RepositoryException {\n return getReferences(null);\n }\n\n @Override\n @Nonnull\n public PropertyIterator getReferences(final String name) throws RepositoryException {\n checkStatus();\n return internalGetReferences(name, false);\n }\n\n /**\n * @see javax.jcr.Node#getWeakReferences()\n */\n @Override\n @Nonnull\n public PropertyIterator getWeakReferences() throws RepositoryException {\n return getWeakReferences(null);\n }\n\n @Override\n @Nonnull\n public PropertyIterator getWeakReferences(String name) throws RepositoryException {\n checkStatus();\n return internalGetReferences(name, true);\n }\n\n private PropertyIterator internalGetReferences(final String name, final boolean weak) throws RepositoryException {\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public PropertyIterator perform() throws InvalidItemStateException {\n IdentifierManager idManager = sessionDelegate.getIdManager();\n\n Set propertyOakPaths = idManager.getReferences(weak, dlg.getTree(), name);\n Iterable properties = Iterables.transform(\n propertyOakPaths,\n new Function() {\n @Override\n public Property apply(String oakPath) {\n PropertyDelegate pd = sessionDelegate.getProperty(oakPath);\n return pd == null ? null : new PropertyImpl(pd);\n }\n }\n );\n\n return new PropertyIteratorAdapter(properties.iterator(), propertyOakPaths.size());\n }\n });\n }\n\n @Override\n public boolean hasNode(final String relPath) throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Boolean perform() throws RepositoryException {\n String oakPath = sessionDelegate.getOakPathOrThrow(relPath);\n return dlg.getChild(oakPath) != null;\n }\n });\n }\n\n @Override\n public boolean hasProperty(final String relPath) throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Boolean perform() throws RepositoryException {\n String oakPath = sessionDelegate.getOakPathOrThrow(relPath);\n return dlg.getProperty(oakPath) != null;\n }\n });\n }\n\n @Override\n public boolean hasNodes() throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Boolean perform() throws RepositoryException {\n return dlg.getChildCount() != 0;\n }\n });\n }\n\n @Override\n public boolean hasProperties() throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Boolean perform() throws RepositoryException {\n return dlg.getPropertyCount() != 0;\n }\n });\n }\n\n /**\n * @see javax.jcr.Node#getPrimaryNodeType()\n */\n @Override\n @Nonnull\n public NodeType getPrimaryNodeType() throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public NodeType perform() throws RepositoryException {\n NodeTypeManager ntMgr = sessionDelegate.getNodeTypeManager();\n String primaryNtName;\n if (hasProperty(Property.JCR_PRIMARY_TYPE)) {\n primaryNtName = getProperty(Property.JCR_PRIMARY_TYPE).getString();\n } else {\n throw new RepositoryException(\"Node \" + getPath() + \" doesn't have primary type set.\");\n }\n return ntMgr.getNodeType(primaryNtName);\n }\n });\n }\n\n /**\n * @see javax.jcr.Node#getMixinNodeTypes()\n */\n @Override\n @Nonnull\n public NodeType[] getMixinNodeTypes() throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public NodeType[] perform() throws RepositoryException {\n // TODO: check if transient changes to mixin-types are reflected here\n if (hasProperty(Property.JCR_MIXIN_TYPES)) {\n NodeTypeManager ntMgr = sessionDelegate.getNodeTypeManager();\n Value[] mixinNames = getProperty(Property.JCR_MIXIN_TYPES).getValues();\n NodeType[] mixinTypes = new NodeType[mixinNames.length];\n for (int i = 0; i < mixinNames.length; i++) {\n mixinTypes[i] = ntMgr.getNodeType(mixinNames[i].getString());\n }\n return mixinTypes;\n } else {\n return new NodeType[0];\n }\n }\n });\n }\n\n @Override\n public boolean isNodeType(final String nodeTypeName) throws RepositoryException {\n checkStatus();\n\n String oakName = sessionDelegate.getOakName(nodeTypeName);\n return sessionDelegate.getEffectiveNodeTypeProvider().isNodeType(dlg.getTree(), oakName);\n }\n\n @Override\n public void setPrimaryType(final String nodeTypeName) throws RepositoryException {\n checkStatus();\n checkProtected();\n if (!isCheckedOut()) {\n throw new VersionException(\"Cannot set primary type. Node is \" +\n \"checked in.\");\n }\n\n internalSetPrimaryType(nodeTypeName);\n }\n\n @Override\n public void addMixin(final String mixinName) throws RepositoryException {\n checkStatus();\n checkProtected();\n\n sessionDelegate.perform(new SessionOperation() {\n @Override\n public Void perform() throws RepositoryException {\n // TODO: figure out the right place for this check\n NodeTypeManager ntm = sessionDelegate.getNodeTypeManager();\n ntm.getNodeType(mixinName); // throws on not found\n // TODO: END\n\n PropertyDelegate mixins = dlg.getProperty(JcrConstants.JCR_MIXINTYPES);\n Value value = sessionDelegate.getValueFactory().createValue(mixinName, PropertyType.NAME);\n\n boolean nodeModified = false;\n if (mixins == null) {\n nodeModified = true;\n dlg.setProperty(JcrConstants.JCR_MIXINTYPES, Collections.singletonList(value));\n } else {\n List values = mixins.getValues();\n if (!values.contains(value)) {\n values.add(value);\n nodeModified = true;\n dlg.setProperty(JcrConstants.JCR_MIXINTYPES, values);\n }\n }\n\n if (nodeModified) {\n autoCreateItems();\n }\n return null;\n }\n });\n }\n\n @Override\n public void removeMixin(final String mixinName) throws RepositoryException {\n checkStatus();\n checkProtected();\n\n sessionDelegate.perform(new SessionOperation() {\n @Override\n public Void perform() throws RepositoryException {\n if (!isNodeType(mixinName)) {\n throw new NoSuchNodeTypeException();\n }\n\n throw new ConstraintViolationException();\n }\n });\n }\n\n @Override\n public boolean canAddMixin(final String mixinName) throws RepositoryException {\n checkStatus();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Boolean perform() throws RepositoryException {\n // TODO: figure out the right place for this check\n NodeTypeManager ntm = sessionDelegate.getNodeTypeManager();\n ntm.getNodeType(mixinName); // throws on not found\n // TODO: END\n\n return isSupportedMixinName(mixinName) && isCheckedOut();\n }\n });\n }\n\n @Override\n @Nonnull\n public NodeDefinition getDefinition() throws RepositoryException {\n if (getDepth() == 0) {\n return dlg.sessionDelegate.getDefinitionProvider().getRootDefinition();\n } else {\n return dlg.sessionDelegate.getDefinitionProvider().getDefinition(getParent(), this);\n }\n }\n\n @Override\n @Nonnull\n public String getCorrespondingNodePath(String workspaceName) throws RepositoryException {\n checkStatus();\n checkValidWorkspace(workspaceName);\n throw new UnsupportedRepositoryOperationException(\"TODO: Node.getCorrespondingNodePath\");\n }\n\n\n @Override\n public void update(String srcWorkspace) throws RepositoryException {\n checkStatus();\n checkValidWorkspace(srcWorkspace);\n ensureNoPendingSessionChanges();\n\n // TODO\n }\n\n /**\n * @see javax.jcr.Node#checkin()\n */\n @Override\n @Nonnull\n public Version checkin() throws RepositoryException {\n return sessionDelegate.getVersionManager().checkin(getPath());\n }\n\n /**\n * @see javax.jcr.Node#checkout()\n */\n @Override\n public void checkout() throws RepositoryException {\n sessionDelegate.getVersionManager().checkout(getPath());\n }\n\n /**\n * @see javax.jcr.Node#doneMerge(javax.jcr.version.Version)\n */\n @Override\n public void doneMerge(Version version) throws RepositoryException {\n sessionDelegate.getVersionManager().doneMerge(getPath(), version);\n }\n\n /**\n * @see javax.jcr.Node#cancelMerge(javax.jcr.version.Version)\n */\n @Override\n public void cancelMerge(Version version) throws RepositoryException {\n sessionDelegate.getVersionManager().cancelMerge(getPath(), version);\n }\n\n /**\n * @see javax.jcr.Node#merge(String, boolean)\n */\n @Override\n @Nonnull\n public NodeIterator merge(String srcWorkspace, boolean bestEffort) throws RepositoryException {\n return sessionDelegate.getVersionManager().merge(getPath(), srcWorkspace, bestEffort);\n }\n\n /**\n * @see javax.jcr.Node#isCheckedOut()\n */\n @Override\n public boolean isCheckedOut() throws RepositoryException {\n try {\n return sessionDelegate.getVersionManager().isCheckedOut(getPath());\n } catch (UnsupportedRepositoryOperationException ex) {\n // when versioning is not supported all nodes are considered to be\n // checked out\n return true;\n }\n }\n\n /**\n * @see javax.jcr.Node#restore(String, boolean)\n */\n @Override\n public void restore(String versionName, boolean removeExisting) throws RepositoryException {\n sessionDelegate.getVersionManager().restore(getPath(), versionName, removeExisting);\n }\n\n /**\n * @see javax.jcr.Node#restore(javax.jcr.version.Version, boolean)\n */\n @Override\n public void restore(Version version, boolean removeExisting) throws RepositoryException {\n sessionDelegate.getVersionManager().restore(version, removeExisting);\n }\n\n /**\n * @see javax.jcr.Node#restore(Version, String, boolean)\n */\n @Override\n public void restore(Version version, String relPath, boolean removeExisting) throws RepositoryException {\n // additional checks are performed with subsequent calls.\n if (hasNode(relPath)) {\n // node at 'relPath' exists -> call restore on the target Node\n getNode(relPath).restore(version, removeExisting);\n } else {\n // TODO\n }\n }\n\n /**\n * @see javax.jcr.Node#restoreByLabel(String, boolean)\n */\n @Override\n public void restoreByLabel(String versionLabel, boolean removeExisting) throws RepositoryException {\n sessionDelegate.getVersionManager().restoreByLabel(getPath(), versionLabel, removeExisting);\n }\n\n /**\n * @see javax.jcr.Node#getVersionHistory()\n */\n @Override\n @Nonnull\n public VersionHistory getVersionHistory() throws RepositoryException {\n return sessionDelegate.getVersionManager().getVersionHistory(getPath());\n }\n\n /**\n * @see javax.jcr.Node#getBaseVersion()\n */\n @Override\n @Nonnull\n public Version getBaseVersion() throws RepositoryException {\n return sessionDelegate.getVersionManager().getBaseVersion(getPath());\n }\n\n /**\n * Checks whether this node is locked by looking for the\n * {@code jcr:lockOwner} property either on this node or\n * on any ancestor that also has the {@code jcr:lockIsDeep}\n * property set to {@code true}.\n */\n @Override\n public boolean isLocked() throws RepositoryException {\n String lockOwner = sessionDelegate.getOakPathOrThrow(JCR_LOCK_OWNER);\n String lockIsDeep = sessionDelegate.getOakPathOrThrow(JCR_LOCK_IS_DEEP);\n\n if (dlg.getProperty(lockOwner) != null) {\n return true;\n }\n\n NodeDelegate parent = dlg.getParent();\n while (parent != null) {\n if (parent.getProperty(lockOwner) != null) {\n PropertyDelegate isDeep = parent.getProperty(lockIsDeep);\n if (isDeep != null && !isDeep.isMultivalue()\n && isDeep.getValue().getBoolean()) {\n return true;\n }\n }\n parent = parent.getParent();\n }\n\n return false;\n }\n\n /**\n * Checks whether this node holds a lock by looking for the\n * {@code jcr:lockOwner} property.\n */\n @Override\n public boolean holdsLock() throws RepositoryException {\n String lockOwner = sessionDelegate.getOakPathOrThrow(JCR_LOCK_OWNER);\n return dlg.getProperty(lockOwner) != null;\n }\n\n /**\n * @see javax.jcr.Node#getLock()\n */\n @Override\n @Nonnull\n public Lock getLock() throws RepositoryException {\n throw new UnsupportedRepositoryOperationException();\n }\n\n /**\n * @see javax.jcr.Node#lock(boolean, boolean)\n */\n @Override\n @Nonnull\n public Lock lock(final boolean isDeep, boolean isSessionScoped)\n throws RepositoryException {\n final String userID = getSession().getUserID();\n\n String lockOwner = sessionDelegate.getOakPathOrThrow(JCR_LOCK_OWNER);\n String lockIsDeep = sessionDelegate.getOakPathOrThrow(JCR_LOCK_IS_DEEP);\n try {\n ContentSession session = sessionDelegate.getContentSession();\n Root root = session.getLatestRoot();\n Tree tree = root.getTree(dlg.getPath());\n if (tree == null) {\n throw new ItemNotFoundException();\n }\n tree.setProperty(lockOwner, userID);\n tree.setProperty(lockIsDeep, isDeep);\n root.commit(); // TODO: fail instead?\n } catch (CommitFailedException e) {\n throw new RepositoryException(\"Unable to lock \" + this, e);\n }\n\n getSession().refresh(true);\n\n if (isSessionScoped) {\n return TODO.dummyImplementation().returnValue(new Lock() {\n @Override\n public String getLockOwner() {\n return userID;\n }\n\n @Override\n public boolean isDeep() {\n return isDeep;\n }\n\n @Override\n public Node getNode() {\n return NodeImpl.this;\n }\n\n @Override\n public String getLockToken() {\n return null;\n }\n\n @Override\n public long getSecondsRemaining() {\n return Long.MAX_VALUE;\n }\n\n @Override\n public boolean isLive() {\n return true;\n }\n\n @Override\n public boolean isSessionScoped() {\n return true;\n }\n\n @Override\n public boolean isLockOwningSession() {\n return true;\n }\n\n @Override\n public void refresh() {\n }\n });\n }\n\n return getLock();\n }\n\n /**\n * @see javax.jcr.Node#unlock()\n */\n @Override\n public void unlock() throws RepositoryException {\n String lockOwner = sessionDelegate.getOakPathOrThrow(JCR_LOCK_OWNER);\n String lockIsDeep = sessionDelegate.getOakPathOrThrow(JCR_LOCK_IS_DEEP);\n try {\n Root root = sessionDelegate.getContentSession().getLatestRoot();\n Tree tree = root.getTree(dlg.getPath());\n if (tree == null) {\n throw new ItemNotFoundException();\n }\n tree.removeProperty(lockOwner);\n tree.removeProperty(lockIsDeep);\n root.commit();\n } catch (CommitFailedException e) {\n throw new RepositoryException(\"Unable to unlock \" + this, e);\n }\n\n getSession().refresh(true);\n }\n\n @Override\n @Nonnull\n public NodeIterator getSharedSet() throws RepositoryException {\n throw new UnsupportedRepositoryOperationException(\"TODO: Node.getSharedSet\");\n }\n\n @Override\n public void removeSharedSet() throws RepositoryException {\n throw new UnsupportedRepositoryOperationException(\"TODO: Node.removeSharedSet\");\n }\n\n @Override\n public void removeShare() throws RepositoryException {\n throw new UnsupportedRepositoryOperationException(\"TODO: Node.removeShare\");\n }\n\n /**\n * @see javax.jcr.Node#followLifecycleTransition(String)\n */\n @Override\n public void followLifecycleTransition(String transition) throws RepositoryException {\n throw new UnsupportedRepositoryOperationException(\"Lifecycle Management is not supported\");\n }\n\n /**\n * @see javax.jcr.Node#getAllowedLifecycleTransistions()\n */\n @Override\n @Nonnull\n public String[] getAllowedLifecycleTransistions() throws RepositoryException {\n throw new UnsupportedRepositoryOperationException(\"Lifecycle Management is not supported\");\n\n }\n\n //------------------------------------------------------------< private >---\n\n private static Iterator nodeIterator(Iterator childNodes) {\n return Iterators.transform(\n childNodes,\n new Function() {\n @Override\n public Node apply(NodeDelegate nodeDelegate) {\n return new NodeImpl(nodeDelegate);\n }\n });\n }\n\n private static Iterator propertyIterator(Iterator properties) {\n return Iterators.transform(\n properties,\n new Function() {\n @Override\n public Property apply(PropertyDelegate propertyDelegate) {\n return new PropertyImpl(propertyDelegate);\n }\n });\n }\n\n private static int getTargetType(Value value, PropertyDefinition definition) {\n if (definition.getRequiredType() == PropertyType.UNDEFINED) {\n return value.getType();\n } else {\n return definition.getRequiredType();\n }\n }\n\n private static int getTargetType(Value[] values, PropertyDefinition definition) {\n if (definition.getRequiredType() == PropertyType.UNDEFINED) {\n if (values.length != 0) {\n for (Value v : values) {\n if (v != null) {\n return v.getType();\n }\n }\n }\n return PropertyType.STRING;\n } else {\n return definition.getRequiredType();\n }\n }\n\n private void autoCreateItems() throws RepositoryException {\n EffectiveNodeType effective = dlg.sessionDelegate.getEffectiveNodeTypeProvider().getEffectiveNodeType(this);\n for (PropertyDefinition pd : effective.getAutoCreatePropertyDefinitions()) {\n if (dlg.getProperty(pd.getName()) == null) {\n if (pd.isMultiple()) {\n dlg.setProperty(pd.getName(), getAutoCreatedValues(pd));\n } else {\n dlg.setProperty(pd.getName(), getAutoCreatedValue(pd));\n }\n }\n }\n for (NodeDefinition nd : effective.getAutoCreateNodeDefinitions()) {\n if (dlg.getChild(nd.getName()) == null) {\n autoCreateNode(nd);\n }\n }\n }\n\n private Value getAutoCreatedValue(PropertyDefinition definition)\n throws RepositoryException {\n String name = definition.getName();\n String declaringNT = definition.getDeclaringNodeType().getName();\n\n if (NodeTypeConstants.JCR_UUID.equals(name)) {\n // jcr:uuid property of the mix:referenceable node type\n if (NodeTypeConstants.MIX_REFERENCEABLE.equals(declaringNT)) {\n return getValueFactory().createValue(IdentifierManager.generateUUID());\n }\n } else if (NodeTypeConstants.JCR_CREATED.equals(name)) {\n // jcr:created property of a version or a mix:created\n if (NodeTypeConstants.MIX_CREATED.equals(declaringNT)\n || NodeTypeConstants.NT_VERSION.equals(declaringNT)) {\n return getValueFactory().createValue(Calendar.getInstance());\n }\n } else if (NodeTypeConstants.JCR_CREATEDBY.equals(name)) {\n String userID = sessionDelegate.getAuthInfo().getUserID();\n // jcr:createdBy property of a mix:created\n if (userID != null\n && NodeTypeConstants.MIX_CREATED.equals(declaringNT)) {\n return getValueFactory().createValue(userID);\n }\n } else if (NodeTypeConstants.JCR_LASTMODIFIED.equals(name)) {\n // jcr:lastModified property of a mix:lastModified\n if (NodeTypeConstants.MIX_LASTMODIFIED.equals(declaringNT)) {\n return getValueFactory().createValue(Calendar.getInstance());\n }\n } else if (NodeTypeConstants.JCR_LASTMODIFIEDBY.equals(name)) {\n String userID = sessionDelegate.getAuthInfo().getUserID();\n // jcr:lastModifiedBy property of a mix:lastModified\n if (userID != null\n && NodeTypeConstants.MIX_LASTMODIFIED.equals(declaringNT)) {\n return getValueFactory().createValue(userID);\n }\n }\n // does the definition have a default value?\n if (definition.getDefaultValues() != null) {\n Value[] values = definition.getDefaultValues();\n if (values.length > 0) {\n return values[0];\n }\n }\n throw new RepositoryException(\"Unable to auto-create value for \" +\n PathUtils.concat(getPath(), name));\n }\n\n private Iterable getAutoCreatedValues(PropertyDefinition definition)\n throws RepositoryException {\n String name = definition.getName();\n\n // default values?\n if (definition.getDefaultValues() != null) {\n return Lists.newArrayList(definition.getDefaultValues());\n }\n throw new RepositoryException(\"Unable to auto-create value for \" +\n PathUtils.concat(getPath(), name));\n }\n\n private void autoCreateNode(NodeDefinition definition)\n throws RepositoryException {\n addNode(definition.getName(), definition.getDefaultPrimaryTypeName());\n }\n\n // FIXME OAK-505: hack to filter for a subset of supported mixins for now\n // this allows only harmless mixin types so that other code like addMixin gets test coverage\n private boolean isSupportedMixinName(String mixinName) throws RepositoryException {\n String oakName = sessionDelegate.getOakPathOrThrow(mixinName);\n return \"mix:title\".equals(oakName) ||\n NodeTypeConstants.MIX_REFERENCEABLE.equals(oakName) ||\n NodeTypeConstants.MIX_VERSIONABLE.equals(oakName) ||\n NodeTypeConstants.MIX_LOCKABLE.equals(oakName);\n }\n\n private void checkValidWorkspace(String workspaceName) throws RepositoryException {\n for (String wn : sessionDelegate.getWorkspace().getAccessibleWorkspaceNames()) {\n if (wn.equals(workspaceName)) {\n return;\n }\n }\n throw new NoSuchWorkspaceException(workspaceName + \" does not exist.\");\n }\n\n private void internalSetPrimaryType(final String nodeTypeName) throws RepositoryException {\n sessionDelegate.perform(new SessionOperation() {\n @Override\n public Void perform() throws RepositoryException {\n // TODO: figure out the right place for this check\n NodeTypeManager ntm = sessionDelegate.getNodeTypeManager();\n NodeType nt = ntm.getNodeType(nodeTypeName); // throws on not found\n if (nt.isAbstract() || nt.isMixin()) {\n throw new ConstraintViolationException();\n }\n // TODO: END\n\n String jcrPrimaryType = sessionDelegate.getOakPathOrThrow(Property.JCR_PRIMARY_TYPE);\n Value value = sessionDelegate.getValueFactory().createValue(nodeTypeName, PropertyType.NAME);\n dlg.setProperty(jcrPrimaryType, value);\n return null;\n }\n });\n }\n\n private Property internalSetProperty(final String jcrName, final Value value,\n final int type, final boolean exactTypeMatch) throws RepositoryException {\n checkStatus();\n checkProtected();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Property perform() throws RepositoryException {\n String oakName = sessionDelegate.getOakPathOrThrow(jcrName);\n if (value == null) {\n if (hasProperty(jcrName)) {\n Property property = getProperty(jcrName);\n property.remove();\n return property;\n } else {\n // Return a property instance which throws on access. See OAK-395\n return new PropertyImpl(new PropertyDelegate(\n sessionDelegate, dlg.getLocation().getChild(oakName)));\n }\n } else {\n PropertyDefinition definition;\n if (hasProperty(jcrName)) {\n definition = getProperty(jcrName).getDefinition();\n } else {\n definition = dlg.sessionDelegate.getDefinitionProvider().getDefinition(NodeImpl.this, oakName, false, type, exactTypeMatch);\n }\n checkProtected(definition);\n if (definition.isMultiple()) {\n throw new ValueFormatException(\"Cannot set single value to multivalued property\");\n }\n\n int targetType = getTargetType(value, definition);\n Value targetValue = ValueHelper.convert(value, targetType, getValueFactory());\n\n return new PropertyImpl(dlg.setProperty(oakName, targetValue));\n }\n }\n });\n }\n\n private Property internalSetProperty(final String jcrName, final Value[] values,\n final int type, final boolean exactTypeMatch) throws RepositoryException {\n checkStatus();\n checkProtected();\n\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Property perform() throws RepositoryException {\n String oakName = sessionDelegate.getOakPathOrThrow(jcrName);\n if (values == null) {\n if (hasProperty(jcrName)) {\n Property property = getProperty(jcrName);\n property.remove();\n return property;\n } else {\n return new PropertyImpl(new PropertyDelegate(\n sessionDelegate, dlg.getLocation().getChild(oakName)));\n }\n } else {\n PropertyDefinition definition;\n if (hasProperty(jcrName)) {\n definition = getProperty(jcrName).getDefinition();\n } else {\n definition = dlg.sessionDelegate.getDefinitionProvider().getDefinition(NodeImpl.this, oakName, true, type, exactTypeMatch);\n }\n checkProtected(definition);\n if (!definition.isMultiple()) {\n throw new ValueFormatException(\"Cannot set value array to single value property\");\n }\n\n int targetType = getTargetType(values, definition);\n Value[] targetValues = ValueHelper.convert(values, targetType, getValueFactory());\n\n Iterable nonNullValues = Iterables.filter(\n Arrays.asList(targetValues),\n Predicates.notNull());\n return new PropertyImpl(dlg.setProperty(oakName, nonNullValues));\n }\n }\n });\n }\n}\n
===================================================================
--- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java (revision 5fdaf7a63b9a1f0a11099754834c910a50348461)
+++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java (revision )
@@ -221,9 +221,9 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public Node perform() throws RepositoryException {
- String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(relPath);
+ String oakPath = sessionDelegate.getOakPathKeepIndex(relPath);
String oakName = PathUtils.getName(oakPath);
- String parentPath = sessionDelegate.getOakPathOrThrow(PathUtils.getParentPath(oakPath));
+ String parentPath = sessionDelegate.getOakPath(PathUtils.getParentPath(oakPath));
// handle index
if (oakName.contains("[")) {
@@ -292,11 +292,11 @@
@Override
public Void perform() throws RepositoryException {
String oakSrcChildRelPath =
- sessionDelegate.getOakPathOrThrowNotFound(srcChildRelPath);
+ sessionDelegate.getOakPath(srcChildRelPath);
String oakDestChildRelPath = null;
if (destChildRelPath != null) {
oakDestChildRelPath =
- sessionDelegate.getOakPathOrThrowNotFound(destChildRelPath);
+ sessionDelegate.getOakPath(destChildRelPath);
}
dlg.orderBefore(oakSrcChildRelPath, oakDestChildRelPath);
return null;
@@ -478,7 +478,7 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public NodeImpl perform() throws RepositoryException {
- String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);
+ String oakPath = sessionDelegate.getOakPath(relPath);
NodeDelegate nd = dlg.getChild(oakPath);
if (nd == null) {
@@ -564,7 +564,7 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public PropertyImpl perform() throws RepositoryException {
- String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);
+ String oakPath = sessionDelegate.getOakPath(relPath);
PropertyDelegate pd = dlg.getProperty(oakPath);
if (pd == null) {
throw new PathNotFoundException(relPath + " not found on " + getPath());
@@ -767,7 +767,7 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public Boolean perform() throws RepositoryException {
- String oakPath = sessionDelegate.getOakPathOrThrow(relPath);
+ String oakPath = sessionDelegate.getOakPath(relPath);
return dlg.getChild(oakPath) != null;
}
});
@@ -780,7 +780,7 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public Boolean perform() throws RepositoryException {
- String oakPath = sessionDelegate.getOakPathOrThrow(relPath);
+ String oakPath = sessionDelegate.getOakPath(relPath);
return dlg.getProperty(oakPath) != null;
}
});
@@ -1099,8 +1099,8 @@
*/
@Override
public boolean isLocked() throws RepositoryException {
- String lockOwner = sessionDelegate.getOakPathOrThrow(JCR_LOCK_OWNER);
- String lockIsDeep = sessionDelegate.getOakPathOrThrow(JCR_LOCK_IS_DEEP);
+ String lockOwner = sessionDelegate.getOakPath(JCR_LOCK_OWNER);
+ String lockIsDeep = sessionDelegate.getOakPath(JCR_LOCK_IS_DEEP);
if (dlg.getProperty(lockOwner) != null) {
return true;
@@ -1127,7 +1127,7 @@
*/
@Override
public boolean holdsLock() throws RepositoryException {
- String lockOwner = sessionDelegate.getOakPathOrThrow(JCR_LOCK_OWNER);
+ String lockOwner = sessionDelegate.getOakPath(JCR_LOCK_OWNER);
return dlg.getProperty(lockOwner) != null;
}
@@ -1149,8 +1149,8 @@
throws RepositoryException {
final String userID = getSession().getUserID();
- String lockOwner = sessionDelegate.getOakPathOrThrow(JCR_LOCK_OWNER);
- String lockIsDeep = sessionDelegate.getOakPathOrThrow(JCR_LOCK_IS_DEEP);
+ String lockOwner = sessionDelegate.getOakPath(JCR_LOCK_OWNER);
+ String lockIsDeep = sessionDelegate.getOakPath(JCR_LOCK_IS_DEEP);
try {
ContentSession session = sessionDelegate.getContentSession();
Root root = session.getLatestRoot();
@@ -1223,8 +1223,8 @@
*/
@Override
public void unlock() throws RepositoryException {
- String lockOwner = sessionDelegate.getOakPathOrThrow(JCR_LOCK_OWNER);
- String lockIsDeep = sessionDelegate.getOakPathOrThrow(JCR_LOCK_IS_DEEP);
+ String lockOwner = sessionDelegate.getOakPath(JCR_LOCK_OWNER);
+ String lockIsDeep = sessionDelegate.getOakPath(JCR_LOCK_IS_DEEP);
try {
Root root = sessionDelegate.getContentSession().getLatestRoot();
Tree tree = root.getTree(dlg.getPath());
@@ -1407,7 +1407,7 @@
// FIXME OAK-505: hack to filter for a subset of supported mixins for now
// this allows only harmless mixin types so that other code like addMixin gets test coverage
private boolean isSupportedMixinName(String mixinName) throws RepositoryException {
- String oakName = sessionDelegate.getOakPathOrThrow(mixinName);
+ String oakName = sessionDelegate.getOakPath(mixinName);
return "mix:title".equals(oakName) ||
NodeTypeConstants.MIX_REFERENCEABLE.equals(oakName) ||
NodeTypeConstants.MIX_VERSIONABLE.equals(oakName) ||
@@ -1435,7 +1435,7 @@
}
// TODO: END
- String jcrPrimaryType = sessionDelegate.getOakPathOrThrow(Property.JCR_PRIMARY_TYPE);
+ String jcrPrimaryType = sessionDelegate.getOakPath(Property.JCR_PRIMARY_TYPE);
Value value = sessionDelegate.getValueFactory().createValue(nodeTypeName, PropertyType.NAME);
dlg.setProperty(jcrPrimaryType, value);
return null;
@@ -1451,7 +1451,7 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public Property perform() throws RepositoryException {
- String oakName = sessionDelegate.getOakPathOrThrow(jcrName);
+ String oakName = sessionDelegate.getOakPath(jcrName);
if (value == null) {
if (hasProperty(jcrName)) {
Property property = getProperty(jcrName);
@@ -1491,7 +1491,7 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public Property perform() throws RepositoryException {
- String oakName = sessionDelegate.getOakPathOrThrow(jcrName);
+ String oakName = sessionDelegate.getOakPath(jcrName);
if (values == null) {
if (hasProperty(jcrName)) {
Property property = getProperty(jcrName);
Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
<+>/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements. See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with\n * the License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.apache.jackrabbit.oak.jcr.version;\n\nimport javax.jcr.InvalidItemStateException;\nimport javax.jcr.ItemExistsException;\nimport javax.jcr.Node;\nimport javax.jcr.NodeIterator;\nimport javax.jcr.PathNotFoundException;\nimport javax.jcr.RepositoryException;\nimport javax.jcr.UnsupportedRepositoryOperationException;\nimport javax.jcr.lock.LockException;\nimport javax.jcr.version.Version;\nimport javax.jcr.version.VersionException;\nimport javax.jcr.version.VersionHistory;\nimport javax.jcr.version.VersionManager;\n\nimport org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;\nimport org.apache.jackrabbit.oak.jcr.NodeDelegate;\nimport org.apache.jackrabbit.oak.jcr.SessionDelegate;\nimport org.apache.jackrabbit.oak.jcr.SessionOperation;\nimport org.apache.jackrabbit.oak.util.TODO;\n\npublic class VersionManagerImpl implements VersionManager {\n\n private final VersionManagerDelegate versionManagerDelegate;\n\n public VersionManagerImpl(SessionDelegate sessionDelegate) {\n this.versionManagerDelegate = VersionManagerDelegate.create(sessionDelegate);\n }\n\n @Override\n public Node setActivity(Node activity) throws RepositoryException {\n return TODO.unimplemented().returnValue(null);\n }\n\n @Override\n public void restoreByLabel(\n String absPath, String versionLabel, boolean removeExisting)\n throws RepositoryException {\n TODO.unimplemented().doNothing();\n }\n\n @Override\n public void restore(\n String absPath, Version version, boolean removeExisting)\n throws RepositoryException {\n TODO.unimplemented().doNothing();\n }\n\n @Override\n public void restore(\n String absPath, String versionName, boolean removeExisting)\n throws RepositoryException {\n TODO.unimplemented().doNothing();\n }\n\n @Override\n public void restore(Version version, boolean removeExisting)\n throws RepositoryException {\n TODO.unimplemented().doNothing();\n }\n\n @Override\n public void restore(Version[] versions, boolean removeExisting)\n throws ItemExistsException,\n UnsupportedRepositoryOperationException, VersionException,\n LockException, InvalidItemStateException, RepositoryException {\n TODO.unimplemented().doNothing();\n }\n\n @Override\n public void removeActivity(Node activityNode)\n throws RepositoryException {\n TODO.unimplemented().doNothing();\n }\n\n @Override\n public NodeIterator merge(\n String absPath, String srcWorkspace,\n boolean bestEffort, boolean isShallow)\n throws RepositoryException {\n return TODO.unimplemented().returnValue(NodeIteratorAdapter.EMPTY);\n }\n\n @Override\n public NodeIterator merge(\n String absPath, String srcWorkspace, boolean bestEffort)\n throws RepositoryException {\n return TODO.unimplemented().returnValue(NodeIteratorAdapter.EMPTY);\n }\n\n @Override\n public NodeIterator merge(Node activityNode) throws RepositoryException {\n return TODO.unimplemented().returnValue(NodeIteratorAdapter.EMPTY);\n }\n\n @Override\n public boolean isCheckedOut(final String absPath) throws RepositoryException {\n final SessionDelegate sessionDelegate = versionManagerDelegate.getSessionDelegate();\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Boolean perform() throws RepositoryException {\n String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);\n NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);\n if (nodeDelegate == null) {\n throw new PathNotFoundException(absPath);\n }\n return versionManagerDelegate.isCheckedOut(nodeDelegate);\n }\n });\n }\n\n @Override\n public VersionHistory getVersionHistory(final String absPath)\n throws RepositoryException {\n final SessionDelegate sessionDelegate = versionManagerDelegate.getSessionDelegate();\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public VersionHistory perform() throws RepositoryException {\n String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);\n NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);\n if (nodeDelegate == null) {\n throw new PathNotFoundException(absPath);\n }\n return new VersionHistoryImpl(\n versionManagerDelegate.getVersionHistory(nodeDelegate));\n }\n });\n }\n\n @Override\n public Version getBaseVersion(final String absPath) throws RepositoryException {\n final SessionDelegate sessionDelegate = versionManagerDelegate.getSessionDelegate();\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Version perform() throws RepositoryException {\n String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);\n NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);\n if (nodeDelegate == null) {\n throw new PathNotFoundException(absPath);\n }\n return new VersionImpl(\n versionManagerDelegate.getBaseVersion(nodeDelegate));\n }\n });\n }\n\n @Override\n public Node getActivity() throws RepositoryException {\n return TODO.unimplemented().returnValue(null);\n }\n\n @Override\n public void doneMerge(String absPath, Version version)\n throws RepositoryException {\n TODO.unimplemented().doNothing();\n }\n\n @Override\n public Node createConfiguration(String absPath) throws RepositoryException {\n return TODO.unimplemented().returnValue(null);\n }\n\n @Override\n public Node createActivity(String title) throws RepositoryException {\n return TODO.unimplemented().returnValue(null);\n }\n\n @Override\n public Version checkpoint(String absPath) throws RepositoryException {\n return TODO.unimplemented().returnValue(null);\n }\n\n @Override\n public void checkout(final String absPath) throws RepositoryException {\n if (true) {\n TODO.unimplemented().doNothing();\n }\n final SessionDelegate sessionDelegate = versionManagerDelegate.getSessionDelegate();\n sessionDelegate.perform(new SessionOperation() {\n @Override\n public Void perform() throws RepositoryException {\n String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);\n NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);\n if (nodeDelegate == null) {\n throw new PathNotFoundException(absPath);\n }\n if (sessionDelegate.getLockManager().isLocked(absPath)) {\n throw new LockException(\"Node at \" + absPath + \" is locked\");\n }\n versionManagerDelegate.checkout(nodeDelegate);\n return null;\n }\n });\n }\n\n @Override\n public Version checkin(final String absPath) throws RepositoryException {\n if (true) {\n return TODO.dummyImplementation().returnValue(getBaseVersion(absPath));\n }\n final SessionDelegate sessionDelegate = versionManagerDelegate.getSessionDelegate();\n return sessionDelegate.perform(new SessionOperation() {\n @Override\n public Version perform() throws RepositoryException {\n String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);\n NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);\n if (nodeDelegate == null) {\n throw new PathNotFoundException(absPath);\n }\n if (sessionDelegate.getLockManager().isLocked(absPath)) {\n throw new LockException(\"Node at \" + absPath + \" is locked\");\n }\n return new VersionImpl(versionManagerDelegate.checkin(nodeDelegate));\n }\n });\n }\n\n @Override\n public void cancelMerge(String absPath, Version version)\n throws RepositoryException {\n TODO.unimplemented().doNothing();\n }\n\n}\n
===================================================================
--- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java (revision 5fdaf7a63b9a1f0a11099754834c910a50348461)
+++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java (revision )
@@ -115,7 +115,7 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public Boolean perform() throws RepositoryException {
- String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);
+ String oakPath = sessionDelegate.getOakPath(absPath);
NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
if (nodeDelegate == null) {
throw new PathNotFoundException(absPath);
@@ -132,7 +132,7 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public VersionHistory perform() throws RepositoryException {
- String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);
+ String oakPath = sessionDelegate.getOakPath(absPath);
NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
if (nodeDelegate == null) {
throw new PathNotFoundException(absPath);
@@ -149,7 +149,7 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public Version perform() throws RepositoryException {
- String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);
+ String oakPath = sessionDelegate.getOakPath(absPath);
NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
if (nodeDelegate == null) {
throw new PathNotFoundException(absPath);
@@ -195,7 +195,7 @@
sessionDelegate.perform(new SessionOperation() {
@Override
public Void perform() throws RepositoryException {
- String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);
+ String oakPath = sessionDelegate.getOakPath(absPath);
NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
if (nodeDelegate == null) {
throw new PathNotFoundException(absPath);
@@ -218,7 +218,7 @@
return sessionDelegate.perform(new SessionOperation() {
@Override
public Version perform() throws RepositoryException {
- String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);
+ String oakPath = sessionDelegate.getOakPath(absPath);
NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
if (nodeDelegate == null) {
throw new PathNotFoundException(absPath);
Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
<+>/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements. See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with\n * the License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.apache.jackrabbit.oak.jcr;\n\nimport java.io.IOException;\nimport java.io.InputStream;\n\nimport javax.annotation.Nonnull;\nimport javax.jcr.NamespaceRegistry;\nimport javax.jcr.RepositoryException;\nimport javax.jcr.Session;\nimport javax.jcr.UnsupportedRepositoryOperationException;\nimport javax.jcr.ValueFactory;\nimport javax.jcr.lock.LockManager;\nimport javax.jcr.nodetype.NodeTypeManager;\nimport javax.jcr.observation.ObservationManager;\nimport javax.jcr.query.QueryManager;\nimport javax.jcr.version.Version;\nimport javax.jcr.version.VersionManager;\n\nimport org.apache.jackrabbit.api.JackrabbitWorkspace;\nimport org.apache.jackrabbit.api.security.authorization.PrivilegeManager;\nimport org.apache.jackrabbit.oak.api.Root;\nimport org.apache.jackrabbit.oak.api.Tree;\nimport org.apache.jackrabbit.oak.commons.PathUtils;\nimport org.apache.jackrabbit.oak.jcr.lock.LockManagerImpl;\nimport org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;\nimport org.apache.jackrabbit.oak.jcr.version.VersionManagerImpl;\nimport org.apache.jackrabbit.oak.namepath.NamePathMapper;\nimport org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry;\nimport org.apache.jackrabbit.oak.plugins.nodetype.write.ReadWriteNodeTypeManager;\nimport org.apache.jackrabbit.util.Text;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.xml.sax.ContentHandler;\nimport org.xml.sax.InputSource;\n\nimport static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;\n\n/**\n * TODO document\n */\npublic class WorkspaceImpl implements JackrabbitWorkspace {\n\n /**\n * logger instance\n */\n private static final Logger log = LoggerFactory.getLogger(WorkspaceImpl.class);\n\n private final SessionDelegate sessionDelegate;\n private final QueryManagerImpl queryManager;\n private final LockManager lockManager;\n private final VersionManagerImpl versionManager;\n\n public WorkspaceImpl(SessionDelegate sessionDelegate) {\n this.sessionDelegate = sessionDelegate;\n this.queryManager = new QueryManagerImpl(sessionDelegate);\n this.lockManager = new LockManagerImpl(sessionDelegate);\n this.versionManager = new VersionManagerImpl(sessionDelegate);\n }\n\n //----------------------------------------------------------< Workspace >---\n @Override\n public Session getSession() {\n return sessionDelegate.getSession();\n }\n\n @Override\n public String getName() {\n return sessionDelegate.getWorkspaceName();\n }\n\n @Override\n public void copy(String srcAbsPath, String destAbsPath) throws RepositoryException {\n copy(getName(), srcAbsPath, destAbsPath);\n }\n\n @Override\n public void copy(String srcWorkspace, String srcAbsPath, String destAbsPath) throws RepositoryException {\n ensureIsAlive();\n\n if (!getName().equals(srcWorkspace)) {\n throw new UnsupportedRepositoryOperationException(\"Not implemented.\");\n }\n\n sessionDelegate.checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath, 1));\n\n String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(destAbsPath);\n String oakName = PathUtils.getName(oakPath);\n // handle index\n if (oakName.contains(\"[\")) {\n throw new RepositoryException(\"Cannot create a new node using a name including an index\");\n }\n\n sessionDelegate.copy(\n sessionDelegate.getOakPathOrThrowNotFound(srcAbsPath),\n sessionDelegate.getOakPathOrThrowNotFound(oakPath));\n }\n\n @Override\n public void clone(String srcWorkspace, String srcAbsPath, String destAbsPath, boolean removeExisting) throws RepositoryException {\n ensureIsAlive();\n\n sessionDelegate.checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath, 1));\n\n // TODO\n throw new UnsupportedRepositoryOperationException(\"Not implemented.\");\n }\n\n @Override\n public void move(String srcAbsPath, String destAbsPath) throws RepositoryException {\n ensureIsAlive();\n\n sessionDelegate.checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath, 1));\n\n String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(destAbsPath);\n String oakName = PathUtils.getName(oakPath);\n // handle index\n if (oakName.contains(\"[\")) {\n throw new RepositoryException(\"Cannot create a new node using a name including an index\");\n }\n\n sessionDelegate.move(\n sessionDelegate.getOakPathOrThrowNotFound(srcAbsPath),\n sessionDelegate.getOakPathOrThrowNotFound(oakPath),\n false);\n }\n\n @Override\n public void restore(Version[] versions, boolean removeExisting) throws RepositoryException {\n getVersionManager().restore(versions, removeExisting);\n }\n\n @Override\n public LockManager getLockManager() {\n return lockManager;\n }\n\n @Override\n public QueryManager getQueryManager() throws RepositoryException {\n ensureIsAlive();\n return queryManager;\n }\n\n @Override\n public NamespaceRegistry getNamespaceRegistry() {\n return new ReadWriteNamespaceRegistry() {\n @Override\n protected Tree getReadTree() {\n return sessionDelegate.getRoot().getTree(\"/\");\n }\n @Override\n protected Root getWriteRoot() {\n return sessionDelegate.getContentSession().getLatestRoot();\n }\n @Override\n protected void refresh() throws RepositoryException {\n getSession().refresh(true);\n }\n };\n }\n\n @Override\n public NodeTypeManager getNodeTypeManager() {\n return new ReadWriteNodeTypeManager() {\n @Override\n protected void refresh() throws RepositoryException {\n getSession().refresh(true);\n }\n\n @Override\n protected Tree getTypes() {\n return sessionDelegate.getRoot().getTree(NODE_TYPES_PATH);\n }\n\n @Nonnull\n @Override\n protected Root getWriteRoot() {\n return sessionDelegate.getContentSession().getLatestRoot();\n }\n\n @Override\n protected ValueFactory getValueFactory() {\n return sessionDelegate.getValueFactory();\n }\n\n @Nonnull\n @Override\n protected NamePathMapper getNamePathMapper() {\n return sessionDelegate.getNamePathMapper();\n }\n };\n }\n\n @Override\n public ObservationManager getObservationManager() throws RepositoryException {\n ensureIsAlive();\n\n return sessionDelegate.getObservationManager();\n }\n\n @Override\n public VersionManager getVersionManager() throws RepositoryException {\n ensureIsAlive();\n return versionManager;\n }\n\n @Override\n public String[] getAccessibleWorkspaceNames() throws RepositoryException {\n ensureIsAlive();\n\n // TODO -> SPI\n return new String[] {getName()};\n }\n\n @Override\n public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws RepositoryException {\n ensureIsAlive();\n\n // TODO\n throw new UnsupportedRepositoryOperationException(\"TODO: Workspace.getImportContentHandler\");\n }\n\n @Override\n public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, RepositoryException {\n ensureIsAlive();\n\n // TODO -> SPI\n throw new UnsupportedRepositoryOperationException(\"TODO: Workspace.importXML\");\n }\n\n @Override\n public void createWorkspace(String name) throws RepositoryException {\n ensureIsAlive();\n\n // TODO -> SPI\n throw new UnsupportedRepositoryOperationException(\"TODO: Workspace.createWorkspace\");\n }\n\n @Override\n public void createWorkspace(String name, String srcWorkspace) throws RepositoryException {\n ensureIsAlive();\n\n // TODO -> SPI\n throw new UnsupportedRepositoryOperationException(\"TODO: Workspace.createWorkspace\");\n }\n\n @Override\n public void deleteWorkspace(String name) throws RepositoryException {\n ensureIsAlive();\n\n // TODO -> SPI\n throw new UnsupportedRepositoryOperationException(\"TODO: Workspace.deleteWorkspace\");\n }\n\n //------------------------------------------------< JackrabbitWorkspace >---\n\n @Override\n public void createWorkspace(String workspaceName, InputSource workspaceTemplate) throws RepositoryException {\n ensureIsAlive();\n\n // TODO -> SPI\n throw new UnsupportedRepositoryOperationException(\"TODO: Workspace.createWorkspace\");\n }\n\n /**\n * @see org.apache.jackrabbit.api.JackrabbitWorkspace#getPrivilegeManager()\n */\n @Override\n public PrivilegeManager getPrivilegeManager() throws RepositoryException {\n return sessionDelegate.getPrivilegeManager();\n }\n\n //------------------------------------------------------------< private >---\n\n private void ensureIsAlive() throws RepositoryException {\n // check session status\n if (!sessionDelegate.isAlive()) {\n throw new RepositoryException(\"This session has been closed.\");\n }\n }\n\n}\n
===================================================================
--- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java (revision 5fdaf7a63b9a1f0a11099754834c910a50348461)
+++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java (revision )
@@ -99,7 +99,7 @@
sessionDelegate.checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath, 1));
- String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(destAbsPath);
+ String oakPath = sessionDelegate.getOakPathKeepIndex(destAbsPath);
String oakName = PathUtils.getName(oakPath);
// handle index
if (oakName.contains("[")) {
@@ -107,8 +107,8 @@
}
sessionDelegate.copy(
- sessionDelegate.getOakPathOrThrowNotFound(srcAbsPath),
- sessionDelegate.getOakPathOrThrowNotFound(oakPath));
+ sessionDelegate.getOakPath(srcAbsPath),
+ sessionDelegate.getOakPath(oakPath));
}
@Override
@@ -127,7 +127,7 @@
sessionDelegate.checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath, 1));
- String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(destAbsPath);
+ String oakPath = sessionDelegate.getOakPathKeepIndex(destAbsPath);
String oakName = PathUtils.getName(oakPath);
// handle index
if (oakName.contains("[")) {
@@ -135,8 +135,8 @@
}
sessionDelegate.move(
- sessionDelegate.getOakPathOrThrowNotFound(srcAbsPath),
- sessionDelegate.getOakPathOrThrowNotFound(oakPath),
+ sessionDelegate.getOakPath(srcAbsPath),
+ sessionDelegate.getOakPath(oakPath),
false);
}
Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
<+>/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements. See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with\n * the License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.apache.jackrabbit.oak.jcr;\n\nimport java.io.IOException;\nimport java.util.Map;\nimport java.util.concurrent.ScheduledExecutorService;\nimport javax.annotation.CheckForNull;\nimport javax.annotation.Nonnull;\nimport javax.jcr.ItemExistsException;\nimport javax.jcr.PathNotFoundException;\nimport javax.jcr.Repository;\nimport javax.jcr.RepositoryException;\nimport javax.jcr.Session;\nimport javax.jcr.UnsupportedRepositoryOperationException;\nimport javax.jcr.Workspace;\nimport javax.jcr.lock.LockManager;\nimport javax.jcr.nodetype.NodeTypeManager;\nimport javax.jcr.observation.ObservationManager;\nimport javax.jcr.query.QueryManager;\nimport javax.jcr.version.VersionManager;\n\nimport org.apache.jackrabbit.api.security.authorization.PrivilegeManager;\nimport org.apache.jackrabbit.api.security.principal.PrincipalManager;\nimport org.apache.jackrabbit.api.security.user.UserManager;\nimport org.apache.jackrabbit.oak.api.AuthInfo;\nimport org.apache.jackrabbit.oak.api.CommitFailedException;\nimport org.apache.jackrabbit.oak.api.ContentSession;\nimport org.apache.jackrabbit.oak.api.Root;\nimport org.apache.jackrabbit.oak.api.QueryEngine;\nimport org.apache.jackrabbit.oak.api.Tree;\nimport org.apache.jackrabbit.oak.api.TreeLocation;\nimport org.apache.jackrabbit.oak.commons.PathUtils;\nimport org.apache.jackrabbit.oak.namepath.LocalNameMapper;\nimport org.apache.jackrabbit.oak.namepath.NameMapper;\nimport org.apache.jackrabbit.oak.namepath.NamePathMapper;\nimport org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;\nimport org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;\nimport org.apache.jackrabbit.oak.plugins.name.Namespaces;\nimport org.apache.jackrabbit.oak.plugins.nodetype.DefinitionProvider;\nimport org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeTypeProvider;\nimport org.apache.jackrabbit.oak.plugins.observation.ObservationManagerImpl;\nimport org.apache.jackrabbit.oak.spi.security.SecurityProvider;\nimport org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\n\nimport com.google.common.collect.Maps;\n\nimport static com.google.common.base.Preconditions.checkNotNull;\n\npublic class SessionDelegate {\n static final Logger log = LoggerFactory.getLogger(SessionDelegate.class);\n\n private final NamePathMapper namePathMapper;\n private final Repository repository;\n private final ScheduledExecutorService executor;\n private final ContentSession contentSession;\n private final ValueFactoryImpl valueFactory;\n private final Workspace workspace;\n private final SessionImpl session;\n private final Root root;\n private final boolean autoRefresh;\n\n private final SecurityProvider securityProvider;\n\n private final IdentifierManager idManager;\n\n private ObservationManagerImpl observationManager;\n private PrincipalManager principalManager;\n private UserManager userManager;\n private PrivilegeManager privilegeManager;\n private boolean isAlive = true;\n private int sessionOpCount;\n private int revision;\n\n SessionDelegate(\n Repository repository, ScheduledExecutorService executor,\n ContentSession contentSession, SecurityProvider securityProvider,\n boolean autoRefresh) {\n\n this.repository = checkNotNull(repository);\n this.executor = executor;\n this.contentSession = checkNotNull(contentSession);\n this.securityProvider = securityProvider;\n this.autoRefresh = autoRefresh;\n\n this.root = contentSession.getLatestRoot();\n // FIXME: do not pass partially initialized 'this'\n this.workspace = new WorkspaceImpl(this);\n\n Map namespaces = Maps.newHashMap();\n NameMapper mapper = new LocalNameMapper(namespaces) {\n @Override\n protected Map getNamespaceMap() {\n return Namespaces.getNamespaceMap(root.getTree(\"/\"));\n }\n };\n this.session = new SessionImpl(this, namespaces);\n this.idManager = new IdentifierManager(root);\n this.namePathMapper = new NamePathMapperImpl(mapper, idManager);\n this.valueFactory = new ValueFactoryImpl(root.getBlobFactory(), namePathMapper);\n }\n\n /**\n * Performs the passed {@code SessionOperation} in a safe execution context. This\n * context ensures that the session is refreshed if necessary and that refreshing\n * occurs before the session operation is performed and the refreshing is done only\n * once.\n *\n * @param sessionOperation the {@code SessionOperation} to perform\n * @param return type of {@code sessionOperation}\n * @return the result of {@code sessionOperation.perform()}\n * @throws RepositoryException\n */\n public T perform(SessionOperation sessionOperation) throws RepositoryException {\n try {\n sessionOpCount++;\n if (needsRefresh()) {\n refresh(true);\n }\n return sessionOperation.perform();\n } finally {\n sessionOpCount--;\n }\n }\n\n private boolean needsRefresh() {\n // Refresh is always needed if this is an auto refresh session. Otherwise\n // refresh in only needed for non re-entrant session operations and only if\n // observation events have actually been delivered\n return autoRefresh ||\n (sessionOpCount <= 1 && observationManager != null && observationManager.hasEvents());\n }\n\n /**\n * Revision of this session. The revision is incremented each time a session is refreshed or saved.\n * This allows items to determine whether they need to re-resolve their underlying state when the\n * revision on which an item is based does not match the revision of the session any more.\n * @return the current revision of this session\n */\n int getRevision() {\n return revision;\n }\n\n public boolean isAlive() {\n return isAlive;\n }\n\n @Nonnull\n public Session getSession() {\n return session;\n }\n\n @Nonnull\n public AuthInfo getAuthInfo() {\n return contentSession.getAuthInfo();\n }\n\n @Nonnull\n public Repository getRepository() {\n return repository;\n }\n\n public void logout() {\n if (!isAlive) {\n // ignore\n return;\n }\n\n isAlive = false;\n if (observationManager != null) {\n observationManager.dispose();\n }\n // TODO\n\n try {\n contentSession.close();\n } catch (IOException e) {\n log.warn(\"Error while closing connection\", e);\n }\n }\n\n @CheckForNull\n public NodeDelegate getRootNode() {\n return getNode(\"/\");\n }\n \n @CheckForNull\n public Root getRoot() {\n return root;\n }\n\n /**\n * {@code NodeDelegate} at the given path\n * @param path Oak path\n * @return The {@code NodeDelegate} at {@code path} or {@code null} if\n * none exists or not accessible.\n */\n @CheckForNull\n public NodeDelegate getNode(String path) {\n return NodeDelegate.create(this, getLocation(path));\n }\n\n @CheckForNull\n public NodeDelegate getNodeByIdentifier(String id) {\n Tree tree = idManager.getTree(id);\n return (tree == null) ? null : new NodeDelegate(this, tree);\n }\n\n @CheckForNull\n /**\n * {@code PropertyDelegate} at the given path\n * @param path Oak path\n * @return The {@code PropertyDelegate} at {@code path} or {@code null} if\n * none exists or not accessible.\n */\n public PropertyDelegate getProperty(String path) {\n TreeLocation location = root.getLocation(path);\n return location.getProperty() == null\n ? null\n : new PropertyDelegate(this, location);\n }\n\n @Nonnull\n public ValueFactoryImpl getValueFactory() {\n return valueFactory;\n }\n\n @Nonnull\n public NamePathMapper getNamePathMapper() {\n return namePathMapper;\n }\n\n public boolean hasPendingChanges() {\n return root.hasPendingChanges();\n }\n\n public void save() throws RepositoryException {\n try {\n root.commit();\n revision++;\n } catch (CommitFailedException e) {\n e.throwRepositoryException();\n }\n }\n\n public void refresh(boolean keepChanges) {\n if (keepChanges) {\n root.rebase();\n } else {\n root.refresh();\n }\n revision++;\n }\n\n /**\n * Returns the Oak name for the given JCR name, or throws a\n * {@link RepositoryException} if the name is invalid or can\n * otherwise not be mapped.\n *\n * @param jcrName JCR name\n * @return Oak name\n * @throws RepositoryException if the name is invalid\n */\n @Nonnull\n public String getOakName(String jcrName) throws RepositoryException {\n return getNamePathMapper().getOakName(jcrName);\n }\n\n /**\n * Shortcut for {@code SessionDelegate.getNamePathMapper().getOakPath(jcrPath)}.\n *\n * @param jcrPath JCR path\n * @return Oak path, or {@code null}\n */\n @CheckForNull\n public String getOakPathOrNull(String jcrPath) {\n return getNamePathMapper().getOakPath(jcrPath);\n }\n\n /**\n * Shortcut for {@code SessionDelegate.getOakPathKeepIndex(jcrPath)}.\n *\n * @param jcrPath JCR path\n * @return Oak path, or {@code null}, with indexes left intact\n * @throws PathNotFoundException \n */\n @Nonnull\n public String getOakPathKeepIndexOrThrowNotFound(String jcrPath) throws PathNotFoundException {\n String oakPath = getNamePathMapper().getOakPathKeepIndex(jcrPath);\n if (oakPath != null) {\n return oakPath;\n } else {\n throw new PathNotFoundException(jcrPath);\n }\n }\n\n /**\n * Returns the Oak path for the given JCR path, or throws a\n * {@link PathNotFoundException} if the path can not be mapped.\n *\n * @param jcrPath JCR path\n * @return Oak path\n * @throws PathNotFoundException if the path can not be mapped\n */\n @Nonnull\n public String getOakPathOrThrowNotFound(String jcrPath) throws PathNotFoundException {\n String oakPath = getOakPathOrNull(jcrPath);\n if (oakPath != null) {\n return oakPath;\n } else {\n throw new PathNotFoundException(jcrPath);\n }\n }\n\n /**\n * Returns the Oak path for the given JCR path, or throws a\n * {@link RepositoryException} if the path can not be mapped.\n *\n * @param jcrPath JCR path\n * @return Oak path\n * @throws RepositoryException if the path can not be mapped\n */\n @Nonnull\n public String getOakPathOrThrow(String jcrPath)\n throws RepositoryException {\n String oakPath = getOakPathOrNull(jcrPath);\n if (oakPath != null) {\n return oakPath;\n } else {\n throw new RepositoryException(\"Invalid name or path: \" + jcrPath);\n }\n }\n\n //----------------------------------------------------------< Workspace >---\n\n @Nonnull\n public Workspace getWorkspace() {\n return workspace;\n }\n\n @Nonnull\n public String getWorkspaceName() {\n return contentSession.getWorkspaceName();\n }\n\n /**\n * Copy a node\n * @param srcPath oak path to the source node to copy\n * @param destPath oak path to the destination\n * @throws RepositoryException\n */\n public void copy(String srcPath, String destPath) throws RepositoryException {\n // check destination\n Tree dest = getTree(destPath);\n if (dest != null) {\n throw new ItemExistsException(destPath);\n }\n\n // check parent of destination\n String destParentPath = PathUtils.getParentPath(destPath);\n Tree destParent = getTree(destParentPath);\n if (destParent == null) {\n throw new PathNotFoundException(PathUtils.getParentPath(destPath));\n }\n\n // check source exists\n Tree src = getTree(srcPath);\n if (src == null) {\n throw new PathNotFoundException(srcPath);\n }\n\n try {\n Root currentRoot = contentSession.getLatestRoot();\n currentRoot.copy(srcPath, destPath);\n currentRoot.commit();\n }\n catch (CommitFailedException e) {\n e.throwRepositoryException();\n }\n }\n\n /**\n * Move a node\n * @param srcPath oak path to the source node to copy\n * @param destPath oak path to the destination\n * @param transientOp whether or not to perform the move in transient space\n * @throws RepositoryException\n */\n public void move(String srcPath, String destPath, boolean transientOp)\n throws RepositoryException {\n\n Root moveRoot = transientOp ? root : contentSession.getLatestRoot();\n\n // check destination\n Tree dest = moveRoot.getTree(destPath);\n if (dest != null) {\n throw new ItemExistsException(destPath);\n }\n\n // check parent of destination\n String destParentPath = PathUtils.getParentPath(destPath);\n Tree destParent = moveRoot.getTree(destParentPath);\n if (destParent == null) {\n throw new PathNotFoundException(PathUtils.getParentPath(destPath));\n }\n\n // check source exists\n Tree src = moveRoot.getTree(srcPath);\n if (src == null) {\n throw new PathNotFoundException(srcPath);\n }\n\n try {\n moveRoot.move(srcPath, destPath);\n if (!transientOp) {\n moveRoot.commit();\n }\n } catch (CommitFailedException e) {\n e.throwRepositoryException();\n }\n }\n\n @Nonnull\n public LockManager getLockManager() throws RepositoryException {\n return workspace.getLockManager();\n }\n\n @Nonnull\n public QueryEngine getQueryEngine() {\n return root.getQueryEngine();\n }\n\n @Nonnull\n public QueryManager getQueryManager() throws RepositoryException {\n return workspace.getQueryManager();\n }\n\n @Nonnull\n public NodeTypeManager getNodeTypeManager() throws RepositoryException {\n return workspace.getNodeTypeManager();\n }\n\n @Nonnull\n public VersionManager getVersionManager() throws RepositoryException {\n return workspace.getVersionManager();\n }\n\n @Nonnull\n public ObservationManager getObservationManager() {\n if (observationManager == null) {\n observationManager = new ObservationManagerImpl(getRoot(), getNamePathMapper(), executor);\n }\n return observationManager;\n }\n\n public IdentifierManager getIdManager() {\n return idManager;\n }\n\n @Nonnull\n public ContentSession getContentSession() {\n return contentSession;\n }\n\n //-----------------------------------------------------------< internal >---\n\n /**\n * Get the {@code Tree} with the given path\n * @param path oak path\n * @return tree at the given path or {@code null} if no such tree exists or\n * if the tree at {@code path} is not accessible.\n */\n @CheckForNull\n Tree getTree(String path) {\n return root.getTree(path);\n }\n\n @Nonnull\n TreeLocation getLocation(String path) {\n return root.getLocation(path);\n }\n\n @Nonnull\n PrincipalManager getPrincipalManager() throws RepositoryException {\n if (principalManager == null) {\n if (securityProvider != null) {\n principalManager = securityProvider.getPrincipalConfiguration().getPrincipalManager(session, root, getNamePathMapper());\n } else {\n throw new UnsupportedRepositoryOperationException(\"Principal management not supported.\");\n }\n }\n return principalManager;\n }\n\n @Nonnull\n UserManager getUserManager() throws UnsupportedRepositoryOperationException {\n if (userManager == null) {\n if (securityProvider != null) {\n userManager = securityProvider.getUserConfiguration().getUserManager(root, getNamePathMapper());\n } else {\n throw new UnsupportedRepositoryOperationException(\"User management not supported.\");\n }\n }\n return userManager;\n }\n\n @Nonnull\n PrivilegeManager getPrivilegeManager() throws UnsupportedRepositoryOperationException {\n if (privilegeManager == null) {\n if (securityProvider != null) {\n privilegeManager = securityProvider.getPrivilegeConfiguration().getPrivilegeManager(root, getNamePathMapper());\n } else {\n throw new UnsupportedRepositoryOperationException(\"Privilege management not supported.\");\n }\n }\n return privilegeManager;\n }\n\n @Nonnull\n EffectiveNodeTypeProvider getEffectiveNodeTypeProvider() throws RepositoryException {\n return (EffectiveNodeTypeProvider) workspace.getNodeTypeManager();\n }\n\n @Nonnull\n DefinitionProvider getDefinitionProvider() throws RepositoryException {\n return (DefinitionProvider) workspace.getNodeTypeManager();\n }\n\n void checkProtectedNodes(String... absJcrPaths) throws RepositoryException {\n for (String absPath : absJcrPaths) {\n NodeImpl node = (NodeImpl) session.getNode(absPath);\n node.checkProtected();\n }\n }\n}\n
===================================================================
--- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java (revision 5fdaf7a63b9a1f0a11099754834c910a50348461)
+++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java (revision )
@@ -301,35 +301,17 @@
* @throws PathNotFoundException
*/
@Nonnull
- public String getOakPathKeepIndexOrThrowNotFound(String jcrPath) throws PathNotFoundException {
+ public String getOakPathKeepIndex(String jcrPath) throws RepositoryException {
String oakPath = getNamePathMapper().getOakPathKeepIndex(jcrPath);
if (oakPath != null) {
return oakPath;
} else {
- throw new PathNotFoundException(jcrPath);
+ throw new RepositoryException("Invalid name or path: " + jcrPath);
}
}
/**
* Returns the Oak path for the given JCR path, or throws a
- * {@link PathNotFoundException} if the path can not be mapped.
- *
- * @param jcrPath JCR path
- * @return Oak path
- * @throws PathNotFoundException if the path can not be mapped
- */
- @Nonnull
- public String getOakPathOrThrowNotFound(String jcrPath) throws PathNotFoundException {
- String oakPath = getOakPathOrNull(jcrPath);
- if (oakPath != null) {
- return oakPath;
- } else {
- throw new PathNotFoundException(jcrPath);
- }
- }
-
- /**
- * Returns the Oak path for the given JCR path, or throws a
* {@link RepositoryException} if the path can not be mapped.
*
* @param jcrPath JCR path
@@ -337,7 +319,7 @@
* @throws RepositoryException if the path can not be mapped
*/
@Nonnull
- public String getOakPathOrThrow(String jcrPath)
+ public String getOakPath(String jcrPath)
throws RepositoryException {
String oakPath = getOakPathOrNull(jcrPath);
if (oakPath != null) {
Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
<+>/*\n * Licensed to the Apache Software Foundation (ASF) under one\n * or more contributor license agreements. See the NOTICE file\n * distributed with this work for additional information\n * regarding copyright ownership. The ASF licenses this file\n * to you under the Apache License, Version 2.0 (the\n * \"License\"); you may not use this file except in compliance\n * with the License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\npackage org.apache.jackrabbit.oak.jcr.query;\n\nimport java.util.HashMap;\nimport java.util.List;\nimport javax.jcr.ItemNotFoundException;\nimport javax.jcr.Node;\nimport javax.jcr.PathNotFoundException;\nimport javax.jcr.RepositoryException;\nimport javax.jcr.Value;\nimport javax.jcr.ValueFactory;\nimport javax.jcr.query.InvalidQueryException;\nimport javax.jcr.query.Query;\nimport javax.jcr.query.QueryResult;\nimport javax.jcr.version.VersionException;\n\nimport org.apache.jackrabbit.JcrConstants;\nimport org.apache.jackrabbit.oak.commons.PathUtils;\nimport org.apache.jackrabbit.oak.jcr.NodeDelegate;\nimport org.apache.jackrabbit.oak.jcr.NodeImpl;\nimport org.apache.jackrabbit.oak.jcr.SessionDelegate;\n\n/**\n * The implementation of the corresponding JCR interface.\n */\npublic class QueryImpl implements Query {\n\n private final QueryManagerImpl manager;\n private final HashMap bindVariableMap = new HashMap();\n private final String language;\n private final String statement;\n private long limit = Long.MAX_VALUE;\n private long offset;\n private boolean parsed;\n private String storedQueryPath;\n\n QueryImpl(QueryManagerImpl manager, String statement, String language) {\n this.manager = manager;\n this.statement = statement;\n this.language = language;\n }\n\n void setStoredQueryPath(String storedQueryPath) {\n this.storedQueryPath = storedQueryPath;\n }\n\n @Override\n public void bindValue(String varName, Value value) throws RepositoryException {\n parse();\n if (!bindVariableMap.containsKey(varName)) {\n throw new IllegalArgumentException(\"Variable name \" + varName + \" is not a valid variable in this query\");\n }\n bindVariableMap.put(varName, value);\n }\n\n private void parse() throws InvalidQueryException {\n if (parsed) {\n return;\n }\n List names = manager.parse(statement, language);\n for (String n : names) {\n bindVariableMap.put(n, null);\n }\n parsed = true;\n }\n\n @Override\n public QueryResult execute() throws RepositoryException {\n return manager.executeQuery(statement, language, limit, offset, bindVariableMap);\n }\n\n @Override\n public String[] getBindVariableNames() throws RepositoryException {\n parse();\n String[] names = new String[bindVariableMap.size()];\n bindVariableMap.keySet().toArray(names);\n return names;\n }\n\n @Override\n public String getLanguage() {\n return language;\n }\n\n @Override\n public String getStatement() {\n return statement;\n }\n\n @Override\n public String getStoredQueryPath() throws RepositoryException {\n if (storedQueryPath == null) {\n throw new ItemNotFoundException(\"Not a stored query\");\n }\n return storedQueryPath;\n }\n\n @Override\n public void setLimit(long limit) {\n if (limit < 0) {\n throw new IllegalArgumentException(\"Limit may not be negative, is: \" + limit);\n }\n this.limit = limit;\n }\n\n @Override\n public void setOffset(long offset) {\n if (offset < 0) {\n throw new IllegalArgumentException(\"Offset may not be negative, is: \" + offset);\n }\n this.offset = offset;\n }\n\n @Override\n public Node storeAsNode(String absPath) throws RepositoryException {\n manager.ensureIsAlive();\n SessionDelegate sessionDelegate = manager.getSessionDelegate();\n String oakPath = sessionDelegate.getOakPathOrThrow(absPath);\n String parent = PathUtils.getParentPath(oakPath);\n NodeDelegate parentDelegate = sessionDelegate.getNode(parent);\n if (parentDelegate == null) {\n throw new PathNotFoundException(\"The specified path does not exist: \" + parent);\n }\n Node parentNode = new NodeImpl(parentDelegate);\n if (!parentNode.isCheckedOut()) {\n throw new VersionException(\"Cannot store query. Node at \" +\n absPath + \" is checked in.\");\n }\n String nodeName = PathUtils.getName(oakPath);\n ValueFactory vf = sessionDelegate.getValueFactory();\n Node n = parentNode.addNode(nodeName, JcrConstants.NT_QUERY);\n n.setProperty(JcrConstants.JCR_STATEMENT, vf.createValue(statement));\n n.setProperty(JcrConstants.JCR_LANGUAGE, vf.createValue(language));\n setStoredQueryPath(oakPath);\n return n;\n }\n\n}\n
===================================================================
--- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java (revision 5fdaf7a63b9a1f0a11099754834c910a50348461)
+++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java (revision )
@@ -132,7 +132,7 @@
public Node storeAsNode(String absPath) throws RepositoryException {
manager.ensureIsAlive();
SessionDelegate sessionDelegate = manager.getSessionDelegate();
- String oakPath = sessionDelegate.getOakPathOrThrow(absPath);
+ String oakPath = sessionDelegate.getOakPath(absPath);
String parent = PathUtils.getParentPath(oakPath);
NodeDelegate parentDelegate = sessionDelegate.getNode(parent);
if (parentDelegate == null) {