Package mfinder

Source Code of mfinder.MFinderException

/*
* Copyright (C) 2010-2011 sunjumper@163.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package mfinder;

import mfinder.impl.ActionProxy;
import mfinder.impl.InterceptorProxy;
import mfinder.impl.ResultTypeProxy;

/**
* mfinder用此异常或其子异常来标识mfinder特定的异常信息。
*/
public class MFinderException extends RuntimeException {

    /** 定位异常发生对象 */
    private Object target;

    /**
     * 构造一个包含指定详细消息和异常发生对象的MFinderException。
     *
     * @param message 详细消息。
     * @param target 异常发生的对象。
     */
    public MFinderException(String message, Object target) {
        super(message);
        this.target = target;
    }

    /**
     * 构造一个包含指定的异常原因和发生对象的MFinderException。
     *
     * @param cause 异常原因。
     * @param target 异常发生的对象。
     */
    public MFinderException(Throwable cause, Object target) {
        super(cause);
        this.target = target;
    }

    /**
     * 构造一个包含指定详细消息、原因和发生对象的MFinderException。
     *
     * @param message 详细消息。
     * @param cause 异常原因。
     * @param target 异常发生的对象。
     */
    public MFinderException(String message, Throwable cause, Object target) {
        super(message, cause);
        this.target = target;
    }

    /**
     * 返回异常发生的对象。
     *
     * @return 异常发生的对象,未知或不存在则返回null。
     */
    public Object getTarget() {
        return target;
    }

    /**
     * 返回异常发生的对象信息。
     *
     * @return 常发生对象的方法描述信息。
     *
     * @see ActionProxy#getMethodInfo()
     */
    public String getTargetInfo() {
        if (target == null)
            return null;
        if (target instanceof ActionProxy) {
            ActionProxy ap = (ActionProxy) target;
            return "action[\"" + ap.getPath() + "\"] - " + ap.getMethodInfo();
        }
        if (target instanceof InterceptorProxy) {
            InterceptorProxy ip = (InterceptorProxy) target;
            return "interceptor[\"" + ip.getName() + "\"] - " + ip.getMethodInfo();
        }
        if (target instanceof ResultTypeProxy) {
            ResultTypeProxy rp = (ResultTypeProxy) target;
            return "result[\"" + rp.getType() + "\"] - " + rp.getMethodInfo();
        }
        return target.toString();
    }
}
TOP

Related Classes of mfinder.MFinderException

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.