01: /*
02: * Enhydra Java Application Server Project
03: *
04: * The contents of this file are subject to the Enhydra Public License
05: * Version 1.1 (the "License"); you may not use this file except in
06: * compliance with the License. You may obtain a copy of the License on
07: * the Enhydra web site (http://www.enhydra.org/).
08: *
09: * Software distributed under the License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11: * the License for the specific terms governing rights and limitations
12: * under the License.
13: *
14: * The Initial Developer of the Enhydra Application Server is Lutris
15: * Technologies, Inc. The Enhydra Application Server and portions created
16: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17: * All Rights Reserved.
18: *
19: * Contributor(s):
20: *
21: * $Id: MasterScreenFactory.java,v 1.1 2006-09-11 12:30:02 sinisa Exp $
22: */
23: package org.enhydra.barracuda.config;
24:
25: import java.io.*;
26: import java.util.*;
27: import java.lang.ref.*;
28: import java.net.*;
29: import javax.servlet.*;
30: import javax.servlet.http.*;
31:
32: import org.w3c.dom.*;
33: import org.w3c.dom.html.*;
34:
35: import org.enhydra.barracuda.config.events.*;
36: import org.enhydra.barracuda.config.xmlc.*;
37: import org.barracudamvc.core.comp.*;
38: import org.barracudamvc.core.util.dom.*;
39: import org.barracudamvc.core.event.*;
40: import org.barracudamvc.core.event.helper.*;
41: import org.barracudamvc.core.forms.*;
42: import org.barracudamvc.core.view.*;
43: import org.barracudamvc.core.util.http.*;
44: import org.barracudamvc.plankton.data.*;
45:
46: /**
47: * <p>This class is used to get an instance of the MasterScreen.
48: * We don't use a static getInstance() method here because it needs
49: * to use an inner class to act as a ReferenceFactory. Consequently,
50: * you would use the factory like this:
51: *
52: * <p>new MasterScreenFactory().getInstance(...);
53: */
54: public class MasterScreenFactory {
55:
56: public static final String KEY = MasterScreenFactory.class
57: .getName()
58: + ".Key";
59:
60: public MasterScreen getInstance(EventGateway eg,
61: ControlEventContext context, Locale locale) {
62: //get the appropriate screen for the desired context and locale
63: ReferenceFactory rf = new LocalReferenceFactory(
64: getRootGateway(eg), locale);
65: MasterScreen screen = (MasterScreen) SessionServices
66: .getObjectFromCache(context, KEY + locale, rf);
67: return screen;
68: }
69:
70: protected EventGateway getRootGateway(EventGateway eg) {
71: EventGateway egParent = eg.getParent();
72: if (egParent == null)
73: return eg;
74: else
75: return getRootGateway(egParent);
76: }
77:
78: class LocalReferenceFactory implements ReferenceFactory {
79: EventGateway egRoot = null;
80: Locale locale = null;
81:
82: public LocalReferenceFactory(EventGateway iegRoot,
83: Locale ilocale) {
84: egRoot = iegRoot;
85: locale = ilocale;
86: }
87:
88: public Reference getObjectReference() {
89: return new SoftReference(new MasterScreen(egRoot, locale));
90: }
91: }
92: }
|