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

File AbstractExtensionEvent.java

 

Coverage histogram

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

Code metrics

0
12
9
1
129
55
9
0.75
1.33
9
1

Classes

Class Line # Actions
AbstractExtensionEvent 31 12 0% 9 2
0.904761990.5%
 

Contributing tests

This file is covered by 94 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.extension.event;
21   
22    import org.apache.commons.lang3.StringUtils;
23    import org.xwiki.extension.ExtensionId;
24   
25    /**
26    * Base class for all {@link ExtensionEvent}.
27    *
28    * @version $Id: 047fbcb6d77e4c49972ca73bacf9026a750a420d $
29    * @since 4.0M1
30    */
 
31    public abstract class AbstractExtensionEvent implements ExtensionEvent
32    {
33    /**
34    * @see #getExtensionId()
35    */
36    private ExtensionId extensionId;
37   
38    /**
39    * @see #getNamespace()
40    */
41    private String namespace;
42   
43    /**
44    * Required since null namespace means root namespace.
45    */
46    private boolean noNamespace;
47   
48    /**
49    * Default constructor.
50    */
 
51  205 toggle public AbstractExtensionEvent()
52    {
53  205 this.noNamespace = true;
54    }
55   
56    /**
57    * @param extensionId the event related extension identifier
58    * @param namespace the namespace on which the event happened
59    */
 
60  290 toggle protected AbstractExtensionEvent(ExtensionId extensionId, String namespace)
61    {
62  290 this.extensionId = extensionId;
63  290 this.namespace = namespace;
64  290 this.noNamespace = false;
65    }
66   
67    /**
68    * @param extensionId the event related extension identifier
69    *
70    * @since 9.0RC1
71    * @since 8.4.1
72    * @since 7.4.6
73    */
 
74  8 toggle protected AbstractExtensionEvent(ExtensionId extensionId)
75    {
76  8 this.extensionId = extensionId;
77  8 this.noNamespace = true;
78    }
79   
80    // ExtensionEvent
81   
 
82  376 toggle @Override
83    public ExtensionId getExtensionId()
84    {
85  376 return this.extensionId;
86    }
87   
 
88  312 toggle @Override
89    public String getNamespace()
90    {
91  312 return this.namespace;
92    }
93   
 
94  0 toggle @Override
95    public boolean hasNamespace()
96    {
97  0 return !this.noNamespace;
98    }
99   
100    // Event
101   
 
102  173 toggle @Override
103    public boolean matches(Object event)
104    {
105  173 return this.getClass() == event.getClass()
106    && matchesExtensionId(((AbstractExtensionEvent) event).getExtensionId())
107    && matchesNamespace(((AbstractExtensionEvent) event).getNamespace());
108    }
109   
110    /**
111    * @param extensionId the event related extension identifier
112    * @return <code>true</code> if the passed event matches this event, <code>false</code> otherwise.
113    */
 
114  173 toggle private boolean matchesExtensionId(ExtensionId extensionId)
115    {
116  173 return this.extensionId == null || this.extensionId.equals(extensionId)
117    || (this.extensionId.getVersion() == null && this.extensionId.getId().equals(extensionId.getId()));
118    }
119   
120    /**
121    * @param namespace the event related namespace
122    * @return <code>true</code> if the passed event matches this event, <code>false</code> otherwise.
123    */
 
124  173 toggle private boolean matchesNamespace(String namespace)
125    {
126  173 return this.noNamespace || StringUtils.equals(this.namespace, namespace);
127    }
128   
129    }