XMLMailFactoryBean xref

View Javadoc

    1   package com.ozacc.mail.spring;
    2
    3   import java.io.File;
    4
    5   import org.springframework.beans.factory.config.AbstractFactoryBean;
    6   import org.springframework.core.io.Resource;
    7
    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;
    12
    13  /***
    14   * Spring¤ÎÀßÄ?¥Õ¥¡¥¤¥?¤Ç»ØÄê¤µ¤?¤¿¥úÁ±¡¼¥·¥ç¥ó¤ÎXML¥Õ¥¡¥¤¥?¤«¤éMail¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤¹¤?FactoryBean¡£
    15   * ¥Ç¥Õ¥©¥?¥È¤Ç¤Ï¡¢singleton¥×¥úÁÑ¥Æ¥£¤Ïfalse¤ËÀßÄê¤µ¤?¤Þ¤¹¡£
    16   * <p>
    17   * location¡¢classPath¡¢filePath¤Î½ç¤Ç¡¢°?ÈÖÀè¤Ë¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?¥×¥úÁÑ¥Æ¥£ÃÍ¤¬XML¥Õ¥¡¥¤¥?¤Î¥Ñ¥¹¤È¤·¤Æ»È¤?¤?¤Þ¤¹¡£
    18   *
    19   * @see com.ozacc.mail.impl.XMLMailBuilderImpl
    20   *
    21   * @since 1.0
    22   * @author Tomohiro Otsuka
    23   * @version $Id: XMLMailFactoryBean.java,v 1.4 2004/09/13 19:48:16 otsuka Exp $
    24   */
    25  public class XMLMailFactoryBean extends AbstractFactoryBean {
    26
    27  	private String classPath;
    28
    29  	private String filePath;
    30
    31  	private Resource location;
    32
    33  	private MailBuilder mailBuilder;
    34
    35  	/***
    36  	 * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£
    37  	 */
    38  	public XMLMailFactoryBean() {
    39  		setSingleton(false);
    40  	}
    41
    42  	/***
    43  	 * @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
    44  	 */
    45  	protected Object createInstance() throws Exception {
    46  		if (mailBuilder == null) {
    47  			init();
    48  		}
    49
    50  		if (getLocation() != null && getLocation().getFile() != null) {
    51  			return mailBuilder.buildMail(getLocation().getFile());
    52  		}
    53  		if (getClassPath() != null) {
    54  			return mailBuilder.buildMail(getClassPath());
    55  		}
    56  		if (getFilePath() != null) {
    57  			return mailBuilder.buildMail(new File(getFilePath()));
    58  		}
    59  		throw new MailBuildException("Mail¥¤¥ó¥¹¥¿¥ó¥¹¤ÎÀ¸À®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£XML¥Ç¡¼¥¿¤Î¥úÁ±¡¼¥·¥ç¥ó¤¬»ØÄê¤µ¤?¤Æ¤¤¤Þ¤»¤ó¡£");
    60  	}
    61
    62  	/***
    63  	 * mailBuilder¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤·¤Þ¤¹¡£
    64  	 */
    65  	private void init() {
    66  		mailBuilder = new XMLMailBuilderImpl();
    67  	}
    68
    69  	/***
    70  	 * @see org.springframework.beans.factory.FactoryBean#getObjectType()
    71  	 */
    72  	public Class getObjectType() {
    73  		return Mail.class;
    74  	}
    75
    76  	/***
    77  	 * <code>MailBuilder</code>¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Î¼ÂÁõ¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤ò¥»¥Ã¥È¤·¤Þ¤¹¡£
    78  	 * ¥Ç¥Õ¥©¥?¥È¤Ç¤Ï¡¢<code>XMLMailBuilderImpl</code>¤¬»ÈÍÑ¤µ¤?¤Þ¤¹¡£
    79  	 * <p>
    80  	 * ¤¿¤À¤·¡¢¤³¤³¤Ç¥»¥Ã¥È¤·¤Ê¤¤¾?¹ç¤Ï¡¢<code>XMLMailFactoryBean</code>¤Ò¤È¤Ä¤ËÉÕ¤¡¢
    81  	 * <code>XMLMailBuilderImpl</code>¥¤¥ó¥¹¥¿¥ó¥¹°?¤Ä¤¬ÊÝ»?¤µ¤?¤Þ¤¹¡£
    82  	 * ¥·¥ó¥°¥?¥È¥ó¤Î<code>MailBuilder</code>¥¤¥ó¥¹¥¿¥ó¥¹¤ò¥»¥Ã¥È¤¹¤?¤³¤È¤ò¿ä¾©¤·¤Þ¤¹¡£
    83  	 *
    84  	 * @param mailBuilder MailBuilder¥¤¥ó¥¹¥¿¥ó¥¹
    85  	 */
    86  	public void setMailBuilder(MailBuilder mailBuilder) {
    87  		this.mailBuilder = mailBuilder;
    88  	}
    89
    90  	/***
    91  	 * @return Returns the classPath.
    92  	 */
    93  	public String getClassPath() {
    94  		return classPath;
    95  	}
    96
    97  	/***
    98  	 * @param classPath The classPath to set.
    99  	 */
    100 	public void setClassPath(String classPath) {
    101 		this.classPath = classPath;
    102 	}
    103
    104 	/***
    105 	 * @return Returns the filePath.
    106 	 */
    107 	public String getFilePath() {
    108 		return filePath;
    109 	}
    110
    111 	/***
    112 	 * @param filePath The filePath to set.
    113 	 */
    114 	public void setFilePath(String filePath) {
    115 		this.filePath = filePath;
    116 	}
    117
    118 	/***
    119 	 * @return Returns the location.
    120 	 */
    121 	public Resource getLocation() {
    122 		return location;
    123 	}
    124
    125 	/***
    126 	 * @param location The location to set.
    127 	 */
    128 	public void setLocation(Resource location) {
    129 		this.location = location;
    130 	}
    131 }