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; 028 029import ca.uhn.fhir.model.api.annotation.Child; 030import ca.uhn.fhir.model.api.annotation.Description; 031 032public class RuntimeChildResourceBlockDefinition extends BaseRuntimeDeclaredChildDefinition { 033 034// private RuntimeResourceBlockDefinition myElementDef; 035 private Class<? extends IBase> myResourceBlockType; 036 private FhirContext myContext; 037 038 public RuntimeChildResourceBlockDefinition(FhirContext theContext, Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName, Class<? extends IBase> theResourceBlockType) throws ConfigurationException { 039 super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName); 040 myContext = theContext; 041 myResourceBlockType = theResourceBlockType; 042 } 043 044 @Override 045 public BaseRuntimeElementCompositeDefinition getChildByName(String theName) { 046 if (getElementName().equals(theName)) { 047 return getDefinition(); 048 } 049 return null; 050 } 051 052 private BaseRuntimeElementCompositeDefinition getDefinition() { 053 return (BaseRuntimeElementCompositeDefinition) myContext.getElementDefinition(myResourceBlockType); 054 } 055 056 @Override 057 public String getChildNameByDatatype(Class<? extends IBase> theDatatype) { 058 if (myResourceBlockType.equals(theDatatype)) { 059 return getElementName(); 060 } 061 return null; 062 } 063 064 @Override 065 public BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theDatatype) { 066 if (myResourceBlockType.equals(theDatatype)) { 067 return getDefinition(); 068 } 069 return null; 070 } 071 072 @Override 073 public Set<String> getValidChildNames() { 074 return Collections.singleton(getElementName()); 075 } 076 077 @Override 078 void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) { 079// myElementDef = (RuntimeResourceBlockDefinition) theClassToElementDefinitions.get(myResourceBlockType); 080 } 081 082}