Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.apache.felix.dm.context; |
| 20 | |
| 21 | import java.util.Dictionary; |
| 22 | import java.util.Hashtable; |
| 23 | |
| 24 | /** |
| 25 | * An event holds all data that belongs to some external event as it comes in via |
| 26 | * the 'changed' callback of a dependency. |
| 27 | * |
| 28 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 29 | */ |
| 30 | public class Event implements Comparable<Event> { |
| 31 | protected final static Dictionary<Object, Object> EMPTY_PROPERTIES = new Hashtable<>(); |
| 32 | private final Object m_event; // the actual event object (a Service, a Bundle, a Configuration, etc ...) |
| 33 | |
| 34 | public Event(Object event) { |
| 35 | m_event = event; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Returns the actual event object wrapped by this event (a Service Dependency, a Bundle for Bundle Dependency, etc...). |
| 40 | */ |
| 41 | @SuppressWarnings("unchecked") |
| 42 | public <T> T getEvent() { |
| 43 | return (T) m_event; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Returns the properties of the actual event object wrapped by this event (Service Dependency properties, ...). |
| 48 | */ |
| 49 | @SuppressWarnings("unchecked") |
| 50 | public <K,V> Dictionary<K,V> getProperties() { |
| 51 | return (Dictionary<K,V>) EMPTY_PROPERTIES; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public int hashCode() { |
| 56 | return m_event.hashCode(); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public boolean equals(Object obj) { |
| 61 | // an instanceof check here is not "strong" enough with subclasses overriding the |
| 62 | // equals: we need to be sure that a.equals(b) == b.equals(a) at all times |
| 63 | if (obj != null && obj.getClass().equals(Event.class)) { |
| 64 | return (((Event) obj).m_event).equals(m_event); |
| 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public int compareTo(Event o) { |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Release the resources this event is holding (like service reference for example). |
| 76 | */ |
| 77 | public void close() { |
| 78 | } |
| 79 | } |