1 17 package org.apache.geronimo.clustering.wadi; 18 19 import java.util.Collection ; 20 import java.util.Map ; 21 import java.util.Set ; 22 23 import org.apache.geronimo.clustering.Session; 24 import org.codehaus.wadi.web.WebSession; 25 26 30 public class WADISessionAdaptor implements Session { 31 private final WebSession session; 32 private final Map state; 33 34 public WADISessionAdaptor(WebSession session) { 35 this.session = session; 36 37 state = new StateMap(); 38 } 39 40 public String getSessionId() { 41 return session.getId(); 42 } 43 44 public void release() { 45 try { 46 session.destroy(); 47 } catch (Exception e) { 48 throw new IllegalStateException ("Cannot release session " + session); 49 } 50 } 51 52 public Object addState(String key, Object value) { 53 return session.setAttribute(key, value); 54 } 55 56 public Object getState(String key) { 57 return session.getAttribute(key); 58 } 59 60 public Object removeState(String key) { 61 return session.removeAttribute(key); 62 } 63 64 public Map getState() { 65 return state; 66 } 67 68 private class StateMap implements Map { 69 70 public Object put(Object key, Object value) { 71 String wadiKey = ensureTypeAndCast(key); 72 return addState(wadiKey, value); 73 } 74 75 public Object remove(Object key) { 76 String wadiKey = ensureTypeAndCast(key); 77 return removeState(wadiKey); 78 } 79 80 public void clear() { 81 throw new UnsupportedOperationException (); 82 } 83 84 public boolean containsKey(Object key) { 85 throw new UnsupportedOperationException (); 86 } 87 88 public boolean containsValue(Object value) { 89 throw new UnsupportedOperationException (); 90 } 91 92 public Set entrySet() { 93 throw new UnsupportedOperationException (); 94 } 95 96 public Object get(Object key) { 97 String wadiKey = ensureTypeAndCast(key); 98 return getState(wadiKey); 99 } 100 101 public boolean isEmpty() { 102 throw new UnsupportedOperationException (); 103 } 104 105 public Set keySet() { 106 return session.getAttributeNameSet(); 107 } 108 109 public void putAll(Map t) { 110 throw new UnsupportedOperationException (); 111 } 112 113 public int size() { 114 return session.getAttributeNameSet().size(); 115 } 116 117 public Collection values() { 118 throw new UnsupportedOperationException (); 119 } 120 121 private String ensureTypeAndCast(Object key) { 122 if (!(key instanceof String )) { 123 throw new ClassCastException (String .class + " is expected."); 124 } 125 return (String ) key; 126 } 127 } 128 } 129 | Popular Tags |