001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.webapps.session.transformation;
018:
019: import org.apache.avalon.framework.service.ServiceException;
020: import org.apache.cocoon.ProcessingException;
021: import org.apache.cocoon.environment.Session;
022: import org.apache.cocoon.transformation.AbstractSAXTransformer;
023: import org.apache.cocoon.webapps.session.ContextManager;
024: import org.apache.cocoon.webapps.session.FormManager;
025: import org.apache.cocoon.webapps.session.SessionManager;
026:
027: /**
028: * This class is the basis for all session transformers.
029: *
030: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
031: * @deprecated This block is deprecated and will be removed in future versions.
032: * @version $Id: AbstractSessionTransformer.java 433543 2006-08-22 06:22:54Z crossley $
033: */
034: public abstract class AbstractSessionTransformer extends
035: AbstractSAXTransformer {
036:
037: private SessionManager sessionManager;
038: private FormManager formManager;
039: private ContextManager contextManager;
040:
041: /**
042: * Get the SessionManager component
043: */
044: protected SessionManager getSessionManager()
045: throws ProcessingException {
046: if (this .sessionManager == null) {
047: try {
048: this .sessionManager = (SessionManager) this .manager
049: .lookup(SessionManager.ROLE);
050: } catch (ServiceException ce) {
051: throw new ProcessingException(
052: "Error during lookup of SessionManager component.",
053: ce);
054: }
055: }
056: return this .sessionManager;
057: }
058:
059: /**
060: * Get the ContextManager component
061: */
062: protected ContextManager getContextManager()
063: throws ProcessingException {
064: if (this .contextManager == null) {
065: try {
066: this .contextManager = (ContextManager) this .manager
067: .lookup(ContextManager.ROLE);
068: } catch (ServiceException ce) {
069: throw new ProcessingException(
070: "Error during lookup of ContextManager component.",
071: ce);
072: }
073: }
074: return this .contextManager;
075: }
076:
077: /**
078: * Get the FormManager component
079: */
080: protected FormManager getFormManager() throws ProcessingException {
081: if (this .formManager == null) {
082: try {
083: this .formManager = (FormManager) this .manager
084: .lookup(FormManager.ROLE);
085: } catch (ServiceException ce) {
086: throw new ProcessingException(
087: "Error during lookup of FormManager component.",
088: ce);
089: }
090: }
091: return this .formManager;
092: }
093:
094: /**
095: * Recycle this component.
096: */
097: public void recycle() {
098: this .manager.release(this .sessionManager);
099: this .manager.release(this .formManager);
100: this .manager.release(this .contextManager);
101: this .sessionManager = null;
102: this .formManager = null;
103: this .contextManager = null;
104:
105: super .recycle();
106: }
107:
108: /**
109: * Get the current session if available or return <code>null</code>.
110: * @return The Session object or null.
111: */
112: public Session getSession() throws ProcessingException {
113: return this .getSessionManager().getSession(false);
114: }
115: }
|