Michael E. Rodriguez | cafcf24 | 2006-03-25 17:25:49 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2006 The Apache Software Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | */ |
| 17 | package org.apache.felix.servicebinder.impl; |
| 18 | |
| 19 | import org.apache.felix.servicebinder.architecture.DependencyChangeEvent; |
| 20 | import org.apache.felix.servicebinder.architecture.InstanceChangeEvent; |
| 21 | import org.apache.felix.servicebinder.architecture.ServiceBinderListener; |
| 22 | |
| 23 | /** |
| 24 | * |
| 25 | * @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a> |
| 26 | */ |
| 27 | public class ArchitectureEventMulticaster implements ServiceBinderListener |
| 28 | { |
| 29 | /** |
| 30 | * |
| 31 | * @uml.property name="a" |
| 32 | * @uml.associationEnd multiplicity="(0 1)" |
| 33 | */ |
| 34 | protected ServiceBinderListener a; |
| 35 | |
| 36 | /** |
| 37 | * |
| 38 | * @uml.property name="b" |
| 39 | * @uml.associationEnd multiplicity="(0 1)" |
| 40 | */ |
| 41 | protected ServiceBinderListener b; |
| 42 | |
| 43 | protected ArchitectureEventMulticaster(ServiceBinderListener a, ServiceBinderListener b) |
| 44 | { |
| 45 | this.a = a; |
| 46 | this.b = b; |
| 47 | } |
| 48 | |
| 49 | public void dependencyChanged(DependencyChangeEvent e) |
| 50 | { |
| 51 | a.dependencyChanged(e); |
| 52 | b.dependencyChanged(e); |
| 53 | } |
| 54 | |
| 55 | public void instanceReferenceChanged(InstanceChangeEvent e) |
| 56 | { |
| 57 | a.instanceReferenceChanged(e); |
| 58 | b.instanceReferenceChanged(e); |
| 59 | } |
| 60 | |
| 61 | public static ServiceBinderListener add(ServiceBinderListener a, ServiceBinderListener b) |
| 62 | { |
| 63 | if (a == null) |
| 64 | return b; |
| 65 | else if (b == null) |
| 66 | return a; |
| 67 | else |
| 68 | return new ArchitectureEventMulticaster(a, b); |
| 69 | } |
| 70 | |
| 71 | public static ServiceBinderListener remove(ServiceBinderListener a, ServiceBinderListener b) |
| 72 | { |
| 73 | if ((a == null) || (a == b)) |
| 74 | return null; |
| 75 | else if (a instanceof ArchitectureEventMulticaster) |
| 76 | return add (remove (((ArchitectureEventMulticaster) a).a, b),remove (((ArchitectureEventMulticaster) a).b, b)); |
| 77 | else |
| 78 | return a; |
| 79 | } |
| 80 | } |