1 /*
2 * Copyright 2011 Vincent Behar
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.rundeck.api.parser;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import org.dom4j.Node;
21 import org.rundeck.api.domain.RundeckExecution;
22
23 /**
24 * Parser for a {@link List} of {@link RundeckExecution}
25 *
26 * @author Vincent Behar
27 */
28 public class ExecutionsParser implements XmlNodeParser<List<RundeckExecution>> {
29
30 private final String xpath;
31
32 /**
33 * @param xpath of the executions elements
34 */
35 public ExecutionsParser(String xpath) {
36 super();
37 this.xpath = xpath;
38 }
39
40 @Override
41 public List<RundeckExecution> parseXmlNode(Node node) {
42 List<RundeckExecution> executions = new ArrayList<RundeckExecution>();
43
44 @SuppressWarnings("unchecked")
45 List<Node> execNodes = node.selectNodes(xpath);
46
47 for (Node execNode : execNodes) {
48 RundeckExecution execution = new ExecutionParser().parseXmlNode(execNode);
49 executions.add(execution);
50 }
51
52 return executions;
53 }
54
55 }