📄 matchloader.java
字号:
/*********************************************************************** * Copyright (c) 2000-2004 The Apache Software Foundation. * * All rights reserved. * * ------------------------------------------------------------------- * * 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.apache.james.transport;import javax.mail.MessagingException;import org.apache.avalon.framework.configuration.Configurable;import org.apache.avalon.framework.configuration.Configuration;import org.apache.avalon.framework.configuration.ConfigurationException;import org.apache.james.core.MatcherConfigImpl;import org.apache.mailet.MailetContext;import org.apache.mailet.MailetException;import org.apache.mailet.Matcher;/** * Loads Matchers for use inside James. * */public class MatchLoader extends Loader implements Configurable { /** * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration) */ public void configure(Configuration conf) throws ConfigurationException { getPackages(conf,MATCHER_PACKAGE); configureMailetClassLoader(); } /** * Get a new Matcher with the specified name acting * in the specified context. * * @param matchName the name of the matcher to be loaded * @param context the MailetContext to be passed to the new * matcher * @throws MessagingException if an error occurs */ public Matcher getMatcher(String matchName, MailetContext context) throws MessagingException { try { String condition = (String) null; int i = matchName.indexOf('='); if (i != -1) { condition = matchName.substring(i + 1); matchName = matchName.substring(0, i); } for (i = 0; i < packages.size(); i++) { String className = (String) packages.elementAt(i) + matchName; try { MatcherConfigImpl configImpl = new MatcherConfigImpl(); configImpl.setMatcherName(matchName); configImpl.setCondition(condition); configImpl.setMailetContext(context); Matcher matcher = (Matcher) mailetClassLoader.loadClass(className).newInstance(); matcher.init(configImpl); return matcher; } catch (ClassNotFoundException cnfe) { //do this so we loop through all the packages } } StringBuffer exceptionBuffer = new StringBuffer(128) .append("Requested matcher not found: ") .append(matchName) .append(". looked in ") .append(packages.toString()); throw new ClassNotFoundException(exceptionBuffer.toString()); } catch (MessagingException me) { throw me; } catch (Exception e) { StringBuffer exceptionBuffer = new StringBuffer(128).append("Could not load matcher (").append(matchName).append( ")"); throw new MailetException(exceptionBuffer.toString(), e); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -