1 18 package org.apache.beehive.netui.pageflow; 19 20 import org.apache.beehive.netui.pageflow.internal.InternalConstants; 21 import org.apache.beehive.netui.pageflow.internal.InternalUtils; 22 import org.apache.beehive.netui.pageflow.internal.CachedFacesBackingInfo; 23 import org.apache.beehive.netui.pageflow.internal.AdapterManager; 24 import org.apache.beehive.netui.pageflow.internal.CachedSharedFlowRefInfo; 25 import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils; 26 import org.apache.beehive.netui.util.internal.cache.ClassLevelCache; 27 import org.apache.beehive.netui.util.logging.Logger; 28 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 import javax.servlet.ServletContext ; 32 import java.util.Map ; 33 import java.util.Collections ; 34 import java.lang.reflect.Field ; 35 36 50 public abstract class FacesBackingBean 51 extends PageFlowManagedObject 52 { 53 private static final String CACHED_INFO_KEY = "cachedInfo"; 54 private static final Logger _log = Logger.getInstance( FacesBackingBean.class ); 55 56 private Map _pageInputs; 57 58 59 63 public void persistInSession( HttpServletRequest request, HttpServletResponse response ) 64 { 65 HttpServletRequest unwrappedRequest = PageFlowUtils.unwrapMultipart( request ); 66 ScopedServletUtils.setScopedSessionAttr( InternalConstants.FACES_BACKING_ATTR, this, unwrappedRequest ); 67 } 68 69 72 protected void removeFromSession( HttpServletRequest request ) 73 { 74 HttpServletRequest unwrappedRequest = PageFlowUtils.unwrapMultipart( request ); 75 ScopedServletUtils.removeScopedSessionAttr( InternalConstants.FACES_BACKING_ATTR, unwrappedRequest ); 76 } 77 78 86 public void ensureFailover( HttpServletRequest request ) 87 { 88 HttpServletRequest unwrappedRequest = PageFlowUtils.unwrapMultipart( request ); 89 String attr = 90 ScopedServletUtils.getScopedSessionAttrName( InternalConstants.FACES_BACKING_ATTR, unwrappedRequest ); 91 ServletContext servletContext = InternalUtils.getServletContext( request ); 92 AdapterManager.getServletContainerAdapter( servletContext ).ensureFailover( attr, this, unwrappedRequest ); 93 } 94 95 98 public String getDisplayName() 99 { 100 return getClass().getName(); 101 } 102 103 106 public void reinitialize( HttpServletRequest request, HttpServletResponse response, ServletContext servletContext ) 107 { 108 super.reinitialize( request, response, servletContext ); 109 110 if ( _pageInputs == null ) 111 { 112 Map map = InternalUtils.getActionOutputMap( request, false ); 113 if ( map != null ) _pageInputs = Collections.unmodifiableMap( map ); 114 } 115 116 Field pageFlowMemberField = getCachedInfo().getPageFlowMemberField(); 120 121 if ( fieldIsUninitialized( pageFlowMemberField ) ) 124 { 125 PageFlowController pfc = PageFlowUtils.getCurrentPageFlow( request ); 126 initializeField( pageFlowMemberField, pfc ); 127 } 128 129 CachedSharedFlowRefInfo.SharedFlowFieldInfo[] sharedFlowMemberFields = 133 getCachedInfo().getSharedFlowMemberFields(); 134 135 if ( sharedFlowMemberFields != null ) 136 { 137 for ( int i = 0; i < sharedFlowMemberFields.length; i++ ) 138 { 139 CachedSharedFlowRefInfo.SharedFlowFieldInfo fi = sharedFlowMemberFields[i]; 140 Field field = fi.field; 141 142 if ( fieldIsUninitialized( field ) ) 143 { 144 Map sharedFlows = PageFlowUtils.getSharedFlows( request ); 145 String name = fi.sharedFlowName; 146 SharedFlowController sf = 147 name != null ? ( SharedFlowController ) sharedFlows.get( name ) : PageFlowUtils.getGlobalApp( request ); 148 149 if ( sf != null ) 150 { 151 initializeField( field, sf ); 152 } 153 else 154 { 155 _log.error( "Could not find shared flow with name \"" + fi.sharedFlowName 156 + "\" to initialize field " + field.getName() + " in " + getClass().getName() ); 157 } 158 } 159 } 160 } 161 } 162 163 169 protected Object getPageInput( String pageInputName ) 170 { 171 return _pageInputs != null ? _pageInputs.get( pageInputName ) : null; 172 } 173 174 179 public Map getPageInputMap() 180 { 181 return _pageInputs; 182 } 183 184 private CachedFacesBackingInfo getCachedInfo() 185 { 186 ClassLevelCache cache = ClassLevelCache.getCache( getClass() ); 187 CachedFacesBackingInfo info = ( CachedFacesBackingInfo ) cache.getCacheObject( CACHED_INFO_KEY ); 188 189 if ( info == null ) 190 { 191 info = new CachedFacesBackingInfo( getClass(), getServletContext() ); 192 cache.setCacheObject( CACHED_INFO_KEY, info ); 193 } 194 195 return info; 196 } 197 } 198 | Popular Tags |