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

File ClassPropertyReference.java

 

Coverage histogram

../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

6
14
7
1
127
49
11
0.79
2
7
1.57

Classes

Class Line # Actions
ClassPropertyReference 30 14 0% 11 10
0.629629663%
 

Contributing tests

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