001: /* The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
002: *
003: * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * 1. Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * 2. Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in
014: * the documentation and/or other materials provided with the
015: * distribution.
016: *
017: * 3. The end-user documentation included with the redistribution,
018: * if any, must include the following acknowledgment:
019: * "This product includes software developed by Jcorporate Ltd.
020: * (http://www.jcorporate.com/)."
021: * Alternately, this acknowledgment may appear in the software itself,
022: * if and wherever such third-party acknowledgments normally appear.
023: *
024: * 4. "Jcorporate" and product names such as "Expresso" must
025: * not be used to endorse or promote products derived from this
026: * software without prior written permission. For written permission,
027: * please contact info@jcorporate.com.
028: *
029: * 5. Products derived from this software may not be called "Expresso",
030: * or other Jcorporate product names; nor may "Expresso" or other
031: * Jcorporate product names appear in their name, without prior
032: * written permission of Jcorporate Ltd.
033: *
034: * 6. No product derived from this software may compete in the same
035: * market space, i.e. framework, without prior written permission
036: * of Jcorporate Ltd. For written permission, please contact
037: * partners@jcorporate.com.
038: *
039: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
040: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
041: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
042: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
043: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
044: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
045: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
046: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
047: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
048: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
049: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
050: * SUCH DAMAGE.
051: * ====================================================================
052: *
053: * This software consists of voluntary contributions made by many
054: * individuals on behalf of the Jcorporate Ltd. Contributions back
055: * to the project(s) are encouraged when you make modifications.
056: * Please send them to support@jcorporate.com. For more information
057: * on Jcorporate Ltd. and its products, please see
058: * <http://www.jcorporate.com/>.
059: *
060: * Portions of this software are based upon other open source
061: * products and are subject to their respective licenses.
062: */
063:
064: package com.jcorporate.expresso.core.registry;
065:
066: import com.jcorporate.expresso.core.security.User;
067:
068: /**
069: * Thread context is closely tied with the RequestRegistry. What it does
070: * is glean the RequestRegistry from one thread and allow that information
071: * to be passed to another.
072: * <p>Typical Usage:
073: * <code><pre>
074: * //Sets the internal members
075: * ExpressoThreadContext context = new ExpressoThreadContext();
076: * <p/>
077: * //Sample thread
078: * Thread myThread = new MyThread();
079: * myThread.setThreadContext(context);
080: * <p/>
081: * .....
082: * <p/>
083: * Then in 'MyThread'....
084: * <p/>
085: * void run() {
086: * context.applySettingsToCurrentThread();
087: * ....
088: * }
089: * </pre></code>
090: * </p>
091: * <p>If you change the API for the RequestRegistry by adding more items
092: * , then you need to change this class as well to allow transport of the
093: * request registry between threads.</p>
094: *
095: * @author Michael Rimov
096: */
097: public class ExpressoThreadContext {
098: /**
099: * The Security credentials of the user who's permissions are being
100: * used for this thread.
101: */
102: private User user;
103:
104: /**
105: * The data context that is being used for defaults for this thread.
106: */
107: private String dataContext;
108:
109: /**
110: * Default constructor.
111: */
112: public ExpressoThreadContext() {
113: super ();
114: setDataContext(RequestRegistry.getDataContext());
115: setUser(RequestRegistry.getUser());
116: }
117:
118: /**
119: * Takes the settings that were in the thread that this object
120: * resided in when it was created and applies it to the thread that
121: * it is currently running in.
122: */
123: public void applyToCurrentThread() {
124: new MutableRequestRegistry(getDataContext(), getUser());
125: }
126:
127: /**
128: * Protected setter. Sets the user for the thread context.
129: *
130: * @param user User
131: */
132: protected void setUser(User user) {
133: this .user = user;
134: }
135:
136: /**
137: * Sets the data context. Protected.
138: *
139: * @param dataContext String
140: */
141: protected void setDataContext(String dataContext) {
142: this .dataContext = dataContext;
143: }
144:
145: /**
146: * Retreive the user.
147: *
148: * @return User
149: */
150: public User getUser() {
151: return user;
152: }
153:
154: /**
155: * Retrieve the data context.
156: *
157: * @return String
158: */
159: public String getDataContext() {
160: return dataContext;
161: }
162: }
|