1 /*******************************************************************************
2 * Copyright (c) 2011 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 * Polytechnique Montréal - Initial API and implementation
11 * Bernd Hufmann - Productification, enhancements and fixes
13 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.lttng
.tracecontrol
.model
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Arrays
;
18 import java
.util
.List
;
20 import org
.eclipse
.linuxtools
.lttng
.LttngConstants
;
21 import org
.eclipse
.linuxtools
.lttng
.tracecontrol
.model
.TargetResource
;
22 import org
.eclipse
.rse
.core
.subsystems
.AbstractResource
;
23 import org
.eclipse
.rse
.core
.subsystems
.ISubSystem
;
26 * <b><u>ProviderResource</u></b>
28 * This models a remote resource representing a provider defined on a particular system.
31 public class ProviderResource
extends AbstractResource
{
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
37 private TargetResource
[] fTargets
;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
45 public ProviderResource() {
50 * Constructor for ProviderResource when given a parent subsystem.
52 public ProviderResource(ISubSystem parentSubSystem
) {
53 super(parentSubSystem
);
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
60 * Returns the name of the provider resource.
64 public String
getName() {
69 * Sets the name of the provider resource.
71 * @param name The fName to set
73 public void setName(String name
) {
78 * Returns the targets (children).
80 * @return TargetResource[]
82 public TargetResource
[] getTargets() {
83 Arrays
.sort(fTargets
);
88 * Returns whether the provider is for UST or kernel traces.
90 * @return true if UST, false for kernel
92 public boolean isUst() {
93 return fName
.equals(LttngConstants
.Lttng_Provider_Ust
);
97 * Sets the targets (children).
99 * @param newTargets The new targets to set
101 public void setTargets(TargetResource
[] newTargets
) {
102 fTargets
= newTargets
;
106 * Removes all targets (children).
108 public void removeAllTargets() {
109 for (int i
= 0; i
< fTargets
.length
; i
++) {
110 fTargets
[i
].removeAllTraces();
116 * Refreshes provider with other targets list. If target already exists in this
117 * provider, reuse the target from this provider and don't override.
119 * @param otherTargets
121 public void refreshTargets(TargetResource
[] otherTargets
) {
122 List
<TargetResource
> newTargets
= new ArrayList
<TargetResource
>();
123 for (int i
= 0; i
< otherTargets
.length
; i
++) {
124 boolean added
= false;
125 for (int j
= 0; j
< fTargets
.length
; j
++) {
126 if (otherTargets
[i
].equals(fTargets
[j
])) {
127 newTargets
.add(fTargets
[j
]);
128 fTargets
[j
].refreshTraces(otherTargets
[i
].getTraces());
134 newTargets
.add(otherTargets
[i
]);
137 fTargets
= newTargets
.toArray(new TargetResource
[0]);
142 * @see java.lang.Object#toString()
145 @SuppressWarnings("nls")
146 public String
toString() {
147 return "[ProviderResource (" + fName
+ ")]";