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

File ObjectReference.java

 

Coverage histogram

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

Code metrics

6
14
7
1
124
47
11
0.79
2
7
1.57

Classes

Class Line # Actions
ObjectReference 30 14 0% 11 4
0.851851985.2%
 

Contributing tests

This file is covered by 82 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: 27ca7730a23ebeb3b3bd3ae6502307269de616f4 $
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  16556 toggle public ObjectReference(EntityReference reference)
39    {
40  16557 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  21162 toggle public ObjectReference(String objectName, DocumentReference documentReference)
61    {
62  21162 super(objectName, EntityType.OBJECT, documentReference);
63    }
64   
65    /**
66    * Deprecated constructor.
67    * @param wiki wiki where the parent document of the object is
68    * @param space space where the parent document of the object is
69    * @param document parent document of the object
70    * @param objectName the name of the object
71    */
 
72  1 toggle @Deprecated
73    public ObjectReference(String wiki, String space, String document, String objectName)
74    {
75  1 this(objectName, new DocumentReference(wiki, space, document));
76    }
77   
78    /**
79    * {@inheritDoc}
80    * <p>
81    * Overridden to check the type to be an object type.
82    * </p>
83    *
84    * @see org.xwiki.model.reference.EntityReference#setType(org.xwiki.model.EntityType)
85    */
 
86  37721 toggle @Override
87    protected void setType(EntityType type)
88    {
89  37722 if (type != EntityType.OBJECT) {
90  1 throw new IllegalArgumentException("Invalid type [" + type + "] for an object reference");
91    }
92   
93  37720 super.setType(EntityType.OBJECT);
94    }
95   
96    /**
97    * {@inheritDoc}
98    * <p>
99    * Overridden to ensure that the parent of an object is always a document.
100    * </p>
101    *
102    * @see org.xwiki.model.reference.EntityReference#setParent(org.xwiki.model.reference.EntityReference)
103    */
 
104  37720 toggle @Override
105    protected void setParent(EntityReference parent)
106    {
107  37722 if (parent instanceof DocumentReference) {
108  37692 super.setParent(parent);
109  37691 return;
110    }
111   
112  29 if (parent == null || parent.getType() != EntityType.DOCUMENT) {
113  2 throw new IllegalArgumentException("Invalid parent reference [" + parent + "] in an object reference");
114    }
115   
116  27 super.setParent(new DocumentReference(parent));
117    }
118   
 
119  0 toggle @Override
120    public ObjectReference replaceParent(EntityReference oldParent, EntityReference newParent)
121    {
122  0 return new ObjectReference(this, oldParent, newParent);
123    }
124    }