CRXSessionProvider.java
2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Repository
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.servlet.ServletContext
* javax.servlet.ServletException
* javax.servlet.http.HttpServletRequest
*/
package com.day.crx.explorer.impl.j2ee;
import com.day.crx.explorer.impl.j2ee.JCRExplorerServlet;
import com.day.crx.explorer.impl.j2ee.SessionProvider;
import java.util.HashMap;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
public class CRXSessionProvider
implements SessionProvider {
private SessionProvider base;
private ServletContext ctx;
private final HashMap<Session, Counter> ownSessions = new HashMap();
public CRXSessionProvider(ServletContext ctx, SessionProvider base) {
this.base = base;
this.ctx = ctx;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public Session getSession(HttpServletRequest request, Repository rep, String workspace) throws ServletException, RepositoryException {
Session session = JCRExplorerServlet.getSession(request);
if (session == null && this.base != null) {
return this.base.getSession(request, rep, workspace);
}
HashMap<Session, Counter> hashMap = this.ownSessions;
synchronized (hashMap) {
Counter c = this.ownSessions.get((Object)session);
if (c == null) {
c = new Counter();
this.ownSessions.put(session, c);
}
c.inc();
}
return session;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void releaseSession(Session session) {
HashMap<Session, Counter> hashMap = this.ownSessions;
synchronized (hashMap) {
Counter c = this.ownSessions.get((Object)session);
if (c == null) {
this.base.releaseSession(session);
} else if (c.dec() == 0) {
this.ownSessions.remove((Object)session);
}
}
}
private static class Counter {
private int i = 0;
private Counter() {
}
public int inc() {
return ++this.i;
}
public int dec() {
return --this.i;
}
}
}