View Javadoc

1   /*
2    * Copyright 2006 Outsource Cafe, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the 'License')
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an 'AS IS' BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }