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

File DefaultRestURLGenerator.java

 

Coverage histogram

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

Code metrics

0
5
1
1
60
32
2
0.4
5
1
2

Classes

Class Line # Actions
DefaultRestURLGenerator 43 5 0% 2 1
0.833333383.3%
 

Contributing tests

No tests hitting this source file were found.

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.rest.internal.url;
21   
22    import java.lang.reflect.ParameterizedType;
23    import java.net.URL;
24   
25    import javax.inject.Inject;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.manager.ComponentLookupException;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.component.util.DefaultParameterizedType;
32    import org.xwiki.model.reference.EntityReference;
33    import org.xwiki.rest.XWikiRestException;
34    import org.xwiki.rest.url.ParametrizedRestURLGenerator;
35    import org.xwiki.rest.url.RestURLGenerator;
36   
37    /**
38    * @version $Id: 9f558c690b1b99f2b74843ae65ef4dcc6098a0a5 $
39    * @since 7.2M1
40    */
41    @Component
42    @Singleton
 
43    public class DefaultRestURLGenerator implements RestURLGenerator
44    {
45    @Inject
46    private ComponentManager componentManager;
47   
 
48  1083 toggle @Override
49    public URL getURL(EntityReference entityReference) throws XWikiRestException
50    {
51  1083 try {
52  1083 ParameterizedType type = new DefaultParameterizedType(null, ParametrizedRestURLGenerator.class,
53    entityReference.getClass());
54  1083 ParametrizedRestURLGenerator parametrizedRestURLGenerator = componentManager.getInstance(type);
55  1083 return parametrizedRestURLGenerator.getURL(entityReference);
56    } catch (ComponentLookupException e) {
57  0 throw new XWikiRestException(String.format("Unsupported entity type: [%s]", entityReference.getClass()), e);
58    }
59    }
60    }