1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.util.template;
1819// Jetspeed20import org.apache.jetspeed.util.template.JetspeedLink;
21import org.apache.jetspeed.services.resources.JetspeedResources;
2223// Turbine24import org.apache.turbine.util.TurbineException;
25import org.apache.turbine.services.factory.FactoryService;
26import org.apache.turbine.services.pool.TurbinePool;
27import org.apache.turbine.services.TurbineServices;
28import org.apache.turbine.util.RunData;
2930/***31 * Return a JetspeedLink object. The object may be32 * returned from a pool or instanciated. The pool33 * is maintained by Turbine's pool service.34 *35 */36publicclassJetspeedLinkFactory37 {
38/***39 * Name of class for JetspeedLink. The class is the same one used40 * by the tool <code>jslink</code>, so the class name is retrieved from41 * the tool's configuration.42 */43privatestatic String JETSPEEDLINK_CLASSNAME = JetspeedResources.getString("tool.request.jslink","org.apache.jetspeed.util.template.BaseJetspeedLink");
44privatestatic FactoryService factoryService = (FactoryService) TurbineServices.
45 getInstance().getService(FactoryService.SERVICE_NAME);
464748/***49 * Get an JetspeedLink object. The object may be retreived50 * from a pool. If no object is available in the pool, then one will51 * be instanciated.52 *53 * The JetspeedLink's init() should be called to return a valid link.54 *55 * @throws TurbineException by Turbine's pool service56 * @return JetspeedLink57 */58staticJetspeedLink getInstance()
59 throws TurbineException
60 {
61JetspeedLink jsLink = (JetspeedLink) TurbinePool.getInstance( JETSPEEDLINK_CLASSNAME);
62if (jsLink == null)
63 jsLink = (JetspeedLink) factoryService.getInstance(JETSPEEDLINK_CLASSNAME);
64return jsLink;
65 }
6667/***68 * Get an initialized JetspeedLink object. The object may be retreived69 * from a pool. If no object is available in the pool, then one will70 * be instanciated. The object will be initialized with Rundata.71 *72 * @param rundata The request data.73 * @throws TurbineException by Turbine's pool service74 * @return JetspeedLink75 */76publicstaticJetspeedLink getInstance( RunData rundata)
77 throws TurbineException
78 {
79JetspeedLink jsLink = getInstance();
80if (jsLink != null)
81 jsLink.init(rundata);
82return jsLink;
83 }
8485/***86 * Return an object to the pool87 *88 * @param jetspeedLink object to return to pool89 */90publicstaticvoid putInstance(JetspeedLink jetspeedLink)
91 {
92if (jetspeedLink != null)
93 TurbinePool.putInstance( jetspeedLink);
94return;
95 }
96 }