1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.util.template;
18
19
20 import org.apache.jetspeed.util.template.JetspeedLink;
21 import org.apache.jetspeed.services.resources.JetspeedResources;
22
23
24 import org.apache.turbine.util.TurbineException;
25 import org.apache.turbine.services.factory.FactoryService;
26 import org.apache.turbine.services.pool.TurbinePool;
27 import org.apache.turbine.services.TurbineServices;
28 import org.apache.turbine.util.RunData;
29
30 /***
31 * Return a JetspeedLink object. The object may be
32 * returned from a pool or instanciated. The pool
33 * is maintained by Turbine's pool service.
34 *
35 */
36 public class JetspeedLinkFactory
37 {
38 /***
39 * Name of class for JetspeedLink. The class is the same one used
40 * by the tool <code>jslink</code>, so the class name is retrieved from
41 * the tool's configuration.
42 */
43 private static String JETSPEEDLINK_CLASSNAME = JetspeedResources.getString("tool.request.jslink","org.apache.jetspeed.util.template.BaseJetspeedLink");
44 private static FactoryService factoryService = (FactoryService) TurbineServices.
45 getInstance().getService(FactoryService.SERVICE_NAME);
46
47
48 /***
49 * Get an JetspeedLink object. The object may be retreived
50 * from a pool. If no object is available in the pool, then one will
51 * be instanciated.
52 *
53 * The JetspeedLink's init() should be called to return a valid link.
54 *
55 * @throws TurbineException by Turbine's pool service
56 * @return JetspeedLink
57 */
58 static JetspeedLink getInstance()
59 throws TurbineException
60 {
61 JetspeedLink jsLink = (JetspeedLink) TurbinePool.getInstance( JETSPEEDLINK_CLASSNAME);
62 if (jsLink == null)
63 jsLink = (JetspeedLink) factoryService.getInstance(JETSPEEDLINK_CLASSNAME);
64 return jsLink;
65 }
66
67 /***
68 * Get an initialized JetspeedLink object. The object may be retreived
69 * from a pool. If no object is available in the pool, then one will
70 * be instanciated. The object will be initialized with Rundata.
71 *
72 * @param rundata The request data.
73 * @throws TurbineException by Turbine's pool service
74 * @return JetspeedLink
75 */
76 public static JetspeedLink getInstance( RunData rundata)
77 throws TurbineException
78 {
79 JetspeedLink jsLink = getInstance();
80 if (jsLink != null)
81 jsLink.init(rundata);
82 return jsLink;
83 }
84
85 /***
86 * Return an object to the pool
87 *
88 * @param jetspeedLink object to return to pool
89 */
90 public static void putInstance(JetspeedLink jetspeedLink)
91 {
92 if (jetspeedLink != null)
93 TurbinePool.putInstance( jetspeedLink);
94 return;
95 }
96 }