Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java @ 6933:468d9ebda4ce
Datacage: Add dc:all-state-successors() to enable predicates like dc:contains(dc:all-state-successors($artifact-name, $current-state-id), 'state.winfo.calculation_mode') which recursively collects all successor state ids an check for containment.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Tue, 27 Aug 2013 19:14:12 +0200 |
parents | 00aa1bc72a65 |
children | 1dff8e71c4d6 |
comparison
equal
deleted
inserted
replaced
6932:b78d110135ec | 6933:468d9ebda4ce |
---|---|
8 | 8 |
9 package org.dive4elements.river.artifacts.datacage.templating; | 9 package org.dive4elements.river.artifacts.datacage.templating; |
10 | 10 |
11 import java.text.SimpleDateFormat; | 11 import java.text.SimpleDateFormat; |
12 import java.util.Collection; | 12 import java.util.Collection; |
13 import java.util.Collections; | |
13 import java.util.Date; | 14 import java.util.Date; |
14 import java.util.List; | 15 import java.util.List; |
15 import java.util.Map; | 16 import java.util.Map; |
16 import java.util.HashMap; | 17 import java.util.HashMap; |
18 import java.util.Set; | |
17 | 19 |
18 import java.lang.reflect.InvocationTargetException; | 20 import java.lang.reflect.InvocationTargetException; |
19 import java.lang.reflect.Method; | 21 import java.lang.reflect.Method; |
20 | 22 |
21 import javax.xml.namespace.QName; | 23 import javax.xml.namespace.QName; |
23 import javax.xml.xpath.XPathFunction; | 25 import javax.xml.xpath.XPathFunction; |
24 import javax.xml.xpath.XPathFunctionException; | 26 import javax.xml.xpath.XPathFunctionException; |
25 import javax.xml.xpath.XPathFunctionResolver; | 27 import javax.xml.xpath.XPathFunctionResolver; |
26 | 28 |
27 import org.apache.log4j.Logger; | 29 import org.apache.log4j.Logger; |
30 import org.dive4elements.artifactdatabase.transition.TransitionEngine; | |
31 import org.dive4elements.artifacts.GlobalContext; | |
32 import org.dive4elements.river.artifacts.context.RiverContext; | |
33 import org.dive4elements.river.artifacts.context.RiverContextFactory; | |
28 | 34 |
29 | 35 |
30 /** Resolves functions (e.g. dc:contains) in Datacage/Meta-Data system. */ | 36 /** Resolves functions (e.g. dc:contains) in Datacage/Meta-Data system. */ |
31 public class FunctionResolver | 37 public class FunctionResolver |
32 implements XPathFunctionResolver | 38 implements XPathFunctionResolver |
147 if (o instanceof String) { | 153 if (o instanceof String) { |
148 return FunctionResolver.this.buildHelper.frames.getNull( | 154 return FunctionResolver.this.buildHelper.frames.getNull( |
149 (String)o, StackFrames.NULL); | 155 (String)o, StackFrames.NULL); |
150 } | 156 } |
151 return StackFrames.NULL; | 157 return StackFrames.NULL; |
158 } | |
159 }); | |
160 | |
161 addFunction("all-state-successors", 2, new XPathFunction() { | |
162 @Override | |
163 public Object evaluate(List args) throws XPathFunctionException { | |
164 Object artifactName = args.get(0); | |
165 Object stateId = args.get(1); | |
166 | |
167 return artifactName instanceof String | |
168 && stateId instanceof String | |
169 ? allStateSuccessors((String)artifactName, (String)stateId) | |
170 : Collections.<String>emptySet(); | |
152 } | 171 } |
153 }); | 172 }); |
154 } | 173 } |
155 | 174 |
156 /** | 175 /** |
376 throw new XPathFunctionException(iae); | 395 throw new XPathFunctionException(iae); |
377 } | 396 } |
378 } | 397 } |
379 return ""; | 398 return ""; |
380 } | 399 } |
400 | |
401 public Set<String> allStateSuccessors(String artifactName, String stateId) { | |
402 GlobalContext gc = RiverContextFactory.getGlobalContext(); | |
403 if (gc == null) { | |
404 return Collections.<String>emptySet(); | |
405 } | |
406 Object o = gc.get(RiverContext.TRANSITION_ENGINE_KEY); | |
407 if (o instanceof TransitionEngine) { | |
408 TransitionEngine te = (TransitionEngine)o; | |
409 return te.allRecursiveSuccessorStateIds(artifactName, stateId); | |
410 } | |
411 return Collections.<String>emptySet(); | |
412 } | |
381 } | 413 } |
382 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 414 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |