@@ -83,7 +83,7 @@ public static List<Configuration> getConfigurations(Element root) throws Contain
.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 @@ interface PropertyChildren {
* @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 Map<String, Property> properties() {
}
@ 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 ());
}
}
}
}