Skip to content

Commit 26bbc4c

Browse files
committed
Added ParamProvider for ParamFinder
1 parent 3223992 commit 26bbc4c

File tree

5 files changed

+75
-4
lines changed

5 files changed

+75
-4
lines changed

fj-core/src/main/java/org/fugerit/java/core/cfg/xml/PropertyCatalog.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import java.util.Properties;
55

66
import org.fugerit.java.core.cfg.ConfigException;
7+
import org.fugerit.java.core.lang.helpers.ClassHelper;
78
import org.fugerit.java.core.lang.helpers.StringUtils;
89
import org.fugerit.java.core.util.collection.ListMapStringKey;
910
import org.fugerit.java.core.util.regex.ParamFinder;
11+
import org.fugerit.java.core.util.regex.ParamProvider;
1012
import org.w3c.dom.Element;
1113

1214
public class PropertyCatalog extends ListMapCatalogConfig<PropertyHolder> {
@@ -20,6 +22,8 @@ public PropertyCatalog() {
2022

2123
public static final String PROP_MAP_SYSTEM_ENV = "map-system-properties";
2224

25+
public static final String PROP_PATH_PARAM_PROVIDER = "path-param-provider";
26+
2327
/**
2428
*
2529
*/
@@ -29,7 +33,9 @@ public PropertyCatalog() {
2933
protected PropertyHolder customEntryHandling(String dataListId, PropertyHolder current, Element element) throws ConfigException {
3034
PropertyHolder holder = super.customEntryHandling(dataListId, current, element);
3135
try {
32-
if ( !this.getMapSysEnv().isEmpty() ) {
36+
if ( this.getParamProvider() != null ) {
37+
holder.setPath( PARAM_FINDER.substitute( holder.getPath() , this.getParamProvider().getProperties() ) );
38+
} else if ( !this.getMapSysEnv().isEmpty() ) {
3339
holder.setPath( PARAM_FINDER.substitute( holder.getPath() , this.getMapSysEnv() ) );
3440
}
3541
holder.init( this, dataListId );
@@ -52,6 +58,23 @@ public void configure(Element tag) throws ConfigException {
5258

5359
private static ParamFinder PARAM_FINDER = ParamFinder.newFinder();
5460

61+
private ParamProvider pathParamProvider;
62+
63+
private ParamProvider getParamProvider() throws ConfigException {
64+
if ( this.pathParamProvider == null ) {
65+
String pathParamProviderType = this.getGeneralProps().getProperty( PROP_PATH_PARAM_PROVIDER );
66+
if ( pathParamProviderType != null ) {
67+
logger.info( PROP_PATH_PARAM_PROVIDER+" -> "+pathParamProviderType );
68+
try {
69+
this.pathParamProvider = (ParamProvider) ClassHelper.newInstance( pathParamProviderType );
70+
} catch (Exception e) {
71+
throw new ConfigException( e );
72+
}
73+
}
74+
}
75+
return this.pathParamProvider;
76+
}
77+
5578
private Properties mapSysEnv;
5679

5780
private Properties getMapSysEnv() {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.fugerit.java.core.util.regex;
2+
3+
import java.util.Properties;
4+
5+
public interface ParamProvider {
6+
7+
Properties getProperties();
8+
9+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.fugerit.java.core.util.regex;
2+
3+
import java.io.Serializable;
4+
import java.util.Properties;
5+
6+
public class SimpleParamProvider implements ParamProvider, Serializable {
7+
8+
private static final long serialVersionUID = -6113410989966425831L;
9+
10+
private Properties props;
11+
12+
public SimpleParamProvider() {
13+
this.props = new Properties();
14+
}
15+
16+
@Override
17+
public Properties getProperties() {
18+
return this.props;
19+
}
20+
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package test.org.fugerit.java.core.cfg.xml;
2+
3+
import org.fugerit.java.core.util.regex.SimpleParamProvider;
4+
5+
public class TestParamProvider extends SimpleParamProvider {
6+
7+
/**
8+
*
9+
*/
10+
private static final long serialVersionUID = 1549784901025171679L;
11+
12+
public TestParamProvider() {
13+
super();
14+
this.getProperties().setProperty( "base-conf-path" , "core/cfg/xml/props" );
15+
}
16+
17+
}

fj-core/src/test/resources/core/cfg/xml/property-catalog-test.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<data-catalog-config
22
check-duplicate-id="fail"
33
type="org.fugerit.java.core.cfg.xml.PropertyHolder"
4-
default-catalog="TEST">
4+
default-catalog="TEST"
5+
path-param-provider="test.org.fugerit.java.core.cfg.xml.TestParamProvider">
56

67
<data-list id="TEST">
78
<data id="props-01" description="First JUNIT config properties"
8-
mode="classloader" path="core/cfg/xml/props/props-01.properties"/>
9+
mode="classloader" path="${base-conf-path}/props-01.properties"/>
910
<data id="props-02" description="Second JUNIT config properties"
10-
mode="classloader" path="core/cfg/xml/props/props-02.xml" xml="true"/>
11+
mode="classloader" path="${base-conf-path}/props-02.xml" xml="true"/>
1112
<!--
1213
* When this mode is used, you must define in PATH reference to other holders in the same catalog, semicolon separated.
1314
* For instace if props-01 and props-02 are two holder in the same catalog :

0 commit comments

Comments
 (0)