commit | author | age
|
70a614
|
1 |
package de.uhilger.um.api; |
U |
2 |
|
|
3 |
import de.uhilger.baselink.PersistenceManager; |
|
4 |
import de.uhilger.baselink.Record; |
|
5 |
import de.uhilger.transit.web.RequestKontext; |
|
6 |
import de.uhilger.transit.web.WebKontext; |
|
7 |
import static de.uhilger.um.api.UserMgr.UM_DB; |
|
8 |
import java.util.Properties; |
|
9 |
import javax.servlet.ServletContext; |
|
10 |
import javax.servlet.http.HttpServletRequest; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
*/ |
|
15 |
public abstract class Api implements WebKontext, RequestKontext { |
|
16 |
|
|
17 |
/** Zeiger zum Servlet-Kontext dieser Anwendung */ |
|
18 |
private ServletContext ctx; |
|
19 |
|
|
20 |
private HttpServletRequest request; |
|
21 |
|
|
22 |
protected PersistenceManager getDb() { |
|
23 |
return (PersistenceManager) ctx.getAttribute(UM_DB); |
|
24 |
} |
|
25 |
|
|
26 |
protected String getSql(String id) { |
|
27 |
Properties sql = (Properties) ctx.getAttribute(UserMgr.UM_SQL_PROPERTIES); |
|
28 |
return sql.getProperty(id); |
|
29 |
} |
|
30 |
|
|
31 |
protected Record getMapper(String mapperName) { |
|
32 |
Record record = null; |
|
33 |
Object o = getServletContext().getAttribute(mapperName); |
|
34 |
if(o instanceof Record) { |
|
35 |
record = (Record) o; |
|
36 |
} |
|
37 |
return record; |
|
38 |
} |
|
39 |
|
|
40 |
/* ------------- Implementierung WebKontext ------------- */ |
|
41 |
|
|
42 |
@Override |
|
43 |
public ServletContext getServletContext() { |
|
44 |
return ctx; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public void setServletContext(ServletContext servletContext) { |
|
49 |
this.ctx = servletContext; |
|
50 |
} |
|
51 |
|
|
52 |
/* ------------- Implementierung RequestKontext ------------- */ |
|
53 |
|
|
54 |
@Override |
|
55 |
public HttpServletRequest getRequest() { |
|
56 |
return request; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public void setRequest(HttpServletRequest r) { |
|
61 |
this.request = r; |
|
62 |
} |
|
63 |
|
|
64 |
} |