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

File ObjectPropertyReference.java

 

Coverage histogram

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

Code metrics

6
14
7
1
129
49
11
0.79
2
7
1.57

Classes

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

Contributing tests

This file is covered by 35 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: 5a10bbbc1c5d5c9beed7fffa6c3850a25e187029 $
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  2418 toggle public ObjectPropertyReference(EntityReference reference)
39    {
40  2418 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  21566 toggle public ObjectPropertyReference(String propertyName, ObjectReference objectReference)
64    {
65  21565 super(propertyName, EntityType.OBJECT_PROPERTY, objectReference);
66    }
67   
68    /**
69    * Deprecated constructor.
70    * @param wiki the wiki of the document where the parent object of this property is
71    * @param space the space of the document where the parent object of this property is
72    * @param page the document where the parent object of this property is
73    * @param objectName the name of the parent object of this property
74    * @param propertyName the name of the property to refer to
75    */
 
76  1 toggle @Deprecated
77    public ObjectPropertyReference(String wiki, String space, String page, String objectName, String propertyName)
78    {
79  1 this(propertyName, new ObjectReference(wiki, space, page, objectName));
80    }
81   
82    /**
83    * {@inheritDoc}
84    * <p>
85    * Overridden to check the type to be a property type.
86    * </p>
87    *
88    * @see org.xwiki.model.reference.EntityReference#setType(org.xwiki.model.EntityType)
89    */
 
90  23987 toggle @Override
91    protected void setType(EntityType type)
92    {
93  23985 if (type != EntityType.OBJECT_PROPERTY) {
94  1 throw new IllegalArgumentException("Invalid type [" + type + "] for an object property reference");
95    }
96   
97  23984 super.setType(EntityType.OBJECT_PROPERTY);
98    }
99   
100    /**
101    * {@inheritDoc}
102    * <p>
103    * Overridden to ensure that the parent of a property is always an object.
104    * </p>
105    *
106    * @see org.xwiki.model.reference.EntityReference#setParent(org.xwiki.model.reference.EntityReference)
107    */
 
108  23983 toggle @Override
109    protected void setParent(EntityReference parent)
110    {
111  23986 if (parent instanceof ObjectReference) {
112  23966 super.setParent(parent);
113  23967 return;
114    }
115   
116  19 if (parent == null || parent.getType() != EntityType.OBJECT) {
117  2 throw new IllegalArgumentException("Invalid parent reference [" + parent
118    + "] in an object property reference");
119    }
120   
121  17 super.setParent(new ObjectReference(parent));
122    }
123   
 
124  0 toggle @Override
125    public ObjectPropertyReference replaceParent(EntityReference oldParent, EntityReference newParent)
126    {
127  0 return new ObjectPropertyReference(this, oldParent, newParent);
128    }
129    }