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.metadata;
17  
18  import javax.xml.bind.annotation.XmlEnum;
19  import javax.xml.bind.annotation.XmlEnumValue;
20  import javax.xml.bind.annotation.XmlType;
21  /**
22   * Describes the availability of an entry.
23   * 
24   * @author Jens Riemschneider
25   */
26  @XmlType(name = "AvailabilityStatus")
27  @XmlEnum(String.class)
28  public enum AvailabilityStatus {
29      /** The entry is approved. */
30      @XmlEnumValue("Approved") APPROVED("Approved", "urn:oasis:names:tc:ebxml-regrep:StatusType:Approved"),
31      /** The entry is deprecated. */
32      @XmlEnumValue("Deprecated") DEPRECATED("Deprecated", "urn:oasis:names:tc:ebxml-regrep:StatusType:Deprecated"),
33      /** The entry is submitted. */
34      @XmlEnumValue("Submitted") SUBMITTED("Submitted", "urn:oasis:names:tc:ebxml-regrep:StatusType:Submitted");
35      
36      private final String opcode;
37      private final String queryOpcode;
38  
39      /**
40       * @return the opcode used as a string representation in non-query transformations.
41       */
42      public String getOpcode() {
43          return opcode;
44      }
45      
46      /**
47       * @return the opcode used as a string representation in transformations for query 
48       *          requests and responses.
49       */
50      public String getQueryOpcode() {
51          return queryOpcode;
52      }
53  
54      AvailabilityStatus(String opcode, String queryOpcode) {
55          this.opcode = opcode;
56          this.queryOpcode = queryOpcode;
57      }
58  
59      /**
60       * Returns the availability status represented by the given opcode.
61       * This method takes standard opcodes and query opcodes into account.
62       * @param opcode
63       *          the opcode to look up. Can be <code>null</code>.
64       * @return the status. <code>null</code> if the opcode was <code>null</code>
65       *          or could not be found.
66       *          <br>See ITI TF v.8.0 Vol. 2a Section 3.18.4.1.2.3.6.
67       */
68      public static AvailabilityStatus valueOfOpcode(String opcode) {
69          if (opcode == null) {
70              return null;
71          }
72          
73          for (AvailabilityStatus status : AvailabilityStatus.values()) {
74              if (opcode.equals(status.getOpcode()) || opcode.equals(status.getQueryOpcode())) {
75                  return status;
76              }
77          }
78          
79          return null;
80      }
81  
82      /**
83       * Retrieves the representation of a given status.
84       * <p>
85       * This is a <code>null</code>-safe version of {@link #getOpcode()}.
86       * @param status
87       *          the status. Can be <code>null</code>.
88       * @return the representation or <code>null</code> if the status was <code>null</code>.
89       */
90      public static String toOpcode(AvailabilityStatus status) {
91          return status != null ? status.getOpcode() : null;
92      }
93  
94      /**
95       * Retrieves the query representation of a given status.
96       * <p>
97       * This is a <code>null</code>-safe version of {@link #getQueryOpcode()}.
98       * @param status
99       *          the status. Can be <code>null</code>.
100      * @return the representation or <code>null</code> if the status was <code>null</code>.
101      */
102     public static String toQueryOpcode(AvailabilityStatus status) {
103         return status != null ? status.getQueryOpcode() : null;
104     }
105 }