1 /***************************************************************** 2 * Licensed to the Apache Software Foundation (ASF) under one * 3 * or more contributor license agreements. See the NOTICE file * 4 * distributed with this work for additional information * 5 * regarding copyright ownership. The ASF licenses this file * 6 * to you under the Apache License, Version 2.0 (the * 7 * "License"); you may not use this file except in compliance * 8 * with the License. You may obtain a copy of the License at * 9 * * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, * 13 * software distributed under the License is distributed on an * 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 * KIND, either express or implied. See the License for the * 16 * specific language governing permissions and limitations * 17 * under the License. * 18 ****************************************************************/ 19 package org.apache.james.transport; 20 import java.io.File; 21 import java.util.Vector; 22 23 import org.apache.avalon.framework.activity.Initializable; 24 import org.apache.avalon.framework.configuration.Configurable; 25 import org.apache.avalon.framework.configuration.Configuration; 26 import org.apache.avalon.framework.configuration.ConfigurationException; 27 import org.apache.avalon.framework.context.Context; 28 import org.apache.avalon.framework.context.ContextException; 29 import org.apache.avalon.framework.context.Contextualizable; 30 import org.apache.avalon.framework.logger.AbstractLogEnabled; 31 import org.apache.avalon.framework.service.DefaultServiceManager; 32 import org.apache.avalon.framework.service.ServiceException; 33 import org.apache.avalon.framework.service.ServiceManager; 34 import org.apache.avalon.framework.service.Serviceable; 35 import org.apache.mailet.MailetContext; 36 37 /*** 38 * 39 * $Id: Loader.java 494012 2007-01-08 10:23:58Z norman $ 40 */ 41 public abstract class Loader extends AbstractLogEnabled implements Contextualizable, Serviceable, Configurable, Initializable { 42 43 protected String baseDirectory = null; 44 protected final String MAILET_PACKAGE = "mailetpackage"; 45 protected final String MATCHER_PACKAGE = "matcherpackage"; 46 /*** 47 * The list of packages that may contain Mailets or matchers 48 */ 49 protected Vector packages; 50 51 /*** 52 * System service manager 53 */ 54 private ServiceManager serviceManager; 55 56 /*** 57 * Mailet context 58 */ 59 protected MailetContext mailetContext; 60 61 /*** 62 * @see org.apache.avalon.framework.context.Contextualizable#contextualize(Context) 63 */ 64 public void contextualize(final Context context) throws ContextException 65 { 66 try 67 { 68 baseDirectory = ((File)context.get( "app.home") ).getCanonicalPath(); 69 } 70 catch (Throwable e) 71 { 72 getLogger().error( "can't get base directory for mailet loader" ); 73 throw new ContextException("can't contextualise mailet loader " + e.getMessage(), e); 74 } 75 } 76 77 protected void getPackages(Configuration conf, String packageType) 78 throws ConfigurationException { 79 packages = new Vector(); 80 packages.addElement(""); 81 final Configuration[] pkgConfs = conf.getChildren(packageType); 82 for (int i = 0; i < pkgConfs.length; i++) { 83 Configuration c = pkgConfs[i]; 84 String packageName = c.getValue(); 85 if (!packageName.endsWith(".")) { 86 packageName += "."; 87 } 88 packages.addElement(packageName); 89 } 90 } 91 92 /*** 93 * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) 94 */ 95 public void service(ServiceManager sm) throws ServiceException { 96 serviceManager = new DefaultServiceManager(sm); 97 } 98 99 /*** 100 * @see org.apache.avalon.framework.activity.Initializable#initialize() 101 */ 102 public void initialize() throws Exception { 103 mailetContext = (MailetContext) serviceManager.lookup("org.apache.mailet.MailetContext"); 104 } 105 106 /*** 107 * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) 108 */ 109 public abstract void configure(Configuration arg0) throws ConfigurationException; 110 111 }