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: ****************************************************************/package org.apache.james.transport;
019:
020: import java.io.File;
021: import java.util.Vector;
022:
023: import org.apache.avalon.framework.activity.Initializable;
024: import org.apache.avalon.framework.configuration.Configurable;
025: import org.apache.avalon.framework.configuration.Configuration;
026: import org.apache.avalon.framework.configuration.ConfigurationException;
027: import org.apache.avalon.framework.context.Context;
028: import org.apache.avalon.framework.context.ContextException;
029: import org.apache.avalon.framework.context.Contextualizable;
030: import org.apache.avalon.framework.logger.AbstractLogEnabled;
031: import org.apache.avalon.framework.service.DefaultServiceManager;
032: import org.apache.avalon.framework.service.ServiceException;
033: import org.apache.avalon.framework.service.ServiceManager;
034: import org.apache.avalon.framework.service.Serviceable;
035: import org.apache.mailet.MailetContext;
036:
037: /**
038: *
039: * $Id: Loader.java 494012 2007-01-08 10:23:58Z norman $
040: */
041: public abstract class Loader extends AbstractLogEnabled implements
042: Contextualizable, Serviceable, Configurable, Initializable {
043:
044: protected String baseDirectory = null;
045: protected final String MAILET_PACKAGE = "mailetpackage";
046: protected final String MATCHER_PACKAGE = "matcherpackage";
047: /**
048: * The list of packages that may contain Mailets or matchers
049: */
050: protected Vector packages;
051:
052: /**
053: * System service manager
054: */
055: private ServiceManager serviceManager;
056:
057: /**
058: * Mailet context
059: */
060: protected MailetContext mailetContext;
061:
062: /**
063: * @see org.apache.avalon.framework.context.Contextualizable#contextualize(Context)
064: */
065: public void contextualize(final Context context)
066: throws ContextException {
067: try {
068: baseDirectory = ((File) context.get("app.home"))
069: .getCanonicalPath();
070: } catch (Throwable e) {
071: getLogger().error(
072: "can't get base directory for mailet loader");
073: throw new ContextException(
074: "can't contextualise mailet loader "
075: + e.getMessage(), e);
076: }
077: }
078:
079: protected void getPackages(Configuration conf, String packageType)
080: throws ConfigurationException {
081: packages = new Vector();
082: packages.addElement("");
083: final Configuration[] pkgConfs = conf.getChildren(packageType);
084: for (int i = 0; i < pkgConfs.length; i++) {
085: Configuration c = pkgConfs[i];
086: String packageName = c.getValue();
087: if (!packageName.endsWith(".")) {
088: packageName += ".";
089: }
090: packages.addElement(packageName);
091: }
092: }
093:
094: /**
095: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
096: */
097: public void service(ServiceManager sm) throws ServiceException {
098: serviceManager = new DefaultServiceManager(sm);
099: }
100:
101: /**
102: * @see org.apache.avalon.framework.activity.Initializable#initialize()
103: */
104: public void initialize() throws Exception {
105: mailetContext = (MailetContext) serviceManager
106: .lookup("org.apache.mailet.MailetContext");
107: }
108:
109: /**
110: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
111: */
112: public abstract void configure(Configuration arg0)
113: throws ConfigurationException;
114:
115: }
|