1    /*
2     * Copyright 2010 :torweg free software group
3     *
4     * This program is free software: you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation, either version 3 of the License, or
7     * (at your option) any later version.
8     * 
9     * This program is distributed in the hope that it will be useful,
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    * GNU General Public License for more details.
13    * 
14    * You should have received a copy of the GNU General Public License
15    * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16    *
17    */
18   package org.torweg.pulse.util.requestbean;
19   
20   import org.torweg.pulse.annotations.RequestBean;
21   import org.torweg.pulse.service.event.Event;
22   import org.torweg.pulse.service.event.EventManager;
23   import org.torweg.pulse.service.request.ServiceRequest;
24   
25   /**
26    * a basic implementation of a request bean with access to the current {@code
27    * ServiceRequest}.&nbsp;Useful for extension.
28    * 
29    * @author Thomas Weber
30    * @version $Revision: 1411 $
31    */
32   public class RequestAwareRequestBean {
33   
34       /**
35        * the injected bundle.
36        */
37       @RequestBean.ServiceRequest
38       private ServiceRequest request;
39   
40       /**
41        * returns the {@code Bundle}.
42        * 
43        * @return the bundle
44        */
45       public final ServiceRequest getServiceRequest() {
46           return this.request;
47       }
48   
49       /**
50        * adds the given {@code Event} to the {@code EventManager}.
51        * 
52        * @param e
53        *            the event to add
54        * @return {@code true}, if and only if the event has been added.
55        *         Otherwise {@code false}.
56        */
57       public final boolean addEvent(final Event e) {
58           EventManager manager = this.request.getEventManager();
59           if (e.isStopEvent() && (manager.getStopEvent() != null)) {
60               return false;
61           }
62           if (e.isOutputEvent() && (manager.getOutputEvent() != null)) {
63               return false;
64           }
65           manager.addEvent(e);
66           return true;
67       }
68   }
69