1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.components.factorybeans;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import javax.servlet.ServletConfig;
23
24 import org.apache.pluto.factory.Factory;
25 import org.springframework.beans.factory.BeanCreationException;
26 import org.springframework.beans.factory.config.AbstractFactoryBean;
27
28 /***
29 * <p>
30 * PlutoFactoryFactoryBean
31 * </p>
32 * <p>
33 *
34 * </p>
35 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
36 * @version $Id: PlutoFactoryFactoryBean.java 516448 2007-03-09 16:25:47Z ate $
37 *
38 */
39 public class PlutoFactoryFactoryBean extends AbstractFactoryBean
40 {
41
42 private String className;
43 private Map props;
44 private ServletConfig servletConfig;
45 private Object bean;
46
47 /***
48 * <p>
49 * createInstance
50 * </p>
51 *
52 * @see org.springframework.beans.factory.config.AbstractFactoryBean#createInstance()
53 * @return
54 * @throws java.lang.Exception
55 */
56 protected Object createInstance() throws Exception
57 {
58 Factory factory;
59 if(bean == null && className != null)
60 {
61 factory = (Factory)Thread.currentThread()
62 .getContextClassLoader().loadClass(className).newInstance();
63 }
64 else if(bean != null)
65 {
66 factory = (Factory)bean;
67 }
68 else
69 {
70 throw new BeanCreationException("PlutoFactoryFactoryBean requires either a 'className' or a 'bean' reference to be set.");
71 }
72
73 if(props == null)
74 {
75 props = new HashMap();
76 }
77
78 factory.init(servletConfig, props);
79 return factory;
80 }
81
82 /***
83 * <p>
84 * getObjectType
85 * </p>
86 *
87 * @see org.springframework.beans.factory.FactoryBean#getObjectType()
88 * @return
89 */
90 public Class getObjectType()
91 {
92 return Factory.class;
93 }
94
95
96
97
98 /***
99 * @return Returns the props.
100 */
101 public Map getProps()
102 {
103 return props;
104 }
105 /***
106 * @param props The props to set.
107 */
108 public void setProps( Map props )
109 {
110 this.props = props;
111 }
112 /***
113 * @return Returns the servletConfig.
114 */
115 public ServletConfig getServletConfig()
116 {
117 return servletConfig;
118 }
119 /***
120 * @param servletConfig The servletConfig to set.
121 */
122 public void setServletConfig( ServletConfig servletConfig )
123 {
124 this.servletConfig = servletConfig;
125 }
126 /***
127 * @return Returns the className.
128 */
129 public String getClassName()
130 {
131 return className;
132 }
133 /***
134 * @param className The className to set.
135 */
136 public void setClassName( String className )
137 {
138 this.className = className;
139 }
140
141 public Object getBean()
142 {
143 return bean;
144 }
145
146
147 public void setBean(Object bean)
148 {
149 this.bean = bean;
150 }
151
152 }