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.XMLMailBuilder;
11
12 /***
13 * Spring¤ÎÀßÄ?¥Õ¥¡¥¤¥?¤Ç»ØÄꤵ¤?¤¿¥úÁ±¡¼¥·¥ç¥ó¤ÎXML¥Õ¥¡¥¤¥?¤«¤éMail¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤¹¤?FactoryBean¡£
14 * ¥Ç¥Õ¥©¥?¥È¤Ç¤Ï¡¢singleton¥×¥úÁѥƥ£¤Ïfalse¤ËÀßÄꤵ¤?¤Þ¤¹¡£
15 * <p>
16 * location¡¢classPath¡¢filePath¤Î½ç¤Ç¡¢°?ÈÖÀè¤Ë¥»¥Ã¥È¤µ¤?¤Æ¤¤¤?¥×¥úÁѥƥ£Ãͤ¬XML¥Õ¥¡¥¤¥?¤Î¥Ñ¥¹¤È¤·¤Æ»È¤?¤?¤Þ¤¹¡£
17 *
18 * @author Tomohiro Otsuka
19 * @version $Id: XMLMailFactoryBean.java,v 1.2 2004/09/11 01:41:59 otsuka Exp $
20 */
21 public class XMLMailFactoryBean extends AbstractFactoryBean {
22
23 private String classPath;
24
25 private String filePath;
26
27 private Resource location;
28
29 private XMLMailBuilder mailBuilder;
30
31 /***
32 * ¥³¥ó¥¹¥È¥é¥¯¥¿¡£
33 */
34 public XMLMailFactoryBean() {
35 mailBuilder = XMLMailBuilder.getInstance();
36 setSingleton(false);
37 }
38
39 /***
40 * @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
41 */
42 protected Object createInstance() throws Exception {
43 if (getLocation() != null && getLocation().getFile() != null) {
44 return mailBuilder.buildMail(getLocation().getFile());
45 }
46 if (getClassPath() != null) {
47 return mailBuilder.buildMail(getClassPath());
48 }
49 if (getFilePath() != null) {
50 return mailBuilder.buildMail(new File(getFilePath()));
51 }
52 throw new MailBuildException("Mail¥¤¥ó¥¹¥¿¥ó¥¹¤ÎÀ¸À®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£XML¥Ç¡¼¥¿¤Î¥úÁ±¡¼¥·¥ç¥ó¤¬»ØÄꤵ¤?¤Æ¤¤¤Þ¤»¤ó¡£");
53 }
54
55 /***
56 * @see org.springframework.beans.factory.FactoryBean#getObjectType()
57 */
58 public Class getObjectType() {
59 return Mail.class;
60 }
61
62 /***
63 * @return Returns the classPath.
64 */
65 public String getClassPath() {
66 return classPath;
67 }
68
69 /***
70 * @param classPath The classPath to set.
71 */
72 public void setClassPath(String classPath) {
73 this.classPath = classPath;
74 }
75
76 /***
77 * @return Returns the filePath.
78 */
79 public String getFilePath() {
80 return filePath;
81 }
82
83 /***
84 * @param filePath The filePath to set.
85 */
86 public void setFilePath(String filePath) {
87 this.filePath = filePath;
88 }
89
90 /***
91 * @return Returns the location.
92 */
93 public Resource getLocation() {
94 return location;
95 }
96
97 /***
98 * @param location The location to set.
99 */
100 public void setLocation(Resource location) {
101 this.location = location;
102 }
103 }