View Javadoc
1   package ca.uhn.fhir.model.api;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.model.primitive.IdDt;
24  import ca.uhn.fhir.parser.DataFormatException;
25  import ca.uhn.fhir.util.CoverageIgnore;
26  
27  public abstract class BaseIdentifiableElement extends BaseElement implements IIdentifiableElement {
28  
29  	private static final long serialVersionUID = -7816838417076777914L;
30  	private String myElementSpecificId;
31  
32  	@Override
33  	public String getElementSpecificId() {
34  		return myElementSpecificId;
35  	}
36  
37  	/**
38  	 * @deprecated Use {@link #getElementSpecificId()} instead. This method will be removed because it is easily
39  	 *             confused with other ID methods (such as patient#getIdentifier)
40  	 */
41  	@CoverageIgnore
42  	@Deprecated
43  	@Override
44  	public IdDt getId() {
45  		if (myElementSpecificId == null) {
46  			return new LockedId();
47  		}
48  		return new LockedId(myElementSpecificId);
49  	}
50  
51  	@Override
52  	public void setElementSpecificId(String theElementSpecificId) {
53  		myElementSpecificId = theElementSpecificId;
54  	}
55  
56  	/**
57  	 * @deprecated Use {@link #setElementSpecificId(String)} instead. This method will be removed because it is easily
58  	 *             confused with other ID methods (such as patient#getIdentifier)
59  	 */
60  	@CoverageIgnore
61  	@Deprecated
62  	@Override
63  	public void setId(IdDt theId) {
64  		if (theId == null) {
65  			myElementSpecificId = null;
66  		} else {
67  			myElementSpecificId = theId.getValue();
68  		}
69  	}
70  
71  	/**
72  	 * @deprecated Use {@link #setElementSpecificId(String)} instead. This method will be removed because it is easily
73  	 *             confused with other ID methods (such as patient#getIdentifier)
74  	 */
75  	@CoverageIgnore
76  	@Override
77  	@Deprecated
78  	public void setId(String theId) {
79  		myElementSpecificId = theId;
80  	}
81  
82  	@CoverageIgnore
83  	private static class LockedId extends IdDt {
84  
85  		@CoverageIgnore
86  		public LockedId() {
87  		}
88  
89  		@CoverageIgnore
90  		public LockedId(String theElementSpecificId) {
91  			super(theElementSpecificId);
92  		}
93  
94  		@Override
95  		@CoverageIgnore
96  		public IdDt setValue(String theValue) throws DataFormatException {
97  			throw new UnsupportedOperationException("Use IElement#setElementSpecificId(String) to set the element ID for an element");
98  		}
99  
100 		@Override
101 		@CoverageIgnore
102 		public void setValueAsString(String theValue) throws DataFormatException {
103 			throw new UnsupportedOperationException("Use IElement#setElementSpecificId(String) to set the element ID for an element");
104 		}
105 
106 	}
107 
108 }