1 package com.ozacc.mail.spring;
5 import org.springframework.beans.factory.config.AbstractFactoryBean;
6 import org.springframework.core.io.Resource;
8 import com.ozacc.mail.Mail;
9 import com.ozacc.mail.MailBuildException;
10 import com.ozacc.mail.MailBuilder;
11 import com.ozacc.mail.impl.XMLMailBuilderImpl;
14 * Springの設定ファイルで指定されたロケーションのXMLファイルからMailインスタンスを生成するFactoryBean。
15 * デフォルトでは、singletonプロパティはfalseに設定されます。
17 * location、classPath、filePathの順で、一番先にセットされているプロパティ値がXMLファイルのパスとして使われます。
19 * @see com.ozacc.mail.impl.XMLMailBuilderImpl
22 * @author Tomohiro Otsuka
23 * @version $Id: XMLMailFactoryBean.java,v 1.4 2004/09/13 19:48:16 otsuka Exp $
25 public class XMLMailFactoryBean extends AbstractFactoryBean<Mail> {
27 private String classPath;
29 private String filePath;
31 private Resource location;
33 private MailBuilder mailBuilder;
38 public XMLMailFactoryBean() {
43 * @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
45 protected Mail createInstance() throws Exception {
46 if (mailBuilder == null) {
50 if (getLocation() != null) {
51 return mailBuilder.buildMail(getLocation().getFile());
53 if (getClassPath() != null) {
54 return mailBuilder.buildMail(getClassPath());
56 if (getFilePath() != null) {
57 return mailBuilder.buildMail(new File(getFilePath()));
59 throw new MailBuildException("Mailインスタンスの生成に失敗しました。XMLデータのロケーションが指定されていません。");
63 * mailBuilderインスタンスを生成します。
66 mailBuilder = new XMLMailBuilderImpl();
70 * @see org.springframework.beans.factory.FactoryBean#getObjectType()
72 public Class<Mail> getObjectType() {
77 * <code>MailBuilder</code>インターフェースの実装クラスのインスタンスをセットします。
78 * デフォルトでは、<code>XMLMailBuilderImpl</code>が使用されます。
80 * ただし、ここでセットしない場合は、<code>XMLMailFactoryBean</code>ひとつに付き、
81 * <code>XMLMailBuilderImpl</code>インスタンス一つが保持されます。
82 * シングルトンの<code>MailBuilder</code>インスタンスをセットすることを推奨します。
84 * @param mailBuilder MailBuilderインスタンス
86 public void setMailBuilder(MailBuilder mailBuilder) {
87 this.mailBuilder = mailBuilder;
91 * @return Returns the classPath.
93 public String getClassPath() {
98 * @param classPath The classPath to set.
100 public void setClassPath(String classPath) {
101 this.classPath = classPath;
105 * @return Returns the filePath.
107 public String getFilePath() {
112 * @param filePath The filePath to set.
114 public void setFilePath(String filePath) {
115 this.filePath = filePath;
119 * @return Returns the location.
121 public Resource getLocation() {
126 * @param location The location to set.
128 public void setLocation(Resource location) {
129 this.location = location;