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

File XarObjectPropertySerializerManager.java

 

Coverage histogram

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

Code metrics

6
9
2
1
79
39
5
0.56
4.5
2
2.5

Classes

Class Line # Actions
XarObjectPropertySerializerManager 38 9 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 43 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.xar.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25    import javax.inject.Singleton;
26   
27    import org.apache.commons.lang3.StringUtils;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.manager.ComponentLookupException;
30    import org.xwiki.component.manager.ComponentManager;
31   
32    /**
33    * @version $Id: 03012147ea7f028cd27bfd36fedf53bfb32da81b $
34    * @since 5.4M1
35    */
36    @Component(roles = XarObjectPropertySerializerManager.class)
37    @Singleton
 
38    public class XarObjectPropertySerializerManager
39    {
40    @Inject
41    @Named("context")
42    private Provider<ComponentManager> componentManagerProvider;
43   
44    @Inject
45    private XarObjectPropertySerializer defaultPropertySerializer;
46   
47    /**
48    * @param type the property type for which to find a serializer
49    * @return the property serializer, if none could be found for the provided type the default one is returned
50    * @throws ComponentLookupException when failing to lookup property serializer
51    */
 
52  151964 toggle public XarObjectPropertySerializer getPropertySerializer(String type) throws ComponentLookupException
53    {
54  151964 if (type != null) {
55  148365 ComponentManager componentManager = this.componentManagerProvider.get();
56   
57  148365 if (componentManager.hasComponent(XarObjectPropertySerializer.class, type)) {
58    // First try to use the specified class type as hint.
59  4 return getInstance(type, componentManager);
60    } else {
61    // In previous versions the class type was the full Java class name of the property class
62    // implementation. Extract the hint by removing the Java package prefix and the Class suffix.
63  148361 String simpleType = StringUtils.removeEnd(StringUtils.substringAfterLast(type, "."), "Class");
64   
65  148361 if (componentManager.hasComponent(XarObjectPropertySerializer.class, simpleType)) {
66  28423 return getInstance(simpleType, componentManager);
67    }
68    }
69    }
70   
71  123537 return this.defaultPropertySerializer;
72    }
73   
 
74  28427 toggle private XarObjectPropertySerializer getInstance(String type, ComponentManager componentManager)
75    throws ComponentLookupException
76    {
77  28427 return componentManager.getInstance(XarObjectPropertySerializer.class, type);
78    }
79    }