Example usage for java.lang.reflect Field getDeclaringClass

List of usage examples for java.lang.reflect Field getDeclaringClass

Introduction

In this page you can find the example usage for java.lang.reflect Field getDeclaringClass.

Prototype

@Override
public Class<?> getDeclaringClass() 

Source Link

Document

Returns the Class object representing the class or interface that declares the field represented by this Field object.

Usage

From source file:org.evosuite.testcase.TestCodeVisitor.java

/**
 * <p>//from   www .  j av a  2 s  .c o  m
 * visitPrimitiveFieldAssertion
 * </p>
 * 
 * @param assertion
 *            a {@link org.evosuite.assertion.PrimitiveFieldAssertion}
 *            object.
 */
protected void visitPrimitiveFieldAssertion(PrimitiveFieldAssertion assertion) {
    VariableReference source = assertion.getSource();
    Object value = assertion.getValue();
    Field field = assertion.getField();

    String target = "";
    if (Modifier.isStatic(field.getModifiers())) {
        target = getClassName(field.getDeclaringClass()) + "." + field.getName();
    } else {
        target = getVariableName(source) + "." + field.getName();
    }

    if (value == null) {
        testCode += "assertNull(" + target + ");";
    } else if (value.getClass().equals(Long.class)) {
        testCode += "assertEquals(" + NumberFormatter.getNumberString(value) + ", " + target + ");";
    } else if (value.getClass().equals(Float.class)) {
        testCode += "assertEquals(" + NumberFormatter.getNumberString(value) + ", " + target + ", "
                + NumberFormatter.getNumberString(Properties.FLOAT_PRECISION) + ");";
    } else if (value.getClass().equals(Double.class)) {
        testCode += "assertEquals(" + NumberFormatter.getNumberString(value) + ", " + target + ", "
                + NumberFormatter.getNumberString(Properties.DOUBLE_PRECISION) + ");";
    } else if (value.getClass().equals(Character.class)) {
        testCode += "assertEquals(" + NumberFormatter.getNumberString(value) + ", " + target + ");";
    } else if (value.getClass().equals(String.class)) {
        testCode += "assertEquals(" + NumberFormatter.getNumberString(value) + ", " + target + ");";
    } else if (value.getClass().equals(Boolean.class)) {
        Boolean flag = (Boolean) value;
        if (flag) {
            testCode += "assertTrue(";
        } else {
            testCode += "assertFalse(";
        }
        testCode += "" + target + ");";
    } else if (value.getClass().isEnum()) {
        testCode += "assertEquals(" + NumberFormatter.getNumberString(value) + ", " + target + ");";
        // Make sure the enum is imported in the JUnit test
        getClassName(value.getClass());

    } else
        testCode += "assertEquals(" + NumberFormatter.getNumberString(value) + ", " + target + ");";
}

From source file:adalid.core.AbstractPersistentEntity.java

@Override
public Map<String, Property> getJoinedTablePropertiesMap() {
    Map<String, Property> map = new LinkedHashMap<>();
    Field field;
    Class<?> clazz;/*from   ww  w. ja v  a2s .co m*/
    Class<?> type = getDataType();
    Property property;
    Map<String, Property> thisPropertiesMap = getPropertiesMap();
    for (String key : thisPropertiesMap.keySet()) {
        property = thisPropertiesMap.get(key);
        if (property.isBaseField()) {
            map.put(key, property);
        } else {
            field = property.getDeclaringField();
            clazz = field.getDeclaringClass();
            if (clazz.equals(type)) {
                map.put(key, property);
            }
        }
    }
    return map;
}

From source file:com.haulmont.chile.core.loader.ChileAnnotationsLoader.java

protected MetadataObjectInfo<MetaProperty> loadCollectionProperty(MetaClassImpl metaClass, Field field) {
    Collection<MetadataObjectInitTask> tasks = new ArrayList<>();

    MetaPropertyImpl property = new MetaPropertyImpl(metaClass, field.getName());

    Class type = getFieldType(field);

    Range.Cardinality cardinality = getCardinality(field);
    boolean ordered = isOrdered(field);
    boolean mandatory = isMandatory(field);
    String inverseField = getInverseField(field);

    Map<String, Object> map = new HashMap<>();
    map.put("cardinality", cardinality);
    map.put("ordered", ordered);
    map.put("mandatory", mandatory);
    if (inverseField != null)
        map.put("inverseField", inverseField);

    MetadataObjectInfo<Range> info = loadRange(property, type, map);
    Range range = info.getObject();//from   ww w . j ava 2  s  .  c o  m
    if (range != null) {
        ((AbstractRange) range).setCardinality(cardinality);
        ((AbstractRange) range).setOrdered(ordered);
        property.setRange(range);
        assignPropertyType(field, property, range);
        assignInverse(property, range, inverseField);
    }
    property.setMandatory(mandatory);

    tasks.addAll(info.getTasks());
    property.setAnnotatedElement(field);
    property.setDeclaringClass(field.getDeclaringClass());
    property.setJavaType(field.getType());

    return new MetadataObjectInfo<>(property, tasks);
}

From source file:com.haulmont.cuba.core.sys.MetaModelLoader.java

protected MetadataObjectInfo<MetaProperty> loadProperty(MetaClassImpl metaClass, Field field) {
    Collection<RangeInitTask> tasks = new ArrayList<>();

    MetaPropertyImpl property = new MetaPropertyImpl(metaClass, field.getName());

    Range.Cardinality cardinality = getCardinality(field);
    Map<String, Object> map = new HashMap<>();
    map.put("cardinality", cardinality);
    boolean mandatory = isMandatory(field);
    map.put("mandatory", mandatory);
    Datatype datatype = getAdaptiveDatatype(field);
    map.put("datatype", datatype);
    String inverseField = getInverseField(field);
    if (inverseField != null)
        map.put("inverseField", inverseField);

    Class<?> type;/*w  w  w  .  j  a  v  a 2 s . c om*/
    Class typeOverride = getTypeOverride(field);
    if (typeOverride != null)
        type = typeOverride;
    else
        type = field.getType();

    property.setMandatory(mandatory);
    property.setReadOnly(!setterExists(field));
    property.setAnnotatedElement(field);
    property.setDeclaringClass(field.getDeclaringClass());

    MetadataObjectInfo<Range> info = loadRange(property, type, map);
    Range range = info.getObject();
    if (range != null) {
        ((AbstractRange) range).setCardinality(cardinality);
        property.setRange(range);
        assignPropertyType(field, property, range);
        assignInverse(property, range, inverseField);
    }

    if (info.getObject() != null && info.getObject().isEnum()) {
        property.setJavaType(info.getObject().asEnumeration().getJavaClass());
    } else {
        property.setJavaType(field.getType());
    }

    tasks.addAll(info.getTasks());

    return new MetadataObjectInfo<>(property, tasks);
}

From source file:com.github.helenusdriver.driver.impl.TableInfoImpl.java

/**
 * Finds and record all fields annotated as columns for this table.
 *
 * @author paouelle//w w w .  j a va2  s .co m
 *
 * @param  mgr the non-<code>null</code> statement manager
 * @throws IllegalArgumentException if unable to find a getter or setter
 *         method for the field of if improperly annotated
 */
private void findColumnFields(StatementManagerImpl mgr) {
    // make sure to walk up the class hierarchy
    FieldInfoImpl<T> lastPartitionKey = null;
    FieldInfoImpl<T> lastClusteringKey = null;

    for (final Field f : ReflectionUtils.getAllFieldsAnnotatedWith(clazz, Column.class, true)) {
        final Pair<String, Class<?>> pf = Pair.of(f.getName(), f.getDeclaringClass());
        FieldInfoImpl<T> field = fields.get(pf);

        if (field == null) {
            field = new FieldInfoImpl<>(this, f);
            if (!field.isColumn()) {
                // not annotated as a column for this table so skip it
                continue;
            }
            fields.put(pf, field);
        }
        final FieldInfoImpl<T> oldc = columns.put(field.getColumnName(), field);

        if (oldc != null) {
            throw new IllegalArgumentException(clazz.getSimpleName()
                    + " cannot annotate more than one field with the same column name '" + field.getColumnName()
                    + ((table != null) ? "' for table '" + table.name() : "") + "': found '"
                    + oldc.getDeclaringClass().getSimpleName() + "." + oldc.getName() + "' and '"
                    + field.getDeclaringClass().getSimpleName() + "." + field.getName() + "'");
        }
        if (field.isTypeKey()) { // by design will be false if no table is defined
            final FieldInfoImpl<T> oldk = typeKeyColumn.getValue();

            if (oldk != null) {
                throw new IllegalArgumentException(clazz.getSimpleName()
                        + " cannot annotate more than one field as a type key for table '" + table.name()
                        + "': found '" + oldk.getDeclaringClass().getSimpleName() + "." + oldk.getName()
                        + "' and '" + field.getDeclaringClass().getSimpleName() + "." + field.getName() + "'");
            }
            typeKeyColumn.setValue(field);
            mandatoryAndPrimaryKeyColumns.put(field.getColumnName(), field);
            if (field.isIndex()) {
                indexColumns.put(field.getColumnName(), field);
            }
        }
        if (field.isPartitionKey()) {
            lastPartitionKey = field;
            mandatoryAndPrimaryKeyColumns.put(field.getColumnName(), field);
            primaryKeyColumns.put(field.getColumnName(), field);
            partitionKeyColumns.put(field.getColumnName(), field);
            if (field.isFinal()) {
                finalPrimaryKeyValues.put(field.getColumnName(), field.getFinalValue());
            }
            if (field.isMultiKey()) {
                multiKeyColumns.put(field.getColumnName(), field);
                multiKeyColumnsList.add(field);
            }
        } else if (field.isClusteringKey()) {
            lastClusteringKey = field;
            mandatoryAndPrimaryKeyColumns.put(field.getColumnName(), field);
            primaryKeyColumns.put(field.getColumnName(), field);
            clusteringKeyColumns.put(field.getColumnName(), field);
            if (field.isFinal()) {
                finalPrimaryKeyValues.put(field.getColumnName(), field.getFinalValue());
            }
            if (field.isMultiKey()) {
                multiKeyColumns.put(field.getColumnName(), field);
                multiKeyColumnsList.add(field);
            }
        } else if (!field.isTypeKey()) {
            if (field.isIndex()) {
                indexColumns.put(field.getColumnName(), field);
            }
            if (field.isMandatory()) {
                mandatoryAndPrimaryKeyColumns.put(field.getColumnName(), field);
                nonPrimaryKeyColumns.put(field.getColumnName(), field);
            } else {
                nonPrimaryKeyColumns.put(field.getColumnName(), field);
            }
        }
    }
    if (table != null) {
        org.apache.commons.lang3.Validate.isTrue(!partitionKeyColumns.isEmpty(),
                "%s must annotate one field as a partition primary key for table '%s'", clazz.getSimpleName(),
                table.name());
    }
    // filters out columns if need be
    mgr.filter(this);
    // finalize table keys
    reorderPrimaryKeys();
    if (lastPartitionKey != null) {
        lastPartitionKey.setLast();
    }
    if (lastClusteringKey != null) {
        lastClusteringKey.setLast();
    }
}

From source file:com.haulmont.chile.core.loader.ChileAnnotationsLoader.java

protected MetadataObjectInfo<MetaProperty> loadProperty(MetaClassImpl metaClass, Field field) {
    Collection<MetadataObjectInitTask> tasks = new ArrayList<>();

    MetaPropertyImpl property = new MetaPropertyImpl(metaClass, field.getName());

    Range.Cardinality cardinality = getCardinality(field);
    Map<String, Object> map = new HashMap<>();
    map.put("cardinality", cardinality);
    boolean mandatory = isMandatory(field);
    map.put("mandatory", mandatory);
    Datatype datatype = getDatatype(field);
    map.put("datatype", datatype);
    String inverseField = getInverseField(field);
    if (inverseField != null)
        map.put("inverseField", inverseField);

    Class<?> type;//from ww  w . j av  a2s  .  c  o m
    Class typeOverride = getTypeOverride(field);
    if (typeOverride != null)
        type = typeOverride;
    else
        type = field.getType();

    MetadataObjectInfo<Range> info = loadRange(property, type, map);
    Range range = info.getObject();
    if (range != null) {
        ((AbstractRange) range).setCardinality(cardinality);
        property.setRange(range);
        assignPropertyType(field, property, range);
        assignInverse(property, range, inverseField);
    }
    property.setMandatory(mandatory);
    property.setReadOnly(!setterExists(field));
    property.setAnnotatedElement(field);
    property.setDeclaringClass(field.getDeclaringClass());

    if (info.getObject() != null && info.getObject().isEnum()) {
        property.setJavaType(info.getObject().asEnumeration().getJavaClass());
    } else {
        property.setJavaType(field.getType());
    }

    tasks.addAll(info.getTasks());

    return new MetadataObjectInfo<>(property, tasks);
}

From source file:com.github.helenusdriver.driver.impl.StatementManagerImpl.java

/**
 * {@inheritDoc}//from   w w  w. j  a v  a 2s  .c  o m
 *
 * @author paouelle
 *
 * @see com.github.helenusdriver.driver.StatementManager#getColumnNamesFor(java.lang.Class, java.lang.reflect.Field)
 */
@Override
protected <T> Set<String> getColumnNamesFor(Class<T> clazz, Field field) {
    final ClassInfoImpl<?> cinfo = getClassInfoImpl(clazz);
    final Set<String> names = new LinkedHashSet<>(cinfo.getNumTables()); // preserve order

    for (final TableInfoImpl<?> tinfo : cinfo.getTables()) {
        final FieldInfoImpl<?> column = tinfo.getColumnByField(field);

        if (column != null) {
            names.add(column.getColumnName());
        }
    }
    org.apache.commons.lang3.Validate.isTrue(!names.isEmpty(), "field '%s.%s' is not annotated as a column",
            field.getDeclaringClass().getName(), field.getName());
    return names;
}

From source file:adalid.core.AbstractPersistentEntity.java

/**
 * @return the expressions that are checks
 *///w ww. j a  v  a 2 s .c o  m
//  @Override
public List<Expression> getChecksList() {
    List<Expression> list = new ArrayList<>();
    Field field;
    Class<?> clazz;
    Class<?> baseTableClass = getBaseTableClass();
    boolean joinedTable = isJoinedTable();
    for (Expression expression : getExpressionsList()) {
        if (expression instanceof Check) {
            field = expression.getDeclaringField();
            clazz = field.getType();
            if (Check.class.isAssignableFrom(clazz)) {
                if (expression.isInherited()) {
                    if (joinedTable) {
                        continue;
                    }
                    if (baseTableClass != null) {
                        clazz = field.getDeclaringClass();
                        if (!baseTableClass.isAssignableFrom(clazz)) {
                            continue;
                        }
                    }
                }
                list.add(expression);
            }
        }
    }
    return list;
}

From source file:org.raml.emitter.RamlEmitterV2.java

private void dumpScalarField(StringBuilder dump, int depth, Field field, Object pojo, String includeField) {
    try {//from  w w  w .  j a  v  a  2s .c o m
        currentField = field;
        Object value = field.get(pojo);
        if (field.getName().equals("content")) {
            System.out.println("a");
        }
        if (value == ParamType.STRING) {
            return;
        }
        if (field.getName().equals("required")) {
            if (value != null && value.equals(false)) {
                return;
            }
        }
        if (field.getName().equals("repeat")) {
            if (value != null && value.equals(false)) {
                return;
            }
        }
        if (field.getName().equals("schema")) {
            value = adjustSchema(value);
        }
        if (field.getName().equals("content")) {
            value = adjustDocumentationContent(value);
        }
        if (field.getName().equals("example")) {
            value = adjustExample(value);
        }
        if (value == null) {
            return;
        }
        dump.append(indent(depth)).append(alias(field)).append(YAML_MAP_SEP);
        if (isPojo(value.getClass())) {
            dump.append("\n");
            dumpPojo(dump, depth + 1, value);
        } else {
            String sanitizeScalarValue = sanitizeScalarValue(depth, value, true);
            if (isSeparated && includeField != null && includeField.length() > 0) {
                try {
                    Field declaredField = field.getDeclaringClass().getDeclaredField(includeField);
                    declaredField.setAccessible(true);
                    Object object = declaredField.get(pojo);
                    if (object != null && object instanceof String) {
                        dump.append("!include " + object.toString()).append("\n");
                        if (writer != null) {
                            writer.write(object.toString(), value.toString());
                        }
                        return;
                    }

                } catch (NoSuchFieldException e) {
                    throw new IllegalStateException();
                } catch (SecurityException e) {
                    throw new IllegalStateException();
                }
            }

            dump.append(sanitizeScalarValue).append("\n");
        }
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition.java

@SuppressWarnings("unchecked")
private void scanCompositeElementForChildren(Set<String> elementNames,
        TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> theOrderToElementDef,
        TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> theOrderToExtensionDef) {
    int baseElementOrder = 0;

    for (ScannedField next : myScannedFields) {
        if (next.isFirstFieldInNewClass()) {
            baseElementOrder = theOrderToElementDef.isEmpty() ? 0
                    : theOrderToElementDef.lastEntry().getKey() + 1;
        }/*from w ww .  j a v a2s.c o  m*/

        Class<?> declaringClass = next.getField().getDeclaringClass();

        Description descriptionAnnotation = ModelScanner.pullAnnotation(next.getField(), Description.class);

        TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> orderMap = theOrderToElementDef;
        Extension extensionAttr = ModelScanner.pullAnnotation(next.getField(), Extension.class);
        if (extensionAttr != null) {
            orderMap = theOrderToExtensionDef;
        }

        Child childAnnotation = next.getChildAnnotation();
        Field nextField = next.getField();
        String elementName = childAnnotation.name();
        int order = childAnnotation.order();
        boolean childIsChoiceType = false;
        boolean orderIsReplaceParent = false;

        if (order == Child.REPLACE_PARENT) {

            if (extensionAttr != null) {

                for (Entry<Integer, BaseRuntimeDeclaredChildDefinition> nextEntry : orderMap.entrySet()) {
                    BaseRuntimeDeclaredChildDefinition nextDef = nextEntry.getValue();
                    if (nextDef instanceof RuntimeChildDeclaredExtensionDefinition) {
                        if (nextDef.getExtensionUrl().equals(extensionAttr.url())) {
                            orderIsReplaceParent = true;
                            order = nextEntry.getKey();
                            orderMap.remove(nextEntry.getKey());
                            elementNames.remove(elementName);
                            break;
                        }
                    }
                }
                if (order == Child.REPLACE_PARENT) {
                    throw new ConfigurationException("Field " + nextField.getName() + "' on target type "
                            + declaringClass.getSimpleName() + " has order() of REPLACE_PARENT ("
                            + Child.REPLACE_PARENT + ") but no parent element with extension URL "
                            + extensionAttr.url() + " could be found on type "
                            + nextField.getDeclaringClass().getSimpleName());
                }

            } else {

                for (Entry<Integer, BaseRuntimeDeclaredChildDefinition> nextEntry : orderMap.entrySet()) {
                    BaseRuntimeDeclaredChildDefinition nextDef = nextEntry.getValue();
                    if (elementName.equals(nextDef.getElementName())) {
                        orderIsReplaceParent = true;
                        order = nextEntry.getKey();
                        BaseRuntimeDeclaredChildDefinition existing = orderMap.remove(nextEntry.getKey());
                        elementNames.remove(elementName);

                        /*
                         * See #350 - If the original field (in the superclass) with the given name is a choice, then we need to make sure
                         * that the field which replaces is a choice even if it's only a choice of one type - this is because the
                         * element name when serialized still needs to reflect the datatype
                         */
                        if (existing instanceof RuntimeChildChoiceDefinition) {
                            childIsChoiceType = true;
                        }
                        break;
                    }
                }
                if (order == Child.REPLACE_PARENT) {
                    throw new ConfigurationException("Field " + nextField.getName() + "' on target type "
                            + declaringClass.getSimpleName() + " has order() of REPLACE_PARENT ("
                            + Child.REPLACE_PARENT + ") but no parent element with name " + elementName
                            + " could be found on type " + nextField.getDeclaringClass().getSimpleName());
                }

            }

        }

        if (order < 0 && order != Child.ORDER_UNKNOWN) {
            throw new ConfigurationException("Invalid order '" + order + "' on @Child for field '"
                    + nextField.getName() + "' on target type: " + declaringClass);
        }

        if (order != Child.ORDER_UNKNOWN && !orderIsReplaceParent) {
            order = order + baseElementOrder;
        }
        // int min = childAnnotation.min();
        // int max = childAnnotation.max();

        /*
         * Anything that's marked as unknown is given a new ID that is <0 so that it doesn't conflict with any given IDs and can be figured out later
         */
        if (order == Child.ORDER_UNKNOWN) {
            order = Integer.valueOf(0);
            while (orderMap.containsKey(order)) {
                order++;
            }
        }

        List<Class<? extends IBase>> choiceTypes = next.getChoiceTypes();

        if (orderMap.containsKey(order)) {
            throw new ConfigurationException("Detected duplicate field order '" + childAnnotation.order()
                    + "' for element named '" + elementName + "' in type '" + declaringClass.getCanonicalName()
                    + "' - Already had: " + orderMap.get(order).getElementName());
        }

        if (elementNames.contains(elementName)) {
            throw new ConfigurationException("Detected duplicate field name '" + elementName + "' in type '"
                    + declaringClass.getCanonicalName() + "'");
        }

        Class<?> nextElementType = next.getElementType();

        BaseRuntimeDeclaredChildDefinition def;
        if (childAnnotation.name().equals("extension")
                && IBaseExtension.class.isAssignableFrom(nextElementType)) {
            def = new RuntimeChildExtension(nextField, childAnnotation.name(), childAnnotation,
                    descriptionAnnotation);
        } else if (childAnnotation.name().equals("modifierExtension")
                && IBaseExtension.class.isAssignableFrom(nextElementType)) {
            def = new RuntimeChildExtension(nextField, childAnnotation.name(), childAnnotation,
                    descriptionAnnotation);
        } else if (BaseContainedDt.class.isAssignableFrom(nextElementType)
                || (childAnnotation.name().equals("contained")
                        && IBaseResource.class.isAssignableFrom(nextElementType))) {
            /*
             * Child is contained resources
             */
            def = new RuntimeChildContainedResources(nextField, childAnnotation, descriptionAnnotation,
                    elementName);
        } else if (IAnyResource.class.isAssignableFrom(nextElementType)
                || IResource.class.equals(nextElementType)) {
            /*
             * Child is a resource as a direct child, as in Bundle.entry.resource
             */
            def = new RuntimeChildDirectResource(nextField, childAnnotation, descriptionAnnotation,
                    elementName);
        } else {
            childIsChoiceType |= choiceTypes.size() > 1;
            if (childIsChoiceType && !BaseResourceReferenceDt.class.isAssignableFrom(nextElementType)
                    && !IBaseReference.class.isAssignableFrom(nextElementType)) {
                def = new RuntimeChildChoiceDefinition(nextField, elementName, childAnnotation,
                        descriptionAnnotation, choiceTypes);
            } else if (extensionAttr != null) {
                /*
                 * Child is an extension
                 */
                Class<? extends IBase> et = (Class<? extends IBase>) nextElementType;

                Object binder = null;
                if (BoundCodeDt.class.isAssignableFrom(nextElementType)
                        || IBoundCodeableConcept.class.isAssignableFrom(nextElementType)) {
                    binder = ModelScanner.getBoundCodeBinder(nextField);
                }

                def = new RuntimeChildDeclaredExtensionDefinition(nextField, childAnnotation,
                        descriptionAnnotation, extensionAttr, elementName, extensionAttr.url(), et, binder);

                if (IBaseEnumeration.class.isAssignableFrom(nextElementType)) {
                    ((RuntimeChildDeclaredExtensionDefinition) def).setEnumerationType(
                            ReflectionUtil.getGenericCollectionTypeOfFieldWithSecondOrderForList(nextField));
                }
            } else if (BaseResourceReferenceDt.class.isAssignableFrom(nextElementType)
                    || IBaseReference.class.isAssignableFrom(nextElementType)) {
                /*
                 * Child is a resource reference
                 */
                List<Class<? extends IBaseResource>> refTypesList = new ArrayList<Class<? extends IBaseResource>>();
                for (Class<? extends IElement> nextType : childAnnotation.type()) {
                    if (IBaseReference.class.isAssignableFrom(nextType)) {
                        refTypesList.add(myContext.getVersion().getVersion().isRi() ? IAnyResource.class
                                : IResource.class);
                        continue;
                    } else if (IBaseResource.class.isAssignableFrom(nextType) == false) {
                        throw new ConfigurationException("Field '" + nextField.getName() + "' in class '"
                                + nextField.getDeclaringClass().getCanonicalName() + "' is of type "
                                + BaseResourceReferenceDt.class + " but contains a non-resource type: "
                                + nextType.getCanonicalName());
                    }
                    refTypesList.add((Class<? extends IBaseResource>) nextType);
                }
                def = new RuntimeChildResourceDefinition(nextField, elementName, childAnnotation,
                        descriptionAnnotation, refTypesList);

            } else if (IResourceBlock.class.isAssignableFrom(nextElementType)
                    || IBaseBackboneElement.class.isAssignableFrom(nextElementType)
                    || IBaseDatatypeElement.class.isAssignableFrom(nextElementType)) {
                /*
                 * Child is a resource block (i.e. a sub-tag within a resource) TODO: do these have a better name according to HL7?
                 */

                Class<? extends IBase> blockDef = (Class<? extends IBase>) nextElementType;
                def = new RuntimeChildResourceBlockDefinition(myContext, nextField, childAnnotation,
                        descriptionAnnotation, elementName, blockDef);
            } else if (IDatatype.class.equals(nextElementType) || IElement.class.equals(nextElementType)
                    || "Type".equals(nextElementType.getSimpleName())
                    || IBaseDatatype.class.equals(nextElementType)) {

                def = new RuntimeChildAny(nextField, elementName, childAnnotation, descriptionAnnotation);
            } else if (IDatatype.class.isAssignableFrom(nextElementType)
                    || IPrimitiveType.class.isAssignableFrom(nextElementType)
                    || ICompositeType.class.isAssignableFrom(nextElementType)
                    || IBaseDatatype.class.isAssignableFrom(nextElementType)
                    || IBaseExtension.class.isAssignableFrom(nextElementType)) {
                Class<? extends IBase> nextDatatype = (Class<? extends IBase>) nextElementType;

                if (IPrimitiveType.class.isAssignableFrom(nextElementType)) {
                    if (nextElementType.equals(BoundCodeDt.class)) {
                        IValueSetEnumBinder<Enum<?>> binder = ModelScanner.getBoundCodeBinder(nextField);
                        Class<? extends Enum<?>> enumType = ModelScanner
                                .determineEnumTypeForBoundField(nextField);
                        def = new RuntimeChildPrimitiveBoundCodeDatatypeDefinition(nextField, elementName,
                                childAnnotation, descriptionAnnotation, nextDatatype, binder, enumType);
                    } else if (IBaseEnumeration.class.isAssignableFrom(nextElementType)) {
                        Class<? extends Enum<?>> binderType = ModelScanner
                                .determineEnumTypeForBoundField(nextField);
                        def = new RuntimeChildPrimitiveEnumerationDatatypeDefinition(nextField, elementName,
                                childAnnotation, descriptionAnnotation, nextDatatype, binderType);
                    } else {
                        def = new RuntimeChildPrimitiveDatatypeDefinition(nextField, elementName,
                                descriptionAnnotation, childAnnotation, nextDatatype);
                    }
                } else {
                    if (IBoundCodeableConcept.class.isAssignableFrom(nextElementType)) {
                        IValueSetEnumBinder<Enum<?>> binder = ModelScanner.getBoundCodeBinder(nextField);
                        Class<? extends Enum<?>> enumType = ModelScanner
                                .determineEnumTypeForBoundField(nextField);
                        def = new RuntimeChildCompositeBoundDatatypeDefinition(nextField, elementName,
                                childAnnotation, descriptionAnnotation, nextDatatype, binder, enumType);
                    } else if (BaseNarrativeDt.class.isAssignableFrom(nextElementType)
                            || INarrative.class.isAssignableFrom(nextElementType)) {
                        def = new RuntimeChildNarrativeDefinition(nextField, elementName, childAnnotation,
                                descriptionAnnotation, nextDatatype);
                    } else {
                        def = new RuntimeChildCompositeDatatypeDefinition(nextField, elementName,
                                childAnnotation, descriptionAnnotation, nextDatatype);
                    }
                }

            } else {
                throw new ConfigurationException(
                        "Field '" + elementName + "' in type '" + declaringClass.getCanonicalName()
                                + "' is not a valid child type: " + nextElementType);
            }

            Binding bindingAnnotation = ModelScanner.pullAnnotation(nextField, Binding.class);
            if (bindingAnnotation != null) {
                if (isNotBlank(bindingAnnotation.valueSet())) {
                    def.setBindingValueSet(bindingAnnotation.valueSet());
                }
            }

        }

        orderMap.put(order, def);
        elementNames.add(elementName);
    }
}