View Javadoc
1   /*
2    * Copyright 2012 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   * Type of a document entry.
27   * @author Dmytro Rud
28   */
29  @XmlType(name = "DocumentEntryType")
30  @XmlEnum(String.class)
31  public enum DocumentEntryType {
32      @XmlEnumValue("stable") STABLE("urn:uuid:7edca82f-054d-47f2-a032-9b2a5b5186c1"),
33      @XmlEnumValue("on-demand") ON_DEMAND("urn:uuid:34268e47-fdf5-41a6-ba33-82133c465248");
34  
35      public static final String[] STABLE_OR_ON_DEMAND = new String[] {
36              STABLE.getUuid(),
37              ON_DEMAND.getUuid(),
38      };
39  
40      private final String uuid;
41  
42      DocumentEntryType(String uuid) {
43          this.uuid = uuid;
44      }
45  
46      public String getUuid() {
47          return uuid;
48      }
49  
50      public static String toUuid(DocumentEntryType type) {
51          return (type != null) ? type.uuid : null;
52      }
53  
54      public static DocumentEntryType valueOfUuid(String uuid) {
55          for (DocumentEntryType type : DocumentEntryType.values()) {
56              if (type.uuid.equals(uuid)) {
57                  return type;
58              }
59          }
60  
61          throw new XDSMetaDataException(ValidationMessage.WRONG_DOCUMENT_ENTRY_TYPE, uuid);
62      }
63  }