1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.component
;
15 import java
.util
.ArrayList
;
16 import java
.util
.HashMap
;
17 import java
.util
.List
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfData
;
23 * <b><u>TmfProviderManager.java</u></b>
25 * Singleton that keeps track of the event providers.
27 public class TmfProviderManager
{
29 // ------------------------------------------------------------------------
30 // Keeps track of the providers for each event type
31 // ------------------------------------------------------------------------
33 private static Map
<Class
<?
extends TmfData
>, List
<TmfProvider
<?
extends TmfData
>>> fProviders
=
34 new HashMap
<Class
<?
extends TmfData
>, List
<TmfProvider
<?
extends TmfData
>>>();
37 * Registers [provider] as a provider of [eventType]
42 public static <T
extends TmfData
> void register(Class
<T
> eventType
, TmfProvider
<?
extends TmfData
> provider
) {
43 if (fProviders
.get(eventType
) == null)
44 fProviders
.put(eventType
, new ArrayList
<TmfProvider
<?
extends TmfData
>>());
45 assert(fProviders
.get(eventType
) != null);
46 fProviders
.get(eventType
).add(provider
);
50 * Re-registers [provider] as a provider of [eventType]
55 public static <T
extends TmfData
> void deregister(Class
<T
> eventType
, TmfProvider
<?
extends TmfData
> provider
) {
56 List
<TmfProvider
<?
extends TmfData
>> list
= fProviders
.get(eventType
);
58 list
.remove(provider
);
60 fProviders
.remove(eventType
);
65 * Returns the list of components that provide [eventType]
70 @SuppressWarnings("unchecked")
71 public static TmfProvider
<?
extends TmfData
>[] getProviders(Class
<?
extends TmfData
> eventType
) {
72 List
<TmfProvider
<?
extends TmfData
>> list
= fProviders
.get(eventType
);
74 list
= new ArrayList
<TmfProvider
<?
extends TmfData
>>();
75 TmfProvider
<?
extends TmfData
>[] result
= new TmfProvider
[list
.size()];
76 return list
.toArray(result
);
80 * Returns the list of components of type [providerType] that provide [eventType]
86 @SuppressWarnings("unchecked")
87 public static TmfProvider
<?
extends TmfData
>[] getProviders(Class
<?
extends TmfData
> eventType
, Class
<?
extends TmfProvider
<?
extends TmfData
>> providerType
) {
88 TmfProvider
<?
extends TmfData
>[] list
= getProviders(eventType
);
89 List
<TmfProvider
<?
extends TmfData
>> result
= new ArrayList
<TmfProvider
<?
extends TmfData
>>();
91 for (TmfProvider
<?
extends TmfData
> provider
: list
) {
92 if (provider
.getClass() == providerType
) {
97 TmfProvider
<?
extends TmfData
>[] array
= new TmfProvider
[result
.size()];
98 return result
.toArray(array
);
This page took 0.031263 seconds and 5 git commands to generate.