1 16 package org.apache.cocoon.util.location; 17 18 import java.util.ArrayList ; 19 import java.util.Collections ; 20 import java.util.List ; 21 22 import org.apache.commons.lang.exception.NestableRuntimeException; 23 24 36 public class LocatedRuntimeException extends NestableRuntimeException implements LocatableException, MultiLocatable { 37 38 private List locations; 39 40 public LocatedRuntimeException(String message) { 41 this(message, null, null, true); 42 } 43 44 public LocatedRuntimeException(String message, Throwable cause) throws LocatedRuntimeException { 45 this(message, cause, null, true); 46 } 47 48 public LocatedRuntimeException(String message, Location location) { 49 this(message, null, location, true); 50 } 51 52 public LocatedRuntimeException(String message, Throwable cause, Location location) throws LocatedRuntimeException { 53 this(message, cause, location, true); 54 } 55 56 public LocatedRuntimeException(String message, Throwable cause, Location location, boolean rethrowLocated) 57 throws LocatedRuntimeException { 58 super(message, cause); 59 if (rethrowLocated && cause instanceof LocatedRuntimeException) { 60 LocatedRuntimeException lreCause = (LocatedRuntimeException)cause; 61 lreCause.addLocation(location); 62 throw lreCause; 64 } 65 66 LocatedException.ensureCauseChainIsSet(cause); 67 LocatedException.addCauseLocations(this, cause); 68 addLocation(location); 69 } 70 71 public Location getLocation() { 72 return locations == null ? null : (Location)locations.get(0); 73 } 74 75 public List getLocations() { 76 return locations == null ? Collections.EMPTY_LIST : locations; 77 } 78 79 public String getRawMessage() { 80 return super.getMessage(); 81 } 82 83 public String getMessage() { 84 return LocatedException.getMessage(super.getMessage(), locations); 85 } 86 87 public void addLocation(Location loc) { 88 if (LocationUtils.isUnknown(loc)) 89 return; 90 91 if (locations == null) { 92 this.locations = new ArrayList (1); } 94 locations.add(LocationImpl.get(loc)); 95 } 96 } 97 | Popular Tags |