001package org.hl7.fhir.r5.patterns;
002
003/*-
004 * #%L
005 * org.hl7.fhir.r5
006 * %%
007 * Copyright (C) 2014 - 2019 Health Level 7
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
023
024import java.util.List;
025
026import org.hl7.fhir.r5.model.Annotation;
027import org.hl7.fhir.r5.model.Base;
028import org.hl7.fhir.r5.model.DomainResource;
029import org.hl7.fhir.r5.model.Element;
030import org.hl7.fhir.r5.model.Extension;
031import org.hl7.fhir.r5.model.Resource;
032
033public class PatternBaseImpl implements PatternBase {
034
035  private Base wrapped;
036  
037  public PatternBaseImpl(Base wrapped) {
038    super();
039    this.wrapped = wrapped;
040  }
041
042  @Override
043  public String getId() {
044    if (wrapped instanceof Element)
045      return ((Element) wrapped).getId();
046    if (wrapped instanceof Resource)
047      return ((Resource) wrapped).getId();
048    return null;
049  }
050
051  @Override
052  public PatternBase setId(String value) {
053    if (wrapped instanceof Element)
054      ((Element) wrapped).setId(value);
055    else if (wrapped instanceof Resource)
056      ((Resource) wrapped).setId(value);
057    else
058      throw new Error("this should not happen? wrapped = "+wrapped.getClass().getName());
059    return this;
060  }
061
062  @Override
063  public List<Extension> getExtension() {
064    if (wrapped instanceof Element)
065      return ((Element) wrapped).getExtension();
066    if (wrapped instanceof DomainResource)
067      return ((DomainResource) wrapped).getExtension();
068    return null;
069  }
070
071
072  protected Annotation convertStringToAnnotation(String value) {
073    if (value == null)
074      return null;
075    else
076      return new Annotation().setText(value);
077  }
078  
079  protected String convertAnnotationToString(Annotation value) {
080    if (value == null)
081      return null;
082    else
083      return value.getText();
084  }
085
086
087}