AppModule.java

Go to the documentation of this file.
00001 package cedar.hepdata.webapp.services;
00002 
00003 import java.io.IOException;
00004 
00005 import org.apache.commons.logging.Log;
00006 import org.apache.tapestry.ioc.Configuration;
00007 import org.apache.tapestry.ioc.MappedConfiguration;
00008 import org.apache.tapestry.ioc.OrderedConfiguration;
00009 //import org.apache.tapestry.ioc.ServiceBinder;
00010 import org.apache.tapestry.ioc.annotations.InjectService;
00011 import org.apache.tapestry.services.Request;
00012 import org.apache.tapestry.services.RequestFilter;
00013 import org.apache.tapestry.services.RequestHandler;
00014 import org.apache.tapestry.services.Response;
00015 
00020 public class AppModule {
00021 
00022 
00023     public void contributeHibernateSessionSource(Configuration<String> cfg) {
00024         cfg.add("cedar.hepdata.model");
00025     }
00026 
00027 
00028 
00029     //public static void bind(ServiceBinder binder)
00030     //{
00031         // binder.bind(MyServiceInterface.class, MyServiceImpl.class);
00032 
00033         // Make bind() calls on the binder object to define most IoC services.
00034         // Use service builder methods (example below) when the implementation
00035         // is provided inline, or requires more initialization than simply
00036         // invoking the constructor.
00037     //}
00038 
00039 
00040     public static void contributeApplicationDefaults(
00041             MappedConfiguration<String, String> configuration)
00042     {
00043         // Contributions to ApplicationDefaults will override any contributions to
00044         // FactoryDefaults (with the same key). Here we're restricting the supported
00045         // locales to just "en" (English). As you add localised message catalogs and other assets,
00046         // you can extend this list of locales (it's a comma seperated series of locale names;
00047         // the first locale name is the default when there's no reasonable match).
00048 
00049         configuration.add("tapestry.supported-locales", "en");
00050     }
00051 
00052 
00071     public RequestFilter buildTimingFilter(final Log log)
00072     {
00073         return new RequestFilter()
00074         {
00075             public boolean service(Request request, Response response, RequestHandler handler)
00076                     throws IOException
00077             {
00078                 long startTime = System.currentTimeMillis();
00079 
00080                 try
00081                 {
00082                     // The reponsibility of a filter is to invoke the corresponding method
00083                     // in the handler. When you chain multiple filters together, each filter
00084                     // received a handler that is a bridge to the next filter.
00085 
00086                     return handler.service(request, response);
00087                 }
00088                 finally
00089                 {
00090                     long elapsed = System.currentTimeMillis() - startTime;
00091 
00092                     log.info(String.format("Request time: %d ms", elapsed));
00093                 }
00094             }
00095         };
00096     }
00097 
00103     public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
00104             @InjectService("TimingFilter")
00105             RequestFilter filter)
00106     {
00107         // Each contribution to an ordered configuration has a name, When necessary, you may
00108         // set constraints to precisely control the invocation order of the contributed filter
00109         // within the pipeline.
00110 
00111         configuration.add("Timing", filter);
00112     }
00113 }

Generated on Tue Apr 21 15:55:00 2009 for HepData Web servlets by  doxygen 1.5.5