001/* 002 * #%L 003 * HAPI FHIR - Core Library 004 * %% 005 * Copyright (C) 2014 - 2023 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.context; 021 022import java.lang.reflect.Field; 023import java.util.Collections; 024import java.util.Map; 025import java.util.Set; 026 027import org.hl7.fhir.instance.model.api.IBase; 028import org.hl7.fhir.instance.model.api.IBaseResource; 029 030import ca.uhn.fhir.model.api.annotation.Child; 031import ca.uhn.fhir.model.api.annotation.Description; 032 033public class RuntimeChildDirectResource extends BaseRuntimeDeclaredChildDefinition { 034 035// private RuntimeElemContainedResources myElem; 036 private FhirContext myContext; 037 038 RuntimeChildDirectResource(Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName) throws ConfigurationException { 039 super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName); 040 } 041 042 @Override 043 public BaseRuntimeElementDefinition<?> getChildByName(String theName) { 044 return new RuntimeElementDirectResource(false); 045 } 046 047 @SuppressWarnings("unchecked") 048 @Override 049 public BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theType) { 050 return myContext.getResourceDefinition((Class<? extends IBaseResource>) theType); 051 } 052 053 @Override 054 public String getChildNameByDatatype(Class<? extends IBase> theDatatype) { 055 return getElementName(); 056 } 057 058 @Override 059 public Set<String> getValidChildNames() { 060 return Collections.singleton(getElementName()); 061 } 062 063 @Override 064 void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) { 065 myContext = theContext; 066 } 067 068}