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

File ClassPropertyReference.java

 

Coverage histogram

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

Code metrics

10
20
9
1
154
64
15
0.75
2.22
9
1.67

Classes

Class Line # Actions
ClassPropertyReference 30 20 0% 15 10
0.7435897674.4%
 

Contributing tests

This file is covered by 38 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 a class in a document (the description of the property).
26    *
27    * @version $Id: a23cb70c57f8780ad61d5de03d36f15f1fee2880 $
28    * @since 3.2M1
29    */
 
30    public class ClassPropertyReference 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  16 toggle public ClassPropertyReference(EntityReference reference)
39    {
40  16 super(reference);
41    }
42   
43    /**
44    * Clone an ClassPropertyReference, 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 ClassPropertyReference(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 classReference the reference to the class whose property is
62    */
 
63  10410 toggle public ClassPropertyReference(String propertyName, DocumentReference classReference)
64    {
65  10410 super(propertyName, EntityType.CLASS_PROPERTY, classReference);
66    }
67   
68    /**
69    * Clone an ClassPropertyReference, 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 ClassPropertyReference(EntityReference reference, EntityReference parent)
76    {
77  1 super(reference, parent);
78    }
79   
80    /**
81    * Deprecated constructor.
82    *
83    * @param wiki the wiki of the document where the parent class of this property is
84    * @param space the space of the document where the parent class of this property is
85    * @param page the document where the parent class of this property is
86    * @param propertyName the name of the property to refer to
87    */
 
88  0 toggle @Deprecated
89    public ClassPropertyReference(String wiki, String space, String page, String propertyName)
90    {
91  0 this(propertyName, new DocumentReference(wiki, space, page));
92    }
93   
94    /**
95    * {@inheritDoc}
96    * <p>
97    * Overridden to check the type to be a property type.
98    *
99    * @see org.xwiki.model.reference.EntityReference#setType(org.xwiki.model.EntityType)
100    */
 
101  10430 toggle @Override
102    protected void setType(EntityType type)
103    {
104  10430 if (type != EntityType.CLASS_PROPERTY) {
105  1 throw new IllegalArgumentException("Invalid type [" + type + "] for a class property reference");
106    }
107   
108  10429 super.setType(EntityType.CLASS_PROPERTY);
109    }
110   
111    /**
112    * {@inheritDoc}
113    * <p>
114    * Overridden to ensure that the parent of a property is always an object.
115    * </p>
116    *
117    * @see org.xwiki.model.reference.EntityReference#setParent(org.xwiki.model.reference.EntityReference)
118    */
 
119  10428 toggle @Override
120    protected void setParent(EntityReference parent)
121    {
122  10429 if (parent instanceof DocumentReference) {
123  10412 super.setParent(parent);
124  10412 return;
125    }
126   
127  17 if (parent == null || parent.getType() != EntityType.DOCUMENT) {
128  2 throw new IllegalArgumentException(
129    "Invalid parent reference [" + parent + "] in a class property reference");
130    }
131   
132  15 super.setParent(new DocumentReference(parent));
133    }
134   
 
135  0 toggle @Override
136    public ClassPropertyReference replaceParent(EntityReference oldParent, EntityReference newParent)
137    {
138  0 if (newParent == oldParent) {
139  0 return this;
140    }
141   
142  0 return new ClassPropertyReference(this, oldParent, newParent);
143    }
144   
 
145  2 toggle @Override
146    public ClassPropertyReference replaceParent(EntityReference newParent)
147    {
148  2 if (newParent == getParent()) {
149  1 return this;
150    }
151   
152  1 return new ClassPropertyReference(this, newParent);
153    }
154    }