Skip to content
Permalink
Browse files

Improved: Avoid unecessary breakage in ‘ContainerConfig’

(OFBIZ-11256)

This restores ‘public’ modifiers on fields and move the ‘Property’
inner class back to ‘Configuration’ to avoid breakage of client code
extending the ‘Container’ interface.

In order to smooth the transition towards using getters instead of
direct field accesss, the public modifiers on fields are now marked as
deprecated.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1868628 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Oct 19, 2019
1 parent f5aac70 commit 2c686c4655d58e99d0bf8e40dfb83075904cbe0e
@@ -83,7 +83,7 @@ public static Configuration getConfiguration(String containerName) throws Contai
.map(Configuration::new)
.collect(collectingAndThen(toList(), Collections::unmodifiableList));
synchronized (ContainerConfig.class) {
res.forEach(cfg -> configurations.put(cfg.name, cfg));
res.forEach(cfg -> configurations.put(cfg.name(), cfg));
}
return res;
}
@@ -95,20 +95,20 @@ public static Configuration getConfiguration(String containerName) throws Contai
* @param name the child property identifier
* @return the property corresponding to {@code name} or {@code null} if the identifier is absent.
*/
Property getProperty(String name);
Configuration.Property getProperty(String name);
}

public static String getPropertyValue(PropertyChildren parentProp, String name, String defaultValue) {
Property prop = parentProp.getProperty(name);
if (prop == null || UtilValidate.isEmpty(prop.value)) {
Configuration.Property prop = parentProp.getProperty(name);
if (prop == null || UtilValidate.isEmpty(prop.value())) {
return defaultValue;
}
return prop.value;
}

public static int getPropertyValue(PropertyChildren parentProp, String name, int defaultValue) {
Property prop = parentProp.getProperty(name);
if (prop == null || UtilValidate.isEmpty(prop.value)) {
Configuration.Property prop = parentProp.getProperty(name);
if (prop == null || UtilValidate.isEmpty(prop.value())) {
return defaultValue;
}
try {
@@ -119,8 +119,8 @@ public static int getPropertyValue(PropertyChildren parentProp, String name, int
}

public static boolean getPropertyValue(PropertyChildren parentProp, String name, boolean defaultValue) {
Property prop = parentProp.getProperty(name);
if (prop == null || UtilValidate.isEmpty(prop.value)) {
Configuration.Property prop = parentProp.getProperty(name);
if (prop == null || UtilValidate.isEmpty(prop.value())) {
return defaultValue;
}
return "true".equalsIgnoreCase(prop.value);
@@ -130,14 +130,16 @@ public static boolean getPropertyValue(PropertyChildren parentProp, String name,
* A container configuration.
*/
public static final class Configuration implements PropertyChildren {
//ALLOW PUBLIC FIELDS
/** The identifier of the configuration. */
private final String name;
@Deprecated public final String name;
/** The name of class the configuration. */
private final String className;
@Deprecated public final String className;
/** The list of loader names triggering the launch of the container. */
private final List<String> loaders;
@Deprecated public final List<String> loaders;
/** The container property elements. */
private final Map<String, Property> properties;
@Deprecated public final Map<String, Property> properties;
//FORBID PUBLIC FIELDS

/**
* Constructs a container configuration.
@@ -180,7 +182,7 @@ public String className() {
}

@Override
public Property getProperty(String name) {
public Configuration.Property getProperty(String name) {
return properties().get(name);
}

@@ -193,96 +195,98 @@ public Property getProperty(String name) {
public List<Property> getPropertiesWithValue(String value) {
return Property.getPropertiesWithValue(properties(), value);
}
}

/**
* A tree of container configuration properties.
*/
public static final class Property implements PropertyChildren {
/** The identifier of the configuration element */
private final String name;
/** The value associated with the {@code name} identifier. */
private final String value;
/** The properties children */
private final Map<String, Property> properties;

/**
* Constructs a container configuration element.
*
* @param element the {@code <property>} XML element containing the configuration.
* A tree of container configuration properties.
*/
public Property(Element element) {
name = element.getAttribute("name");
String value = element.getAttribute("value");
if (UtilValidate.isEmpty(value)) {
value = UtilXml.childElementValue(element, "property-value");
public static final class Property implements PropertyChildren {
//ALLOW PUBLIC FIELDS
/** The identifier of the configuration element */
@Deprecated public final String name;
/** The value associated with the {@code name} identifier. */
@Deprecated public final String value;
/** The properties children */
@Deprecated public final Map<String, Property> properties;
//FORBID PUBLIC FIELDS

/**
* Constructs a container configuration element.
*
* @param element the {@code <property>} XML element containing the configuration.
*/
public Property(Element element) {
name = element.getAttribute("name");
String value = element.getAttribute("value");
if (UtilValidate.isEmpty(value)) {
value = UtilXml.childElementValue(element, "property-value");
}
this.value = value;
this.properties = parseProps(element);
}
this.value = value;
this.properties = parseProps(element);
}

/**
* @return the name
*/
public String name() {
return name;
}
/**
* @return the name
*/
public String name() {
return name;
}

/**
* @return the value
*/
public String value() {
return value;
}
/**
* @return the value
*/
public String value() {
return value;
}

/**
* @return the properties
*/
public Map<String, Property> properties() {
return properties;
}
/**
* @return the properties
*/
public Map<String, Property> properties() {
return properties;
}

@Override
public Property getProperty(String name) {
return properties.get(name);
}
@Override
public Configuration.Property getProperty(String name) {
return properties().get(name);
}

/**
* Provides all the child properties whose values are equal a specified value.
*
* @param value the value to match
* @return a list of matching properties
*/
public List<Property> getPropertiesWithValue(String value) {
return getPropertiesWithValue(properties, value);
}
/**
* Provides all the child properties whose values are equal a specified value.
*
* @param value the value to match
* @return a list of matching properties
*/
public List<Property> getPropertiesWithValue(String value) {
return getPropertiesWithValue(properties(), value);
}

/**
* Aggregates the {@code <property>} XML elements in a Map.
*
* @param root the root XML Element containing {@code <property>} children
* @return a map of property elements
*/
private static Map<String, Property> parseProps(Element root) {
LinkedHashMap<String, Property> res = new LinkedHashMap<>();
UtilXml.childElementList(root, "property").forEach(el -> {
Property p = new Property(el);
res.put(p.name, p);
});
return Collections.unmodifiableMap(res);
}
/**
* Aggregates the {@code <property>} XML elements in a Map.
*
* @param root the root XML Element containing {@code <property>} children
* @return a map of property elements
*/
private static Map<String, Property> parseProps(Element root) {
LinkedHashMap<String, Property> res = new LinkedHashMap<>();
UtilXml.childElementList(root, "property").forEach(el -> {
Property p = new Property(el);
res.put(p.name(), p);
});
return Collections.unmodifiableMap(res);
}

/**
* Provides all the child properties whose values are equal a specified value.
*
* @param value the value to match
* @return a list of matching properties
*/
private static List<Property> getPropertiesWithValue(Map<String, Property> propkvs, String value) {
return propkvs.values().stream()
.filter(Objects::nonNull)
.filter(p -> value.equals(p.value))
.collect(toList());
/**
* Provides all the child properties whose values are equal a specified value.
*
* @param value the value to match
* @return a list of matching properties
*/
private static List<Property> getPropertiesWithValue(Map<String, Property> propkvs, String value) {
return propkvs.values().stream()
.filter(Objects::nonNull)
.filter(p -> value.equals(p.value()))
.collect(toList());
}
}
}
}
@@ -26,6 +26,7 @@
import java.rmi.server.UnicastRemoteObject;
import java.util.List;

import org.apache.ofbiz.base.container.ContainerConfig.Configuration;
import org.apache.ofbiz.base.start.Start;
import org.apache.ofbiz.base.start.StartupCommand;
import org.apache.ofbiz.base.util.RMIExtendedSocketFactory;
@@ -54,11 +55,11 @@ public void init(List<StartupCommand> ofbizCommands, String name, String configF
this.name =name;
this.configFileLocation = configFile;

ContainerConfig.Configuration cfg = ContainerConfig.getConfiguration(name);
Configuration cfg = ContainerConfig.getConfiguration(name);

// get the naming (JNDI) port

ContainerConfig.Property port = cfg.getProperty("port");
Configuration.Property port = cfg.getProperty("port");
if (port.value() != null) {
try {
this.namingPort = Integer.parseInt(port.value()) + Start.getInstance().getConfig().portOffset;
@@ -68,7 +69,7 @@ public void init(List<StartupCommand> ofbizCommands, String name, String configF
}

// get the naming (JNDI) server
ContainerConfig.Property host = cfg.getProperty("host");
Configuration.Property host = cfg.getProperty("host");
if (host != null && host.value() != null) {
this.namingHost = host.value() ;
}

0 comments on commit 2c686c4

Please sign in to comment.
You can’t perform that action at this time.