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

File SpaceReference.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
20
11
1
194
75
19
0.95
1.82
11
1.73

Classes

Class Line # Actions
SpaceReference 38 20 0% 19 4
0.90243990.2%
 

Contributing tests

This file is covered by 907 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.model.reference;
21   
22    import java.beans.Transient;
23    import java.lang.reflect.Type;
24    import java.util.Arrays;
25    import java.util.List;
26   
27    import javax.inject.Provider;
28   
29    import org.xwiki.component.util.DefaultParameterizedType;
30    import org.xwiki.model.EntityType;
31   
32    /**
33    * Represents a reference to a space (space name). Note that nested spaces are supported.
34    *
35    * @version $Id: c7609e3f1ad8f771c8de718e06300f032a1f886e $
36    * @since 2.2M1
37    */
 
38    public class SpaceReference extends EntityReference
39    {
40    /**
41    * The {@link Type} for a {@code Provider<SpaceReference>}.
42    *
43    * @since 7.2M1
44    */
45    public static final Type TYPE_PROVIDER = new DefaultParameterizedType(null, Provider.class, SpaceReference.class);
46   
47    /**
48    * Special constructor that transforms a generic entity reference into a {@link SpaceReference}. It checks the
49    * validity of the passed reference (ie correct type).
50    *
51    * @param reference the entity reference to transforms
52    * @exception IllegalArgumentException if the passed reference is not a valid space reference
53    */
 
54  1107092 toggle public SpaceReference(EntityReference reference)
55    {
56  1107094 super(reference);
57    }
58   
59    /**
60    * Clone an SpaceReference, but replace one of the parent in the chain by a new one.
61    *
62    * @param reference the reference that is cloned
63    * @param oldReference the old parent that will be replaced
64    * @param newReference the new parent that will replace oldReference in the chain
65    * @since 3.3M2
66    */
 
67  0 toggle protected SpaceReference(EntityReference reference, EntityReference oldReference, EntityReference newReference)
68    {
69  0 super(reference, oldReference, newReference);
70    }
71   
72    /**
73    * Create a space reference based on a space name and a parent wiki reference.
74    *
75    * @param spaceName the name of the space
76    * @param parent the wiki reference
77    */
 
78  166369 toggle public SpaceReference(String spaceName, WikiReference parent)
79    {
80  166374 this(spaceName, (EntityReference) parent);
81    }
82   
83    /**
84    * Create a space reference based on a space name and a parent space reference.
85    *
86    * @param spaceName the name of the space
87    * @param parent the space reference
88    */
 
89  155 toggle public SpaceReference(String spaceName, SpaceReference parent)
90    {
91  155 this(spaceName, (EntityReference) parent);
92    }
93   
94    /**
95    * Create a space reference based on a space name and a parent entity reference. The entity reference may be either
96    * a wiki or a space reference.
97    *
98    * @param spaceName the name of the space
99    * @param parent the entity reference
100    */
 
101  6495771 toggle public SpaceReference(String spaceName, EntityReference parent)
102    {
103  6495779 super(spaceName, EntityType.SPACE, parent);
104    }
105   
106    /**
107    * Create a space reference based on a space name and a parent space reference.
108    *
109    * @param wikiName the name of the wiki
110    * @param spaceNames the spaces names
111    * @since 7.4M1
112    */
 
113  36 toggle public SpaceReference(String wikiName, String... spaceNames)
114    {
115  36 this(wikiName, Arrays.<String>asList(spaceNames));
116    }
117   
118    /**
119    * Create a space reference based on a space name and a parent space reference.
120    *
121    * @param wikiName the name of the wiki
122    * @param spaceNames the spaces names
123    * @since 7.4M1
124    */
 
125  2060 toggle public SpaceReference(String wikiName, List<String> spaceNames)
126    {
127  2060 this(spaceNames.get(spaceNames.size() - 1), spaceNames.size() > 1
128    ? new SpaceReference(wikiName, spaceNames.subList(0, spaceNames.size() - 1)) : new WikiReference(wikiName));
129    }
130   
131    /**
132    * {@inheritDoc}
133    * <p>
134    * Overridden in order to verify the validity of the passed parent.
135    * </p>
136    *
137    * @see org.xwiki.model.reference.EntityReference#setParent(EntityReference)
138    * @exception IllegalArgumentException if the passed parent is not a valid space reference parent (ie either a space
139    * reference or a wiki reference)
140    */
 
141  7602774 toggle @Override
142    protected void setParent(EntityReference parent)
143    {
144  7602803 if (parent instanceof SpaceReference || parent instanceof WikiReference) {
145  7393464 super.setParent(parent);
146  7393311 return;
147    }
148   
149  209351 if (parent == null || (parent.getType() != EntityType.SPACE && parent.getType() != EntityType.WIKI)) {
150  2 throw new IllegalArgumentException("Invalid parent reference [" + parent + "] in a space reference");
151    }
152   
153  209345 if (parent.getType() == EntityType.SPACE) {
154  62217 super.setParent(new SpaceReference(parent));
155    } else {
156  147129 super.setParent(new WikiReference(parent));
157    }
158    }
159   
160    /**
161    * {@inheritDoc}
162    * <p>
163    * Overridden in order to verify the validity of the passed type.
164    * </p>
165    *
166    * @see org.xwiki.model.reference.EntityReference#setType(org.xwiki.model.EntityType)
167    * @exception IllegalArgumentException if the passed type is not a space type
168    */
 
169  7602863 toggle @Override
170    protected void setType(EntityType type)
171    {
172  7602858 if (type != EntityType.SPACE) {
173  1 throw new IllegalArgumentException("Invalid type [" + type + "] for a space reference");
174    }
175   
176  7602874 super.setType(EntityType.SPACE);
177    }
178   
 
179  0 toggle @Override
180    public SpaceReference replaceParent(EntityReference oldParent, EntityReference newParent)
181    {
182  0 return new SpaceReference(this, oldParent, newParent);
183    }
184   
185    /**
186    * @return the reference of the wiki containing this space
187    * @since 7.1M2
188    */
 
189  5208212 toggle @Transient
190    public WikiReference getWikiReference()
191    {
192  5208210 return (WikiReference) extractReference(EntityType.WIKI);
193    }
194    }