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

se.l4.commons.serialization.SerializerCollection Maven / Gradle / Ivy

The newest version!
package se.l4.commons.serialization;

import java.lang.annotation.Annotation;

import se.l4.commons.serialization.spi.SerializerResolver;
import se.l4.commons.serialization.spi.Type;
import se.l4.commons.types.InstanceFactory;


/**
 * Collection of {@link Serializer}s and {@link SerializerResolver resolvers}.
 * 
 * @author Andreas Holstenson
 *
 */
public interface SerializerCollection
{
	/**
	 * Get the current instance factory.
	 * 
	 * @return
	 */
	InstanceFactory getInstanceFactory();
	
	/**
	 * Bind a certain type automatically discovering which serializer to
	 * use.
	 * 
	 * @param type
	 */
	SerializerCollection bind(Class type);
	
	/**
	 * Bind a given type to the specified serializer.
	 * 
	 * @param 
	 * @param type
	 * @param serializer
	 */
	 SerializerCollection bind(Class type, Serializer serializer);
	
	/**
	 * Bind a given type to the specified resolver. The resolver will be
	 * asked to resolve a more specific serializer based on type parameters.
	 * 
	 * @param 
	 * @param type
	 * @param resolver
	 */
	 SerializerCollection bind(Class type, SerializerResolver resolver);
	
	/**
	 * Find a serializer suitable for the specific type.
	 * 
	 * @param 
	 * @param type
	 * @return
	 */
	 Serializer find(Class type);
	
	/**
	 * Find a serializer suitable for the specific type.
	 * 
	 * @param 
	 * @param type
	 * @return
	 */
	 Serializer find(Class type, Annotation... hints);
	
	/**
	 * Find a serializer suitable for the specified type.
	 * 
	 * @param type
	 * @return
	 */
	Serializer find(Type type);
	
	/**
	 * Find a serializer suitable for the specified type.
	 * 
	 * @param type
	 * @return
	 */
	Serializer find(Type type, Annotation... hints);
	
	/**
	 * Find a serializer based on its registered name.
	 * 
	 * @param name
	 * @return
	 */
	Serializer find(String name);
	
	/**
	 * Find a serializer based on its registered name.
	 * 
	 * @param namespace
	 * @param name
	 * @return
	 */
	Serializer find(String namespace, String name);
	
	/**
	 * Find a serializer using a specific {@link SerializerResolver}.
	 * 
	 * @param sOrR
	 * @param type
	 * @return
	 */
	 Serializer findVia(Class> resolver, Class type, Annotation... hints);
	
	/**
	 * Find a serializer using a specific {@link SerializerResolver}.
	 * 
	 * @param sOrR
	 * @param type
	 * @return
	 */
	 Serializer findVia(Class> resolver, Type type, Annotation... hints);
	
	/**
	 * Get the resolver this collection would use to resolve a serializer
	 * for the given type.
	 * 
	 * @param type
	 * @return
	 */
	SerializerResolver getResolver(Class type);
	
	/**
	 * Get if the given type can be serialized.
	 * 
	 * @param type
	 * @return
	 */
	boolean isSupported(Class type);
	
	/**
	 * Find the name of the given serializer (if any).
	 * 
	 * @param serializer
	 * @return
	 */
	QualifiedName findName(Serializer serializer);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy