litesoft
@ 947
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.forms.server.support; import java.util.*; import org.litesoft.GWT.forms.server.*; import org.litesoft.ui.def.nonpublic.support.*; public class InstanceHelperManager { private InstanceHelper mRootInstanceHelper = null; private Map<FormDataRowKey, InstanceHelper> mInstanceHelpersByFormDataRowKeys = // null key supported new HashMap<FormDataRowKey, InstanceHelper>(); public synchronized void dispose() { if ( mInstanceHelpersByFormDataRowKeys != null ) { for ( InstanceHelper helper : mInstanceHelpersByFormDataRowKeys.values() ) { try { helper.dispose(); } catch ( RuntimeException e ) { FormServicePeer.LOGGER.error.log( e ); } } mInstanceHelpersByFormDataRowKeys.clear(); mInstanceHelpersByFormDataRowKeys = null; mRootInstanceHelper = null; } } public synchronized InstanceHelper getRootInstanceHelper() { return mRootInstanceHelper; } public synchronized void setRootInstanceHelper( InstanceHelper pRootInstanceHelper ) { add( mRootInstanceHelper = pRootInstanceHelper ); } public synchronized void add( InstanceHelper pInstanceHelper ) { mInstanceHelpersByFormDataRowKeys.put( pInstanceHelper.getFormDataRowKey(), pInstanceHelper ); } public synchronized void remove( FormDataRowKey pFormDataRowKey ) { mInstanceHelpersByFormDataRowKeys.remove( pFormDataRowKey ); } public synchronized void resetAllInstanceHelpers() { for ( InstanceHelper helper : mInstanceHelpersByFormDataRowKeys.values() ) { if ( helper != mRootInstanceHelper ) { helper.dispose(); } } mInstanceHelpersByFormDataRowKeys.clear(); if ( mRootInstanceHelper != null ) { mRootInstanceHelper.resetSavedAttibuteValues(); mInstanceHelpersByFormDataRowKeys.put( mRootInstanceHelper.getFormDataRowKey(), mRootInstanceHelper ); } } public synchronized void loadAllAttributeValues() { if ( mRootInstanceHelper != null ) { mRootInstanceHelper.loadAllAttributeValues(); } } public synchronized ArrayList<FormDataRowKey> getAllCurrentFormDataRowKeys() { return new ArrayList<FormDataRowKey>( mInstanceHelpersByFormDataRowKeys.keySet() ); } public synchronized InstanceHelpersSnapShot getInstanceHelpers() { return new InstanceHelpersSnapShot( mRootInstanceHelper, mInstanceHelpersByFormDataRowKeys.values().toArray( new InstanceHelper[mInstanceHelpersByFormDataRowKeys.size()] ) ); } public synchronized InstanceHelper getInstanceHelper( FormDataRowKey pFormDataRowKey ) { return (pFormDataRowKey == null) ? // null == Root getRootInstanceHelper() : // mInstanceHelpersByFormDataRowKeys.get( pFormDataRowKey ); } } |