- merge update from trunk
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / AbstractController.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.cdm.remote.controller;
11
12 import java.util.Arrays;
13 import java.util.List;
14
15 import javax.servlet.http.HttpServletRequest;
16
17 import org.apache.log4j.Logger;
18
19 import eu.etaxonomy.cdm.api.service.IService;
20 import eu.etaxonomy.cdm.model.common.CdmBase;
21 import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
22
23 /**
24 * @author a.kohlbecker
25 * @date 23.06.2009
26 *
27 * @param <T>
28 * @param <SERVICE>
29 */
30 public abstract class AbstractController<T extends CdmBase, SERVICE extends IService<T>> {
31
32 private static final List<String> DEFAULT_INIT_STRATEGY = Arrays.asList(new String []{
33 "$"
34 });
35
36 public static final Logger logger = Logger.getLogger(AbstractController.class);
37
38 protected SERVICE service;
39
40 public abstract void setService(SERVICE service);
41
42 protected static final Integer DEFAULT_PAGE_SIZE = PagerParameters.DEFAULT_PAGESIZE;
43
44 /**
45 * Default thread priority for long term processes which are running in
46 * separate threads. These batch processes are usually monitored with the
47 * {@link ProgressMonitorController}. This value must be lower than
48 * {@link Thread#NORM_PRIORITY}
49 */
50 public static final int DEFAULT_BATCH_THREAD_PRIORITY = 3;
51
52 protected List<String> initializationStrategy = DEFAULT_INIT_STRATEGY;
53
54 /**
55 * Set the default initialization strategy for this controller.
56 *
57 * @param initializationStrategy
58 */
59 public final void setInitializationStrategy(List<String> initializationStrategy) {
60 this.initializationStrategy = initializationStrategy;
61 }
62
63 /**
64 * Provides access to the default initialization strategy.
65 * The default initialization strategy is predefined for all controllers in
66 * {@link #DEFAULT_INIT_STRATEGY} but can be altered by
67 * concrete implementations by utilizing {@link #setInitializationStrategy(List)}
68 * in the constructor of the specific controller.
69 *
70 * @return the default initialization strategy
71 */
72 public final List<String> getInitializationStrategy() {
73 return this.initializationStrategy;
74 }
75
76 /**
77 * Returns the HTTP request path and query parameters as string
78 *
79 * @param request
80 * @return request path and query parameters as string.
81 */
82 protected String requestPathAndQuery(HttpServletRequest request) {
83 if(request == null) {
84 return "";
85 }
86 StringBuilder b = new StringBuilder();
87 b.append(request.getMethod()).append(": ");
88 b.append(request.getRequestURI());
89 String query = request.getQueryString();
90 if(query != null) {
91 b.append("?").append(query);
92 }
93
94 return b.toString();
95 }
96
97 }