View Javadoc
1   /*
2    * #%L
3    * Coser :: Web
4    * %%
5    * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chemit Tony
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Affero General Public License as published by
9    * the Free Software Foundation, either version 3 of the License, or
10   * (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   * 
17   * You should have received a copy of the GNU Affero General Public License
18   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19   * #L%
20   */
21  package fr.ifremer.coser.web.actions.common;
22  
23  import fr.ifremer.coser.result.CoserRequest;
24  import fr.ifremer.coser.result.CoserRequestBuilder;
25  import fr.ifremer.coser.web.ServiceHelper;
26  import org.nuiton.web.struts2.BaseAction;
27  
28  import java.util.Locale;
29  
30  /**
31   * Created on 3/21/14.
32   *
33   * @author Tony Chemit <chemit@codelutin.com>
34   * @since 1.5
35   */
36  public abstract class AbstractCoserAction extends BaseAction {
37  
38      private static final long serialVersionUID = 1L;
39  
40      /**
41       * To access business layer.
42       *
43       * @since 1.5
44       */
45      protected transient ServiceHelper service;
46  
47      /**
48       * @return a new request builder.
49       * @since 1.5
50       */
51      protected <R extends CoserRequest> CoserRequestBuilder<R> requestBuilder(Class<R> requestType) {
52          return requestBuilder(getLocale(), requestType);
53      }
54  
55      /**
56       * @param locale      locale to use (while using execute and wait action we keep the locale in session...)
57       * @param requestType type of request to build
58       * @return a new request builder.
59       * @since 1.5
60       */
61      protected <R extends CoserRequest> CoserRequestBuilder<R> requestBuilder(Locale locale, Class<R> requestType) {
62          return CoserRequestBuilder.newBuilder(locale, requestType);
63      }
64  
65      /**
66       * @return service helper for this action
67       * @since 1.5
68       */
69      protected ServiceHelper getService() {
70          if (service == null) {
71              service = new ServiceHelper(this);
72          }
73          return service;
74      }
75  }