001/* 
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.felix.ipojo;
020
021/**
022 * This class defines the exception thrown when an instance cannot be configured correctly.
023 * This exception occurs when component metadata are not correct.
024 * @see Exception
025 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
026 */
027public class ConfigurationException extends Exception {
028    
029    /**
030     * Serialization Id.
031     */
032    private static final long serialVersionUID = 1L;
033    
034    /**
035     * The component type on which the error occurs.
036     * Uses the factory name.
037     */
038    private String m_type;
039    
040    /**
041     * Creates a new configuration exception.
042     * @param message the error message
043     * @see Exception#Exception(String)
044     */
045    public ConfigurationException(String message) {
046        this(message, (String) null);
047    }
048
049    /**
050     * Creates a new configuration exception.
051     * @param mes the error message
052     * @param type the component type
053     * @see Exception#Exception(String)
054     */
055    public ConfigurationException(String mes, String type) {
056        this(mes, null, type);
057    }
058
059    public ConfigurationException(String message, Throwable cause) {
060        this(message, cause, null);
061    }
062
063    public ConfigurationException(String message, Throwable cause, String type) {
064        super(message, cause);
065        m_type = type;
066    }
067
068    /**
069     * Gets the error message.
070     * @return the error message.
071     * @see java.lang.Throwable#getMessage()
072     */
073    public String getMessage() {
074        if (m_type == null) {
075            return super.getMessage();
076        } else {
077            return "The configuration is not correct for the type " + m_type + " : " + super.getMessage();
078        }
079    }
080
081}