View Javadoc

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 org.apache.commons.lang.StringUtils;
19  import org.dom4j.Node;
20  import org.rundeck.api.domain.RundeckAbort;
21  import org.rundeck.api.domain.RundeckExecution;
22  import org.rundeck.api.domain.RundeckAbort.AbortStatus;
23  
24  /**
25   * Parser for a single {@link RundeckAbort}
26   * 
27   * @author Vincent Behar
28   */
29  public class AbortParser implements XmlNodeParser<RundeckAbort> {
30  
31      private String xpath;
32  
33      public AbortParser() {
34          super();
35      }
36  
37      /**
38       * @param xpath of the abort element if it is not the root node
39       */
40      public AbortParser(String xpath) {
41          super();
42          this.xpath = xpath;
43      }
44  
45      @Override
46      public RundeckAbort parseXmlNode(Node node) {
47          Node abortNode = xpath != null ? node.selectSingleNode(xpath) : node;
48  
49          RundeckAbort abort = new RundeckAbort();
50  
51          try {
52              abort.setStatus(AbortStatus.valueOf(StringUtils.upperCase(abortNode.valueOf("@status"))));
53          } catch (IllegalArgumentException e) {
54          }
55  
56          Node execNode = abortNode.selectSingleNode("execution");
57          if (execNode != null) {
58              RundeckExecution execution = new ExecutionParser().parseXmlNode(execNode);
59              abort.setExecution(execution);
60          }
61  
62          return abort;
63      }
64  
65  }