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   * Lists all possible types of associations between two documents.
26   *
27   * @author Jens Riemschneider
28   */
29  @XmlType(name = "AssociationType")
30  @XmlEnum(String.class)
31  public enum AssociationType {
32      /** An entry that is appended to another one. */
33      @XmlEnumValue("APND") APPEND("APND", "urn:ihe:iti:2007:AssociationType:APND"),
34      /** An entry that replaced another one. */
35      @XmlEnumValue("RPLC") REPLACE("RPLC", "urn:ihe:iti:2007:AssociationType:RPLC"),
36      /** An entry that transforms another one. */
37      @XmlEnumValue("XFRM") TRANSFORM("XFRM", "urn:ihe:iti:2007:AssociationType:XFRM"),
38      /** An entry that transforms and replaces another one. */
39      @XmlEnumValue("XFRM_RPLC") TRANSFORM_AND_REPLACE("XFRM_RPLC", "urn:ihe:iti:2007:AssociationType:XFRM_RPLC"),
40      /** An entry that is a member of another one. */
41      @XmlEnumValue("HasMember") HAS_MEMBER("HasMember", "urn:oasis:names:tc:ebxml-regrep:AssociationType:HasMember"),
42      /** An entry that represents a signature of another one. */
43      @XmlEnumValue("signs") SIGNS("signs", "urn:ihe:iti:2007:AssociationType:signs"),
44      /** An entry that represents a link to the On-Demand DocumentEntry. */
45      @XmlEnumValue("IsSnapshotOf") IS_SNAPSHOT_OF("IsSnapshotOf", "urn:ihe:iti:2010:AssociationType:IsSnapshotOf"),
46      /** An entry that represents an association for update availability status trigger. */
47      @XmlEnumValue("UpdateAvailabilityStatus") UPDATE_AVAILABILITY_STATUS("UpdateAvailabilityStatus", "urn:ihe:iti:2010:AssociationType:UpdateAvailabilityStatus"),
48      /** An entry that represents an association for submit association trigger. */
49      @XmlEnumValue("SubmitAssociation") SUBMIT_ASSOCIATION("SubmitAssociation", "urn:ihe:iti:2010:AssociationType:SubmitAssociation");
50  
51      private final String opcode21;
52      private final String opcode30;
53  
54      AssociationType(String opcode21, String opcode30) {
55          this.opcode21 = opcode21;
56          this.opcode30 = opcode30;
57      }
58  
59      /**
60       * @return a string representation in ebXML 2.1.
61       */
62      public String getOpcode21() {
63          return opcode21;
64      }
65  
66      /**
67       * @return a string representation in ebXML 3.0.
68       */
69      public String getOpcode30() {
70          return opcode30;
71      }
72  
73      /**
74       * <code>null</code>-safe version of {@link #getOpcode21()}.
75       * @param type
76       *          the type for which to get the opcode. Can be <code>null</code>.
77       * @return the opcode or <code>null</code> if type was <code>null</code>.
78       */
79      public static String getOpcode21(AssociationType type) {
80          return type != null ? type.getOpcode21() : null;
81      }
82  
83      /**
84       * <code>null</code>-safe version of {@link #getOpcode30()}.
85       * @param type
86       *          the type for which to get the opcode. Can be <code>null</code>.
87       * @return the opcode or <code>null</code> if type was <code>null</code>.
88       */
89      public static String getOpcode30(AssociationType type) {
90          return type != null ? type.getOpcode30() : null;
91      }
92  
93      /**
94       * Returns the association type that is represented by the given opcode.
95       * <p>
96       * This method looks up the opcode via the ebXML 2.1 representations.
97       * @param opcode
98       *          the string representation. Can be <code>null</code>.
99       * @return the association type or <code>null</code> if the opcode was <code>null</code>.
100      */
101     public static AssociationType valueOfOpcode21(String opcode) {
102         if (opcode == null) {
103             return null;
104         }
105 
106         for (AssociationType type : AssociationType.values()) {
107             if (opcode.equals(type.getOpcode21())) {
108                 return type;
109             }
110         }
111 
112         throw new XDSMetaDataException(ValidationMessage.INVALID_ASSOCIATION_TYPE);
113     }
114 
115     /**
116      * Returns the association type that is represented by the given opcode.
117      * <p>
118      * This method looks up the opcode via the ebXML 3.0 representations.
119      * @param opcode
120      *          the string representation. Can be <code>null</code>.
121      * @return the association type or <code>null</code> if the opcode was <code>null</code>.
122      */
123     public static AssociationType valueOfOpcode30(String opcode) {
124         if (opcode == null) {
125             return null;
126         }
127 
128         for (AssociationType type : AssociationType.values()) {
129             if (opcode.equals(type.getOpcode30())) {
130                 return type;
131             }
132         }
133 
134         throw new XDSMetaDataException(ValidationMessage.INVALID_ASSOCIATION_TYPE);
135     }
136 
137     /**
138      * @return <code>true</code> if the association contains a replacement.
139      */
140     public boolean isReplace() {
141         return this == REPLACE || this == TRANSFORM_AND_REPLACE;
142     }
143 }