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 */
017package org.apache.commons.math3.exception;
018
019import org.apache.commons.math3.exception.util.Localizable;
020import org.apache.commons.math3.exception.util.LocalizedFormats;
021import org.apache.commons.math3.exception.util.ExceptionContext;
022import 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 */
032public class MathUnsupportedOperationException extends UnsupportedOperationException
033    implements ExceptionContextProvider {
034    /** Serializable version Id. */
035    private static final long serialVersionUID = -6024911025449780478L;
036    /** Context. */
037    private final ExceptionContext context;
038
039    /**
040     * Default constructor.
041     */
042    public MathUnsupportedOperationException() {
043        this(LocalizedFormats.UNSUPPORTED_OPERATION);
044    }
045    /**
046     * @param pattern Message pattern providing the specific context of
047     * the error.
048     * @param args Arguments.
049     */
050    public MathUnsupportedOperationException(Localizable pattern,
051                                             Object ... args) {
052        context = new ExceptionContext(this);
053        context.addMessage(pattern, args);
054    }
055
056    /** {@inheritDoc} */
057    public ExceptionContext getContext() {
058        return context;
059    }
060
061    /** {@inheritDoc} */
062    @Override
063    public String getMessage() {
064        return context.getMessage();
065    }
066
067    /** {@inheritDoc} */
068    @Override
069    public String getLocalizedMessage() {
070        return context.getLocalizedMessage();
071    }
072}