001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019 020package icy.plugin.classloader.exception; 021 022import icy.plugin.classloader.ResourceType; 023 024/** 025 * @author Kamran Zafar 026 * 027 */ 028public class ResourceNotFoundException extends JclException { 029 /** 030 * Default serial id 031 */ 032 private static final long serialVersionUID = 1L; 033 034 private String resourceName; 035 private ResourceType resourceType; 036 037 /** 038 * Default constructor 039 */ 040 public ResourceNotFoundException() { 041 super(); 042 } 043 044 /** 045 * @param message 046 */ 047 public ResourceNotFoundException(String message) { 048 super( message ); 049 } 050 051 /** 052 * @param resource 053 * @param message 054 */ 055 public ResourceNotFoundException(String resource, String message) { 056 super( message ); 057 resourceName = resource; 058 determineResourceType( resource ); 059 } 060 061 /** 062 * @param e 063 * @param resource 064 * @param message 065 */ 066 public ResourceNotFoundException(Throwable e, String resource, String message) { 067 super( message, e ); 068 resourceName = resource; 069 determineResourceType( resource ); 070 } 071 072 /** 073 * @param resourceName 074 */ 075 private void determineResourceType(String resourceName) { 076 if( resourceName.toLowerCase().endsWith( "." + ResourceType.CLASS.name().toLowerCase() ) ) 077 resourceType = ResourceType.CLASS; 078 else if( resourceName.toLowerCase().endsWith( "." + ResourceType.PROPERTIES.name().toLowerCase() ) ) 079 resourceType = ResourceType.PROPERTIES; 080 else if( resourceName.toLowerCase().endsWith( "." + ResourceType.XML.name().toLowerCase() ) ) 081 resourceType = ResourceType.XML; 082 else 083 resourceType = ResourceType.UNKNOWN; 084 } 085 086 /** 087 * @return {@link ResourceType} 088 */ 089 public String getResourceName() { 090 return resourceName; 091 } 092 093 /** 094 * @param resourceName 095 */ 096 public void setResourceName(String resourceName) { 097 this.resourceName = resourceName; 098 } 099 100 /** 101 * @return {@link ResourceType} 102 */ 103 public ResourceType getResourceType() { 104 return resourceType; 105 } 106 107 /** 108 * @param resourceType 109 */ 110 public void setResourceType(ResourceType resourceType) { 111 this.resourceType = resourceType; 112 } 113}