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.components;
018:
019: import java.io.IOException;
020: import java.util.Map;
021:
022: import org.apache.avalon.excalibur.pool.Recyclable;
023: import org.apache.avalon.framework.component.Component;
024: import org.apache.avalon.framework.component.ComponentException;
025: import org.apache.avalon.framework.component.ComponentManager;
026: import org.apache.avalon.framework.component.Composable;
027: import org.apache.avalon.framework.component.Recomposable;
028: import org.apache.avalon.framework.logger.AbstractLogEnabled;
029: import org.apache.cocoon.ProcessingException;
030: import org.apache.cocoon.components.RequestLifecycleComponent;
031: import org.apache.cocoon.environment.ObjectModelHelper;
032: import org.apache.cocoon.environment.Request;
033: import org.apache.cocoon.environment.Response;
034: import org.apache.cocoon.environment.SourceResolver;
035: import org.apache.cocoon.webapps.session.ContextManager;
036: import org.apache.cocoon.webapps.session.FormManager;
037: import org.apache.cocoon.webapps.session.SessionManager;
038: import org.apache.cocoon.webapps.session.TransactionManager;
039: import org.xml.sax.SAXException;
040:
041: /**
042: * The base class for own components
043: * This is only here for compatibility
044: *
045: * @deprecated Lookup the components yourself and use contextualizable to get the
046: * current object model
047: *
048: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
049: * @deprecated This block is deprecated and will be removed in future versions.
050: * @version CVS $Id: AbstractSessionComponent.java 433543 2006-08-22 06:22:54Z crossley $
051: */
052: public abstract class AbstractSessionComponent extends
053: AbstractLogEnabled implements Component, Composable,
054: Recomposable, Recyclable, RequestLifecycleComponent {
055:
056: private SessionManager sessionManager;
057: private FormManager formManager;
058: private ContextManager contextManager;
059: private TransactionManager transactionManager;
060:
061: protected ComponentManager manager;
062:
063: /** The current object model */
064: protected Map objectModel;
065:
066: /** The current source resolver */
067: protected SourceResolver resolver;
068:
069: protected Request request;
070: protected Response response;
071:
072: /**
073: * Composer interface. Get the Avalon ComponentManager.
074: */
075: public void compose(ComponentManager manager)
076: throws ComponentException {
077: this .manager = manager;
078: }
079:
080: /**
081: * Recomposable
082: */
083: public void recompose(ComponentManager componentManager)
084: throws ComponentException {
085: this .recycle();
086: this .manager = componentManager;
087: }
088:
089: /**
090: * Set the <code>SourceResolver</code>, objectModel <code>Map</code>,
091: * used to process the request.
092: * Set up the SessionManager component.
093: * This method is automatically called for each request. Do not invoke
094: * this method by hand.
095: */
096: public void setup(SourceResolver resolver, Map objectModel)
097: throws ProcessingException, SAXException, IOException {
098: this .objectModel = objectModel;
099: this .resolver = resolver;
100: this .request = ObjectModelHelper.getRequest(objectModel);
101: this .response = ObjectModelHelper.getResponse(objectModel);
102: }
103:
104: /**
105: * Get the SessionManager component
106: */
107: protected SessionManager getSessionManager()
108: throws ProcessingException {
109: if (this .sessionManager == null) {
110: try {
111: this .sessionManager = (SessionManager) this .manager
112: .lookup(SessionManager.ROLE);
113: } catch (ComponentException ce) {
114: throw new ProcessingException(
115: "Error during lookup of SessionManager component.",
116: ce);
117: }
118: }
119: return this .sessionManager;
120: }
121:
122: /**
123: * Get the ContextManager component
124: */
125: protected ContextManager getContextManager()
126: throws ProcessingException {
127: if (this .contextManager == null) {
128: try {
129: this .contextManager = (ContextManager) this .manager
130: .lookup(ContextManager.ROLE);
131: } catch (ComponentException ce) {
132: throw new ProcessingException(
133: "Error during lookup of ContextManager component.",
134: ce);
135: }
136: }
137: return this .contextManager;
138: }
139:
140: /**
141: * Get the ContextManager component
142: */
143: protected TransactionManager getTransactionManager()
144: throws ProcessingException {
145: if (this .transactionManager == null) {
146: try {
147: this .transactionManager = (TransactionManager) this .manager
148: .lookup(TransactionManager.ROLE);
149: } catch (ComponentException ce) {
150: throw new ProcessingException(
151: "Error during lookup of TransactionManager component.",
152: ce);
153: }
154: }
155: return this .transactionManager;
156: }
157:
158: /**
159: * Get the FormManager component
160: */
161: protected FormManager getFormManager() throws ProcessingException {
162: if (this .formManager == null) {
163: try {
164: this .formManager = (FormManager) this .manager
165: .lookup(FormManager.ROLE);
166: } catch (ComponentException ce) {
167: throw new ProcessingException(
168: "Error during lookup of FormManager component.",
169: ce);
170: }
171: }
172: return this .formManager;
173: }
174:
175: /**
176: * Recycle
177: */
178: public void recycle() {
179: if (this .manager != null) {
180: this .manager.release((Component) this .sessionManager);
181: this .manager.release((Component) this .formManager);
182: this .manager.release((Component) this .contextManager);
183: this .manager.release((Component) this.transactionManager);
184: }
185: this.transactionManager = null;
186: this.sessionManager = null;
187: this.formManager = null;
188: this.contextManager = null;
189: this.objectModel = null;
190: this.resolver = null;
191: this.request = null;
192: this.response = null;
193: }
194:
195: }
|