1 package org.apache.turbine.services.pull;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.apache.turbine.services.TurbineServices;
20 import org.apache.turbine.util.RunData;
21
22 import org.apache.velocity.context.Context;
23
24 /***
25 * This is a Facade class for PullService.
26 *
27 * This class provides static methods that call related methods of the
28 * implementation of the PullService used by the System, according to
29 * the settings in TurbineResources.
30 *
31 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
32 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
33 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
34 * @version $Id: TurbinePull.java 264148 2005-08-29 14:21:04Z henning $
35 */
36 public abstract class TurbinePull
37 {
38 /***
39 * Utility method for accessing the service
40 * implementation
41 *
42 * @return a PullService implementation instance
43 */
44 public static PullService getService()
45 {
46 return (PullService) TurbineServices
47 .getInstance().getService(PullService.SERVICE_NAME);
48 }
49
50 /***
51 * Get the context containing global tools that will be
52 * use as part of the Turbine Pull Model.
53 *
54 * @return A Context object which contains the
55 * Global Tool instances.
56 */
57 public static final Context getGlobalContext()
58 {
59 return getService().getGlobalContext();
60 }
61
62 /***
63 * Checks whether this service has been registered. This is
64 * required by the TurbineVelocityService so it can determine
65 * whether to attempt to place the ToolBox in the context.
66 * <p>
67 * So users can use Turbine with templates in the traditional
68 * manner. If the Pull Service is not listed in
69 * <code>TurbineResources.props</code>, or no tools are specified
70 * the TurbineVelocityService will behave in its traditional
71 * manner.
72 */
73 public static final boolean isRegistered()
74 {
75 return TurbineServices.getInstance()
76 .isRegistered(PullService.SERVICE_NAME);
77 }
78
79 /***
80 * Return the absolute path of the resources directory
81 * used by application tools.
82 *
83 * @return A directory path in the file system or null.
84 */
85 public static final String getAbsolutePathToResourcesDirectory()
86 {
87 return getService().getAbsolutePathToResourcesDirectory();
88 }
89
90 /***
91 * Return the resources directory. This is relative
92 * to the webapp context.
93 *
94 * @return A directory path to the resources directory relative to the webapp root or null.
95 */
96 public static final String getResourcesDirectory()
97 {
98 return getService().getResourcesDirectory();
99 }
100
101 /***
102 * Populate the given context with all request, session
103 * and persistent scope tools (it is assumed that the context
104 * already wraps the global context, and thus already contains
105 * the global tools).
106 *
107 * @param context a Velocity Context to populate
108 * @param data a RunData object for request specific data
109 */
110 public static void populateContext(Context context, RunData data)
111 {
112 getService().populateContext(context, data);
113 }
114
115 /***
116 * Refresh the global tools. This is necessary
117 * for development work where tools depend
118 * on configuration information. The configuration
119 * information is typically cached after initialization
120 * but during development you might want the tool
121 * to refresh itself on each request.
122 * <p>
123 * If there are objects that don't implement
124 * the ApplicationTool interface, then they won't
125 * be refreshed.
126 * @deprecated No longer needed as Pull and Velocity Service are now more separate.
127 */
128 public static final void refreshGlobalTools()
129 {
130 getService().refreshGlobalTools();
131 }
132
133 /***
134 * Shoud we refresh the tools
135 * on each request. For development purposes.
136 *
137 * @return true if we should refresh the tools on every request.
138 * @deprecated No longer needed as Pull and Velocity Service are now more separate.
139 */
140 public static final boolean refreshToolsPerRequest()
141 {
142 return getService().refreshToolsPerRequest();
143 }
144
145 /***
146 * Release tool instances from the given context to the
147 * object pool
148 *
149 * @param context a Velocity Context to release tools from
150 */
151 public static void releaseTools(Context context)
152 {
153 getService().releaseTools(context);
154 }
155
156 /***
157 * Helper method that allows you to easily get a tool
158 * from a Context. Essentially, it just does the cast
159 * to an Application tool for you.
160 *
161 * @param context a Velocity Context to get tools from
162 * @param name the name of the tool to get
163 * @return ApplicationTool null if no tool could be found
164 */
165 public static ApplicationTool getTool(Context context,
166 String name)
167 {
168 try
169 {
170 return (ApplicationTool) context.get(name);
171 }
172 catch (Exception e)
173 {
174 }
175 return null;
176 }
177 }