View Javadoc
1   /*
2    * Copyright 2009 the original author or authors.
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.openehealth.ipf.commons.ihe.xds.core.responses;
17  
18  import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage;
19  import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;
20  
21  import javax.xml.bind.annotation.XmlEnum;
22  import javax.xml.bind.annotation.XmlEnumValue;
23  import javax.xml.bind.annotation.XmlType;
24  /**
25   * Severities defined by the XDS specification.
26   * @author Jens Riemschneider
27   */
28  @XmlType(name = "Severity")
29  @XmlEnum(String.class)
30  public enum Severity {
31      /** An error. */
32      @XmlEnumValue("Error") ERROR("urn:oasis:names:tc:ebxml-regrep:ErrorSeverityType:Error"),
33      /** A warning. */
34      @XmlEnumValue("Warning") WARNING("urn:oasis:names:tc:ebxml-regrep:ErrorSeverityType:Warning");
35  
36      private final String opcode30;
37      
38      Severity(String opcode30) {
39          this.opcode30 = opcode30;
40      }
41  
42      /**
43       * @return a string representation in ebXML 3.1.
44       */
45      public String getOpcode30() {
46          return opcode30;
47      }
48  
49      /**
50       * <code>null</code>-safe version of {@link #getOpcode30()}.
51       * @param severity
52       *          the type for which to get the opcode. Can be <code>null</code>.
53       * @return the opcode or <code>null</code> if type was <code>null</code>.
54       */
55      public static String getOpcode30(Severity severity) {
56          return severity != null ? severity.getOpcode30() : null;
57      }
58      
59      /**
60       * Returns the severity that is represented by the given opcode.
61       * <p>
62       * This method looks up the opcode via the ebXML 3.0 representation.
63       * @param opcode30
64       *          the string representation. Can be <code>null</code>.
65       * @return the severity.
66       */
67      public static Severity valueOfOpcode30(String opcode30) {
68          for (Severity severity : values()) {
69              if (severity.getOpcode30().equals(opcode30)) {
70                  return severity;
71              }
72          }
73          
74          throw new XDSMetaDataException(ValidationMessage.INVALID_SEVERITY_IN_RESPONSE);
75      }
76  
77  }