KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > config > MasterScreenFactory


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site (http://www.enhydra.org/).
8  *
9  * 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 2004/05/28 19:39:27 slobodan 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.enhydra.barracuda.core.comp.*;
38 import org.enhydra.barracuda.core.util.dom.*;
39 import org.enhydra.barracuda.core.event.*;
40 import org.enhydra.barracuda.core.event.helper.*;
41 import org.enhydra.barracuda.core.forms.*;
42 import org.enhydra.barracuda.core.view.*;
43 import org.enhydra.barracuda.core.util.http.*;
44 import org.enhydra.barracuda.plankton.data.*;
45
46
47 /**
48  * <p>This class is used to get an instance of the MasterScreen.
49  * We don't use a static getInstance() method here because it needs
50  * to use an inner class to act as a ReferenceFactory. Consequently,
51  * you would use the factory like this:
52  *
53  * <p>new MasterScreenFactory().getInstance(...);
54  */

55 public class MasterScreenFactory {
56
57     public static final String JavaDoc KEY = MasterScreenFactory.class.getName()+".Key";
58
59     public MasterScreen getInstance(EventGateway eg, ControlEventContext context, Locale locale) {
60         //get the appropriate screen for the desired context and locale
61
ReferenceFactory rf = new LocalReferenceFactory(getRootGateway(eg), locale);
62         MasterScreen screen = (MasterScreen) SessionServices.getObjectFromCache(context, KEY+locale, rf);
63         return screen;
64     }
65     
66     protected EventGateway getRootGateway(EventGateway eg) {
67         EventGateway egParent = eg.getParent();
68         if (egParent==null) return eg;
69         else return getRootGateway(egParent);
70     }
71     
72     class LocalReferenceFactory implements ReferenceFactory {
73         EventGateway egRoot = null;
74         Locale locale = null;
75
76         public LocalReferenceFactory(EventGateway iegRoot, Locale ilocale) {
77             egRoot = iegRoot;
78             locale = ilocale;
79         }
80         
81         public Reference getObjectReference() {
82             return new SoftReference(new MasterScreen(egRoot, locale));
83         }
84     }
85 }
86
87
88
89
Popular Tags