class ProcessorChainFactory {

	@SuppressWarnings("unchecked")
	public ProcessorChain createProcessorChain(
			ProcessorReferenceChain chainReference,
			DataSource source,
			DataRepository dataRepository) {

		Assert.assertNotNull(chainReference, source, dataRepository);

		SourceAdapter adapter;
		Filter<ObjectNode, ?> firstFilter = null;
		Filter<?, ObjectNode> lastFilter = null;

		Iterator<ProcessorReference> iterator = chainReference.getProcessors().iterator();
		adapter = (SourceAdapter) createProcessorFromAnnotation(adapterFactory, SourceAdapterFactory.class, iterator.next(), source, dataRepository);

		while (iterator.hasNext()) {
			Filter filter = (Filter) createProcessorFromAnnotation(filterFactory, FilterFactory.class, iterator.next(), source, dataRepository);
			if (firstFilter == null) {
				firstFilter = (Filter<ObjectNode, ObjectNode>) filter;
				lastFilter = (Filter<ObjectNode, ObjectNode>) filter;
			} else {
				lastFilter = (Filter<ObjectNode, ObjectNode>) lastFilter.setNextFilter(filter);
			}
		}

		return new ProcessorChain(adapter, firstFilter);
	}

	@Inject public  ProcessorChainFactory(
			SourceAdapterFactory adapterFactory,
			FilterFactory filterFactory);

}