KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > util > template > JetspeedLinkFactory


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 at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * 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 and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.util.template;
18
19 // Jetspeed
20
import org.apache.jetspeed.util.template.JetspeedLink;
21 import org.apache.jetspeed.services.resources.JetspeedResources;
22
23 // Turbine
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 JavaDoc 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 }
97
Popular Tags