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

File DefaultComponentDescriptor.java

 

Coverage histogram

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

Code metrics

6
33
12
1
193
97
16
0.48
2.75
12
1.33

Classes

Class Line # Actions
DefaultComponentDescriptor 38 33 0% 16 21
0.588235358.8%
 

Contributing tests

This file is covered by 3648 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.component.descriptor;
21   
22    import java.util.ArrayList;
23    import java.util.Collection;
24    import java.util.List;
25    import java.util.Objects;
26   
27    import org.apache.commons.lang3.builder.HashCodeBuilder;
28    import org.apache.commons.lang3.builder.ToStringBuilder;
29    import org.xwiki.text.XWikiToStringBuilder;
30   
31    /**
32    * Default implementation of {@link ComponentDescriptor}.
33    *
34    * @version $Id: 9de9ed0419b7c02e1d914072160941d3f5aec849 $
35    * @param <T> the type of the component role
36    * @since 1.7M1
37    */
 
38    public class DefaultComponentDescriptor<T> extends DefaultComponentRole<T> implements ComponentDescriptor<T>
39    {
40    /**
41    * @see #getImplementation()
42    */
43    private Class<? extends T> implementation;
44   
45    /**
46    * @see #getInstantiationStrategy()
47    */
48    private ComponentInstantiationStrategy instantiationStrategy = ComponentInstantiationStrategy.SINGLETON;
49   
50    /**
51    * @see #getComponentDependencies()
52    */
53    private List<ComponentDependency<?>> componentDependencies = new ArrayList<ComponentDependency<?>>();
54   
55    /**
56    * Default constructor.
57    */
 
58  774955 toggle public DefaultComponentDescriptor()
59    {
60    }
61   
62    /**
63    * Creating a new {@link DefaultComponentDescriptor} by cloning the provided {@link ComponentDescriptor}.
64    *
65    * @param descriptor the component descriptor to clone
66    * @since 3.4M1
67    */
 
68  770532 toggle public DefaultComponentDescriptor(ComponentDescriptor<T> descriptor)
69    {
70  770532 super(descriptor);
71   
72  770532 setImplementation(descriptor.getImplementation());
73  770532 setInstantiationStrategy(descriptor.getInstantiationStrategy());
74  770532 for (ComponentDependency<?> dependency : descriptor.getComponentDependencies()) {
75  1475660 addComponentDependency(new DefaultComponentDependency(dependency));
76    }
77    }
78   
79    /**
80    * @param implementation the class of the component implementation
81    */
 
82  1527334 toggle public void setImplementation(Class<? extends T> implementation)
83    {
84  1527334 this.implementation = implementation;
85    }
86   
 
87  1796376 toggle @Override
88    public Class<? extends T> getImplementation()
89    {
90  1796382 return this.implementation;
91    }
92   
93    /**
94    * @param instantiationStrategy the way the component should be instantiated
95    * @see ComponentInstantiationStrategy
96    */
 
97  1512836 toggle public void setInstantiationStrategy(ComponentInstantiationStrategy instantiationStrategy)
98    {
99  1512836 this.instantiationStrategy = instantiationStrategy;
100    }
101   
 
102  8080571 toggle @Override
103    public ComponentInstantiationStrategy getInstantiationStrategy()
104    {
105  8080418 return this.instantiationStrategy;
106    }
107   
 
108  55008021 toggle @Override
109    public Collection<ComponentDependency<?>> getComponentDependencies()
110    {
111  55008024 return this.componentDependencies;
112    }
113   
114    /**
115    * @param componentDependency the dependency to add
116    */
 
117  2951582 toggle public void addComponentDependency(ComponentDependency<?> componentDependency)
118    {
119  2951582 this.componentDependencies.add(componentDependency);
120    }
121   
122    /**
123    * @param role the class of the component role
124    * @param roleHint the hint of the component role
125    * @param <D> the type of the dependency role
126    */
 
127  0 toggle public <D> void addComponentDependency(Class<D> role, String roleHint)
128    {
129  0 DefaultComponentDependency<D> componentDependency = new DefaultComponentDependency<D>();
130  0 componentDependency.setRole(role);
131  0 componentDependency.setRoleHint(roleHint);
132   
133  0 this.componentDependencies.add(componentDependency);
134    }
135   
 
136  0 toggle @Override
137    public String toString()
138    {
139  0 ToStringBuilder builder = new XWikiToStringBuilder(this);
140  0 builder.append("implementation", getImplementation() == null ? null : getImplementation().getName());
141  0 builder.append("instantiation", getInstantiationStrategy());
142  0 return builder.toString();
143    }
144   
145    /**
146    * {@inheritDoc}
147    *
148    * @since 3.3M1
149    */
 
150  144 toggle @Override
151    public boolean equals(Object object)
152    {
153  144 boolean result;
154   
155    // See http://www.technofundo.com/tech/java/equalhash.html for the detail of this algorithm.
156  144 if (this == object) {
157  1 result = true;
158    } else {
159  143 if ((object == null) || (object.getClass() != this.getClass())) {
160  0 result = false;
161    } else {
162    // object must be Syntax at this point
163  143 ComponentDescriptor cd = (ComponentDescriptor) object;
164   
165  143 result =
166    super.equals(cd) && Objects.equals(getImplementation(), cd.getImplementation())
167    && Objects.equals(getInstantiationStrategy(), cd.getInstantiationStrategy())
168    && Objects.equals(getComponentDependencies(), cd.getComponentDependencies());
169    }
170    }
171   
172  144 return result;
173    }
174   
175    /**
176    * {@inheritDoc}
177    *
178    * @since 3.3M1
179    */
 
180  0 toggle @Override
181    public int hashCode()
182    {
183  0 HashCodeBuilder builder = new HashCodeBuilder();
184   
185  0 builder.appendSuper(super.hashCode());
186   
187  0 builder.append(getImplementation());
188  0 builder.append(getInstantiationStrategy());
189  0 builder.append(getComponentDependencies());
190   
191  0 return builder.toHashCode();
192    }
193    }