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

File DefaultExecution.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

12
21
5
1
97
57
12
0.57
4.2
5
2.4

Classes

Class Line # Actions
DefaultExecution 40 21 0% 12 4
0.894736889.5%
 

Contributing tests

This file is covered by 768 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.context.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.context.Execution;
28    import org.xwiki.context.ExecutionContext;
29   
30    /**
31    * Holds the Execution Context object. Note that we require this Execution component since we want to be able to pass
32    * the Execution Context to singleton components. Thus this holder is a singleton itself and the Execution Context is
33    * saved as a ThreadLocal variable.
34    *
35    * @version $Id: d81593c40801a0305e345817f0e14960e2cb37a1 $
36    * @since 1.5M2
37    */
38    @Component
39    @Singleton
 
40    public class DefaultExecution implements Execution
41    {
42    /**
43    * Isolate the execution context by thread.
44    */
45    private ThreadLocal<Stack<ExecutionContext>> context = new ThreadLocal<Stack<ExecutionContext>>();
46   
 
47  33919 toggle @Override
48    public void pushContext(ExecutionContext context)
49    {
50  33918 Stack<ExecutionContext> stack = this.context.get();
51  33918 if (stack == null) {
52  4 stack = new Stack<ExecutionContext>();
53  4 this.context.set(stack);
54  33913 } else if (!stack.isEmpty()) {
55  33916 context.inheritFrom(stack.peek());
56    }
57   
58  33922 stack.push(context);
59    }
60   
 
61  33913 toggle @Override
62    public void popContext()
63    {
64  33915 this.context.get().pop();
65    }
66   
 
67  68272736 toggle @Override
68    public ExecutionContext getContext()
69    {
70  68273363 Stack<ExecutionContext> stack = this.context.get();
71  68284242 return stack == null || stack.isEmpty() ? null : stack.peek();
72    }
73   
 
74  32615 toggle @Override
75    public void setContext(ExecutionContext context)
76    {
77  32643 Stack<ExecutionContext> stack = this.context.get();
78  32655 if (stack == null) {
79  19323 stack = new Stack<ExecutionContext>();
80  19337 this.context.set(stack);
81  19361 stack.push(context);
82  13304 } else if (stack.isEmpty()) {
83  0 stack.push(context);
84    } else {
85  13295 if (context != null) {
86  13302 context.inheritFrom(stack.peek());
87    }
88  13309 stack.set(stack.size() - 1, context);
89    }
90    }
91   
 
92  19434 toggle @Override
93    public void removeContext()
94    {
95  19427 this.context.remove();
96    }
97    }