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

File EntityType.java

 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
13
5
1
189
63
7
0.54
2.6
5
1.4

Classes

Class Line # Actions
EntityType 35 13 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 519 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;
21   
22    import java.util.ArrayList;
23    import java.util.Collections;
24    import java.util.List;
25    import java.util.Locale;
26   
27    import org.xwiki.stability.Unstable;
28   
29    /**
30    * Represents a type of entity (ie a Model Object such as a Wiki, a Space, a Document, an Attachment, etc).
31    *
32    * @version $Id: 1b03b9fcdae6e679021182c35fd9d188becf2902 $
33    * @since 2.2M1
34    */
 
35    public enum EntityType
36    {
37    /**
38    * Represents a Wiki Entity.
39    */
40    WIKI,
41   
42    // Documents
43   
44    /**
45    * Represents a Space Entity.
46    */
47    SPACE(WIKI, null),
48   
49    /**
50    * Represents a Document Entity.
51    */
52    DOCUMENT(SPACE),
53   
54    /**
55    * Represents an Attachment Entity.
56    */
57    ATTACHMENT(DOCUMENT),
58   
59    /**
60    * Represents an Object Entity.
61    */
62    OBJECT(DOCUMENT),
63   
64    /**
65    * Represents an Object Property Entity.
66    */
67    OBJECT_PROPERTY(OBJECT),
68   
69    /**
70    * Represents a class property entity.
71    *
72    * @since 3.2M1
73    */
74    CLASS_PROPERTY(DOCUMENT),
75   
76    /**
77    * Represents a structured part of the content of a document or an object property.
78    *
79    * @since 6.0M1
80    */
81    BLOCK(DOCUMENT, OBJECT_PROPERTY),
82   
83    // Pages
84   
85    /**
86    * Represents a Page Entity.
87    *
88    * @since 10.6RC1
89    */
90    @Unstable
91    PAGE(WIKI, null),
92   
93    /**
94    * Represents an Attachment Entity in a page.
95    *
96    * @since 10.6RC1
97    */
98    @Unstable
99    PAGE_ATTACHMENT(PAGE),
100   
101    /**
102    * Represents an Object Entity in a page.
103    *
104    * @since 10.6RC1
105    */
106    @Unstable
107    PAGE_OBJECT(PAGE),
108   
109    /**
110    * Represents an Object Property Entity in a page.
111    *
112    * @since 10.6RC1
113    */
114    @Unstable
115    PAGE_OBJECT_PROPERTY(PAGE_OBJECT),
116   
117    /**
118    * Represents a class property entity in a page.
119    *
120    * @since 10.6RC1
121    */
122    @Unstable
123    PAGE_CLASS_PROPERTY(PAGE);
124   
125    // TODO: should probably introduce a PAGE_BLOCK when we decide how we want it (we might want to move a two types or
126    // decide to have BLOCK being parent of BLOCK, etc.)
127   
128    /**
129    * The lower case String version of the enum.
130    */
131    private final String lowerCase;
132   
133    private final List<EntityType> allowedParents;
134   
135    private final boolean[] allowedAncestors = new boolean[13];
136   
 
137  2457 toggle EntityType(EntityType... allowedParents)
138    {
139  2457 this.lowerCase = name().toLowerCase(Locale.US);
140   
141  2457 List<EntityType> list = new ArrayList<>(allowedParents.length);
142  2457 for (EntityType parent : allowedParents) {
143  2835 list.add(parent != null ? parent : this);
144    }
145  2457 this.allowedParents = Collections.unmodifiableList(list);
146  2457 setParentTypes(this.allowedParents);
147    }
148   
 
149  8694 toggle private void setParentTypes(List<EntityType> parents)
150    {
151  8694 for (EntityType parent : parents) {
152  9072 if (!this.allowedAncestors[parent.ordinal()]) {
153  6237 this.allowedAncestors[parent.ordinal()] = true;
154   
155  6237 setParentTypes(parent.getAllowedParents());
156    }
157    }
158    }
159   
160    /**
161    * @return the lower case String version of the enum
162    * @since 6.2.1
163    */
 
164  935503 toggle public String getLowerCase()
165    {
166  935624 return this.lowerCase;
167    }
168   
169    /**
170    * @return the list of allowed parent for this entity type
171    * @since 10.6RC1
172    */
 
173  26508624 toggle @Unstable
174    public List<EntityType> getAllowedParents()
175    {
176  26510665 return this.allowedParents;
177    }
178   
179    /**
180    * @param type the type
181    * @return true of the passed type is a possible ancestor of the passed type
182    * @since 10.6RC1
183    */
 
184  10115063 toggle @Unstable
185    public boolean isAllowedAncestor(EntityType type)
186    {
187  10116323 return this.allowedAncestors[type.ordinal()];
188    }
189    }