1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.javagen.agile.core;
17
18 import org.javagen.agile.core.model.Model;
19 import org.javagen.agile.core.util.ModelUtil;
20
21 /***
22 * Using the <code>input</code> node as a starting point, traverses the model tree using
23 * the XPath-like path and returns the result as output.
24 * <p>
25 *
26 * @see ModelUtil for path language syntax
27 * @author Richard Easterling
28 */
29 public class ModelPath implements Generator {
30
31 private Model explicitResult;
32 private String resultPath;
33
34 public void setExplicitResult(Model explicitResult) {
35 this.explicitResult = explicitResult;
36 }
37
38 public void setResultPath(String resultPath) {
39 this.resultPath = resultPath;
40 }
41
42 public Model gen(Model input) {
43 if (explicitResult!=null)
44 return explicitResult;
45 else if (resultPath!=null)
46 return ModelUtil.modelPath(input, resultPath);
47 else
48 return input;
49 }
50
51 }