1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.identityconnectors.framework.impl.api;
24
25 import java.text.MessageFormat;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.Comparator;
30 import java.util.HashSet;
31 import java.util.LinkedHashMap;
32 import java.util.List;
33
34 import org.identityconnectors.common.CollectionUtil;
35 import org.identityconnectors.framework.api.ConfigurationProperties;
36 import org.identityconnectors.framework.api.ConfigurationProperty;
37
38
39 public class ConfigurationPropertiesImpl implements ConfigurationProperties {
40
41
42
43
44
45
46
47 LinkedHashMap<String, ConfigurationPropertyImpl> _properties;
48
49
50
51
52
53 private transient APIConfigurationImpl _parent;
54
55
56
57
58
59 public APIConfigurationImpl getParent() {
60 return _parent;
61 }
62
63 public void setParent(APIConfigurationImpl parent) {
64 _parent = parent;
65 }
66
67 public void setProperties(Collection<ConfigurationPropertyImpl> in) {
68 List<ConfigurationPropertyImpl> properties =
69 new ArrayList<ConfigurationPropertyImpl>(in);
70 Collections.sort(properties, new Comparator<ConfigurationPropertyImpl>() {
71 public int compare(ConfigurationPropertyImpl o1,
72 ConfigurationPropertyImpl o2) {
73 int or1 = o1.getOrder();
74 int or2 = o2.getOrder();
75 return or1 < or2 ? -1 : or1 > or2 ? 1 : 0;
76 }
77 });
78 LinkedHashMap<String, ConfigurationPropertyImpl> temp =
79 new LinkedHashMap<String, ConfigurationPropertyImpl>();
80 for (ConfigurationPropertyImpl property : properties) {
81 temp.put(property.getName(), property);
82 property.setParent(this);
83 }
84 _properties = temp;
85 }
86
87 public Collection<ConfigurationPropertyImpl> getProperties() {
88 return _properties.values();
89 }
90
91
92
93
94
95
96
97
98 public ConfigurationProperty getProperty(String name) {
99 return _properties.get(name);
100 }
101
102
103
104
105 public List<String> getPropertyNames() {
106 List<String> names = new ArrayList<String>(_properties.keySet());
107 return CollectionUtil.newReadOnlyList(names);
108 }
109
110
111
112
113 public void setPropertyValue(String name, Object value) {
114 ConfigurationPropertyImpl property = _properties.get(name);
115 if (property == null) {
116 final String TMPL = "Property ''{0}'' does not exist.";
117 final String MSG = MessageFormat.format(TMPL, name);
118 throw new IllegalArgumentException(MSG);
119 }
120 property.setValue(value);
121 }
122
123 public boolean equals(Object o) {
124 if ( o instanceof ConfigurationPropertiesImpl ) {
125 ConfigurationPropertiesImpl other = (ConfigurationPropertiesImpl)o;
126 HashSet<ConfigurationPropertyImpl> set1 =
127 new HashSet<ConfigurationPropertyImpl>(
128 _properties.values());
129 HashSet<ConfigurationPropertyImpl> set2 =
130 new HashSet<ConfigurationPropertyImpl>(
131 other._properties.values());
132 return set1.equals(set2);
133 }
134 return false;
135 }
136
137 public int hashCode() {
138 HashSet<ConfigurationPropertyImpl> set1 =
139 new HashSet<ConfigurationPropertyImpl>(
140 _properties.values());
141 return set1.hashCode();
142 }
143 }