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.3 2004/09/13 07:12:56 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 mailBuilder = new XMLMailBuilderImpl();
40 setSingleton(false);
41 }
42
43 /***
44 * @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
45 */
46 protected Object createInstance() throws Exception {
47 if (getLocation() != null && getLocation().getFile() != null) {
48 return mailBuilder.buildMail(getLocation().getFile());
49 }
50 if (getClassPath() != null) {
51 return mailBuilder.buildMail(getClassPath());
52 }
53 if (getFilePath() != null) {
54 return mailBuilder.buildMail(new File(getFilePath()));
55 }
56 throw new MailBuildException("Mail¥¤¥ó¥¹¥¿¥ó¥¹¤ÎÀ¸À®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£XML¥Ç¡¼¥¿¤Î¥úÁ±¡¼¥·¥ç¥ó¤¬»ØÄꤵ¤?¤Æ¤¤¤Þ¤»¤ó¡£");
57 }
58
59 /***
60 * @see org.springframework.beans.factory.FactoryBean#getObjectType()
61 */
62 public Class getObjectType() {
63 return Mail.class;
64 }
65
66 /***
67 * @return Returns the classPath.
68 */
69 public String getClassPath() {
70 return classPath;
71 }
72
73 /***
74 * @param classPath The classPath to set.
75 */
76 public void setClassPath(String classPath) {
77 this.classPath = classPath;
78 }
79
80 /***
81 * @return Returns the filePath.
82 */
83 public String getFilePath() {
84 return filePath;
85 }
86
87 /***
88 * @param filePath The filePath to set.
89 */
90 public void setFilePath(String filePath) {
91 this.filePath = filePath;
92 }
93
94 /***
95 * @return Returns the location.
96 */
97 public Resource getLocation() {
98 return location;
99 }
100
101 /***
102 * @param location The location to set.
103 */
104 public void setLocation(Resource location) {
105 this.location = location;
106 }
107 }