001    /*
002     * JBoss DNA (http://www.jboss.org/dna)
003     * See the COPYRIGHT.txt file distributed with this work for information
004     * regarding copyright ownership.  Some portions may be licensed
005     * to Red Hat, Inc. under one or more contributor license agreements.
006     * See the AUTHORS.txt file in the distribution for a full listing of 
007     * individual contributors. 
008     *
009     * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
010     * is licensed to you under the terms of the GNU Lesser General Public License as
011     * published by the Free Software Foundation; either version 2.1 of
012     * the License, or (at your option) any later version.
013     *
014     * JBoss DNA is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017     * Lesser General Public License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this software; if not, write to the Free
021     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023     */
024    package org.jboss.dna.graph.property;
025    
026    import org.jboss.dna.graph.GraphI18n;
027    import org.jboss.dna.graph.Location;
028    
029    /**
030     * @author Randall Hauch
031     */
032    public class PathNotFoundException extends RuntimeException {
033    
034        /**
035         */
036        private static final long serialVersionUID = -3703984046286975978L;
037    
038        private final Location location;
039        private final Path lowestAncestorThatDoesExist;
040    
041        /**
042         * @param location the location of the node that does not exist
043         * @param lowestAncestorThatDoesExist the path of the lowest (closest) ancestor that does exist
044         */
045        public PathNotFoundException( Location location,
046                                      Path lowestAncestorThatDoesExist ) {
047            this.location = location;
048            this.lowestAncestorThatDoesExist = lowestAncestorThatDoesExist;
049        }
050    
051        /**
052         * @param location the location of the node that does not exist
053         * @param lowestAncestorThatDoesExist the path of the lowest (closest) ancestor that does exist
054         * @param message
055         */
056        public PathNotFoundException( Location location,
057                                      Path lowestAncestorThatDoesExist,
058                                      String message ) {
059            super(message);
060            this.location = location;
061            this.lowestAncestorThatDoesExist = lowestAncestorThatDoesExist;
062        }
063    
064        /**
065         * @param location the location of the node that does not exist
066         * @param lowestAncestorThatDoesExist the path of the lowest (closest) ancestor that does exist
067         * @param cause
068         */
069        public PathNotFoundException( Location location,
070                                      Path lowestAncestorThatDoesExist,
071                                      Throwable cause ) {
072            super(cause);
073            this.location = location;
074            this.lowestAncestorThatDoesExist = lowestAncestorThatDoesExist;
075        }
076    
077        /**
078         * @param location the location of the node that does not exist
079         * @param lowestAncestorThatDoesExist the path of the lowest (closest) ancestor that does exist
080         * @param message
081         * @param cause
082         */
083        public PathNotFoundException( Location location,
084                                      Path lowestAncestorThatDoesExist,
085                                      String message,
086                                      Throwable cause ) {
087            super(message, cause);
088            this.location = location;
089            this.lowestAncestorThatDoesExist = lowestAncestorThatDoesExist;
090        }
091    
092        /**
093         * {@inheritDoc}
094         */
095        @Override
096        public String toString() {
097            return super.toString();
098        }
099    
100        /**
101         * {@inheritDoc}
102         * 
103         * @see java.lang.Throwable#getMessage()
104         */
105        @Override
106        public String getMessage() {
107            if (this.lowestAncestorThatDoesExist != null) {
108                return GraphI18n.pathNotFoundExceptionLowestExistingLocationFound.text(super.getMessage(),
109                                                                                       this.lowestAncestorThatDoesExist);
110            }
111            return super.getMessage();
112        }
113    
114        /**
115         * Get the path that was not found
116         * 
117         * @return the path that was not found
118         */
119        public Location getLocation() {
120            return location;
121        }
122    
123        /**
124         * Get the lowest (closest) existing {@link Path#getParent() ancestor} of the {@link #getLocation() non-existant location}.
125         * 
126         * @return the lowest ancestor that does exist
127         */
128        public Path getLowestAncestorThatDoesExist() {
129            return lowestAncestorThatDoesExist;
130        }
131    }