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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/*******************************************************************************
* Copyright (c) 2006, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Martin Oberhuber (Wind River) - Added Javadoc.
* David McKnight (IBM) - [217715] [api] RSE property sets should support nested property sets
* David Dykstal (IBM) - [226561] Add API markup to RSE javadocs for extend / implement
*******************************************************************************/
package org.eclipse.rse.core.model;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;
/**
* A Hashmap based implementation of the {@link IPropertySet} interface.
*
* Not thread-safe since the underlying {@link java.util.HashMap} is
* not thread-safe.
* @noextend This class is not intended to be subclassed by clients.
* The standard extensions are included in the framework.
*/
public class PropertySet extends RSEModelObject implements IPropertySet, IRSEModelObject, ILabeledObject, Observer {
private String _name;
private String _label = null;
private String _description = null;
private Map _properties;
private IPropertySetContainer _container = null;
protected static IPropertyType _defaultType = PropertyType.getStringPropertyType();
/**
* Construct a new PropertySet based on an existing one (i.e. clone it).
* @param propertySet existing Property Set to clone
*/
public PropertySet(IPropertySet propertySet) {
_name = propertySet.getName();
_description = propertySet.getDescription();
_properties = new HashMap();
if (propertySet instanceof ILabeledObject) {
ILabeledObject p = (ILabeledObject) propertySet;
_label = p.getLabel();
}
String[] keys = propertySet.getPropertyKeys();
for (int i = 0; i < keys.length; i++) {
String key = keys[i];
IProperty property = propertySet.getProperty(key);
addProperty(key, new Property(property));
}
setDirty(true);
}
/**
* Construct a new empty PropertySet.
* @param name of the new PropertySet
*/
public PropertySet(String name) {
_name = name;
_properties = new HashMap();
setDirty(true);
}
public String getName() {
return _name;
}
public String getLabel() {
if (_label != null) return _label;
return _name;
}
public void setLabel(String label) {
_label = label;
setDirty(true);
}
public String getDescription() {
return _description;
}
public void setDescription(String description) {
_description = description;
setDirty(true);
}
public String[] getPropertyKeys() {
Set set = _properties.keySet();
return (String[]) set.toArray(new String[set.size()]);
}
public void setName(String name) {
_name = name;
setDirty(true);
}
public void setProperties(Map map) {
_properties = new HashMap(map.size());
for (Iterator z = map.keySet().iterator(); z.hasNext();) {
String key = (String) z.next();
Object value = map.get(key);
if (value instanceof IProperty) {
addProperty(key, (IProperty)value);
} else if (value instanceof String) {
addProperty(key, (String)value);
}
}
}
/**
* Add a typed Property to the set.
*
* In case a Property already exists for the given key, it will be overwritten.
*
* @param key Key to add
* @param property The Property to add
* @return The added Property
*/
public IProperty addProperty(String key, IProperty property) {
_properties.put(key, property);
setDirty(true);
return property;
}
public IProperty addProperty(String key, String value) {
IProperty property = getProperty(key);
if (property != null) {
//FIXME should throw a NumberFormatException or similar,
//if the value does not fit the type of the existing property.
property.setValue(value);
} else {
property = addProperty(key, value, _defaultType);
}
return property;
}
public IProperty addProperty(String key, String value, IPropertyType type) {
IProperty property = new Property(key, value, type, true);
return addProperty(key, property);
}
public boolean removeProperty(String key) {
Object value = _properties.remove(key);
if (value == null) return false;
setDirty(true);
return true;
}
public IProperty getProperty(String key) {
return (IProperty) _properties.get(key);
}
public String getPropertyValue(String key) {
IProperty property = getProperty(key);
if (property != null) {
return property.getValue();
}
return null;
}
public IPropertyType getPropertyType(String key) {
IProperty property = getProperty(key);
if (property != null) {
return property.getType();
}
return null;
}
public boolean commit() {
return getPersistableParent().commit();
}
public IRSEPersistableContainer[] getPersistableChildren() {
return IRSEPersistableContainer.NO_CHILDREN;
}
public IRSEPersistableContainer getPersistableParent() {
IRSEPersistableContainer result = null;
if (_container instanceof IRSEPersistableContainer) {
result = (IRSEPersistableContainer) _container;
}
return result;
}
public void setContainer(IPropertySetContainer container) {
_container = container;
}
public IPropertySetContainer getContainer() {
return _container;
}
public void update(Observable o, Object arg) {
setDirty(true);
}
}
|