Clover Coverage Report - XWiki Commons - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 17:13:48 CET
../../../../img/srcFileCovDistChart6.png 52% of files have more coverage
33   191   16   2.75
6   95   0.48   12
12     1.33  
1    
 
  DefaultComponentDescriptor       Line # 35 33 0% 16 21 58.8% 0.5882353
 
No Tests
 
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   
26    import org.xwiki.component.util.ObjectUtils;
27   
28    /**
29    * Default implementation of {@link ComponentDescriptor}.
30    *
31    * @version $Id: 303b1f5c6f91720bbf899b34a070bdbc1c682f60 $
32    * @param <T> the type of the component role
33    * @since 1.7M1
34    */
 
35    public class DefaultComponentDescriptor<T> extends DefaultComponentRole<T> implements ComponentDescriptor<T>
36    {
37    /**
38    * @see #getImplementation()
39    */
40    private Class< ? extends T> implementation;
41   
42    /**
43    * @see #getInstantiationStrategy()
44    */
45    private ComponentInstantiationStrategy instantiationStrategy = ComponentInstantiationStrategy.SINGLETON;
46   
47    /**
48    * @see #getComponentDependencies()
49    */
50    private List<ComponentDependency< ? >> componentDependencies = new ArrayList<ComponentDependency< ? >>();
51   
52    /**
53    * Default constructor.
54    */
 
55  3990 toggle public DefaultComponentDescriptor()
56    {
57    }
58   
59    /**
60    * Creating a new {@link DefaultComponentDescriptor} by cloning the provided {@link ComponentDescriptor}.
61    *
62    * @param descriptor the component descriptor to clone
63    * @since 3.4M1
64    */
 
65  3913 toggle public DefaultComponentDescriptor(ComponentDescriptor<T> descriptor)
66    {
67  3913 super(descriptor);
68   
69  3913 setImplementation(descriptor.getImplementation());
70  3913 setInstantiationStrategy(descriptor.getInstantiationStrategy());
71  3913 for (ComponentDependency< ? > dependency : descriptor.getComponentDependencies()) {
72  6103 addComponentDependency(new DefaultComponentDependency(dependency));
73    }
74    }
75   
76    /**
77    * @param implementation the class of the component implementation
78    */
 
79  7636 toggle public void setImplementation(Class< ? extends T> implementation)
80    {
81  7636 this.implementation = implementation;
82    }
83   
 
84  9502 toggle @Override
85    public Class< ? extends T> getImplementation()
86    {
87  9502 return implementation;
88    }
89   
90    /**
91    * @param instantiationStrategy the way the component should be instantiated
92    * @see ComponentInstantiationStrategy
93    */
 
94  7610 toggle public void setInstantiationStrategy(ComponentInstantiationStrategy instantiationStrategy)
95    {
96  7610 this.instantiationStrategy = instantiationStrategy;
97    }
98   
 
99  8173 toggle @Override
100    public ComponentInstantiationStrategy getInstantiationStrategy()
101    {
102  8173 return this.instantiationStrategy;
103    }
104   
 
105  5808 toggle @Override
106    public Collection<ComponentDependency< ? >> getComponentDependencies()
107    {
108  5808 return this.componentDependencies;
109    }
110   
111    /**
112    * @param componentDependency the dependency to add
113    */
 
114  12270 toggle public void addComponentDependency(ComponentDependency< ? > componentDependency)
115    {
116  12270 this.componentDependencies.add(componentDependency);
117    }
118   
119    /**
120    * @param role the class of the component role
121    * @param roleHint the hint of the component role
122    * @param <TT> the type of the dependency role
123    */
 
124  0 toggle public <TT> void addComponentDependency(Class<TT> role, String roleHint)
125    {
126  0 DefaultComponentDependency<TT> componentDependency = new DefaultComponentDependency<TT>();
127  0 componentDependency.setRole(role);
128  0 componentDependency.setRoleHint(roleHint);
129   
130  0 this.componentDependencies.add(componentDependency);
131    }
132   
 
133  0 toggle @Override
134    public String toString()
135    {
136  0 StringBuilder buffer = new StringBuilder(super.toString());
137  0 buffer.append(" implementation = [").append(getImplementation() == null ? null : getImplementation().getName())
138    .append("]");
139  0 buffer.append(" instantiation = [").append(getInstantiationStrategy()).append("]");
140   
141  0 return buffer.toString();
142    }
143   
144    /**
145    * {@inheritDoc}
146    *
147    * @since 3.3M1
148    */
 
149  83 toggle @Override
150    public boolean equals(Object object)
151    {
152  83 boolean result;
153   
154    // See http://www.technofundo.com/tech/java/equalhash.html for the detail of this algorithm.
155  83 if (this == object) {
156  1 result = true;
157    } else {
158  82 if ((object == null) || (object.getClass() != this.getClass())) {
159  0 result = false;
160    } else {
161    // object must be Syntax at this point
162  82 ComponentDescriptor cd = (ComponentDescriptor) object;
163   
164  82 result =
165    super.equals(cd) && ObjectUtils.equals(getImplementation(), cd.getImplementation())
166    && ObjectUtils.equals(getInstantiationStrategy(), cd.getInstantiationStrategy())
167    && ObjectUtils.equals(getComponentDependencies(), cd.getComponentDependencies());
168    }
169    }
170   
171  83 return result;
172    }
173   
174    /**
175    * {@inheritDoc}
176    *
177    * @since 3.3M1
178    */
 
179  0 toggle @Override
180    public int hashCode()
181    {
182  0 int hash = 7;
183   
184  0 hash = 31 * hash + super.hashCode();
185  0 hash = 31 * hash + ObjectUtils.hasCode(getImplementation());
186  0 hash = 31 * hash + ObjectUtils.hasCode(getInstantiationStrategy());
187  0 hash = 31 * hash + ObjectUtils.hasCode(getComponentDependencies());
188   
189  0 return hash;
190    }
191    }