class ReportLoadingService {

    public List<ResourceReference> getInputControlReferences(ExecutionContext context, InputControlsContainer container) {
        List<ResourceReference> inputControlRefs = new ArrayList<ResourceReference>();

        container = getFinalResource(context, container);

        if (container instanceof ReferenceNormalizer) {
            try {
                ((ReferenceNormalizer) container).checkReferences();
            } catch (Exception e) {
                // We are going to fix this error here
                ((ReferenceNormalizer) container).normalizeReferences(new MarkAllInputControlsResolved());
            }
        }

        // Get input control references of the container
        if (container.getInputControls() != null) {
            inputControlRefs.addAll(container.getInputControls());
        }

        // Get input control references of the report data source
        Resource dataSource = getFinalResource(ExecutionContextImpl.getRuntimeExecutionContext(context), container.getDataSource(), null);
        if (dataSource instanceof InputControlsContainer && ((InputControlsContainer) dataSource).getInputControls() != null) {

            if (container.getDataSource() != dataSource && dataSource instanceof ReferenceNormalizer) {
                try {
                    ((ReferenceNormalizer) dataSource).checkReferences();
                } catch (Exception e) {
                    // We are going to fix this error here
                    ((ReferenceNormalizer) container).normalizeReferences(new MarkAllInputControlsResolved());
                }
            }

            List<String> containerInputControlNames = new ArrayList<String>(inputControlRefs.size());
            for (ResourceReference ref : inputControlRefs) {
                containerInputControlNames.add(getInputControlParameterName(ref));
            }
            for (ResourceReference dataSourceControlRef : ((InputControlsContainer) dataSource).getInputControls()) {
                String dataSourceControlName = getInputControlParameterName(dataSourceControlRef);
                if (!containerInputControlNames.contains(dataSourceControlName)) {
                    inputControlRefs.add(dataSourceControlRef);
                }
            }
        }

        return inputControlRefs;
    }

}