01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2006, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19:
20: package edu.umd.cs.findbugs.classfile;
21:
22: /**
23: * Exception to indicate that a resource was not found.
24: *
25: * @author David Hovemeyer
26: */
27: public class ResourceNotFoundException extends CheckedAnalysisException {
28: private String resourceName;
29:
30: public static final String MESSAGE_PREFIX = "Resource not found: ";
31:
32: /**
33: * Constructor.
34: *
35: * @param resourceName name of the missing resource
36: */
37: public ResourceNotFoundException(String resourceName) {
38: super (MESSAGE_PREFIX + resourceName);
39: this .resourceName = resourceName;
40: }
41:
42: /**
43: * Constructor.
44: *
45: * @param resourceName name of the missing resource
46: * @param cause underlying cause of the exception
47: */
48: public ResourceNotFoundException(String resourceName,
49: Throwable cause) {
50: super (MESSAGE_PREFIX + resourceName, cause);
51: this .resourceName = resourceName;
52: }
53:
54: /**
55: * Get the name of the resource that was not found.
56: *
57: * @return the name of the resource that was not found
58: */
59: public String getResourceName() {
60: return resourceName;
61: }
62:
63: /**
64: * Convert this exception to a ClassNotFoundException.
65: * This method should only be called if the
66: * ResourceNotFoundException occurs while looking for a class.
67: * The message format is parseable by ClassNotFoundExceptionParser.
68: */
69: public ClassNotFoundException toClassNotFoundException() {
70: ClassDescriptor classDescriptor = DescriptorFactory
71: .createClassDescriptorFromResourceName(resourceName);
72: return new ClassNotFoundException(
73: "ResourceNotFoundException while looking for class "
74: + classDescriptor.toDottedClassName() + ": "
75: + getMessage());
76: }
77: }
|