⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deltasession.java

📁 精通tomcat书籍原代码,希望大家共同学习
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        // Reset the instance variables associated with this Session        attributes.clear();        setAuthType(null);        creationTime = 0L;        expiring = false;        id = null;        lastAccessedTime = 0L;        maxInactiveInterval = -1;        accessCount = 0;        notes.clear();        setPrincipal(null);        isNew = false;        isValid = false;        manager = null;        deltaRequest.clear();    }    /**     * Remove any object bound to the specified name in the internal notes for     * this session.     *     * @param name     *            Name of the note to be removed     */    public void removeNote(String name) {        notes.remove(name);    }    /**     * Remove a session event listener from this component.     */    public void removeSessionListener(SessionListener listener) {        synchronized (listeners) {            listeners.remove(listener);        }    }    /**     * Bind an object to a specified name in the internal notes associated with     * this session, replacing any existing binding for this name.     *     * @param name     *            Name to which the object should be bound     * @param value     *            Object to be bound to the specified name     */    public void setNote(String name, Object value) {        notes.put(name, value);    }    /**     * Return a string representation of this object.     */    public String toString() {        StringBuffer sb = new StringBuffer();        sb.append("DeltaSession[");        sb.append(id);        sb.append("]");        return (sb.toString());    }    // ------------------------------------------------ Session Package Methods    public synchronized void readExternal(ObjectInput in) throws IOException,ClassNotFoundException {        readObjectData(in);    }    /**     * Read a serialized version of the contents of this session object from the     * specified object input stream, without requiring that the StandardSession     * itself have been serialized.     *     * @param stream     *            The object input stream to read from     *     * @exception ClassNotFoundException     *                if an unknown class is specified     * @exception IOException     *                if an input/output error occurs     */    public void readObjectData(ObjectInput stream) throws ClassNotFoundException, IOException {        readObject(stream);    }    /**     * Write a serialized version of the contents of this session object to the     * specified object output stream, without requiring that the     * StandardSession itself have been serialized.     *     * @param stream     *            The object output stream to write to     *     * @exception IOException     *                if an input/output error occurs     */    public void writeObjectData(ObjectOutput stream) throws IOException {        writeObject(stream);    }    public void resetDeltaRequest() {        if (deltaRequest == null) {            deltaRequest = new DeltaRequest(getIdInternal(), false);        } else {            deltaRequest.reset();            deltaRequest.setSessionId(getIdInternal());        }    }    public DeltaRequest getDeltaRequest() {        if (deltaRequest == null) resetDeltaRequest();        return deltaRequest;    }    // ------------------------------------------------- HttpSession Properties    /**     * Return the time when this session was created, in milliseconds since     * midnight, January 1, 1970 GMT.     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     */    public long getCreationTime() {        if (!expiring && !isValid)            throw new IllegalStateException(sm.getString("standardSession.getCreationTime.ise"));        return (this.creationTime);    }    /**     * Return the ServletContext to which this session belongs.     */    public ServletContext getServletContext() {        if (manager == null)            return (null);        Context context = (Context) manager.getContainer();        if (context == null)            return (null);        else            return (context.getServletContext());    }    /**     * Return the session context with which this session is associated.     *     * @deprecated As of Version 2.1, this method is deprecated and has no     *             replacement. It will be removed in a future version of the     *             Java Servlet API.     */    public HttpSessionContext getSessionContext() {        if (sessionContext == null)            sessionContext = new StandardSessionContext();        return (sessionContext);    }    // ----------------------------------------------HttpSession Public Methods    /**     * Return the object bound with the specified name in this session, or     * <code>null</code> if no object is bound with that name.     *     * @param name     *            Name of the attribute to be returned     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     */    public Object getAttribute(String name) {        if (!isValid())            throw new IllegalStateException(sm.getString("standardSession.getAttribute.ise"));        return (attributes.get(name));    }    /**     * Return an <code>Enumeration</code> of <code>String</code> objects     * containing the names of the objects bound to this session.     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     */    public Enumeration getAttributeNames() {        if (!isValid())            throw new IllegalStateException(sm.getString("standardSession.getAttributeNames.ise"));        return (new Enumerator(attributes.keySet(), true));    }    /**     * Return the object bound with the specified name in this session, or     * <code>null</code> if no object is bound with that name.     *     * @param name     *            Name of the value to be returned     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     *     * @deprecated As of Version 2.2, this method is replaced by     *             <code>getAttribute()</code>     */    public Object getValue(String name) {        return (getAttribute(name));    }    /**     * Return the set of names of objects bound to this session. If there are no     * such objects, a zero-length array is returned.     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     *     * @deprecated As of Version 2.2, this method is replaced by     *             <code>getAttributeNames()</code>     */    public String[] getValueNames() {        if (!isValid())            throw new IllegalStateException(sm.getString("standardSession.getValueNames.ise"));        return (keys());    }    /**     * Invalidates this session and unbinds any objects bound to it.     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     */    public void invalidate() {        if (!isValid())            throw new IllegalStateException(sm.getString("standardSession.invalidate.ise"));        // Cause this session to expire        expire();    }    /**     * Return <code>true</code> if the client does not yet know about the     * session, or if the client chooses not to join the session. For example,     * if the server used only cookie-based sessions, and the client has     * disabled the use of cookies, then a session would be new on each request.     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     */    public boolean isNew() {        if (!isValid())            throw new IllegalStateException(sm.getString("standardSession.isNew.ise"));        return (this.isNew);    }    /**     * Bind an object to this session, using the specified name. If an object of     * the same name is already bound to this session, the object is replaced.     * <p>     * After this method executes, and if the object implements     * <code>HttpSessionBindingListener</code>, the container calls     * <code>valueBound()</code> on the object.     *     * @param name     *            Name to which the object is bound, cannot be null     * @param value     *            Object to be bound, cannot be null     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     *     * @deprecated As of Version 2.2, this method is replaced by     *             <code>setAttribute()</code>     */    public void putValue(String name, Object value) {        setAttribute(name, value);    }    /**     * Remove the object bound with the specified name from this session. If the     * session does not have an object bound with this name, this method does     * nothing.     * <p>     * After this method executes, and if the object implements     * <code>HttpSessionBindingListener</code>, the container calls     * <code>valueUnbound()</code> on the object.     *     * @param name     *            Name of the object to remove from this session.     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     */    public void removeAttribute(String name) {        removeAttribute(name, true);    }    /**     * Remove the object bound with the specified name from this session. If the     * session does not have an object bound with this name, this method does     * nothing.     * <p>     * After this method executes, and if the object implements     * <code>HttpSessionBindingListener</code>, the container calls     * <code>valueUnbound()</code> on the object.     *     * @param name     *            Name of the object to remove from this session.     * @param notify     *            Should we notify interested listeners that this attribute is     *            being removed?     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     */    public void removeAttribute(String name, boolean notify) {        removeAttribute(name, notify, true);    }    public void removeAttribute(String name, boolean notify,                                boolean addDeltaRequest) {        // Validate our current state        if (!isValid())            throw new IllegalStateException(sm.getString("standardSession.removeAttribute.ise"));        removeAttributeInternal(name, notify, addDeltaRequest);    }    /**     * Remove the object bound with the specified name from this session. If the     * session does not have an object bound with this name, this method does     * nothing.     * <p>     * After this method executes, and if the object implements     * <code>HttpSessionBindingListener</code>, the container calls     * <code>valueUnbound()</code> on the object.     *     * @param name     *            Name of the object to remove from this session.     *     * @exception IllegalStateException     *                if this method is called on an invalidated session     *     * @deprecated As of Version 2.2, this method is replaced by     *             <code>removeAttribute()</code>     */    public void removeValue(String name) {        removeAttribute(name);    }    /**     * Bind an object to this session, using the specified name. If an object of     * the same name is already bound to this session, the object is replaced.     * <p>     * After this method executes, and if the object implements     * <code>HttpSessionBindingListener</code>, the container calls     * <code>valueBound()</code> on the object.     *     * @param name     *            Name to which the object is bound, cannot be null     * @param value     *            Object to be bound, cannot be null     *     * @exception IllegalArgumentException     *                if an attempt is made to add a non-serializable object in     *                an environment marked distributable.     * @exception IllegalStateException     *                if this method is called on an invalidated session     */    public void setAttribute(String name, Object value) {        setAttribute(name, value, true, true);    }    public void setAttribute(String name, Object value, boolean notify,                             boolean addDeltaRequest) {        // Name cannot be null        if (name == null)            throw new IllegalArgumentException(sm.getString("standardSession.setAttribute.namenull"));        // Null value is the same as removeAttribute()        if (value == null) {            removeAttribute(name);            return;        }        try {            lock();            // Validate our current state            if (!isValid())                throw new IllegalStateException(sm.getString("standardSession.setAttribute.ise"));            if (! (value instanceof java.io.Serializable)) {                throw new IllegalArgumentException("Attribute [" + name + "] is not serializable");            }            if (addDeltaRequest && (deltaRequest != null))                deltaRequest.setAttribute(name, value);            // Construct an event with the new value            HttpSessionBindingEvent event = null;            // Call the valueBound() method if necessary            if (value instanceof HttpSessionBindingListener && notify) {                // Don't call any notification if replacing with the same value                Object oldValue = attributes.get(name);                if (value != oldValue) {                    event = new HttpSessionBindingEvent(getSession(), name, value);                    try {                        ( (HttpSessionBindingListener) value).valueBound(event);                    } catch (Exception x) {                        log.error(sm.getString("deltaSession.valueBound.ex"), x);                    }                }            }            // Replace or add this attribute

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -