1 16 package org.apache.cocoon.webapps.session.components; 17 18 import java.io.IOException ; 19 import java.util.Map ; 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 ; 39 40 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 61 protected Map objectModel; 62 63 64 protected SourceResolver resolver; 65 66 protected Request request; 67 protected Response response; 68 69 70 73 public void compose(ComponentManager manager) 74 throws ComponentException { 75 this.manager = manager; 76 } 77 78 81 public void recompose( ComponentManager componentManager ) 82 throws ComponentException { 83 this.recycle(); 84 this.manager = componentManager; 85 } 86 87 94 public void setup(SourceResolver resolver, Map objectModel) 95 throws ProcessingException, SAXException , IOException { 96 this.objectModel = objectModel; 97 this.resolver = resolver; 98 this.request = ObjectModelHelper.getRequest(objectModel); 99 this.response = ObjectModelHelper.getResponse(objectModel); 100 } 101 102 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 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 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 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 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 |