    001    package org.nanocontainer.script;
    002
    003    import org.picocontainer.PicoException;
    004
    005    /**
    006     * Indicates that a given file extension has no corresponding builder.  The
    007     * message will also indicate all supported builders.
    008     * @author Michael Rimov
    009     * @version 1.0
    010     */
    011    public class UnsupportedScriptTypeException extends PicoException {
    012
    013        private final String specifiedFileExtension;
    014
    015        private final String[] allSupportedFileExtensions;
    016
    017        public UnsupportedScriptTypeException(String specifiedFileExtension, String[] allSupportedFileExtensions) {
    018            super();
    019            this.specifiedFileExtension = specifiedFileExtension;
    020            this.allSupportedFileExtensions = allSupportedFileExtensions;
    021        }
    022
    023
    024
    025        /**
    026         * Transforms the constructor arguments into a real exption
    027         * @param specifiedFileExtension String
    028         * @param allSupportedFileExtensions String[]
    029         * @return String
    030         */
    031        private  String buildExceptionMessage() {
    032            StringBuffer message = new StringBuffer(48);
    033            message.append("Unsupported file extension '");
    034            message.append(specifiedFileExtension);
    035            message.append("'.  Supported extensions are: [");
    036
    037            if (allSupportedFileExtensions != null) {
    038                boolean needPipe = false;
    039                for (int i = 0; i < allSupportedFileExtensions.length; i++) {
    040                    if (needPipe) {
    041                        message.append("|");
    042                    } else {
    043                        needPipe = true;
    044                    }
    045
    046                    message.append(allSupportedFileExtensions[i]);
    047                }
    048
    049                message.append("].");
    050            } else {
    051                message.append(" null ");
    052            }
    053
    054            return message.toString();
    055        }
    056
    057        public String getMessage() {
    058            return buildExceptionMessage();
    059        }
    060
    061        public String[] getSystemSupportedExtensions() {
    062            return allSupportedFileExtensions;
    063        }
    064
    065        public String getRequestedExtension() {
    066            return specifiedFileExtension;
    067        }
    068
    069    }