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 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  /**
26   * Association labeling values used for the associations of submission sets.
27   * @author Jens Riemschneider
28   */
29  @XmlType(name = "AssociationLabel")
30  @XmlEnum(String.class)
31  public enum AssociationLabel {
32      /** Label for associations to documents that are contained in the request. */
33      @XmlEnumValue("Original") ORIGINAL("Original"),
34      /** Label for associations to documents that are only referenced in the request. */
35      @XmlEnumValue("Reference") REFERENCE("Reference");
36      
37      private final String opcode;
38  
39      AssociationLabel(String opcode) {
40          this.opcode = opcode;
41      }
42  
43      /**
44       * @return the opcode representing the association in ebXML.
45       */
46      public String getOpcode() {
47          return opcode;
48      }
49      
50      /**
51       * Null-safe version of {@link #getOpcode()}.
52       * @param label
53       *          the label. Cane be <code>null</code>.
54       * @return the opcode of the label. <code>null</code> if the input was <code>null</code>.
55       */
56      public static String toOpcode(AssociationLabel label) {
57          if (label == null) {
58              return null;
59          }
60          
61          return label.getOpcode();
62      }
63      
64      /**
65       * Returns the association label that is represented by the given opcode.
66       * @param opcode
67       *          the opcode to look for. Can be <code>null</code>.
68       * @return the label. <code>null</code> if the input was <code>null</code>.
69       */
70      public static AssociationLabel fromOpcode(String opcode) {
71          if (opcode == null) {
72              return null;
73          }
74  
75          for (AssociationLabel label : AssociationLabel.values()) {
76              if (opcode.equals(label.getOpcode())) {
77                  return label;
78              }
79          }
80          
81          throw new XDSMetaDataException(ValidationMessage.INVALID_SUBMISSION_SET_STATUS);
82      }
83  }