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 extends BaseXpathParser<RundeckAbort>  {
30  
31      public AbortParser(final String xpath) {
32          super(xpath);
33      }
34  
35      @Override
36      public RundeckAbort parse(Node abortNode) {
37          RundeckAbort abort = new RundeckAbort();
38  
39          try {
40              abort.setStatus(AbortStatus.valueOf(StringUtils.upperCase(abortNode.valueOf("@status"))));
41          } catch (IllegalArgumentException e) {
42              abort.setStatus(null);
43          }
44  
45          Node execNode = abortNode.selectSingleNode("execution");
46          if (execNode != null) {
47              RundeckExecution execution = new ExecutionParser().parseXmlNode(execNode);
48              abort.setExecution(execution);
49          }
50  
51          return abort;
52      }
53  
54  }