| Class | Line # | Actions | |||||
|---|---|---|---|---|---|---|---|
| DefaultObservationContext | 41 | 11 | 0% | 5 | 1 |
| 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.observation.internal; | |
| 21 | ||
| 22 | import java.util.Stack; | |
| 23 | ||
| 24 | import javax.inject.Inject; | |
| 25 | import javax.inject.Singleton; | |
| 26 | ||
| 27 | import org.xwiki.component.annotation.Component; | |
| 28 | import org.xwiki.context.Execution; | |
| 29 | import org.xwiki.context.ExecutionContext; | |
| 30 | import org.xwiki.observation.ObservationContext; | |
| 31 | import org.xwiki.observation.event.BeginEvent; | |
| 32 | ||
| 33 | /** | |
| 34 | * Default implementation of {@link ObservationContext}. | |
| 35 | * | |
| 36 | * @version $Id: 3af3148746f6bbc5805329dc08409752af428261 $ | |
| 37 | * @since 3.2M1 | |
| 38 | */ | |
| 39 | @Component | |
| 40 | @Singleton | |
| 41 | public class DefaultObservationContext implements ObservationContext | |
| 42 | { | |
| 43 | /** | |
| 44 | * The name of the property storing current events. | |
| 45 | */ | |
| 46 | static final String KEY_EVENTS = "observation.currentevents"; | |
| 47 | ||
| 48 | /** | |
| 49 | * The execution. | |
| 50 | */ | |
| 51 | @Inject | |
| 52 | private Execution execution; | |
| 53 | ||
| 54 | /** | |
| 55 | * @return the events stacked in the execution context | |
| 56 | */ | |
| 57 | 220 | private Stack<BeginEvent> getCurrentEvents() |
| 58 | { | |
| 59 | 220 | Stack<BeginEvent> events = null; |
| 60 | ||
| 61 | 220 | ExecutionContext context = this.execution.getContext(); |
| 62 | 220 | if (context != null) { |
| 63 | 220 | events = (Stack<BeginEvent>) context.getProperty(KEY_EVENTS); |
| 64 | } | |
| 65 | ||
| 66 | 220 | return events; |
| 67 | } | |
| 68 | ||
| 69 | 220 | @Override |
| 70 | public boolean isIn(BeginEvent event) | |
| 71 | { | |
| 72 | 220 | Stack<BeginEvent> events = getCurrentEvents(); |
| 73 | ||
| 74 | 220 | if (events != null) { |
| 75 | 205 | for (BeginEvent currentEvent : events) { |
| 76 | 206 | if (event.matches(currentEvent)) { |
| 77 | 28 | return true; |
| 78 | } | |
| 79 | } | |
| 80 | } | |
| 81 | 192 | return false; |
| 82 | } | |
| 83 | } |