001    /*
002     * Created on 29/11/2005
003     *
004     */
005    package org.trails.servlet;
006    
007    import java.util.Locale;
008    import javax.servlet.ServletConfig;
009    
010    import org.apache.hivemind.Registry;
011    import org.apache.hivemind.service.ThreadLocale;
012    import org.apache.tapestry.ApplicationServlet;
013    import org.apache.tapestry.services.RequestLocaleManager;
014    
015    /**
016     * This class will expose the Tapestry Registry as an static atribute.
017     *
018     * @author Eduardo Fernandes Piva (eduardo@gwe.com.br)
019     */
020    public class TrailsApplicationServlet extends ApplicationServlet
021    {
022    
023            /**
024             * This is used to share the Registry among all the
025             */
026            private static Registry tapestryRegistry = null;
027    
028            @Override
029            protected Registry constructRegistry(ServletConfig config)
030            {
031                    synchronized (TrailsApplicationServlet.class)
032                    {
033                            TrailsApplicationServlet.tapestryRegistry = super.constructRegistry(config);
034                            return TrailsApplicationServlet.tapestryRegistry;
035                    }
036            }
037    
038            @Override
039            public void destroy()
040            {
041                    synchronized (TrailsApplicationServlet.class)
042                    {
043                            super.destroy();
044                            TrailsApplicationServlet.tapestryRegistry = null;
045                    }
046            }
047    
048            /*
049                     * Used by Spring.
050                     */
051            public static Registry getRegistry()
052            {
053                    return tapestryRegistry;
054            }
055    
056            public static Locale getCurrentLocale()
057            {
058                    return ((ThreadLocale) tapestryRegistry.getService("hivemind.ThreadLocale", ThreadLocale.class)).getLocale();
059            }
060    }