This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new a5179c9164 FELIX-6500 : Update javadoc and align new methods with
existing ones
a5179c9164 is described below
commit a5179c91640f16947a548d7f1ff65b0a4290f4d9
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed May 4 07:13:45 2022 +0200
FELIX-6500 : Update javadoc and align new methods with existing ones
---
.../internal/configuration/ConfigJsonSupport.java | 48 ++++++++++++++--------
.../felix/webconsole/spi/ConfigurationHandler.java | 23 +++++++----
2 files changed, 44 insertions(+), 27 deletions(-)
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigJsonSupport.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigJsonSupport.java
index f3453dba94..5d0ec7b5bf 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigJsonSupport.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigJsonSupport.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;
@@ -89,7 +90,33 @@ class ConfigJsonSupport {
}
- void configForm( final JSONWriter json, final String pid, final
Configuration config, final String pidFilter, final String locale,
ServiceTracker<ConfigurationHandler, ConfigurationHandler> serviceTracker )
+ /**
+ * Get the list of property names for the form and filter the properties
based on this list
+ */
+ private List<String> getPropertyNamesForForm(final String factoryPid,
final String pid,
+ final Dictionary<String, Object> props,
+ final ServiceTracker<ConfigurationHandler, ConfigurationHandler>
serviceTracker)
+ throws IOException {
+ final List<String> names = new
ArrayList<>(Collections.list(props.keys()));
+ if ( serviceTracker != null && !names.isEmpty()) {
+ final Object[] services = serviceTracker.getServices();
+ if ( services != null ) {
+ for(final Object o : services) {
+ final ConfigurationHandler handler =
(ConfigurationHandler)o;
+ handler.filterProperties(factoryPid, pid, names);
+ }
+ }
+ final List<String> remove = new
ArrayList<>(Collections.list(props.keys()));
+ remove.removeAll(names);
+ for(final String name : remove) {
+ props.remove(name);
+ }
+ }
+ return names;
+ }
+
+ void configForm( final JSONWriter json, final String pid, final
Configuration config, final String pidFilter, final String locale,
+ final ServiceTracker<ConfigurationHandler, ConfigurationHandler>
serviceTracker )
throws IOException {
json.key( ConfigManager.PID );
json.value( pid );
@@ -100,28 +127,13 @@ class ConfigJsonSupport {
}
Dictionary<String, Object> props = null;
- List<String> filteredKeys = Collections.emptyList();
if ( config != null ) {
props = config.getProperties();
- if (props != null && serviceTracker != null) {
- Object[] services = serviceTracker.getServices();
- if (services != null) {
- for(final Object o : services) {
- ConfigurationHandler handler = (ConfigurationHandler)o;
- List<String> allKeys = Collections.list(props.keys());
- filteredKeys = handler.filterProperties(config,
allKeys);
- allKeys.removeAll(filteredKeys);
- for (String key : allKeys) {
- props.remove(key);
- }
- }
- }
- }
}
- final List<String> keys = filteredKeys;
if ( props == null ) {
props = new Hashtable<>();
}
+ final List<String> keys = getPropertyNamesForForm(config != null ?
config.getFactoryPid() : null, pid, props, serviceTracker);
boolean doSimpleMerge = true;
if ( this.mtss != null ) {
@@ -350,7 +362,7 @@ class ConfigJsonSupport {
if (services != null) {
for(final Object o : services) {
ConfigurationHandler handler =
(ConfigurationHandler)o;
- if (!handler.listConfiguration(config)) {
+ if
(!handler.listConfiguration(config.getFactoryPid(), config.getPid())) {
config = null;
break;
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/spi/ConfigurationHandler.java
b/webconsole/src/main/java/org/apache/felix/webconsole/spi/ConfigurationHandler.java
index fcb33ac83c..97378072d2 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/spi/ConfigurationHandler.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/spi/ConfigurationHandler.java
@@ -19,11 +19,10 @@
package org.apache.felix.webconsole.spi;
import java.io.IOException;
+import java.util.Collection;
import java.util.Dictionary;
-import java.util.List;
import org.osgi.annotation.versioning.ConsumerType;
-import org.osgi.service.cm.Configuration;
/**
* A configuration handler allows to hook into the processing of
configurations for
@@ -72,21 +71,27 @@ public interface ConfigurationHandler {
void updateConfiguration(String factoryPid, String pid, Dictionary<String,
Object> props) throws ValidationException, IOException;
/**
- * @param cfg a configuration object
+ * A configuration should be listed
+ * @param factoryPid Optional factory pid
+ * @param pid The pid
* @return true if the configuration may be listed
* @throws IOException For an error
+ * @since 1.1
*/
- default boolean listConfiguration(Configuration cfg) throws IOException {
+ default boolean listConfiguration(String factoryPid, String pid) throws
IOException {
return true;
}
/**
- * @param cfg a configuration object
- * @return the filtered list
+ * Filter the properties do be displayed. Properties that should be hidden
can be removed from the passed in
+ * collection
+ * @param factoryPid Optional factory pid
+ * @param pid The pid
+ * @param propertyNames The mutable collection of property names
* @throws IOException For an error
+ * @since 1.1
*/
- default List<String> filterProperties(Configuration cfg, List<String>
propertyNames) throws IOException {
- return propertyNames;
+ default void filterProperties(String factoryPid, String pid,
Collection<String> propertyNames) throws IOException {
+ // do nothing
}
-
}
\ No newline at end of file