001package org.hl7.fhir.exceptions;
002
003import org.hl7.fhir.utilities.SourceLocation;
004import org.hl7.fhir.utilities.Utilities;
005
006/*
007  Copyright (c) 2011+, HL7, Inc.
008  All rights reserved.
009  
010  Redistribution and use in source and binary forms, with or without modification, 
011  are permitted provided that the following conditions are met:
012    
013   * Redistributions of source code must retain the above copyright notice, this 
014     list of conditions and the following disclaimer.
015   * Redistributions in binary form must reproduce the above copyright notice, 
016     this list of conditions and the following disclaimer in the documentation 
017     and/or other materials provided with the distribution.
018   * Neither the name of HL7 nor the names of its contributors may be used to 
019     endorse or promote products derived from this software without specific 
020     prior written permission.
021  
022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
023  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
024  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
025  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
026  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
027  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
028  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
029  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
030  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
031  POSSIBILITY OF SUCH DAMAGE.
032  
033 */
034
035
036
037public class PathEngineException extends FHIRException {
038
039  private static final long serialVersionUID = 31969342112856390L;
040  private SourceLocation location;
041  private String expression;
042  private String id;
043
044
045  public PathEngineException(String message, Throwable cause) {
046    super(message, cause);
047  }
048
049  public PathEngineException(String message) {
050    super(message);
051  }
052
053  public PathEngineException(String message, SourceLocation location, String expression, Throwable cause) {
054    super(message+rep(location, expression), cause);
055  }
056
057  public PathEngineException(String message, SourceLocation location, String expression) {
058    super(message+rep(location, expression));
059  }
060  
061  public PathEngineException(String message, String id, Throwable cause) {
062    super(message, cause);
063    this.id = id;
064  }
065
066  public PathEngineException(String message, String id) {
067    super(message);
068    this.id = id;
069  }
070
071  public PathEngineException(String message, String id, SourceLocation location, String expression, Throwable cause) {
072    super(message+rep(location, expression), cause);
073    this.id = id;
074  }
075
076  public PathEngineException(String message, String id, SourceLocation location, String expression) {
077    super(message+rep(location, expression));
078    this.id = id;
079  }
080
081        private static String rep(SourceLocation loc, String expr) {
082          if (loc != null) {
083            if (loc.getLine() == 1) {
084              return " (@char "+loc.getColumn()+")";
085            } else { 
086              return " (@line "+loc.getLine()+" char "+loc.getColumn()+")";
087            }
088          } else if (Utilities.noString(expr)) { // can happen in some contexts...
089            return " (@~"+expr+")";
090          } else {
091            return "";
092          }
093  }
094
095  public PathEngineException(Throwable cause) {
096                super(cause);
097        }
098
099  public String getExpression() {
100    return expression;
101  }
102
103  public void setExpression(String expression) {
104    this.expression = expression;
105  }
106
107  public SourceLocation getLocation() {
108    return location;
109  }
110
111  public void setLocation(SourceLocation location) {
112    this.location = location;
113  }
114
115  public String getId() {
116    return id;
117  }
118
119}