litesoft
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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.core; import org.litesoft.core.typeutils.Objects; import org.litesoft.core.util.*; import java.io.*; import java.util.*; @SuppressWarnings({"UnusedDeclaration"}) public class ServerStore implements Disposable { private Map mEntries = new HashMap(); public ServerStore() { } public ServerStore( ServerStore pCopyFrom ) { if ( pCopyFrom != null ) { pCopyFrom.copyTo( mEntries ); } } /** * Returns the object bound with the specified pClass Name in this ServerStore, or * <code>null</code> if no object is bound under the pClass Name. * * @param pClass specifying the Class Name of the object * * @return the object bound with the specified Class Name * * @throws IllegalArgumentException if pClass is null */ @SuppressWarnings({"unchecked"}) public synchronized final <T> T get( Class<T> pClass ) { return (T) mEntries.get( pClass ); } /** * Returns the object bound with the specified Class Name in this ServerStore, or * <code>null</code> if no object is bound under the Class Name. * * @param pClass specifying the Class Name of the object * * @return the object bound with the specified Class Name * * @throws IllegalArgumentException if pClass is null * @throws NoSuchElementException if there is no object bound to the specified Class Name */ public <T extends Serializable> T getRequired( Class<T> pClass ) throws NoSuchElementException { T zInstance = get( pClass ); if ( zInstance == null ) { throw new NoSuchElementException(); } return zInstance; } /** * Binds an object to this ServerStore, using the pClass Name specified. * If an object of the same pClass Name is already bound to this ServerStore, * the object is replaced. * <p/> * <p>If the value passed in is null, this has the same effect as calling * <code>removeAttribute()<code>. * * @param pClass the Class Name to which the object will be bound; * cannot be null * @param pInstance the object to be bound * * @throws IllegalArgumentException if pClass is null */ public final <T, V extends T> void set( Class<T> pClass, V pInstance ) { if ( pInstance == null ) { remove( pClass ); } else { Object zPrev = LLput( assertNotNull( pClass ), pInstance ); if ( pInstance != zPrev ) // Same Object! { LLdispose( zPrev ); } } } /** * Removes the object bound with the specified pClass Name from * this ServerStore. If the ServerStore does not have an object * bound with the specified pClass Name, this method does nothing. * * @param pClass specifying the Class Name of the object * to remove from this ServerStore * * @throws IllegalArgumentException if pClass is null */ public final <T> void remove( Class<T> pClass ) { LLdispose( LLremove( assertNotNull( pClass ) ) ); } @Override protected void finalize() throws Throwable { dispose(); super.finalize(); } @Override public void dispose() { Map zMap; synchronized ( this ) { zMap = mEntries; mEntries = null; } if ( zMap != null ) { for ( Object zInstance : zMap.values() ) { LLdispose( zInstance ); } } } private <T> Class<T> assertNotNull( Class<T> pClass ) { Objects.assertNotNull( "Class", pClass ); return pClass; } @SuppressWarnings({"unchecked"}) private synchronized <T, V extends T> Object LLput( Class<T> pClass, V pInstance ) { return mEntries.put( pClass, pInstance ); } private synchronized <T> Object LLremove( Class<T> pClass ) { return mEntries.remove( pClass ); } private void LLdispose( Object pInstance ) { if ( pInstance instanceof Disposable ) { ((Disposable) pInstance).dispose(); } } @SuppressWarnings({"unchecked"}) private synchronized void copyTo( Map pTarget ) { pTarget.putAll( mEntries ); } } |
Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/core/ServerStore.java
Revision | Author | Commited | Message |
---|---|---|---|
917 Diff | GeorgeS | Sun 08 Dec, 2013 20:49:56 +0000 | 1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model! |
804 Diff | GeorgeS | Wed 15 Aug, 2012 12:48:51 +0000 | |
484 Diff | GeorgeS | Mon 05 Sep, 2011 02:03:16 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
24 Diff | GeorgeS | Wed 24 Feb, 2010 01:51:38 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |