From: <sha...@us...> - 2011-09-01 04:22:18
|
Revision: 3203 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3203&view=rev Author: shadowtm Date: 2011-09-01 04:22:12 +0000 (Thu, 01 Sep 2011) Log Message: ----------- Added Map support for the prefix post processing logic. Modified Paths: -------------- trunk/interfaces/pom.xml trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf Modified: trunk/interfaces/pom.xml =================================================================== --- trunk/interfaces/pom.xml 2011-09-01 03:50:09 UTC (rev 3202) +++ trunk/interfaces/pom.xml 2011-09-01 04:22:12 UTC (rev 3203) @@ -187,7 +187,6 @@ <exclude>org/dllearner/test/SpringTest.java</exclude> <exclude>org/dllearner/test/junit/GeizhalsTest.java</exclude> <exclude>org/dllearner/cli/MoosiqueCLITest.java</exclude> - <exclude>org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java</exclude> </excludes> </configuration> </plugin> Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java 2011-09-01 03:50:09 UTC (rev 3202) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java 2011-09-01 04:22:12 UTC (rev 3203) @@ -63,7 +63,7 @@ } } else if(valueObject instanceof Map) { - throw new Error("Map post processing not implemented yet"); + valueObject = processStringMap(prefixes, (Map)valueObject); } else if(valueObject instanceof Collection){ processStringCollection(prefixes, (Collection<?>) valueObject); } else if(valueObject instanceof Boolean || valueObject instanceof Integer || valueObject instanceof Double) { @@ -74,10 +74,38 @@ option.setValueObject(valueObject); } - } - } + } + } - private void processStringCollection(Map<String,String> prefixes, Collection valueObject) { + + private Map processStringMap(Map<String, String> prefixes, Map inputMap) { + + Map newMap = new HashMap(); + + /** This does the values */ + for (Object keyObject : inputMap.keySet()) { + Object key = keyObject; + Object value = inputMap.get(key); + + if (keyObject instanceof String) { + String keyString = (String) keyObject; + if (value instanceof String) { + String valueString = (String) value; + for (String prefix : prefixes.keySet()) { + value = valueString.replaceAll(prefix + ":", prefixes.get(prefix)); + key = keyString.replaceAll(prefix + ":", prefixes.get(prefix)); + + } + } + } + newMap.put(key, value); + } + + return newMap; + + } + + private void processStringCollection(Map<String, String> prefixes, Collection valueObject) { Map<String, String> oldNewStringValues = new HashMap<String, String>(); Iterator itr = valueObject.iterator(); while (itr.hasNext()) { @@ -85,7 +113,7 @@ Object nextObject = itr.next(); if (nextObject instanceof String) { String oldValue = (String) nextObject; - String newValue = oldValue.replaceAll( prefix + ":", prefixes.get(prefix)); + String newValue = oldValue.replaceAll(prefix + ":", prefixes.get(prefix)); oldNewStringValues.put(oldValue, newValue); } } Modified: trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java 2011-09-01 03:50:09 UTC (rev 3202) +++ trunk/interfaces/src/test/java/org/dllearner/configuration/spring/ConfigurationBasedPropertyOverrideConfigurerTest.java 2011-09-01 04:22:12 UTC (rev 3203) @@ -72,6 +72,7 @@ Assert.assertEquals(thirdBean.getIntValue(), (Integer) 3); TestBean fourthBean = thirdBean.getComponent(); validateFourthBean(fourthBean); + Assert.assertTrue(thirdBean.getMapValue().get("http://localhost/foo#f").equals("http://localhost/foo#g")); } private void validateFirstBean(TestBean testBean) { Modified: trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf =================================================================== --- trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf 2011-09-01 03:50:09 UTC (rev 3202) +++ trunk/interfaces/src/test/resources/org/dllearner/configuration/spring/configurationBasedPropertyOverrideConfigurer.conf 2011-09-01 04:22:12 UTC (rev 3203) @@ -28,8 +28,8 @@ thirdBean.intValue=3 thirdBean.component=fourthBean +thirdBean.mapValue=[("kb:f","kb:g")] - fourthBean.simpleValue="Fourth Bean - not specified in xml" fourthBean.type="org.dllearner.configuration.spring.TestBean" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |