001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source 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, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.config;
030:
031: import com.caucho.util.*;
032:
033: import java.lang.reflect.*;
034:
035: /**
036: * Thrown by the various Builders
037: */
038: public class LineConfigException extends ConfigException implements
039: LineCompileException, LineException {
040: private String _filename;
041: private int _line = -1;
042:
043: /**
044: * Create a null exception
045: */
046: public LineConfigException() {
047: }
048:
049: /**
050: * Creates an exception with a message
051: */
052: public LineConfigException(String msg) {
053: super (msg);
054: }
055:
056: /**
057: * Creates an exception with a message
058: */
059: public LineConfigException(String msg, Throwable cause) {
060: super (msg, cause);
061: }
062:
063: /**
064: * Creates an exception with a message
065: */
066: /*
067: public LineConfigException(Throwable cause)
068: {
069: super(cause);
070: }
071: */
072:
073: public LineConfigException(String filename, int line, String message) {
074: super (filename + ":" + line + ": " + message);
075:
076: _filename = filename;
077: _line = line;
078: }
079:
080: public LineConfigException(String filename, int line,
081: Throwable cause) {
082: super (filename + ":" + line + ": " + cause.getMessage(), cause);
083:
084: _filename = filename;
085: _line = line;
086: }
087:
088: public LineConfigException(String filename, int line,
089: String message, Throwable cause) {
090: super (filename + ":" + line + ": " + message, cause);
091:
092: _filename = filename;
093: _line = line;
094: }
095:
096: public String getFilename() {
097: return _filename;
098: }
099:
100: public int getLineNumber() {
101: return _line;
102: }
103:
104: public String toString() {
105: return getMessage();
106: }
107:
108: public static RuntimeException create(String filename, int line,
109: Throwable e) {
110: String loc = filename + ": " + line + ": ";
111:
112: if (e instanceof LineException) {
113: if (e instanceof RuntimeException)
114: throw (RuntimeException) e;
115: else
116: return new LineConfigException(filename, line, e
117: .getMessage(), e);
118: } else if (e instanceof DisplayableException)
119: return new LineConfigException(filename, line, e
120: .getMessage(), e);
121: else
122: return new LineConfigException(filename, line,
123: e.toString(), e);
124: }
125:
126: public static RuntimeException create(Field field, Throwable e) {
127: return create(loc(field), e);
128: }
129:
130: public static RuntimeException create(Method method, Throwable e) {
131: return create(loc(method), e);
132: }
133:
134: public static RuntimeException create(String loc, Throwable e) {
135: if (e instanceof LineException) {
136: if (e instanceof RuntimeException)
137: return (RuntimeException) e;
138: else
139: return new LineConfigException(e.getMessage(), e);
140: } else if (e instanceof DisplayableException)
141: return new LineConfigException(loc + e.getMessage(), e);
142: else
143: return new LineConfigException(loc + e, e);
144: }
145:
146: public static RuntimeException create(Throwable e) {
147: if (e instanceof LineCompileException)
148: return new LineConfigException(e.getMessage(), e);
149: else if (e instanceof DisplayableException)
150: return new ConfigException(e.getMessage(), e);
151: else
152: return new ConfigException(e.toString(), e);
153: }
154:
155: public static String loc(Field field) {
156: return field.getDeclaringClass().getName() + "."
157: + field.getName() + ": ";
158: }
159:
160: public static String loc(Method method) {
161: return method.getDeclaringClass().getName() + "."
162: + method.getName() + "(): ";
163: }
164: }
|