View Javadoc
1   package ca.uhn.fhir.context;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 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 java.util.List;
24  import java.util.Map;
25  import java.util.Set;
26  import java.util.Map.Entry;
27  
28  import org.hl7.fhir.instance.model.api.IBase;
29  import org.hl7.fhir.instance.model.api.IBaseReference;
30  
31  public abstract class BaseRuntimeChildDefinition {
32  
33  	public abstract IAccessor getAccessor();
34  
35  	public abstract BaseRuntimeElementDefinition<?> getChildByName(String theName);
36  
37  	public abstract BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theType);
38  
39  	public abstract String getChildNameByDatatype(Class<? extends IBase> theDatatype);
40  
41  	public abstract String getElementName();
42  
43  	public String getExtensionUrl() {
44  		return null;
45  	}
46  
47  	public Object getInstanceConstructorArguments() {
48  		return null;
49  	}
50  
51  	public abstract int getMax();
52  
53  	public abstract int getMin();
54  
55  	public abstract IMutator getMutator();
56  
57  	public abstract Set<String> getValidChildNames();
58  
59  	public abstract boolean isSummary();
60  
61  	abstract void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions);
62  
63  	@Override
64  	public String toString() {
65  		return getClass().getSimpleName() + "[" + getElementName() + "]";
66  	}
67  
68  	public interface IAccessor {
69  		List<IBase> getValues(Object theTarget);
70  	}
71  
72  	public interface IMutator {
73  		void addValue(Object theTarget, IBase theValue);
74  
75  		void setValue(Object theTarget, IBase theValue);
76  	}
77  
78  	BaseRuntimeElementDefinition<?> findResourceReferenceDefinition(Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
79  		for (Entry<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> next : theClassToElementDefinitions.entrySet()) {
80  			if (IBaseReference.class.isAssignableFrom(next.getKey())) {
81  				return next.getValue();
82  			}
83  		}
84  		
85  		// Shouldn't happen
86  		throw new IllegalStateException("Unable to find reference type");
87  	}
88  
89  	// public String getExtensionUrl() {
90  	// return null;
91  	// }
92  }