1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.model.reference

File PageObjectReference.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
56% of files have more coverage

Code metrics

10
20
9
1
150
65
15
0.75
2.22
9
1.67

Classes

Class Line # Actions
PageObjectReference 34 20 0% 15 10
0.7435897674.4%
 

Contributing tests

This file is covered by 8 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   
24    import org.xwiki.model.EntityType;
25    import org.xwiki.stability.Unstable;
26   
27    /**
28    * Reference to an object in a page (by classname and index, page, wiki).
29    *
30    * @since 10.6RC1
31    * @version $Id: 72e7bb2a611c206489210925172d87aedd0317a4 $
32    */
33    @Unstable
 
34    public class PageObjectReference extends EntityReference
35    {
36    /**
37    * Constructor which would raise exceptions if the source entity reference does not have the appropriate type or
38    * parent, etc.
39    *
40    * @param reference the raw reference to build this object reference from
41    */
 
42  6 toggle public PageObjectReference(EntityReference reference)
43    {
44  6 super(reference);
45    }
46   
47    /**
48    * Clone an ObjectReference, but replace one of the parent in the chain by a new one.
49    *
50    * @param reference the reference that is cloned
51    * @param oldReference the old parent that will be replaced
52    * @param newReference the new parent that will replace oldReference in the chain
53    */
 
54  0 toggle protected PageObjectReference(EntityReference reference, EntityReference oldReference, EntityReference newReference)
55    {
56  0 super(reference, oldReference, newReference);
57    }
58   
59    /**
60    * @param objectName the name of the object
61    * @param pageReference the reference of the parent page of the object
62    */
 
63  8 toggle public PageObjectReference(String objectName, PageReference pageReference)
64    {
65  8 super(objectName, EntityType.PAGE_OBJECT, pageReference);
66    }
67   
68    /**
69    * Clone an PageObjectReference, but use the specified parent for its new parent.
70    *
71    * @param reference the reference to clone
72    * @param parent the new parent to use
73    * @since 10.8RC1
74    */
 
75  1 toggle public PageObjectReference(EntityReference reference, EntityReference parent)
76    {
77  1 super(reference, parent);
78    }
79   
80    /**
81    * {@inheritDoc}
82    * <p>
83    * Overridden to check the type to be an object type.
84    * </p>
85    *
86    * @see org.xwiki.model.reference.EntityReference#setType(org.xwiki.model.EntityType)
87    */
 
88  18 toggle @Override
89    protected void setType(EntityType type)
90    {
91  18 if (type != EntityType.PAGE_OBJECT) {
92  1 throw new IllegalArgumentException("Invalid type [" + type + "] for an object reference");
93    }
94   
95  17 super.setType(type);
96    }
97   
98    /**
99    * {@inheritDoc}
100    * <p>
101    * Overridden to ensure that the parent of an object is always a page.
102    * </p>
103    *
104    * @see org.xwiki.model.reference.EntityReference#setParent(org.xwiki.model.reference.EntityReference)
105    */
 
106  17 toggle @Override
107    protected void setParent(EntityReference parent)
108    {
109  17 if (parent instanceof PageReference) {
110  13 super.setParent(parent);
111   
112  13 return;
113    }
114   
115  4 if (parent == null || parent.getType() != EntityType.PAGE) {
116  2 throw new IllegalArgumentException("Invalid parent reference [" + parent + "] in an object reference");
117    }
118   
119  2 super.setParent(new PageReference(parent));
120    }
121   
 
122  0 toggle @Override
123    public PageObjectReference replaceParent(EntityReference oldParent, EntityReference newParent)
124    {
125  0 if (newParent == oldParent) {
126  0 return this;
127    }
128   
129  0 return new PageObjectReference(this, oldParent, newParent);
130    }
131   
 
132  2 toggle @Override
133    public PageObjectReference replaceParent(EntityReference newParent)
134    {
135  2 if (newParent == getParent()) {
136  1 return this;
137    }
138   
139  1 return new PageObjectReference(this, newParent);
140    }
141   
142    /**
143    * @return the reference of the page holding this object
144    */
 
145  0 toggle @Transient
146    public PageReference getPageReference()
147    {
148  0 return (PageReference) getParent();
149    }
150    }