View Javadoc
1   package ca.uhn.fhir.model.api;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 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  
26  public abstract class BaseIdentifiableElement extends BaseElement implements IIdentifiableElement {
27  
28  	private String myElementSpecificId;
29  
30  	@Override
31  	public String getElementSpecificId() {
32  		return myElementSpecificId;
33  	}
34  
35  	/**
36  	 * @deprecated Use {@link #getElementSpecificId()} instead. This method will be removed because it is easily
37  	 *             confused with other ID methods (such as patient#getIdentifier)
38  	 */
39  	@Override
40  	public IdDt getId() {
41  		if (myElementSpecificId == null) {
42  			return new LockedId();
43  		} else {
44  			return new LockedId(myElementSpecificId);
45  		}
46  	}
47  
48  	@Override
49  	public void setElementSpecificId(String theElementSpecificId) {
50  		myElementSpecificId = theElementSpecificId;
51  	}
52  
53  	/**
54  	 * @deprecated Use {@link #setElementSpecificId(String)} instead. This method will be removed because it is easily
55  	 *             confused with other ID methods (such as patient#getIdentifier)
56  	 */
57  	@Override
58  	public void setId(IdDt theId) {
59  		if (theId == null) {
60  			myElementSpecificId = null;
61  		} else {
62  			myElementSpecificId = theId.getValue();
63  		}
64  	}
65  
66  	/**
67  	 * @deprecated Use {@link #setElementSpecificId(String)} instead. This method will be removed because it is easily
68  	 *             confused with other ID methods (such as patient#getIdentifier)
69  	 */
70  	@Override
71  	public void setId(String theId) {
72  		myElementSpecificId = theId;
73  	}
74  
75  	private static class LockedId extends IdDt {
76  
77  		public LockedId() {
78  		}
79  
80  		public LockedId(String theElementSpecificId) {
81  			super(theElementSpecificId);
82  		}
83  
84  		@Override
85  		public void setValue(String theValue) throws DataFormatException {
86  			throw new UnsupportedOperationException("Use IElement#setElementSpecificId(String) to set the element ID for an element");
87  		}
88  
89  		@Override
90  		public void setValueAsString(String theValue) throws DataFormatException {
91  			throw new UnsupportedOperationException("Use IElement#setElementSpecificId(String) to set the element ID for an element");
92  		}
93  
94  	}
95  
96  }