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

File DefaultJobContext.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
12
4
1
95
46
9
0.75
3
4
2.25

Classes

Class Line # Actions
DefaultJobContext 41 12 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 106 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.job.internal;
21   
22    import java.util.Stack;
23   
24    import javax.inject.Inject;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.context.Execution;
29    import org.xwiki.context.ExecutionContext;
30    import org.xwiki.job.Job;
31    import org.xwiki.job.JobContext;
32   
33    /**
34    * Default implementation of {@link JobContext}.
35    *
36    * @version $Id: e4bbb16942e930aa7aa54778a14662417d8c8cc0 $
37    * @since 4.0M2
38    */
39    @Component
40    @Singleton
 
41    public class DefaultJobContext implements JobContext
42    {
43    /**
44    * The key associated to the stack of job currently being executed in the {@link ExecutionContext}.
45    */
46    private static final String KEY_CURRENTJOB = "job.current";
47   
48    /**
49    * Used to access the current job from the context.
50    */
51    @Inject
52    private Execution execution;
53   
54    /**
55    * @param create if true create the stack if it does not exists
56    * @return the stack containing the current jobs
57    */
 
58  1620 toggle private Stack<Job> getJobstack(boolean create)
59    {
60  1620 ExecutionContext context = this.execution.getContext();
61   
62  1620 if (context != null) {
63  1462 Stack<Job> stack = (Stack<Job>) context.getProperty(KEY_CURRENTJOB);
64   
65  1462 if (stack == null && create) {
66  351 stack = new Stack<Job>();
67  351 context.setProperty(KEY_CURRENTJOB, stack);
68    }
69   
70  1462 return stack;
71    }
72   
73  158 return null;
74    }
75   
 
76  538 toggle @Override
77    public Job getCurrentJob()
78    {
79  538 Stack<Job> stack = getJobstack(false);
80   
81  538 return stack == null || stack.isEmpty() ? null : stack.peek();
82    }
83   
 
84  541 toggle @Override
85    public void pushCurrentJob(Job job)
86    {
87  541 getJobstack(true).push(job);
88    }
89   
 
90  541 toggle @Override
91    public void popCurrentJob()
92    {
93  541 getJobstack(true).pop();
94    }
95    }