Revision: 20046
http://sourceforge.net/p/gate/code/20046
Author: markagreenwood
Date: 2017-02-01 10:10:20 +0000 (Wed, 01 Feb 2017)
Log Message:
-----------
when resources are persisted we now only save parameter values which differ
from the default values. this simplifies saved applications but also means that
if you upgrade a plugin etc. you'll be guaranteed to get the new behaviour
rather than possible an exception
Modified Paths:
--------------
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PRPersistence.java
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/ResourcePersistence.java
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
Modified:
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PRPersistence.java
===================================================================
---
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PRPersistence.java
2017-02-01 07:14:37 UTC (rev 20045)
+++
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PRPersistence.java
2017-02-01 10:10:20 UTC (rev 20046)
@@ -20,6 +20,7 @@
import gate.ProcessingResource;
import gate.Resource;
import gate.creole.Parameter;
+import gate.creole.ParameterException;
import gate.creole.ParameterList;
import gate.creole.ResourceData;
import gate.creole.ResourceInstantiationException;
@@ -65,12 +66,14 @@
Parameter parameter = parIter.next();
String parName = parameter.getName();
Object parValue = res.getParameterValue(parName);
- ((FeatureMap)runtimeParams).put(parName,parValue);
+ if (storeParameterValue(parValue, parameter.getDefaultValue())) {
+ ((FeatureMap)runtimeParams).put(parName,parValue);
+ }
}
}
runtimeParams = PersistenceManager.
getPersistentRepresentation(runtimeParams);
- }catch(ResourceInstantiationException rie){
+ }catch(ResourceInstantiationException | ParameterException rie){
throw new PersistenceException(rie);
}
}
Modified:
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/ResourcePersistence.java
===================================================================
---
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/ResourcePersistence.java
2017-02-01 07:14:37 UTC (rev 20045)
+++
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/ResourcePersistence.java
2017-02-01 10:10:20 UTC (rev 20046)
@@ -19,6 +19,7 @@
import gate.Gate;
import gate.Resource;
import gate.creole.Parameter;
+import gate.creole.ParameterException;
import gate.creole.ParameterList;
import gate.creole.ResourceData;
import gate.creole.ResourceInstantiationException;
@@ -69,7 +70,9 @@
Parameter parameter = parIter.next();
String parName = parameter.getName();
Object parValue = res.getParameterValue(parName);
- ((FeatureMap)initParams).put(parName, parValue);
+ if (storeParameterValue(parValue, parameter.getDefaultValue())) {
+ ((FeatureMap)initParams).put(parName, parValue);
+ }
}
}
initParams = PersistenceManager.getPersistentRepresentation(initParams);
@@ -80,12 +83,40 @@
((FeatureMap)features).putAll(res.getFeatures());
features = PersistenceManager.getPersistentRepresentation(features);
}
- }catch(ResourceInstantiationException rie){
+ }catch(ResourceInstantiationException | ParameterException rie){
throw new PersistenceException(rie);
}
}
+
+ /**
+ * Returns true if we should store the parameter value as it is
different
+ * from the default value.
+ *
+ * @param value
+ * the value we might store
+ * @param defaultValue
+ * the default value
+ * @return true if we should store the parameter value as it is
different
+ * from the default value, false otherwise
+ */
+ protected static boolean storeParameterValue(Object value, Object
defaultValue) {
+ // if both are null then we don't need to store the value
+ if (value == null && defaultValue == null)
+ return false;
+ // if only one of them is null then we do need to store
+ if (value == null || defaultValue == null)
+ return true;
+ // if neither are null and they are identical objects then we
don't need
+ // to store
+ if (value == defaultValue)
+ return false;
+
+ // only store if the two objects are truly differnet
+ return !value.equals(defaultValue);
+ }
+
@Override
public Object createObject()throws PersistenceException,
ResourceInstantiationException {
Modified:
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
===================================================================
---
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
2017-02-01 07:14:37 UTC (rev 20045)
+++
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
2017-02-01 10:10:20 UTC (rev 20046)
@@ -193,8 +193,8 @@
ResourceReference rr = new ResourceReference(txtFile.toURI());
checkPersistence(xgappFile, rr, "$relpath$test-file.txt");
- rr = new ResourceReference(creolePlugin,"resources/file.txt");
- checkPersistence(xgappFile, rr,
"creole://group;artifact;version/resources/file.txt");
+ rr = new ResourceReference(creolePlugin,"resources/test.txt");
+ checkPersistence(xgappFile, rr,
"creole://group;artifact;version/resources/test.txt");
rr = new ResourceReference(new
URL("http://gate.ac.uk/resource/file.txt"));
checkPersistence(xgappFile, rr, "http://gate.ac.uk/resource/file.txt");
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs