1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.container.internal

File DefaultContainer.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

18
47
17
1
203
145
26
0.55
2.76
17
1.53

Classes

Class Line # Actions
DefaultContainer 41 47 0% 26 45
0.451219545.1%
 

Contributing tests

This file is covered by 53 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.container.internal;
21   
22    import java.util.Stack;
23   
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.container.ApplicationContext;
28    import org.xwiki.container.Container;
29    import org.xwiki.container.Request;
30    import org.xwiki.container.Response;
31    import org.xwiki.container.Session;
32   
33    /**
34    * We're using ThreadLocals to store the request, response and session so that each thread (i.e. each user request) has
35    * its own value for these objects. In addition we sometime need to create a new request, response or session even while
36    * in the same thread. For this use case we've added the possibility to push/pop different implementations for these
37    * Objects.
38    */
39    @Component
40    @Singleton
 
41    public class DefaultContainer implements Container
42    {
43    /**
44    * @deprecated starting with 3.5M1, use the notion of Environment instead
45    */
46    @Deprecated
47    private ApplicationContext applicationContext;
48   
49    private ThreadLocal<Stack<Request>> request = new ThreadLocal<>();
50   
51    private ThreadLocal<Stack<Response>> response = new ThreadLocal<>();
52   
53    private ThreadLocal<Stack<Session>> session = new ThreadLocal<>();
54   
55    /**
56    * @deprecated starting with 3.5M1, use the notion of Environment instead
57    */
 
58  209 toggle @Override
59    @Deprecated
60    public ApplicationContext getApplicationContext()
61    {
62  209 return this.applicationContext;
63    }
64   
 
65  0 toggle @Override
66    public void pushRequest(Request request)
67    {
68  0 Stack<Request> requests = this.request.get();
69  0 if (requests != null) {
70  0 requests.push(request);
71    }
72    }
73   
 
74  0 toggle @Override
75    public void popRequest()
76    {
77  0 Stack<Request> requests = this.request.get();
78  0 if (requests != null) {
79  0 requests.pop();
80    }
81    }
82   
 
83  17032 toggle @Override
84    public Request getRequest()
85    {
86  17029 Request result = null;
87  16977 Stack<Request> requests = this.request.get();
88  16998 if (requests != null) {
89  16968 result = requests.peek();
90    }
91  16989 return result;
92    }
93   
 
94  1716 toggle @Override
95    public Response getResponse()
96    {
97  1716 Response result = null;
98  1716 Stack<Response> responses = this.response.get();
99  1716 if (responses != null) {
100  1716 result = responses.peek();
101    }
102  1716 return result;
103    }
104   
 
105  0 toggle @Override
106    public void pushResponse(Response response)
107    {
108  0 Stack<Response> responses = this.response.get();
109  0 if (responses != null) {
110  0 responses.push(response);
111    }
112    }
113   
 
114  0 toggle @Override
115    public void popResponse()
116    {
117  0 Stack<Response> responses = this.response.get();
118  0 if (responses != null) {
119  0 responses.pop();
120    }
121    }
122   
 
123  0 toggle @Override
124    public Session getSession()
125    {
126  0 Session result = null;
127  0 Stack<Session> sessions = this.session.get();
128  0 if (sessions != null) {
129  0 result = sessions.peek();
130    }
131  0 return result;
132    }
133   
 
134  0 toggle @Override
135    public void pushSession(Session session)
136    {
137  0 Stack<Session> sessions = this.session.get();
138  0 if (sessions != null) {
139  0 sessions.push(session);
140    }
141    }
142   
 
143  0 toggle @Override
144    public void popSession()
145    {
146  0 Stack<Session> sessions = this.session.get();
147  0 if (sessions != null) {
148  0 sessions.pop();
149    }
150    }
151   
152    /**
153    * @deprecated starting with 3.5M1, use the notion of Environment instead
154    */
 
155  116 toggle @Override
156    @Deprecated
157    public void setApplicationContext(ApplicationContext context)
158    {
159  116 this.applicationContext = context;
160    }
161   
 
162  13152 toggle @Override
163    public void setRequest(Request request)
164    {
165  13153 Stack<Request> stack = new Stack<Request>();
166  13092 stack.push(request);
167  13085 this.request.set(stack);
168    }
169   
 
170  13158 toggle @Override
171    public void removeRequest()
172    {
173  13158 this.request.remove();
174    }
175   
 
176  13147 toggle @Override
177    public void setResponse(Response response)
178    {
179  13157 Stack<Response> stack = new Stack<Response>();
180  13140 stack.push(response);
181  13120 this.response.set(stack);
182    }
183   
 
184  13147 toggle @Override
185    public void removeResponse()
186    {
187  13151 this.response.remove();
188    }
189   
 
190  13079 toggle @Override
191    public void setSession(Session session)
192    {
193  13112 Stack<Session> stack = new Stack<Session>();
194  13132 stack.push(session);
195  13147 this.session.set(stack);
196    }
197   
 
198  13153 toggle @Override
199    public void removeSession()
200    {
201  13156 this.session.remove();
202    }
203    }