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

File ObjectReference.java

 

Coverage histogram

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

Code metrics

10
21
10
1
160
66
16
0.76
2.1
10
1.6

Classes

Class Line # Actions
ObjectReference 30 21 0% 16 8
0.8048780680.5%
 

Contributing tests

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