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

File XWikiExtensionRepositoryFactory.java

 

Coverage histogram

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

Code metrics

0
8
4
1
106
59
6
0.75
2
4
1.5

Classes

Class Line # Actions
XWikiExtensionRepositoryFactory 48 8 0% 6 2
0.833333383.3%
 

Contributing tests

This file is covered by 1 test. .

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.extension.repository.xwiki.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25    import javax.xml.bind.JAXBContext;
26    import javax.xml.bind.JAXBException;
27    import javax.xml.bind.Marshaller;
28    import javax.xml.bind.Unmarshaller;
29   
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.component.phase.Initializable;
32    import org.xwiki.component.phase.InitializationException;
33    import org.xwiki.extension.ExtensionLicenseManager;
34    import org.xwiki.extension.internal.ExtensionFactory;
35    import org.xwiki.extension.repository.AbstractExtensionRepositoryFactory;
36    import org.xwiki.extension.repository.ExtensionRepository;
37    import org.xwiki.extension.repository.ExtensionRepositoryDescriptor;
38    import org.xwiki.extension.repository.ExtensionRepositoryException;
39    import org.xwiki.extension.repository.http.internal.HttpClientFactory;
40   
41    /**
42    * @version $Id: 0ca89b1a26ee2406c7ddc9d2ef232710c7e963da $
43    * @since 4.0M1
44    */
45    @Component
46    @Singleton
47    @Named("xwiki")
 
48    public class XWikiExtensionRepositoryFactory extends AbstractExtensionRepositoryFactory implements Initializable
49    {
50    @Inject
51    private ExtensionLicenseManager licenseManager;
52   
53    @Inject
54    private HttpClientFactory httpClientFactory;
55   
56    @Inject
57    private ExtensionFactory factory;
58   
59    private JAXBContext jaxbContext;
60   
 
61  2 toggle @Override
62    public void initialize() throws InitializationException
63    {
64  2 try {
65  2 this.jaxbContext = JAXBContext.newInstance("org.xwiki.extension.repository.xwiki.model.jaxb");
66    } catch (JAXBException e) {
67  0 throw new InitializationException("Failed to create JAXB context", e);
68    }
69    }
70   
71    /**
72    * JAXBContext is thread safe but Marshaller is not.
73    *
74    * @return a new instance of Marshaller
75    * @throws JAXBException if an error was encountered while creating the <tt>Marshaller</tt> object
76    */
 
77  28 toggle public Marshaller createMarshaller() throws JAXBException
78    {
79  28 return this.jaxbContext.createMarshaller();
80    }
81   
82    /**
83    * JAXBContext is thread safe but Unmarshaller is not.
84    *
85    * @return a new instance of Unmarshaller
86    * @throws JAXBException if an error was encountered while creating the <tt>Unmarshaller</tt> object
87    */
 
88  85 toggle public Unmarshaller createUnmarshaller() throws JAXBException
89    {
90  85 return this.jaxbContext.createUnmarshaller();
91    }
92   
93    // ExtensionRepositoryFactory
94   
 
95  2 toggle @Override
96    public ExtensionRepository createRepository(ExtensionRepositoryDescriptor repositoryDescriptor)
97    throws ExtensionRepositoryException
98    {
99  2 try {
100  2 return new XWikiExtensionRepository(repositoryDescriptor, this, this.licenseManager, this.httpClientFactory,
101    this.factory);
102    } catch (Exception e) {
103  0 throw new ExtensionRepositoryException("Failed to create repository [" + repositoryDescriptor + "]", e);
104    }
105    }
106    }