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 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private TmfProviderManager() {}
35 // ------------------------------------------------------------------------
36 // Keeps track of the providers for each event type
37 // ------------------------------------------------------------------------
39 private static Map
<Class
<?
extends TmfData
>, List
<TmfDataProvider
<?
extends TmfData
>>> fProviders
=
40 new HashMap
<Class
<?
extends TmfData
>, List
<TmfDataProvider
<?
extends TmfData
>>>();
43 * Registers [provider] as a provider of [eventType]
48 public static <T
extends TmfData
> void register(Class
<T
> eventType
, TmfDataProvider
<?
extends TmfData
> provider
) {
49 if (fProviders
.get(eventType
) == null)
50 fProviders
.put(eventType
, new ArrayList
<TmfDataProvider
<?
extends TmfData
>>());
51 fProviders
.get(eventType
).add(provider
);
55 * Re-registers [provider] as a provider of [eventType]
60 public static <T
extends TmfData
> void deregister(Class
<T
> dataClass
, TmfDataProvider
<?
extends TmfData
> provider
) {
61 List
<TmfDataProvider
<?
extends TmfData
>> list
= fProviders
.get(dataClass
);
63 list
.remove(provider
);
65 fProviders
.remove(dataClass
);
70 * Returns the list of components that provide [eventType]
75 @SuppressWarnings("unchecked")
76 public static TmfDataProvider
<?
extends TmfData
>[] getProviders(Class
<?
extends TmfData
> dataClass
) {
77 List
<TmfDataProvider
<?
extends TmfData
>> list
= fProviders
.get(dataClass
);
79 list
= new ArrayList
<TmfDataProvider
<?
extends TmfData
>>();
80 TmfDataProvider
<?
extends TmfData
>[] result
= new TmfDataProvider
[list
.size()];
81 return list
.toArray(result
);
85 * Returns the list of components of type [providerType] that provide [eventType]
91 @SuppressWarnings("unchecked")
92 public static TmfDataProvider
<?
extends TmfData
>[] getProviders(Class
<?
extends TmfData
> dataClass
, Class
<?
extends TmfDataProvider
<?
extends TmfData
>> providerClass
) {
93 if (providerClass
== null) {
94 return getProviders(dataClass
);
96 TmfDataProvider
<?
extends TmfData
>[] list
= getProviders(dataClass
);
97 List
<TmfDataProvider
<?
extends TmfData
>> result
= new ArrayList
<TmfDataProvider
<?
extends TmfData
>>();
99 for (TmfDataProvider
<?
extends TmfData
> provider
: list
) {
100 if (provider
.getClass() == providerClass
) {
101 result
.add(provider
);
105 TmfDataProvider
<?
extends TmfData
>[] array
= new TmfDataProvider
[result
.size()];
106 return result
.toArray(array
);
This page took 0.033147 seconds and 6 git commands to generate.