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

File XWikiJaxRsApplication.java

 

Coverage histogram

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

Code metrics

0
8
2
1
82
34
2
0.25
4
2
1

Classes

Class Line # Actions
XWikiJaxRsApplication 50 8 0% 2 0
1.0100%
 

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;
21   
22    import java.lang.reflect.Type;
23    import java.util.HashSet;
24    import java.util.List;
25    import java.util.Set;
26    import java.util.logging.Level;
27   
28    import javax.ws.rs.core.Application;
29   
30    import org.restlet.Context;
31    import org.xwiki.component.descriptor.ComponentDescriptor;
32    import org.xwiki.component.manager.ComponentManager;
33    import org.xwiki.rest.internal.Constants;
34    import org.xwiki.rest.XWikiRestComponent;
35   
36    /**
37    * <p>
38    * This class is used to configure JAX-RS resources and providers. They are dynamically discovered using the component
39    * manager.
40    * </p>
41    * <p>
42    * JAX-RS resources and providers must be declared as components whose hint is the FQN of the class implementing it.
43    * This is needed because of how the Restlet object factory works. When Restlet requests an object it passes to the
44    * factory the FQN name of the class to be instantiated. We use this FQN to lookup the component among the ones that are
45    * implementing the XWikiRestComponent (marker) interface.
46    * </p>
47    *
48    * @version $Id: 83f39dee983d890fd790b2d39598469c90ec6b03 $
49    */
 
50    public class XWikiJaxRsApplication extends Application
51    {
52    /*
53    * The set containing all the discovered resources and providers that will constitute the JAX-RS application.
54    */
55    private Set<Class< ? >> jaxRsClasses;
56   
 
57  18 toggle public XWikiJaxRsApplication(Context context)
58    {
59  18 this.jaxRsClasses = new HashSet<Class< ? >>();
60   
61  18 ComponentManager componentManager =
62    (ComponentManager) context.getAttributes().get(Constants.XWIKI_COMPONENT_MANAGER);
63   
64    /* Look up all the component that are marked as XWikiRestComponent. */
65  18 List<ComponentDescriptor<XWikiRestComponent>> cds =
66    componentManager.getComponentDescriptorList((Type) XWikiRestComponent.class);
67   
68  18 for (ComponentDescriptor<XWikiRestComponent> cd : cds) {
69  1119 this.jaxRsClasses.add(cd.getImplementation());
70  1119 context.getLogger().log(Level.FINE, String.format("%s registered.", cd.getImplementation().getName()));
71    }
72   
73  18 context.getLogger().log(Level.INFO, "RESTful API subsystem initialized.");
74    }
75   
 
76  18 toggle @Override
77    public Set<Class< ? >> getClasses()
78    {
79  18 return jaxRsClasses;
80    }
81   
82    }