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

File DefaultWikiComponent.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart6.png
72% of files have more coverage

Code metrics

0
18
14
1
224
90
14
0.78
1.29
14
1

Classes

Class Line # Actions
DefaultWikiComponent 41 18 0% 14 14
0.562556.2%
 

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.component.wiki.internal;
21   
22    import java.lang.reflect.Type;
23    import java.util.ArrayList;
24    import java.util.HashMap;
25    import java.util.List;
26    import java.util.Map;
27   
28    import org.xwiki.component.descriptor.ComponentDescriptor;
29    import org.xwiki.component.wiki.WikiComponent;
30    import org.xwiki.component.wiki.WikiComponentScope;
31    import org.xwiki.model.reference.DocumentReference;
32    import org.xwiki.rendering.block.XDOM;
33    import org.xwiki.rendering.syntax.Syntax;
34   
35    /**
36    * Default implementation of a wiki component definition.
37    *
38    * @version $Id: 7c8f33d2773c0439cb34e1f050a4bcedb08f2e61 $
39    * @since 4.2M3
40    */
 
41    public class DefaultWikiComponent implements WikiComponent
42    {
43    /**
44    * @see {@link #getDocumentReference()}
45    */
46    private DocumentReference documentReference;
47   
48    /**
49    * @see {@link #getAuthorReference()}
50    */
51    private DocumentReference authorReference;
52   
53    /**
54    * @see {@link #getHandledMethods()}
55    */
56    private Map<String, XDOM> handledMethods = new HashMap<String, XDOM>();
57   
58    /**
59    * @see {@link #getRoleType()}
60    */
61    private Type roleType;
62   
63    /**
64    * @see {@link #getRoleHint()}
65    */
66    private String roleHint;
67   
68    /**
69    * @see {@link #getScope()}
70    */
71    private WikiComponentScope scope;
72   
73    /**
74    * @see {@link #getImplementedInterfaces()}
75    */
76    private List<Class< ? >> implementedInterfaces = new ArrayList<Class< ? >>();
77   
78    /**
79    * @see {@link #getDependencies()}
80    */
81    private Map<String, ComponentDescriptor> dependencies = new HashMap<String, ComponentDescriptor>();
82   
83    /**
84    * @see {@link #getSyntax()}
85    */
86    private Syntax syntax;
87   
88    /**
89    * Constructor of this component.
90    *
91    * @param documentReference the document holding the component definition
92    * @param authorReference the author of the document holding the component definition
93    * @param roleType the role Type implemented
94    * @param roleHint the role hint for this role implementation
95    * @param scope the scope of this component
96    */
 
97  1 toggle public DefaultWikiComponent(DocumentReference documentReference, DocumentReference authorReference,
98    Type roleType, String roleHint, WikiComponentScope scope)
99    {
100  1 this.documentReference = documentReference;
101  1 this.authorReference = authorReference;
102  1 this.roleType = roleType;
103  1 this.roleHint = roleHint;
104  1 this.scope = scope;
105    }
106   
 
107  0 toggle @Override
108    public DocumentReference getDocumentReference()
109    {
110  0 return this.documentReference;
111    }
112   
 
113  0 toggle @Override
114    public DocumentReference getAuthorReference()
115    {
116  0 return this.authorReference;
117    }
118   
119    /**
120    * Get the implementations of all the methods the component handles. It allows to write method implementations in
121    * wiki documents, using script macros. When a method has multiple signatures (different sets of parameters) the
122    * same {@link org.xwiki.rendering.block.XDOM} will be executed.
123    *
124    * @return the map of method name/wiki code this component implementation handles.
125    */
 
126  0 toggle public Map<String, XDOM> getHandledMethods()
127    {
128  0 return this.handledMethods;
129    }
130   
 
131  1 toggle @Override
132    public Type getRoleType()
133    {
134  1 return this.roleType;
135    }
136   
 
137  0 toggle @Override
138    public String getRoleHint()
139    {
140  0 return this.roleHint;
141    }
142   
 
143  0 toggle @Override
144    public WikiComponentScope getScope()
145    {
146  0 return this.scope;
147    }
148   
149    /**
150    * Get the list of interfaces the wiki component implements, apart from its main Role. When the component is
151    * entirely written in a document, it allows the {@link org.xwiki.component.wiki.WikiComponentManager} to add those
152    * Interfaces to the list of implemented interfaces of the {@link java.lang.reflect.Proxy} it will create.
153    *
154    * @return the extra list of interfaces this component implementation implements.
155    */
 
156  1 toggle public List<Class< ? >> getImplementedInterfaces()
157    {
158  1 return this.implementedInterfaces;
159    }
160   
161    /**
162    * Methods returned by {@link #getHandledMethods()} can require other components to be injected in their context.
163    * Each entry in the map returned by this method will be injected in the rendering context when methods will be
164    * executed. The name of the variable in the context is defined by the key in the returned Map.
165    *
166    * @return the map of dependencies of this component
167    */
 
168  0 toggle public Map<String, ComponentDescriptor> getDependencies()
169    {
170  0 return this.dependencies;
171    }
172   
173    /**
174    * @return The syntax in which the component document is written
175    */
 
176  0 toggle public Syntax getSyntax()
177    {
178  0 return syntax;
179    }
180   
181    /**
182    * Sets the handled method.
183    *
184    * @see {@link #getHandledMethods()}
185    *
186    * @param methods the methods this component will handle
187    */
 
188  1 toggle public void setHandledMethods(Map<String, XDOM> methods)
189    {
190  1 this.handledMethods = methods;
191    }
192   
193    /**
194    * Sets the implemented interfaces.
195    *
196    * @see {@link #getImplementedInterfaces()}
197    *
198    * @param interfaces the interfaces this component implements
199    */
 
200  1 toggle public void setImplementedInterfaces(List<Class< ? >> interfaces)
201    {
202  1 this.implementedInterfaces = interfaces;
203    }
204   
205    /**
206    * Sets the component dependencies.
207    *
208    * @param dependencies the dependencies of this component
209    */
 
210  1 toggle public void setDependencies(Map<String, ComponentDescriptor> dependencies)
211    {
212  1 this.dependencies = dependencies;
213    }
214   
215    /**
216    * Set the syntax in which the component document is written.
217    *
218    * @param syntax the syntax to set
219    */
 
220  1 toggle public void setSyntax(Syntax syntax)
221    {
222  1 this.syntax = syntax;
223    }
224    }