001 /******************************************************************************* 002 * Copyright (C) PicoContainer Organization. All rights reserved. 003 * --------------------------------------------------------------------------- 004 * The software in this package is published under the terms of the BSD style 005 * license a copy of which has been included with this distribution in the 006 * LICENSE.txt file. 007 ******************************************************************************/ 008 package org.picocontainer.script; 009 010 import org.picocontainer.PicoException; 011 012 /** 013 * Thrown when a given script type extension has no corresponding builder. The 014 * message will also indicate all supported builders. 015 * 016 * @author Michael Rimov 017 */ 018 @SuppressWarnings("serial") 019 public class UnsupportedScriptTypeException extends PicoException { 020 021 private final String specifiedFileExtension; 022 023 private final String[] allSupportedFileExtensions; 024 025 public UnsupportedScriptTypeException(String specifiedFileExtension, String[] allSupportedFileExtensions) { 026 super(); 027 this.specifiedFileExtension = specifiedFileExtension; 028 this.allSupportedFileExtensions = allSupportedFileExtensions; 029 } 030 031 /** 032 * Builds the exception message from the fields 033 * 034 * @return The exception message 035 */ 036 private String buildExceptionMessage() { 037 StringBuffer message = new StringBuffer(48); 038 message.append("Unsupported file extension '"); 039 message.append(specifiedFileExtension); 040 message.append("'. Supported extensions are: ["); 041 042 if (allSupportedFileExtensions != null) { 043 boolean needPipe = false; 044 for (String allSupportedFileExtension : allSupportedFileExtensions) { 045 if (needPipe) { 046 message.append("|"); 047 } else { 048 needPipe = true; 049 } 050 051 message.append(allSupportedFileExtension); 052 } 053 054 message.append("]."); 055 } else { 056 message.append(" null "); 057 } 058 059 return message.toString(); 060 } 061 062 public String getMessage() { 063 return buildExceptionMessage(); 064 } 065 066 public String[] getSystemSupportedExtensions() { 067 return allSupportedFileExtensions; 068 } 069 070 public String getRequestedExtension() { 071 return specifiedFileExtension; 072 } 073 074 }