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

File XWikiStubContextInitializer.java

 

Coverage histogram

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

Code metrics

4
4
1
1
67
28
3
0.75
4
1
3

Classes

Class Line # Actions
XWikiStubContextInitializer 45 4 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 50 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 com.xpn.xwiki.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.context.ExecutionContext;
28    import org.xwiki.context.ExecutionContextException;
29    import org.xwiki.context.ExecutionContextInitializer;
30   
31    import com.xpn.xwiki.XWikiContext;
32    import com.xpn.xwiki.util.XWikiStubContextProvider;
33   
34    /**
35    * An automatic XWikiContext stub injecter for ExecutionContext for daemons unable to create a proper XWikiContext (no
36    * real request information or not even know about XWikiContext like components).
37    *
38    * @see XWikiStubContextProvider
39    * @version $Id: 1d3a1ed2220fa70ba7e3a81b0f29720b855f0a25 $
40    * @since 2.0M3
41    */
42    @Component
43    @Singleton
44    @Named("XWikiStubContextInitializer")
 
45    public class XWikiStubContextInitializer implements ExecutionContextInitializer
46    {
47    /**
48    * Generate stub XWikiContext.
49    */
50    @Inject
51    private XWikiStubContextProvider stubContextProvider;
52   
 
53  35373 toggle @Override
54    public void initialize(ExecutionContext context) throws ExecutionContextException
55    {
56  35357 if (!context.hasProperty(XWikiContext.EXECUTIONCONTEXT_KEY)) {
57    // if the XWikiContext is not provided in the Execution context it mean the Execution context is being
58    // initialized by a daemon thread
59  5066 XWikiContext stubContext = this.stubContextProvider.createStubContext();
60   
61  5065 if (stubContext != null) {
62    // the stub context has been properly initialized, we declare it in the Execution context
63  4592 stubContext.declareInExecutionContext(context);
64    }
65    }
66    }
67    }