KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > session > SessionAC


1 /*
2   Copyright (C) 2001-2003 Renaud Pawlak <renaud@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.session;
19
20 import java.util.Arrays JavaDoc;
21 import java.util.HashSet JavaDoc;
22 import org.apache.log4j.Logger;
23 import org.objectweb.jac.core.*;
24 import org.objectweb.jac.util.*;
25
26 /**
27  * This aspect component handle the session aspect within JAC
28  * applications.
29  *
30  * <p>The session aspects memorizes some contextual informations as
31  * users id or password and link them to the current session id (the
32  * "Session.sid" attribute in the context). If the client correctly
33  * sets this attribute for each interaction, then the session aspect
34  * restores the saved information so that the user will not have to
35  * input extra information (such as his password) for each
36  * interaction.
37
38  * @see org.objectweb.jac.aspects.session.SessionWrapper
39  *
40  * @author Renaud Pawlak */

41
42 public class SessionAC extends AspectComponent implements SessionConf {
43     static Logger logger = Logger.getLogger("session");
44
45     public static final String JavaDoc SESSION_ID = "Session.sid";
46     public static final String JavaDoc INITIALIZED = "Session.initialized";
47
48     static {
49         Collaboration.setGlobal(SESSION_ID);
50         Collaboration.setGlobal(INITIALIZED);
51     }
52
53     public String JavaDoc[] getDefaultConfigs() {
54         return new String JavaDoc[] {"org/objectweb/jac/aspects/session/session.acc"};
55     }
56
57     SessionWrapper wrapper;
58
59     public void clearCurrentSessionAttribute(String JavaDoc name) {
60         wrapper.clearCurrentSessionAttribute(name);
61     }
62
63     protected SessionWrapper getWrapper() {
64         // We must wait until the AC is registered, because the wrapper
65
// stores the AC's name (which will be NULL is the AC is not registered)
66
if (wrapper==null)
67             wrapper = new SessionWrapper(this);
68         return wrapper;
69     }
70
71     public void defineSessionHandlers(String JavaDoc classExpr,
72                                       String JavaDoc methodExpr,
73                                       String JavaDoc objectExpr) {
74         pointcut(objectExpr, classExpr, methodExpr,
75                  getWrapper(), null);
76     }
77
78     public void definePerSessionObjects(String JavaDoc classExpr,
79                                         String JavaDoc objectExpr) {
80         logger.debug("defining per-session objects: "+
81                      classExpr+","+objectExpr );
82         pointcut(objectExpr, classExpr, "ALL",
83                  PerSessionObjectWrapper.class.getName(),
84                  null, false);
85     }
86
87     HashSet JavaDoc storedAttributes = new HashSet JavaDoc();
88
89     public void declareStoredAttributes(String JavaDoc attributes[]) {
90         storedAttributes.addAll(Arrays.asList(attributes));
91     }
92
93     /**
94      * Stored attributes accessor.
95      *
96      * @return the stored attributes
97      */

98     public String JavaDoc[] getStoredAttributes() {
99         return (String JavaDoc[])storedAttributes.toArray(new String JavaDoc[] {});
100     }
101
102 }
103
Popular Tags