001package ca.uhn.fhir.model.api;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2016 University Health Network
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.model.primitive.IdDt;
024import ca.uhn.fhir.parser.DataFormatException;
025
026public abstract class BaseIdentifiableElement extends BaseElement implements IIdentifiableElement {
027
028        private String myElementSpecificId;
029
030        @Override
031        public String getElementSpecificId() {
032                return myElementSpecificId;
033        }
034
035        /**
036         * @deprecated Use {@link #getElementSpecificId()} instead. This method will be removed because it is easily
037         *             confused with other ID methods (such as patient#getIdentifier)
038         */
039        @Deprecated
040        @Override
041        public IdDt getId() {
042                if (myElementSpecificId == null) {
043                        return new LockedId();
044                } else {
045                        return new LockedId(myElementSpecificId);
046                }
047        }
048
049        @Override
050        public void setElementSpecificId(String theElementSpecificId) {
051                myElementSpecificId = theElementSpecificId;
052        }
053
054        /**
055         * @deprecated Use {@link #setElementSpecificId(String)} instead. This method will be removed because it is easily
056         *             confused with other ID methods (such as patient#getIdentifier)
057         */
058        @Deprecated
059        @Override
060        public void setId(IdDt theId) {
061                if (theId == null) {
062                        myElementSpecificId = null;
063                } else {
064                        myElementSpecificId = theId.getValue();
065                }
066        }
067
068        /**
069         * @deprecated Use {@link #setElementSpecificId(String)} instead. This method will be removed because it is easily
070         *             confused with other ID methods (such as patient#getIdentifier)
071         */
072        @Override
073        @Deprecated
074        public void setId(String theId) {
075                myElementSpecificId = theId;
076        }
077
078        private static class LockedId extends IdDt {
079
080                public LockedId() {
081                }
082
083                public LockedId(String theElementSpecificId) {
084                        super(theElementSpecificId);
085                }
086
087                @Override
088                public IdDt setValue(String theValue) throws DataFormatException {
089                        throw new UnsupportedOperationException("Use IElement#setElementSpecificId(String) to set the element ID for an element");
090                }
091
092                @Override
093                public void setValueAsString(String theValue) throws DataFormatException {
094                        throw new UnsupportedOperationException("Use IElement#setElementSpecificId(String) to set the element ID for an element");
095                }
096
097        }
098
099}