Mercurial > dive4elements > river
changeset 1176:28154920e0b3
Introduced the possibility for States to transform/modify input before the data is added to FLYSArtifact.
flys-artifacts/trunk@2761 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 15 Sep 2011 15:05:24 +0000 |
parents | e6b513495281 |
children | 70b8ac64404b |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java |
diffstat | 3 files changed, 36 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Sep 15 15:00:23 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Sep 15 15:05:24 2011 +0000 @@ -1,3 +1,15 @@ +2011-09-15 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/states/DefaultState.java: + Added a transform() method. This method should be used to transform + input data in form of a string into a better data structure. This state + provides a simple implementation which just returns a StateData object + that contains exactly the input string. + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Transform + input strings using DefaultState.transform() before they are added to + its data pool. + 2011-09-15 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Thu Sep 15 15:00:23 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Thu Sep 15 15:05:24 2011 +0000 @@ -558,6 +558,8 @@ String uri = ArtifactNamespaceContext.NAMESPACE_URI; + DefaultState current = (DefaultState) getCurrentState(context); + for (int i = 0; i < count; i++) { Element node = (Element)nodes.item(i); @@ -567,11 +569,10 @@ if (name.length() > 0 && value.length() > 0) { logger.debug("Save data item for '" + name + "' : " + value); - addData(name, new DefaultStateData(name, null, null, value)); + addData(name, current.transform(this, context, name, value)); } } - DefaultState current = (DefaultState) getCurrentState(context); current.validate(this); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java Thu Sep 15 15:00:23 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java Thu Sep 15 15:05:24 2011 +0000 @@ -22,6 +22,7 @@ import de.intevation.artifactdatabase.ProtocolUtils; +import de.intevation.artifactdatabase.data.DefaultStateData; import de.intevation.artifactdatabase.data.StateData; import de.intevation.artifactdatabase.state.AbstractState; @@ -259,6 +260,26 @@ /** + * This method transform a given value into a StateData object. + * + * @param flys The FLYSArtifact. + * @param name The name of the data object. + * @param val The value of the data object. + * + * @return a StateData object with <i>name</i> and <i>val</i>ue. + */ + public StateData transform( + FLYSArtifact flys, + CallContext cc, + String name, + String val + ) { + logger.debug("Transform data ('" + name + "','" + val + "')"); + return new DefaultStateData(name, null, null, val); + } + + + /** * This method validates the inserted data and returns true, if everything * was correct, otherwise an exception is thrown. *