001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.scripting;
018
019import org.springframework.core.NestedRuntimeException;
020import org.springframework.lang.Nullable;
021
022/**
023 * Exception to be thrown on script compilation failure.
024 *
025 * @author Juergen Hoeller
026 * @since 2.0
027 */
028@SuppressWarnings("serial")
029public class ScriptCompilationException extends NestedRuntimeException {
030
031        @Nullable
032        private final ScriptSource scriptSource;
033
034
035        /**
036         * Constructor for ScriptCompilationException.
037         * @param msg the detail message
038         */
039        public ScriptCompilationException(String msg) {
040                super(msg);
041                this.scriptSource = null;
042        }
043
044        /**
045         * Constructor for ScriptCompilationException.
046         * @param msg the detail message
047         * @param cause the root cause (usually from using an underlying script compiler API)
048         */
049        public ScriptCompilationException(String msg, Throwable cause) {
050                super(msg, cause);
051                this.scriptSource = null;
052        }
053
054        /**
055         * Constructor for ScriptCompilationException.
056         * @param scriptSource the source for the offending script
057         * @param msg the detail message
058         * @since 4.2
059         */
060        public ScriptCompilationException(ScriptSource scriptSource, String msg) {
061                super("Could not compile " + scriptSource + ": " + msg);
062                this.scriptSource = scriptSource;
063        }
064
065        /**
066         * Constructor for ScriptCompilationException.
067         * @param scriptSource the source for the offending script
068         * @param cause the root cause (usually from using an underlying script compiler API)
069         */
070        public ScriptCompilationException(ScriptSource scriptSource, Throwable cause) {
071                super("Could not compile " + scriptSource, cause);
072                this.scriptSource = scriptSource;
073        }
074
075        /**
076         * Constructor for ScriptCompilationException.
077         * @param scriptSource the source for the offending script
078         * @param msg the detail message
079         * @param cause the root cause (usually from using an underlying script compiler API)
080         */
081        public ScriptCompilationException(ScriptSource scriptSource, String msg, Throwable cause) {
082                super("Could not compile " + scriptSource + ": " + msg, cause);
083                this.scriptSource = scriptSource;
084        }
085
086
087        /**
088         * Return the source for the offending script.
089         * @return the source, or {@code null} if not available
090         */
091        @Nullable
092        public ScriptSource getScriptSource() {
093                return this.scriptSource;
094        }
095
096}