View Javadoc

    1   package com.ozacc.mail.spring;
    2
    3   import java.util.ArrayList;
    4   import java.util.Iterator;
    5   import java.util.List;
    6
    7   import org.quartz.JobExecutionContext;
    8   import org.quartz.JobExecutionException;
    9   import org.springframework.scheduling.quartz.QuartzJobBean;
    10
    11  import com.ozacc.mail.fetch.FetchMailPro;
    12  import com.ozacc.mail.fetch.ReceivedMail;
    13  import com.ozacc.mail.mailet.MailetWrapper;
    14
    15  /***
    16   *
    17   * @author Tomohiro Otsuka
    18   * @version $Id: MailetRunnerJob.java,v 1.1.2.2 2005/01/18 07:22:20 otsuka Exp $
    19   */
    20  public class MailetRunnerJob extends QuartzJobBean {
    21
    22  	private List mailetWrapperList;
    23
    24  	private FetchMailPro fetchMailPro;
    25
    26  	/***
    27  	 * コンストラクタ。
    28  	 */
    29  	public MailetRunnerJob() {
    30  		mailetWrapperList = new ArrayList();
    31  	}
    32
    33  	/***
    34  	 * @see org.springframework.scheduling.quartz.QuartzJobBean#executeInternal(org.quartz.JobExecutionContext)
    35  	 */
    36  	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    37  		fetchMailPro.connect();
    38  		try {
    39  			int count = fetchMailPro.getMailCount();
    40  			for (int i = 1; i <= count; i++) {
    41  				ReceivedMail mail = fetchMailPro.getMail(i);
    42  				processMail(mail);
    43  			}
    44  		} finally {
    45  			if (fetchMailPro.isConnected()) {
    46  				fetchMailPro.disconnect();
    47  			}
    48  		}
    49  	}
    50
    51  	/***
    52  	 * 指定された受信メールに対してMailetを適用します。
    53  	 *
    54  	 * @param mail MailetUnitに渡す受信メール
    55  	 */
    56  	private void processMail(ReceivedMail mail) {
    57  		for (Iterator itr = mailetWrapperList.iterator(); itr.hasNext();) {
    58  			MailetWrapper mailetUnit = (MailetWrapper)itr.next();
    59  			mailetUnit.execute(mail);
    60  		}
    61  	}
    62
    63  	/***
    64  	 * @param fetchMailPro The fetchMailPro to set.
    65  	 */
    66  	public void setFetchMailPro(FetchMailPro fetchMailPro) {
    67  		this.fetchMailPro = fetchMailPro;
    68  	}
    69
    70  	/***
    71  	 * @param mailetWrapperList The mailetWrapperList to set.
    72  	 */
    73  	public void setMailetWrapperList(List mailetWrapperList) {
    74  		this.mailetWrapperList = mailetWrapperList;
    75  	}
    76
    77  }