KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > webapps > session > components > AbstractSessionComponent


1 /*
2  * Copyright 1999-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 package org.apache.cocoon.webapps.session.components;
17
18 import java.io.IOException JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.avalon.excalibur.pool.Recyclable;
22 import org.apache.avalon.framework.component.Component;
23 import org.apache.avalon.framework.component.ComponentException;
24 import org.apache.avalon.framework.component.ComponentManager;
25 import org.apache.avalon.framework.component.Composable;
26 import org.apache.avalon.framework.component.Recomposable;
27 import org.apache.avalon.framework.logger.AbstractLogEnabled;
28 import org.apache.cocoon.ProcessingException;
29 import org.apache.cocoon.components.RequestLifecycleComponent;
30 import org.apache.cocoon.environment.ObjectModelHelper;
31 import org.apache.cocoon.environment.Request;
32 import org.apache.cocoon.environment.Response;
33 import org.apache.cocoon.environment.SourceResolver;
34 import org.apache.cocoon.webapps.session.ContextManager;
35 import org.apache.cocoon.webapps.session.FormManager;
36 import org.apache.cocoon.webapps.session.SessionManager;
37 import org.apache.cocoon.webapps.session.TransactionManager;
38 import org.xml.sax.SAXException JavaDoc;
39
40 /**
41  * The base class for own components
42  * This is only here for compatibility
43  *
44  * @deprecated Lookup the components yourself and use contextualizable to get the
45  * current object model
46  *
47  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
48  * @version CVS $Id: AbstractSessionComponent.java 30932 2004-07-29 17:35:38Z vgritsenko $
49 */

50 public abstract class AbstractSessionComponent extends AbstractLogEnabled
51     implements Component, Composable, Recomposable, Recyclable, RequestLifecycleComponent {
52
53     private SessionManager sessionManager;
54     private FormManager formManager;
55     private ContextManager contextManager;
56     private TransactionManager transactionManager;
57     
58     protected ComponentManager manager;
59
60     /** The current object model */
61     protected Map JavaDoc objectModel;
62
63     /** The current source resolver */
64     protected SourceResolver resolver;
65
66     protected Request request;
67     protected Response response;
68
69
70     /**
71      * Composer interface. Get the Avalon ComponentManager.
72      */

73     public void compose(ComponentManager manager)
74     throws ComponentException {
75         this.manager = manager;
76     }
77
78     /**
79      * Recomposable
80      */

81     public void recompose( ComponentManager componentManager )
82     throws ComponentException {
83         this.recycle();
84         this.manager = componentManager;
85     }
86
87     /**
88      * Set the <code>SourceResolver</code>, objectModel <code>Map</code>,
89      * used to process the request.
90      * Set up the SessionManager component.
91      * This method is automatically called for each request. Do not invoke
92      * this method by hand.
93      */

94     public void setup(SourceResolver resolver, Map JavaDoc objectModel)
95     throws ProcessingException, SAXException JavaDoc, IOException JavaDoc {
96         this.objectModel = objectModel;
97         this.resolver = resolver;
98         this.request = ObjectModelHelper.getRequest(objectModel);
99         this.response = ObjectModelHelper.getResponse(objectModel);
100     }
101
102     /**
103      * Get the SessionManager component
104      */

105     protected SessionManager getSessionManager()
106     throws ProcessingException {
107         if (this.sessionManager == null) {
108             try {
109                 this.sessionManager = (SessionManager)this.manager.lookup(SessionManager.ROLE);
110             } catch (ComponentException ce) {
111                 throw new ProcessingException("Error during lookup of SessionManager component.", ce);
112             }
113         }
114         return this.sessionManager;
115     }
116
117     /**
118      * Get the ContextManager component
119      */

120     protected ContextManager getContextManager()
121     throws ProcessingException {
122         if (this.contextManager == null) {
123             try {
124                 this.contextManager = (ContextManager)this.manager.lookup(ContextManager.ROLE);
125             } catch (ComponentException ce) {
126                 throw new ProcessingException("Error during lookup of ContextManager component.", ce);
127             }
128         }
129         return this.contextManager;
130     }
131
132     /**
133      * Get the ContextManager component
134      */

135     protected TransactionManager getTransactionManager()
136     throws ProcessingException {
137         if (this.transactionManager == null) {
138             try {
139                 this.transactionManager = (TransactionManager)this.manager.lookup(TransactionManager.ROLE);
140             } catch (ComponentException ce) {
141                 throw new ProcessingException("Error during lookup of TransactionManager component.", ce);
142             }
143         }
144         return this.transactionManager;
145     }
146
147     /**
148      * Get the FormManager component
149      */

150     protected FormManager getFormManager()
151     throws ProcessingException {
152         if (this.formManager == null) {
153             try {
154                 this.formManager = (FormManager)this.manager.lookup(FormManager.ROLE);
155             } catch (ComponentException ce) {
156                 throw new ProcessingException("Error during lookup of FormManager component.", ce);
157             }
158         }
159         return this.formManager;
160     }
161
162     /**
163      * Recycle
164      */

165     public void recycle() {
166         if (this.manager != null) {
167             this.manager.release( (Component)this.sessionManager);
168             this.manager.release( (Component)this.formManager);
169             this.manager.release( (Component)this.contextManager);
170             this.manager.release( (Component)this.transactionManager);
171         }
172         this.transactionManager = null;
173         this.sessionManager = null;
174         this.formManager = null;
175         this.contextManager = null;
176         this.objectModel = null;
177         this.resolver = null;
178         this.request = null;
179         this.response = null;
180     }
181
182 }
183
Popular Tags