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

File ObjectPropertyReference.java

 

Coverage histogram

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

Code metrics

10
20
9
1
155
64
15
0.75
2.22
9
1.67

Classes

Class Line # Actions
ObjectPropertyReference 30 20 0% 15 8
0.794871879.5%
 

Contributing tests

This file is covered by 37 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    * References a property in an object in a document (the value of the property).
26    *
27    * @since 2.3M1
28    * @version $Id: aa6f3451c78ca1b7e5ded32274d98d0ebe9401fb $
29    */
 
30    public class ObjectPropertyReference 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  33591 toggle public ObjectPropertyReference(EntityReference reference)
39    {
40  33591 super(reference);
41    }
42   
43    /**
44    * Clone an ObjectPropertyReference, 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 ObjectPropertyReference(EntityReference reference, EntityReference oldReference,
52    EntityReference newReference)
53    {
54  0 super(reference, oldReference, newReference);
55    }
56   
57    /**
58    * Builds a property reference for the passed property in the passed object.
59    *
60    * @param propertyName the name of the property to create reference for
61    * @param objectReference the reference to the object whose property is
62    */
 
63  651680 toggle public ObjectPropertyReference(String propertyName, ObjectReference objectReference)
64    {
65  651680 super(propertyName, EntityType.OBJECT_PROPERTY, objectReference);
66    }
67   
68    /**
69    * Clone an ObjectPropertyReference, 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 ObjectPropertyReference(EntityReference reference, EntityReference parent)
76    {
77  1 super(reference, parent);
78    }
79   
80    /**
81    * Deprecated constructor.
82    * @param wiki the wiki of the document where the parent object of this property is
83    * @param space the space of the document where the parent object of this property is
84    * @param page the document where the parent object of this property is
85    * @param objectName the name of the parent object of this property
86    * @param propertyName the name of the property to refer to
87    */
 
88  1 toggle @Deprecated
89    public ObjectPropertyReference(String wiki, String space, String page, String objectName, String propertyName)
90    {
91  1 this(propertyName, new ObjectReference(wiki, space, page, objectName));
92    }
93   
94    /**
95    * {@inheritDoc}
96    * <p>
97    * Overridden to check the type to be a property type.
98    * </p>
99    *
100    * @see org.xwiki.model.reference.EntityReference#setType(org.xwiki.model.EntityType)
101    */
 
102  685270 toggle @Override
103    protected void setType(EntityType type)
104    {
105  685274 if (type != EntityType.OBJECT_PROPERTY) {
106  1 throw new IllegalArgumentException("Invalid type [" + type + "] for an object property reference");
107    }
108   
109  685273 super.setType(EntityType.OBJECT_PROPERTY);
110    }
111   
112    /**
113    * {@inheritDoc}
114    * <p>
115    * Overridden to ensure that the parent of a property is always an object.
116    * </p>
117    *
118    * @see org.xwiki.model.reference.EntityReference#setParent(org.xwiki.model.reference.EntityReference)
119    */
 
120  685274 toggle @Override
121    protected void setParent(EntityReference parent)
122    {
123  685269 if (parent instanceof ObjectReference) {
124  685247 super.setParent(parent);
125  685254 return;
126    }
127   
128  19 if (parent == null || parent.getType() != EntityType.OBJECT) {
129  2 throw new IllegalArgumentException("Invalid parent reference [" + parent
130    + "] in an object property reference");
131    }
132   
133  17 super.setParent(new ObjectReference(parent));
134    }
135   
 
136  0 toggle @Override
137    public ObjectPropertyReference replaceParent(EntityReference oldParent, EntityReference newParent)
138    {
139  0 if (newParent == oldParent) {
140  0 return this;
141    }
142   
143  0 return new ObjectPropertyReference(this, oldParent, newParent);
144    }
145   
 
146  2 toggle @Override
147    public ObjectPropertyReference replaceParent(EntityReference newParent)
148    {
149  2 if (newParent == getParent()) {
150  1 return this;
151    }
152   
153  1 return new ObjectPropertyReference(this, newParent);
154    }
155    }