Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5a7a114b53bb8edf7ccf59e234634ea93e88b7d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*******************************************************************************
 *  Copyright (c) 2007, 2017 IBM Corporation and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 * 
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.equinox.internal.provisional.frameworkadmin;

import java.util.*;
import org.eclipse.equinox.frameworkadmin.BundleInfo;

/**
 * This object is instantiated by {@link Manipulator#getConfigData()};
 * The class that keeps some parameters of the {@link Manipulator}
 * created this object. The manipulating of the parameters will affect
 * the  {@link Manipulator}.
 *   
 * @see Manipulator
 */
public class ConfigData {
	final private String fwName;
	final private String fwVersion;
	final private String launcherName;
	final private String launcherVersion;
	private int beginningFwStartLevel = BundleInfo.NO_LEVEL;
	private int initialBundleStartLevel = BundleInfo.NO_LEVEL;
	// List of BundleInfo
	private LinkedHashSet<BundleInfo> bundlesList = new LinkedHashSet<>();

	private Properties properties = new Properties();

	public ConfigData(String fwName, String fwVersion, String launcherName, String launcherVersion) {
		this.fwName = fwName;
		this.fwVersion = fwVersion;
		this.launcherName = launcherName;
		this.launcherVersion = launcherVersion;
		this.initialize();
	}

	public void addBundle(BundleInfo bundleInfo) {
		bundlesList.add(bundleInfo);
	}

	public int getBeginingFwStartLevel() {
		return beginningFwStartLevel;
	}

	public BundleInfo[] getBundles() {
		if (bundlesList.size() == 0)
			return new BundleInfo[0];
		BundleInfo[] ret = new BundleInfo[bundlesList.size()];
		bundlesList.toArray(ret);
		return ret;
	}

	public String getProperty(String key) {
		return properties.getProperty(key);
	}

	public Properties getProperties() {
		Properties ret = new Properties();
		ret.putAll(properties);
		return ret;
	}

	public String getFwName() {
		return fwName;
	}

	public String getFwVersion() {
		return fwVersion;
	}

	public int getInitialBundleStartLevel() {
		return initialBundleStartLevel;
	}

	public String getLauncherName() {
		return launcherName;
	}

	public String getLauncherVersion() {
		return launcherVersion;
	}

	public void initialize() {
		beginningFwStartLevel = BundleInfo.NO_LEVEL;
		initialBundleStartLevel = BundleInfo.NO_LEVEL;
		bundlesList.clear();
		properties.clear();
		properties.clear();
	}

	public boolean removeBundle(BundleInfo bundleInfo) {
		if (bundleInfo == null)
			throw new IllegalArgumentException("Bundle info can't be null:" + bundleInfo); //$NON-NLS-1$
		return bundlesList.remove(bundleInfo);
	}

	public void setBeginningFwStartLevel(int startLevel) {
		beginningFwStartLevel = startLevel;
	}

	public void setBundles(BundleInfo[] bundleInfos) {
		bundlesList.clear();
		if (bundleInfos != null)
			for (int i = 0; i < bundleInfos.length; i++)
				bundlesList.add(bundleInfos[i]);
	}

	public void setProperty(String key, String value) {
		if (value == null)
			properties.remove(key);
		else
			properties.setProperty(key, value);
	}

	public void appendProperties(Properties props) {
		properties.putAll(props);
	}

	public void setProperties(Properties props) {
		properties.clear();
		properties.putAll(props);
	}

	public void setInitialBundleStartLevel(int startLevel) {
		initialBundleStartLevel = startLevel;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("Class:" + getClass().getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("============Independent===============\n"); //$NON-NLS-1$
		sb.append("fwName=" + fwName + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("fwVersion=" + fwVersion + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("launcherName=" + launcherName + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("launcherVersion=" + launcherVersion + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("beginningFwStartLevel=" + beginningFwStartLevel + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("initialBundleStartLevel=" + initialBundleStartLevel + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		if (this.bundlesList.size() == 0)
			sb.append("bundlesList=null\n"); //$NON-NLS-1$
		else {
			sb.append("bundlesList=\n"); //$NON-NLS-1$
			int i = 0;
			for (Iterator<BundleInfo> iter = bundlesList.iterator(); iter.hasNext();) {
				sb.append("\tbundlesList[" + i + "]=" + iter.next().toString() + "\n"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
				i++;
			}
		}

		sb.append("============ Properties ===============\n"); //$NON-NLS-1$
		sb.append("fwIndependentProps="); //$NON-NLS-1$
		setPropsStrings(sb, properties);
		return sb.toString();
	}

	private static void setPropsStrings(StringBuffer sb, Properties props) {
		if (props.size() > 0) {
			sb.append("\n"); //$NON-NLS-1$
			for (Enumeration<Object> enumeration = props.keys(); enumeration.hasMoreElements();) {
				String key = (String) enumeration.nextElement();
				String value = props.getProperty(key);
				if (value == null || value.equals("")) //$NON-NLS-1$
					continue;
				sb.append("\t{" + key + " ,\t" + value + "}\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
			}
		} else
			sb.append("empty\n"); //$NON-NLS-1$
	}
}

Back to the top