1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.cocoon.webapps.session.transformation;
18
19 import org.apache.avalon.framework.service.ServiceException;
20 import org.apache.cocoon.ProcessingException;
21 import org.apache.cocoon.environment.Session;
22 import org.apache.cocoon.transformation.AbstractSAXTransformer;
23 import org.apache.cocoon.webapps.session.ContextManager;
24 import org.apache.cocoon.webapps.session.FormManager;
25 import org.apache.cocoon.webapps.session.SessionManager;
26
27 /**
28 * This class is the basis for all session transformers.
29 *
30 * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
31 * @deprecated This block is deprecated and will be removed in future versions.
32 * @version $Id: AbstractSessionTransformer.java 433543 2006-08-22 06:22:54Z crossley $
33 */
34 public abstract class AbstractSessionTransformer extends AbstractSAXTransformer {
35
36 private SessionManager sessionManager;
37 private FormManager formManager;
38 private ContextManager contextManager;
39
40 /**
41 * Get the SessionManager component
42 */
43 protected SessionManager getSessionManager()
44 throws ProcessingException {
45 if (this.sessionManager == null) {
46 try {
47 this.sessionManager = (SessionManager)this.manager.lookup(SessionManager.ROLE);
48 } catch (ServiceException ce) {
49 throw new ProcessingException("Error during lookup of SessionManager component.", ce);
50 }
51 }
52 return this.sessionManager;
53 }
54
55 /**
56 * Get the ContextManager component
57 */
58 protected ContextManager getContextManager()
59 throws ProcessingException {
60 if (this.contextManager == null) {
61 try {
62 this.contextManager = (ContextManager)this.manager.lookup(ContextManager.ROLE);
63 } catch (ServiceException ce) {
64 throw new ProcessingException("Error during lookup of ContextManager component.", ce);
65 }
66 }
67 return this.contextManager;
68 }
69
70 /**
71 * Get the FormManager component
72 */
73 protected FormManager getFormManager()
74 throws ProcessingException {
75 if (this.formManager == null) {
76 try {
77 this.formManager = (FormManager)this.manager.lookup(FormManager.ROLE);
78 } catch (ServiceException ce) {
79 throw new ProcessingException("Error during lookup of FormManager component.", ce);
80 }
81 }
82 return this.formManager;
83 }
84
85 /**
86 * Recycle this component.
87 */
88 public void recycle() {
89 this.manager.release( this.sessionManager);
90 this.manager.release( this.formManager);
91 this.manager.release( this.contextManager);
92 this.sessionManager = null;
93 this.formManager = null;
94 this.contextManager = null;
95
96 super.recycle();
97 }
98
99 /**
100 * Get the current session if available or return <code>null</code>.
101 * @return The Session object or null.
102 */
103 public Session getSession()
104 throws ProcessingException {
105 return this.getSessionManager().getSession(false);
106 }
107 }