KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > webapps > session > transformation > AbstractSessionTransformer


1 /*
2  * Copyright 1999-2005 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.transformation;
17
18 import org.apache.avalon.framework.service.ServiceException;
19 import org.apache.cocoon.ProcessingException;
20 import org.apache.cocoon.environment.Session;
21 import org.apache.cocoon.transformation.AbstractSAXTransformer;
22 import org.apache.cocoon.webapps.session.ContextManager;
23 import org.apache.cocoon.webapps.session.FormManager;
24 import org.apache.cocoon.webapps.session.SessionManager;
25
26 /**
27  * This class is the basis for all session transformers.
28  *
29  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
30  * @version $Id: AbstractSessionTransformer.java 168366 2005-05-05 18:23:18Z vgritsenko $
31 */

32 public abstract class AbstractSessionTransformer extends AbstractSAXTransformer {
33
34     private SessionManager sessionManager;
35     private FormManager formManager;
36     private ContextManager contextManager;
37
38     /**
39      * Get the SessionManager component
40      */

41     protected SessionManager getSessionManager()
42     throws ProcessingException {
43         if (this.sessionManager == null) {
44             try {
45                 this.sessionManager = (SessionManager)this.manager.lookup(SessionManager.ROLE);
46             } catch (ServiceException ce) {
47                 throw new ProcessingException("Error during lookup of SessionManager component.", ce);
48             }
49         }
50         return this.sessionManager;
51     }
52
53     /**
54      * Get the ContextManager component
55      */

56     protected ContextManager getContextManager()
57     throws ProcessingException {
58         if (this.contextManager == null) {
59             try {
60                 this.contextManager = (ContextManager)this.manager.lookup(ContextManager.ROLE);
61             } catch (ServiceException ce) {
62                 throw new ProcessingException("Error during lookup of ContextManager component.", ce);
63             }
64         }
65         return this.contextManager;
66     }
67
68     /**
69      * Get the FormManager component
70      */

71     protected FormManager getFormManager()
72     throws ProcessingException {
73         if (this.formManager == null) {
74             try {
75                 this.formManager = (FormManager)this.manager.lookup(FormManager.ROLE);
76             } catch (ServiceException ce) {
77                 throw new ProcessingException("Error during lookup of FormManager component.", ce);
78             }
79         }
80         return this.formManager;
81     }
82
83     /**
84      * Recycle this component.
85      */

86     public void recycle() {
87         this.manager.release( this.sessionManager);
88         this.manager.release( this.formManager);
89         this.manager.release( this.contextManager);
90         this.sessionManager = null;
91         this.formManager = null;
92         this.contextManager = null;
93
94         super.recycle();
95     }
96
97     /**
98      * Get the current session if available or return <code>null</code>.
99      * @return The Session object or null.
100      */

101     public Session getSession()
102     throws ProcessingException {
103         return this.getSessionManager().getSession(false);
104     }
105 }
106
Popular Tags