⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exceptiontranslationadvice.java

📁 java 和flex的整合,主要是spring和flex的整合,不可多得啊
💻 JAVA
字号:
/* * Copyright 2002-2009 the original author or authors. *  * 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 org.springframework.flex.core;import java.util.HashSet;import java.util.Set;import org.springframework.aop.ThrowsAdvice;import org.springframework.util.ClassUtils;import flex.messaging.MessageException;/** * Catches Throwable objects and looks for a registered {@link ExceptionTranslator} that knows how to translate them to * more specific BlazeDS MessageExceptions to be re-thrown so that a proper AMF error will be sent back to the client. *  * <p> * If the caught object is an instance of {@link MessageException} with the generic "Server.Processing" fault code, a * translator will be looked up for the root cause exception type rather than the generic wrapper MessageException. *  * @author Jeremy Grelle */public class ExceptionTranslationAdvice implements ThrowsAdvice {    private static final String SERVER_PROCESSING_CODE = "Server.Processing";    private Set<ExceptionTranslator> exceptionTranslators = new HashSet<ExceptionTranslator>();    /**     * Apply translation to the thrown exception.     *      * @param t the thrown exception     * @throws Throwable the translated exception     */    public void afterThrowing(Throwable t) throws Throwable {        Class<?> candidate = t.getClass();        if (ClassUtils.isAssignable(MessageException.class, candidate)) {            MessageException me = (MessageException) t;            if (SERVER_PROCESSING_CODE.equals(me.getCode()) && me.getRootCause() != null) {                candidate = me.getRootCause().getClass();                t = me.getRootCause();            }        }        for (ExceptionTranslator translator : this.exceptionTranslators) {            if (translator.handles(candidate)) {                MessageException result = translator.translate(t);                if (result != null) {                    throw result;                }            }        }        throw t;    }    /**     * Returns the set of provided exception translators     *      * @return the exception translators     */    public Set<ExceptionTranslator> getExceptionTranslators() {        return this.exceptionTranslators;    }    /**     * Sets the provided exception translators     *      * @param translators the exception translators to set     */    public void setExceptionTranslators(Set<ExceptionTranslator> translators) {        this.exceptionTranslators = translators;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -