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

File AbstractEntityReferenceResolver.java

 

Coverage histogram

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

Code metrics

10
14
1
1
82
29
8
0.57
14
1
8

Classes

Class Line # Actions
AbstractEntityReferenceResolver 34 14 0% 8 0
1.0100%
 

Contributing tests

This file is covered by 444 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   
21    package org.xwiki.model.internal.reference;
22   
23    import org.xwiki.model.EntityType;
24    import org.xwiki.model.reference.EntityReference;
25   
26    /**
27    * Generic entity reference resolver deferring resolution and default values to extending classes but resolving default
28    * value from the first optional parameter when provided and is an instance of a entity reference. This is use by most
29    * resolver to provide relative resolution to a provided reference.
30    *
31    * @version $Id: 713684afc59c8db65b94bd6f5eaafb3e2f5a00cc $
32    * @since 3.3M2
33    */
 
34    public abstract class AbstractEntityReferenceResolver
35    {
36    /**
37    * @param type the entity type for which to return the default value to use (since the use has not specified it)
38    * @param parameters optional parameters. Their meaning depends on the resolver implementation
39    * @return the default value to use
40    * @since 7.2M1
41    */
42    protected abstract EntityReference getDefaultReference(EntityType type, Object... parameters);
43   
44    /**
45    * Resolve default reference for a given reference type.
46    *
47    * @param type the type for which a default name is requested
48    * @param parameters optional parameters, if the first parameter is an entity reference which is of the given type
49    * or contains the given types in its parent chain, use the name of the reference having the requested
50    * type in place of the default value
51    * @return the reference for the given type
52    * @since 7.2M1
53    */
 
54  1423625 toggle protected EntityReference resolveDefaultReference(EntityType type, Object... parameters)
55    {
56  1423620 EntityReference resolvedDefaultValue = null;
57   
58  1423609 if (parameters.length > 0 && parameters[0] instanceof EntityReference) {
59    // Try to extract the type from the passed parameter.
60  448703 EntityReference referenceParameter = (EntityReference) parameters[0];
61  448695 EntityReference extractedReference = referenceParameter.extractReference(type);
62  448671 if (extractedReference != null) {
63  393932 resolvedDefaultValue = extractedReference;
64   
65    // Get rid of parent if any
66  393935 EntityReference parent = extractedReference.getParent();
67  394683 while (parent != null && parent.getType() == type) {
68  754 parent = parent.getParent();
69    }
70  393926 if (parent != null) {
71  15272 resolvedDefaultValue = resolvedDefaultValue.removeParent(parent);
72    }
73    }
74    }
75   
76  1423578 if (resolvedDefaultValue == null) {
77  1029654 resolvedDefaultValue = getDefaultReference(type, parameters);
78    }
79   
80  1423607 return resolvedDefaultValue;
81    }
82    }