1 /* 2 * ModeShape (http://www.modeshape.org) 3 * See the COPYRIGHT.txt file distributed with this work for information 4 * regarding copyright ownership. Some portions may be licensed 5 * to Red Hat, Inc. under one or more contributor license agreements. 6 * See the AUTHORS.txt file in the distribution for a full listing of 7 * individual contributors. 8 * 9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape 10 * is licensed to you under the terms of the GNU Lesser General Public License as 11 * published by the Free Software Foundation; either version 2.1 of 12 * the License, or (at your option) any later version. 13 * 14 * ModeShape is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this software; if not, write to the Free 21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 23 */ 24 package org.modeshape.jcr; 25 26 import javax.jcr.Item; 27 import javax.jcr.ItemNotFoundException; 28 import javax.jcr.Node; 29 import javax.jcr.RepositoryException; 30 import javax.jcr.nodetype.ConstraintViolationException; 31 import net.jcip.annotations.Immutable; 32 import org.modeshape.graph.Location; 33 import org.modeshape.graph.session.GraphSession.NodeId; 34 35 /** 36 * A concrete implementation of a root {@link Node JCR Node}. 37 */ 38 @Immutable 39 final class JcrRootNode extends AbstractJcrNode { 40 41 JcrRootNode( SessionCache cache, 42 NodeId nodeId, 43 Location location ) { 44 super(cache, nodeId, location); 45 } 46 47 /** 48 * {@inheritDoc} 49 * 50 * @see org.modeshape.jcr.AbstractJcrNode#isRoot() 51 */ 52 @Override 53 boolean isRoot() { 54 return true; 55 } 56 57 /** 58 * {@inheritDoc} 59 * 60 * @return 0; 61 * @see javax.jcr.Item#getDepth() 62 */ 63 @Override 64 public int getDepth() { 65 return 0; 66 } 67 68 /** 69 * {@inheritDoc} 70 * 71 * @return 1; 72 * @see javax.jcr.Node#getIndex() 73 */ 74 public int getIndex() { 75 return 1; 76 } 77 78 /** 79 * {@inheritDoc} 80 * 81 * @return ""; 82 * @see javax.jcr.Item#getName() 83 */ 84 public String getName() { 85 return ""; 86 } 87 88 /** 89 * {@inheritDoc} 90 * 91 * @throws ItemNotFoundException always 92 * @see javax.jcr.Item#getParent() 93 */ 94 @Override 95 public AbstractJcrNode getParent() throws ItemNotFoundException { 96 throw new ItemNotFoundException(JcrI18n.rootNodeHasNoParent.text()); 97 } 98 99 /** 100 * {@inheritDoc} 101 * 102 * @return "/"; 103 * @see javax.jcr.Item#getPath() 104 */ 105 public String getPath() { 106 return "/"; 107 } 108 109 /** 110 * {@inheritDoc} 111 * 112 * @see org.modeshape.jcr.AbstractJcrItem#getAncestor(int) 113 */ 114 @Override 115 public final Item getAncestor( int depth ) throws RepositoryException { 116 if (depth == 0) return this; 117 if (depth < 0) { 118 throw new ItemNotFoundException(JcrI18n.noNegativeDepth.text(depth)); 119 } 120 throw new ItemNotFoundException(JcrI18n.tooDeep.text(depth)); 121 } 122 123 /** 124 * {@inheritDoc} 125 * 126 * @see javax.jcr.Item#remove() 127 */ 128 public void remove() throws ConstraintViolationException { 129 String msg = JcrI18n.unableToRemoveRootNode.text(cache.workspaceName()); 130 throw new ConstraintViolationException(msg); 131 } 132 133 }