001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.math3.exception;
018    
019    import org.apache.commons.math3.exception.util.Localizable;
020    import org.apache.commons.math3.exception.util.LocalizedFormats;
021    import org.apache.commons.math3.exception.util.ExceptionContext;
022    import org.apache.commons.math3.exception.util.ExceptionContextProvider;
023    
024    /**
025     * Base class for all unsupported features.
026     * It is used for all the exceptions that have the semantics of the standard
027     * {@link UnsupportedOperationException}, but must also provide a localized
028     * message.
029     *
030     * @since 2.2
031     * @version $Id: MathUnsupportedOperationException.java 1364378 2012-07-22 17:42:38Z tn $
032     */
033    public class MathUnsupportedOperationException extends UnsupportedOperationException
034        implements ExceptionContextProvider {
035        /** Serializable version Id. */
036        private static final long serialVersionUID = -6024911025449780478L;
037        /** Context. */
038        private final ExceptionContext context;
039    
040        /**
041         * Default constructor.
042         */
043        public MathUnsupportedOperationException() {
044            this(LocalizedFormats.UNSUPPORTED_OPERATION);
045        }
046        /**
047         * @param pattern Message pattern providing the specific context of
048         * the error.
049         * @param args Arguments.
050         */
051        public MathUnsupportedOperationException(Localizable pattern,
052                                                 Object ... args) {
053            context = new ExceptionContext(this);
054            context.addMessage(pattern, args);
055        }
056    
057        /** {@inheritDoc} */
058        public ExceptionContext getContext() {
059            return context;
060        }
061    
062        /** {@inheritDoc} */
063        @Override
064        public String getMessage() {
065            return context.getMessage();
066        }
067    
068        /** {@inheritDoc} */
069        @Override
070        public String getLocalizedMessage() {
071            return context.getLocalizedMessage();
072        }
073    }