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 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.core; import org.litesoft.commonfoundation.typeutils.Objects; import java.io.*; import java.util.*; @SuppressWarnings({"UnusedDeclaration"}) public abstract class ServerSession { /** * Returns the object bound with the specified pClass Name in this ServerSession, 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 * @throws IllegalStateException if this method is called on an * expired ServerSession */ @SuppressWarnings({"unchecked"}) public <T extends Serializable> T getAttribute( Class<T> pClass ) { return (T) LLgetAttribute( toName( pClass ) ); } /** * Returns the object bound with the specified Class Name in this ServerSession, 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 * @throws IllegalStateException if this method is called on an * expired ServerSession */ public <T extends Serializable> T getRequired( Class<T> pClass ) throws NoSuchElementException { T zInstance = getAttribute( pClass ); if ( zInstance == null ) { throw new NoSuchElementException(); } return zInstance; } /** * Binds an object to this ServerSession, using the pClass Name specified. * If an object of the same pClass Name is already bound to this ServerSession, * 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 * @throws IllegalStateException if this method is called on an * expired ServerSession */ public <T extends Serializable, V extends T> void setAttribute( Class<T> pClass, V pInstance ) { if ( pInstance == null ) { LLremoveAttribute( toName( pClass ) ); } else { LLsetAttribute( toName( pClass ), pInstance ); } } /** * Removes the object bound with the specified pClass Name from * this ServerSession. If the ServerSession 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 ServerSession * * @throws IllegalArgumentException if pClass is null * @throws IllegalStateException if this method is called on an * expired ServerSession */ public <T extends Serializable> void removeAttribute( Class<T> pClass ) { LLremoveAttribute( toName( pClass ) ); } private String toName( Class<?> pClass ) { Objects.assertNotNull( "Class", pClass ); return pClass.getName(); } abstract protected Serializable LLgetAttribute( String pName ); abstract protected void LLsetAttribute( String pName, Serializable pInstance ); abstract protected void LLremoveAttribute( String pName ); } |
Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/core/ServerSession.java
Revision | Author | Commited | Message |
---|---|---|---|
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
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 |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |