1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.container.internal

File DefaultContainer.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
76% 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 44
0.4634146446.3%
 

Contributing tests

This file is covered by 64 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  246 toggle @Override
59    @Deprecated
60    public ApplicationContext getApplicationContext()
61    {
62  246 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  154664 toggle @Override
84    public Request getRequest()
85    {
86  154706 Request result = null;
87  154726 Stack<Request> requests = this.request.get();
88  154709 if (requests != null) {
89  154290 result = requests.peek();
90    }
91  154714 return result;
92    }
93   
 
94  78343 toggle @Override
95    public Response getResponse()
96    {
97  78346 Response result = null;
98  78349 Stack<Response> responses = this.response.get();
99  78350 if (responses != null) {
100  70991 result = responses.peek();
101    }
102  78347 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  39 toggle @Override
156    @Deprecated
157    public void setApplicationContext(ApplicationContext context)
158    {
159  39 this.applicationContext = context;
160    }
161   
 
162  72161 toggle @Override
163    public void setRequest(Request request)
164    {
165  72185 Stack<Request> stack = new Stack<Request>();
166  72175 stack.push(request);
167  72189 this.request.set(stack);
168    }
169   
 
170  50745 toggle @Override
171    public void removeRequest()
172    {
173  50769 this.request.remove();
174    }
175   
 
176  58070 toggle @Override
177    public void setResponse(Response response)
178    {
179  58114 Stack<Response> stack = new Stack<Response>();
180  58099 stack.push(response);
181  58130 this.response.set(stack);
182    }
183   
 
184  50759 toggle @Override
185    public void removeResponse()
186    {
187  50776 this.response.remove();
188    }
189   
 
190  50767 toggle @Override
191    public void setSession(Session session)
192    {
193  50770 Stack<Session> stack = new Stack<Session>();
194  50765 stack.push(session);
195  50766 this.session.set(stack);
196    }
197   
 
198  50757 toggle @Override
199    public void removeSession()
200    {
201  50779 this.session.remove();
202    }
203    }