Skip to content
Permalink
Browse files

Improved: Add ‘PropertyChildren’ interface

(OFBIZ-11256)

This allows removing some duplicated method overloads.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1868626 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Oct 19, 2019
1 parent cd13058 commit 80c46f9c8cc48addebfa870678575730e60fc8fa
Showing with 16 additions and 44 deletions.
  1. +16 −44 framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java
@@ -72,7 +72,7 @@ public static Configuration getConfiguration(String containerName) throws Contai
}

/**
* Finds the container configuration elements in a .
* Finds the container configuration elements in a XML file.
*
* @param root the URL of the XML file which cannot be {@code null}
* @return a list of container configuration
@@ -88,43 +88,25 @@ public static Configuration getConfiguration(String containerName) throws Contai
return res;
}

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

public static int getPropertyValue(Configuration parentProp, String name, int defaultValue) {
Property prop = parentProp.getProperty(name);
if (prop == null || UtilValidate.isEmpty(prop.value)) {
return defaultValue;
}
try {
return Integer.parseInt(prop.value);
} catch (Exception e) {
return defaultValue;
}
}

public static boolean getPropertyValue(Configuration parentProp, String name, boolean defaultValue) {
Property prop = parentProp.getProperty(name);
if (prop == null || UtilValidate.isEmpty(prop.value)) {
return defaultValue;
}
return "true".equalsIgnoreCase(prop.value);
interface PropertyChildren {
/**
* Provides the child property corresponding to a specified identifier.
*
* @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);
}

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

public static int getPropertyValue(Property parentProp, String name, int defaultValue) {
public static int getPropertyValue(PropertyChildren parentProp, String name, int defaultValue) {
Property prop = parentProp.getProperty(name);
if (prop == null || UtilValidate.isEmpty(prop.value)) {
return defaultValue;
@@ -136,7 +118,7 @@ public static int getPropertyValue(Property parentProp, String name, int default
}
}

public static boolean getPropertyValue(Property parentProp, String name, boolean defaultValue) {
public static boolean getPropertyValue(PropertyChildren parentProp, String name, boolean defaultValue) {
Property prop = parentProp.getProperty(name);
if (prop == null || UtilValidate.isEmpty(prop.value)) {
return defaultValue;
@@ -147,7 +129,7 @@ public static boolean getPropertyValue(Property parentProp, String name, boolean
/**
* A container configuration.
*/
public static class Configuration {
public static final class Configuration implements PropertyChildren {
/** The identifier of the configuration. */
private final String name;
/** The name of class the configuration. */
@@ -197,12 +179,7 @@ public String className() {
return properties;
}

/**
* Provides the child property corresponding to a specified identifier.
*
* @param name the child property identifier
* @return the property corresponding to {@code name} or {@code null} if the identifier is absent.
*/
@Override
public Property getProperty(String name) {
return properties().get(name);
}
@@ -221,7 +198,7 @@ public Property getProperty(String name) {
/**
* A tree of container configuration properties.
*/
public static class Property {
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. */
@@ -265,12 +242,7 @@ public String value() {
return properties;
}

/**
* Provides the child property corresponding to a specified identifier.
*
* @param name the child property identifier
* @return the property corresponding to {@code name} or {@code null} if the identifier is absent.
*/
@Override
public Property getProperty(String name) {
return properties.get(name);
}

0 comments on commit 80c46f9

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