All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.imunity.vaadin.endpoint.common.plugins.attributes.metadata.AttributeMetadataHandlerRegistry Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2013 ICM Uniwersytet Warszawski All rights reserved.
 * See LICENCE.txt file for licensing information.
 */
package io.imunity.vaadin.endpoint.common.plugins.attributes.metadata;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Gives access to {@link WebAttributeMetadataHandler}s for given metadata types.
 * 
 * @author K. Benedyczak
 */
@Component
public class AttributeMetadataHandlerRegistry
{
	private final Map factoriesByType =
			new HashMap();
	
	@Autowired
	public AttributeMetadataHandlerRegistry(List factories)
	{
		for (WebAttributeMetadataHandlerFactory factory: factories)
			factoriesByType.put(factory.getSupportedMetadata(), factory);
	}
	
	public WebAttributeMetadataHandler getHandler(String metadataId)
	{
		WebAttributeMetadataHandlerFactory factory = factoriesByType.get(metadataId);
		if (factory == null)
			throw new IllegalArgumentException("Metadata " + metadataId + " has no handler factory registered");
		return factory.newInstance();
	}
	
	public Set getSupportedSyntaxes()
	{
		return new HashSet<>(factoriesByType.keySet());
	}
}







© 2015 - 2025 Weber Informatics LLC | Privacy Policy