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.mailrepository;
019:
020: import org.apache.avalon.cornerstone.services.store.Store;
021: import org.apache.avalon.framework.activity.Initializable;
022: import org.apache.avalon.framework.configuration.Configurable;
023: import org.apache.avalon.framework.configuration.Configuration;
024: import org.apache.avalon.framework.configuration.ConfigurationException;
025: import org.apache.avalon.framework.logger.AbstractLogEnabled;
026: import org.apache.avalon.framework.service.ServiceException;
027: import org.apache.avalon.framework.service.ServiceManager;
028: import org.apache.avalon.framework.service.Serviceable;
029: import org.apache.james.services.SpoolRepository;
030: import org.apache.mailet.Mail;
031:
032: import javax.mail.MessagingException;
033:
034: import java.util.Collection;
035: import java.util.Iterator;
036:
037: /**
038: * This is a wrapper for the various implementations of SpoolRepositories.
039: * This does select the real spool repository via the select method of the
040: * provided Store.
041: *
042: * <p>The select method requires a configuration object with the form:
043: * <br><spoolrepository destinationURL="file://path-to-root-dir-for-repository"
044: * <br> type="SPOOL">
045: * <br></spoolrepository>
046: *
047: * @version This is $Revision: 165416 $
048: */
049: public class MailStoreSpoolRepository extends AbstractLogEnabled
050: implements Serviceable, Initializable, Configurable,
051: SpoolRepository {
052:
053: /**
054: * The wrapped spoolRepository
055: */
056: private SpoolRepository spoolRep;
057:
058: /**
059: * The providing mailStore
060: */
061: private Store mailStore;
062:
063: /**
064: * The repository configuration
065: */
066: private Configuration configuration;
067:
068: /**
069: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
070: */
071: public void service(ServiceManager serviceManager)
072: throws ServiceException {
073: mailStore = (Store) serviceManager.lookup(Store.ROLE);
074: }
075:
076: /**
077: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
078: */
079: public void configure(Configuration conf)
080: throws ConfigurationException {
081: this .configuration = conf;
082: }
083:
084: /**
085: * @see org.apache.avalon.framework.activity.Initializable#initialize()
086: */
087: public void initialize() throws Exception {
088: try {
089: spoolRep = (SpoolRepository) mailStore
090: .select(configuration);
091: } catch (Exception e) {
092: getLogger().error("Cannot open private SpoolRepository");
093: throw e;
094: }
095: if (getLogger().isInfoEnabled()) {
096: getLogger().info(
097: "SpoolRepository opened: " + spoolRep.hashCode());
098: }
099: }
100:
101: /**
102: * @see org.apache.james.services.SpoolRepository#accept()
103: */
104: public Mail accept() throws InterruptedException {
105: return spoolRep.accept();
106: }
107:
108: /**
109: * @see org.apache.james.services.SpoolRepository#accept(long)
110: */
111: public Mail accept(final long delay) throws InterruptedException {
112: return spoolRep.accept(delay);
113: }
114:
115: /**
116: * @see org.apache.james.services.SpoolRepository#accept(org.apache.james.services.SpoolRepository.AcceptFilter)
117: */
118: public Mail accept(SpoolRepository.AcceptFilter filter)
119: throws InterruptedException {
120: return spoolRep.accept(filter);
121: }
122:
123: /**
124: * @see org.apache.james.services.MailRepository#store(org.apache.james.core.MailImpl)
125: */
126: public void store(Mail mc) throws MessagingException {
127: spoolRep.store(mc);
128: }
129:
130: /**
131: * @see org.apache.james.services.MailRepository#list()
132: */
133: public Iterator list() throws MessagingException {
134: return spoolRep.list();
135: }
136:
137: /**
138: * @see org.apache.james.services.MailRepository#retrieve(java.lang.String)
139: */
140: public Mail retrieve(String key) throws MessagingException {
141: return spoolRep.retrieve(key);
142: }
143:
144: /**
145: * @see org.apache.james.services.MailRepository#remove(org.apache.james.core.MailImpl)
146: */
147: public void remove(Mail mail) throws MessagingException {
148: spoolRep.remove(mail);
149: }
150:
151: /**
152: * @see org.apache.james.services.MailRepository#remove(java.util.Collection)
153: */
154: public void remove(Collection mails) throws MessagingException {
155: spoolRep.remove(mails);
156: }
157:
158: /**
159: * @see org.apache.james.services.MailRepository#remove(java.lang.String)
160: */
161: public void remove(String key) throws MessagingException {
162: spoolRep.remove(key);
163: }
164:
165: /**
166: * @see org.apache.james.services.MailRepository#lock(java.lang.String)
167: */
168: public boolean lock(String key) throws MessagingException {
169: return spoolRep.lock(key);
170: }
171:
172: /**
173: * @see org.apache.james.services.MailRepository#unlock(java.lang.String)
174: */
175: public boolean unlock(String key) throws MessagingException {
176: return spoolRep.unlock(key);
177: }
178:
179: }
|