litesoft
@ 151
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.orsup.transact.nonpublic; import org.litesoft.orsup.transact.*; public class TransactionAugmentationManagerImpl implements TransactionAugmentationManagerInternalExtension { private HistoryAugmentorFactory mHistoryAugmentorFactory = null; private TransactionAugmentorFactory[] mAugmentorFactories = TransactionAugmentorFactory.EMPTY_ARRAY; @Override public synchronized HistoryAugmentorFactory getHistoryAugmentorFactory() { return mHistoryAugmentorFactory; } @Override public synchronized void setHistoryAugmentorFactory( HistoryAugmentorFactory pFactory ) { mHistoryAugmentorFactory = pFactory; } @Override public synchronized TransactionAugmentorFactory[] getTransactionAugmentors() { return (mAugmentorFactories.length == 0) ? mAugmentorFactories : mAugmentorFactories.clone(); } @Override public synchronized void addTransactionAugmentor( TransactionAugmentorFactory pFactory ) { if ( pFactory != null ) { int zCurLen = mAugmentorFactories.length; if ( zCurLen == 0 ) { mAugmentorFactories = new TransactionAugmentorFactory[]{pFactory}; } else if ( -1 == findTransactionAugmentor( pFactory ) ) { TransactionAugmentorFactory[] zFactories = new TransactionAugmentorFactory[zCurLen + 1]; System.arraycopy( mAugmentorFactories, 0, zFactories, 1, zCurLen ); zFactories[0] = pFactory; mAugmentorFactories = zFactories; } } } @Override public synchronized boolean removeTransactionAugmentor( Class<? extends TransactionAugmentorFactory> pFactoryClass ) { boolean rv = false; for ( int at; -1 != (at = findTransactionAugmentor( pFactoryClass )); ) { rv = true; removeTransactionAugmentor( at ); } return rv; } @Override public synchronized boolean removeTransactionAugmentor( TransactionAugmentorFactory pFactory ) { int at = findTransactionAugmentor( pFactory ); if ( at != -1 ) { removeTransactionAugmentor( at ); return true; } return false; } @Override public synchronized void clearTransactionAugmentors() { mAugmentorFactories = TransactionAugmentorFactory.EMPTY_ARRAY; } @Override public synchronized TransactionAugmentorFactory[] getRawTransactionAugmentorsArray() { return mAugmentorFactories; } private int findTransactionAugmentor( Class<? extends TransactionAugmentorFactory> pFactoryClass ) { if ( pFactoryClass != null ) { for ( int i = mAugmentorFactories.length; --i >= 0; ) { if ( pFactoryClass == mAugmentorFactories[i].getClass() ) { return i; } } } return -1; } private int findTransactionAugmentor( TransactionAugmentorFactory pFactory ) { if ( pFactory != null ) { for ( int i = mAugmentorFactories.length; --i >= 0; ) { if ( pFactory == mAugmentorFactories[i] ) { return i; } } } return -1; } private void removeTransactionAugmentor( int pIndex ) { int ndxTo, curLength = mAugmentorFactories.length; if ( curLength <= 1 ) { mAugmentorFactories = TransactionAugmentorFactory.EMPTY_ARRAY; return; } TransactionAugmentorFactory[] newAFs = new TransactionAugmentorFactory[curLength - 1]; for ( int ndxFrom = ndxTo = 0; ndxFrom < mAugmentorFactories.length; ndxFrom++ ) { if ( ndxFrom != pIndex ) { newAFs[ndxTo++] = mAugmentorFactories[ndxFrom]; } } mAugmentorFactories = newAFs; } } |