KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > pull > TurbinePull


1 package org.apache.turbine.services.pull;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
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,v 1.7.2.2 2004/05/20 03:06:48 seade Exp $
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 JavaDoc 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 JavaDoc 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 JavaDoc name)
167     {
168         try
169         {
170             return (ApplicationTool) context.get(name);
171         }
172         catch (Exception JavaDoc e)
173         {
174         }
175         return null;
176     }
177 }
178
Popular Tags