1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.api

File Class.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
76% of files have more coverage

Code metrics

18
74
17
2
315
172
26
0.35
4.35
8.5
1.53

Classes

Class Line # Actions
Class 35 73 0% 25 58
0.4579439245.8%
PropertyComparator 308 1 0% 1 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 com.xpn.xwiki.api;
21   
22    import java.util.ArrayList;
23    import java.util.Arrays;
24    import java.util.Comparator;
25    import java.util.List;
26   
27    import org.xwiki.model.reference.DocumentReference;
28   
29    import com.xpn.xwiki.XWikiContext;
30    import com.xpn.xwiki.XWikiException;
31    import com.xpn.xwiki.objects.BaseObject;
32    import com.xpn.xwiki.objects.BaseProperty;
33    import com.xpn.xwiki.objects.classes.BaseClass;
34   
 
35    public class Class extends Collection
36    {
 
37  30520 toggle public Class(BaseClass obj, XWikiContext context)
38    {
39  30520 super(obj, context);
40    }
41   
 
42  876 toggle protected BaseClass getBaseClass()
43    {
44  876 return (BaseClass) getCollection();
45    }
46   
 
47  334 toggle @Override
48    public DocumentReference getReference()
49    {
50  334 return getBaseClass().getReference();
51    }
52   
53    /**
54    * Returns a String table of the property names.
55    *
56    * @see com.xpn.xwiki.api.Collection#getPropertyNames()
57    */
 
58  1251 toggle @Override
59    public java.lang.Object[] getPropertyNames()
60    {
61  1251 Element[] properties = getProperties();
62  1251 if (properties == null) {
63  0 return super.getPropertyNames();
64    }
65  1251 String[] props = new String[properties.length];
66  15715 for (int i = 0; i < properties.length; i++) {
67  14464 String propname = properties[i].getName();
68  14464 props[i] = propname;
69    }
70  1251 return props;
71    }
72   
73    /**
74    * Get the names of the class properties that are enabled.
75    *
76    * @return a list of enabled property names
77    * @see #getEnabledProperties()
78    * @see PropertyClass#isDisabled()
79    * @since 2.4M2
80    */
 
81  0 toggle public List<String> getEnabledPropertyNames()
82    {
83  0 List<com.xpn.xwiki.objects.classes.PropertyClass> properties = this.getBaseClass().getEnabledProperties();
84  0 List<String> result = new ArrayList<String>(properties.size());
85  0 for (com.xpn.xwiki.objects.classes.PropertyClass property : properties) {
86  0 if (property != null) {
87  0 result.add(property.getName());
88    }
89    }
90  0 return result;
91    }
92   
93    /**
94    * Get the names of the class properties that are disabled.
95    *
96    * @return a list of disabled property names
97    * @see #getDisabledProperties()
98    * @see PropertyClass#isDisabled()
99    * @since 2.4M2
100    */
 
101  0 toggle public List<String> getDisabledPropertyNames()
102    {
103  0 List<com.xpn.xwiki.objects.classes.PropertyClass> properties = this.getBaseClass().getDisabledProperties();
104  0 List<String> result = new ArrayList<String>(properties.size());
105  0 for (com.xpn.xwiki.objects.classes.PropertyClass property : properties) {
106  0 if (property != null) {
107  0 result.add(property.getName());
108    }
109    }
110  0 return result;
111    }
112   
113    /**
114    * Get the names of the class properties that are disabled, and exist in the given object. This list is a subset of
115    * all the disabled properties in a class, since the object could have been created and stored before some of the
116    * class properties were added.
117    *
118    * @param object the instance of this class where the disabled properties must exist
119    * @return a list of disabled property names
120    * @see #getDisabledObjectProperties(Object)
121    * @see PropertyClass#isDisabled()
122    * @since 2.4M2
123    */
 
124  0 toggle public List<String> getDisabledObjectPropertyNames(Object object)
125    {
126  0 List<com.xpn.xwiki.objects.classes.PropertyClass> properties =
127    this.getBaseClass().getDisabledObjectProperties(object.getBaseObject());
128  0 List<String> result = new ArrayList<String>(properties.size());
129  0 for (com.xpn.xwiki.objects.classes.PropertyClass property : properties) {
130  0 if (property != null) {
131  0 result.add(property.getName());
132    }
133    }
134  0 return result;
135    }
136   
137    /**
138    * Get the names of deprecated properties of the given object compared to the class. A deprecated property is a
139    * property which exists in the Object but doesn't exist anymore in the Class. This is used for synchronization of
140    * existing or imported Objects with respect to the modifications of their associated Class.
141    *
142    * @param object the instance of this class where to look for undefined properties
143    * @return a list of deprecated property names
144    * @see #getDeprecatedObjectProperties(Object)
145    * @since 2.4M2
146    */
 
147  0 toggle public List<String> getDeprecatedObjectPropertyNames(Object object)
148    {
149  0 List<BaseProperty> properties = this.getBaseClass().getDeprecatedObjectProperties(object.getBaseObject());
150  0 List<String> result = new ArrayList<String>(properties.size());
151  0 for (BaseProperty property : properties) {
152  0 if (property != null) {
153  0 result.add(property.getName());
154    }
155    }
156  0 return result;
157    }
158   
159    /**
160    * @return an array with the properties of the class
161    */
 
162  4189 toggle @Override
163    public Element[] getProperties()
164    {
165  4189 @SuppressWarnings("unchecked")
166    java.util.Collection<com.xpn.xwiki.objects.classes.PropertyClass> coll = getCollection().getFieldList();
167  4189 if (coll == null) {
168  0 return null;
169    }
170  4189 PropertyClass[] properties = new PropertyClass[coll.size()];
171  4189 int i = 0;
172  4189 for (com.xpn.xwiki.objects.classes.PropertyClass prop : coll) {
173  35623 properties[i++] = new PropertyClass(prop, getXWikiContext());
174    }
175  4189 Arrays.sort(properties, new PropertyComparator());
176  4189 return properties;
177    }
178   
179    /**
180    * Get the list of enabled (the default, normal state) property definitions that exist in this class.
181    *
182    * @return a list containing the enabled properties of the class
183    * @see PropertyClass#isDisabled()
184    * @see #getEnabledPropertyNames()
185    * @since 2.4M2
186    */
 
187  0 toggle public List<PropertyClass> getEnabledProperties()
188    {
189  0 List<com.xpn.xwiki.objects.classes.PropertyClass> enabledProperties =
190    getBaseClass().getEnabledProperties();
191   
192  0 List<PropertyClass> result = new ArrayList<PropertyClass>(enabledProperties.size());
193   
194  0 for (com.xpn.xwiki.objects.classes.PropertyClass property : enabledProperties) {
195  0 result.add(new PropertyClass(property, getXWikiContext()));
196    }
197   
198  0 return result;
199    }
200   
201    /**
202    * Get the list of disabled property definitions that exist in this class.
203    *
204    * @return a list containing the disabled properties of the class
205    * @see PropertyClass#isDisabled()
206    * @see #getDisabledPropertyNames()
207    * @since 2.4M2
208    */
 
209  0 toggle public List<PropertyClass> getDisabledProperties()
210    {
211  0 List<com.xpn.xwiki.objects.classes.PropertyClass> disabledProperties =
212    getBaseClass().getDisabledProperties();
213   
214  0 List<PropertyClass> result = new ArrayList<PropertyClass>(disabledProperties.size());
215   
216  0 for (com.xpn.xwiki.objects.classes.PropertyClass property : disabledProperties) {
217  0 result.add(new PropertyClass(property, getXWikiContext()));
218    }
219   
220  0 return result;
221    }
222   
223    /**
224    * Get the list of disabled properties that exist in a given object. This list is a subset of all the disabled
225    * properties in a class, since the object could have been created and stored before some of the class properties
226    * were added.
227    *
228    * @param object the instance of this class where the disabled properties must exist
229    * @return a list containing the disabled properties of the given object
230    * @see PropertyClass#isDisabled()
231    * @see #getDisabledObjectPropertyNames(Object)
232    * @since 2.4M2
233    */
 
234  0 toggle public List<PropertyClass> getDisabledObjectProperties(Object object)
235    {
236  0 List<com.xpn.xwiki.objects.classes.PropertyClass> disabledObjectProperties =
237    getBaseClass().getDisabledObjectProperties(object.getBaseObject());
238   
239  0 List<PropertyClass> result = new ArrayList<PropertyClass>(disabledObjectProperties.size());
240  0 for (com.xpn.xwiki.objects.classes.PropertyClass property : disabledObjectProperties) {
241  0 result.add(new PropertyClass(property, getXWikiContext()));
242    }
243   
244  0 return result;
245    }
246   
247    /**
248    * Retrieves deprecated properties of the given object compared to the class. A deprecated property is a property
249    * which exists in the Object but doesn't exist anymore in the Class. This is used for synchronization of existing
250    * or imported Objects with respect to the modifications of their associated Class.
251    *
252    * @param object the instance of this class where to look for undefined properties
253    * @return a list containing the properties of the object which don't exist in the class
254    * @see #getDeprecatedObjectPropertyNames(Object)
255    * @since 2.4M2
256    */
 
257  398 toggle public List<Property> getDeprecatedObjectProperties(Object object)
258    {
259  398 List<BaseProperty> deprecatedObjectProperties =
260    getBaseClass().getDeprecatedObjectProperties(object.getBaseObject());
261   
262  398 List<Property> result = new ArrayList<Property>(deprecatedObjectProperties.size());
263  398 for (BaseProperty property : deprecatedObjectProperties) {
264  14 result.add(new Property(property, getXWikiContext()));
265    }
266   
267  398 return result;
268    }
269   
270    /**
271    * @param name the name of the element
272    * @return the PropertyClass for the given name
273    * @see PropertyClass
274    * @see Element
275    */
 
276  23778 toggle public Element get(String name)
277    {
278  23778 com.xpn.xwiki.objects.classes.PropertyClass property =
279    (com.xpn.xwiki.objects.classes.PropertyClass) getCollection().safeget(name);
280  23778 if (property != null) {
281  21343 return new PropertyClass(property, getXWikiContext());
282    }
283  2435 return null;
284    }
285   
286    /**
287    * @return the BaseClass (without the wrapping) if you have the programming right.
288    */
 
289  138 toggle public BaseClass getXWikiClass()
290    {
291  138 if (hasProgrammingRights()) {
292  135 return (BaseClass) getCollection();
293    } else {
294  3 return null;
295    }
296    }
297   
298    /**
299    * @return a new object from this class
300    */
 
301  144 toggle public Object newObject() throws XWikiException
302    {
303  144 BaseObject obj = (BaseObject) getBaseClass().newObject(getXWikiContext());
304  144 return obj.newObjectApi(obj, getXWikiContext());
305    }
306    }
307   
 
308    class PropertyComparator implements Comparator<PropertyClass>
309    {
 
310  96110 toggle @Override
311    public int compare(PropertyClass o1, PropertyClass o2)
312    {
313  96110 return o1.getNumber() - o2.getNumber();
314    }
315    }