Index: src/main/java/org/drools/SessionConfiguration.java =================================================================== --- src/main/java/org/drools/SessionConfiguration.java (revision 30510) +++ src/main/java/org/drools/SessionConfiguration.java (working copy) @@ -159,6 +159,8 @@ } else if ( name.equals( "drools.clockType" ) ) { setClockType( ClockType.resolveClockType( StringUtils.isEmpty( value ) ? "realtime" : value ) ); } + + chainedProperties.setProperty(name, value); } public String getProperty(String name) { @@ -173,7 +175,7 @@ return this.clockType.toExternalForm(); } - return null; + return chainedProperties.getProperty(name, null); } /** Index: src/main/java/org/drools/util/ChainedProperties.java =================================================================== --- src/main/java/org/drools/util/ChainedProperties.java (revision 30510) +++ src/main/java/org/drools/util/ChainedProperties.java (working copy) @@ -17,11 +17,9 @@ import java.util.Map; import java.util.Properties; -public class ChainedProperties - implements - Externalizable { - private List props; - private List defaultProps; +public class ChainedProperties implements Externalizable { + private List props; + private List defaultProps; public ChainedProperties() { @@ -49,8 +47,8 @@ } } - this.props = new ArrayList(); - this.defaultProps = new ArrayList(); + this.props = new ArrayList(); + this.defaultProps = new ArrayList(); // Properties added in precedence order @@ -132,9 +130,10 @@ } } - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - props = (List)in.readObject(); - defaultProps = (List)in.readObject(); + @SuppressWarnings("unchecked") + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + props = (List)in.readObject(); + defaultProps = (List)in.readObject(); } public void writeExternal(ObjectOutput out) throws IOException { @@ -142,15 +141,14 @@ out.writeObject(defaultProps); } - private Enumeration getResources(String name, + private Enumeration getResources(String name, ClassLoader classLoader) { - Enumeration enumeration = null; try { - enumeration = classLoader.getResources( name ); + return classLoader.getResources( name ); } catch ( IOException e ) { e.printStackTrace(); + return null; } - return enumeration; } public void addProperties(Properties properties) { @@ -160,38 +158,40 @@ public String getProperty(String key, String defaultValue) { String value = null; - for ( Iterator it = this.props.iterator(); it.hasNext(); ) { - Properties props = (Properties) it.next(); - value = props.getProperty( key ); - if ( value != null ) { - break; - } - } - if ( value == null ) { - for ( Iterator it = this.defaultProps.iterator(); it.hasNext(); ) { - Properties props = (Properties) it.next(); - value = props.getProperty( key ); - if ( value != null ) { - break; - } - } - } + for (Iterator it = this.props.iterator(); it.hasNext() && value == null;) { + value = it.next().getProperty(key); + } + for (Iterator it = this.defaultProps.iterator(); it.hasNext() && value == null;) { + value = it.next().getProperty(key); + } return (value != null) ? value : defaultValue; } - public void mapStartsWith(Map map, + public void setProperty(String key, String value) { + for (Properties prop : props) { + if (prop.containsKey(key)) { + prop.setProperty(key, value); + } + } + } + + public String getProperty(String key) { + return getProperty(key, null); + } + + public void mapStartsWith(Map map, String startsWith, boolean includeSubProperties) { - for ( Iterator it = this.props.iterator(); it.hasNext(); ) { - Properties props = (Properties) it.next(); + for ( Iterator it = this.props.iterator(); it.hasNext(); ) { + Properties props = it.next(); mapStartsWith( map, props, startsWith, includeSubProperties ); } - for ( Iterator it = this.defaultProps.iterator(); it.hasNext(); ) { - Properties props = (Properties) it.next(); + for ( Iterator it = this.defaultProps.iterator(); it.hasNext(); ) { + Properties props = it.next(); mapStartsWith( map, props, startsWith, @@ -199,13 +199,13 @@ } } - private void mapStartsWith(Map map, + private void mapStartsWith(Map map, Properties properties, String startsWith, boolean includeSubProperties) { - Enumeration enumeration = properties.propertyNames(); - while ( enumeration.hasMoreElements() ) { - String key = (String) enumeration.nextElement(); + + for (Enumeration enumeration = properties.propertyNames(); enumeration.hasMoreElements(); ) { + String key = enumeration.nextElement().toString(); if ( key.startsWith( startsWith ) ) { if ( !includeSubProperties && key.substring( startsWith.length() + 1 ).indexOf( '.' ) > 0 ) { // +1 to the length, as we do allow the direct property, just not ones below it @@ -221,24 +221,24 @@ } } - private void loadProperties(Enumeration enumeration, - List chain) { + private void loadProperties(Enumeration enumeration, + List chain) { if ( enumeration == null ) { return; } while ( enumeration.hasMoreElements() ) { - URL url = (URL) enumeration.nextElement(); + URL url = enumeration.nextElement(); loadProperties( url, chain ); } } private void loadProperties(String fileName, - List chain) { + List chain) { if ( fileName != null ) { File file = new File( fileName ); - if ( file != null && file.exists() ) { + if ( file.exists() ) { try { loadProperties( file.toURL(), chain ); @@ -252,7 +252,7 @@ } private void loadProperties(URL confURL, - List chain) { + List chain) { if ( confURL == null ) { return; } @@ -261,6 +261,7 @@ properties.load( confURL.openStream() ); chain.add( properties ); } catch ( IOException e ) { + e.printStackTrace(); //throw new IllegalArgumentException( "Invalid URL to properties file '" + confURL.toExternalForm() + "'" ); } }