001: /*
002: * $Id: AnySession.java,v 1.24 2002/09/16 08:05:03 jkl Exp $
003: *
004: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
005: *
006: * Use is subject to license terms, as defined in
007: * Anvil Sofware License, Version 1.1. See LICENSE
008: * file, or http://njet.org/license-1.1.txt
009: */
010: package anvil.core.net;
011:
012: import anvil.core.Any;
013: import anvil.core.AnyAbstractClass;
014: import anvil.core.Array;
015: import anvil.script.Context;
016: import anvil.session.Session;
017: import anvil.java.util.BindingEnumeration;
018: import java.util.Enumeration;
019:
020: ///
021: /// @class Session
022: /// The session datatype is used for representing a unique
023: /// user session.
024: ///
025: /// @attribute variable
026: /// Returns a value bound to given name, or undefined
027: /// if there was no such binding.
028: /// @synopsis object <i>session</i>.<i>variable</i>
029:
030: /// @reference variable
031: /// Returns a value bound to given name, or undefined
032: /// if there was no such binding.
033: /// @synopsis "object <i>session</i>[<i>variable</i>]"
034:
035: /**
036: * class AnySession
037: *
038: * @author: Jani Lehtimäki
039: */
040: public class AnySession extends AnyAbstractClass {
041: public static final anvil.script.compiler.NativeClass __class__ = new anvil.script.compiler.NativeClass(
042: "Session",
043: AnySession.class,
044: //DOC{{
045: ""
046: + "\n"
047: + " @class Session\n"
048: + " The session datatype is used for representing a unique\n"
049: + " user session.\n"
050: + "\n"
051: + " @attribute \"Session <i>session</i>.<i>attribute</i>\"\n"
052: + " Attributes stored to session.\n"
053: + " @reference \"Session <i>session</i>[<i>attribute</i>]\"\n"
054: + " Attributes stored to session.\n"
055: + " @method getCitizen\n"
056: + " Returns name of the citizen logged in, or null if none.\n"
057: + " @synopsis string getCitizen()\n"
058: + " @return citizen name\n"
059: + " @method getID\n"
060: + " Returns the unique ID of this session.\n"
061: + " @synopsis string getID()\n"
062: + " @method getLastAccessTime\n"
063: + " Returns timestamp when this session was last accessed.\n"
064: + " @synopsis int getLastAccessTime()\n"
065: + " @return timestamp\n"
066: + " @method getCreationTime\n"
067: + " Returns timestamp when this session was created.\n"
068: + " @synopsis int getCreationTime()\n"
069: + " @return timestamp\n"
070: + " @method touch\n"
071: + " Updates time of last access.\n"
072: + " @synopsis void touch()\n"
073: + " @method invalidate\n"
074: + " Invalidates this session, removing it from session container\n"
075: + " @synopsis void invalidate()\n"
076: //}}DOC
077: );
078: static {
079: NetModule.class.getName();
080: }
081:
082: private Session _session;
083:
084: public AnySession(Session session) {
085: _session = session;
086: }
087:
088: public final anvil.script.ClassType classOf() {
089: return __class__;
090: }
091:
092: public Object toObject() {
093: return _session;
094: }
095:
096: public Any getAttribute(Context context, String attribute) {
097: return Any.create(_session.getAttribute(attribute));
098: }
099:
100: public Any setAttribute(Context context, String attribute, Any value) {
101: _session.setAttribute(attribute, value);
102: return value;
103: }
104:
105: public Any checkAttribute(Context context, String attribute) {
106: Object value = _session.getAttribute(attribute);
107: if (value != null) {
108: return Any.create(value);
109: } else {
110: return Any.UNDEFINED;
111: }
112: }
113:
114: public boolean deleteAttribute(Context context, String attribute) {
115: _session.removeAttribute(attribute);
116: return true;
117: }
118:
119: public Any getReference(Context context, Any index) {
120: return getAttribute(context, index.toString());
121: }
122:
123: public Any setReference(Context context, Any index, Any value) {
124: return setAttribute(context, index.toString(), value);
125: }
126:
127: public Any setReference(Context context, Any value) {
128: return value;
129: }
130:
131: public Any checkReference(Context context, Any index) {
132: return checkAttribute(context, index.toString());
133: }
134:
135: public boolean deleteReference(Context context, Any index) {
136: return deleteAttribute(context, index.toString());
137: }
138:
139: public boolean contains(Any value) {
140: Enumeration e = _session.enumeration();
141: while (e.hasMoreElements()) {
142: Any elem = Any.create(e.nextElement());
143: if (elem.equals(value)) {
144: return true;
145: }
146: }
147: return false;
148: }
149:
150: public BindingEnumeration enumeration() {
151: return _session.enumeration();
152: }
153:
154: /// @method getCitizen
155: /// Returns name of the citizen logged in, or null if none.
156: /// @synopsis string getCitizen()
157: /// @return citizen name
158: public Any m_getCitizen() {
159: return Any.create(_session.getCitizen());
160: }
161:
162: /// @method getID
163: /// Returns the unique ID of this session.
164: /// @synopsis string getID()
165: public Any m_getID() {
166: return Any.create(_session.getId());
167: }
168:
169: /// @method getLastAccessTime
170: /// Returns timestamp when this session was last accessed.
171: /// @synopsis int getLastAccessTime()
172: /// @return timestamp
173: public Any m_getLastAccessTime() {
174: return Any.create(_session.getLastAccessTime());
175: }
176:
177: /// @method getCreationTime
178: /// Returns timestamp when this session was created.
179: /// @synopsis int getCreationTime()
180: /// @return timestamp
181: public Any m_getCreationTime() {
182: return Any.create(_session.getCreationTime());
183: }
184:
185: /// @method touch
186: /// Updates time of last access.
187: /// @synopsis void touch()
188: public Any m_touch() {
189: _session.touch();
190: return this ;
191: }
192:
193: /// @method invalidate
194: /// Invalidates this session, removing it from session container
195: /// @synopsis void invalidate()
196: public Any m_invalidate() {
197: _session.invalidate();
198: return this;
199: }
200:
201: }
|