ProviderFactory API needs a bit refactoring?

From: Liu, Jervis <>
Date: Tue, 6 Nov 2007 00:19:11 -0500

Hi, It seems to me that the ProviderFactory API needs a bit refactoring in order to accommodate a more complex EntityProvider searching algorithm. For example, what we have currently in ProviderFactory is as below:

public abstract class ProviderFactory {
    public abstract <T> EntityProvider<T> createEntityProvider(Class<T> type);

I.e., given a Java type then ProviderFactory returns an instance of EntityProvider that supports this Java type. However if we look into EntityProvider API, we will find a parameter of Java class is not enough for ProviderFactory to identify an EntityProvider to use for following reasons:

a). EntityProvider can be annotated with @ProduceMime/_at_ConsumeMime and an EntityProvider can support different mime types for produce and consume. In this case when we ask ProviderFactory to return us a most appropriate EntityProvider, we really need to tell ProviderFactory the EntityProvider being requested is used for producing or consuming.

b). ProviderFactory also needs to know the mine types of the request, this has been clearly stated in the spec, section 3.1.3:

"2. Select the set of EntityProvider classes that support the media type of the request,"

Enclosed below is a ProviderFactory I wrote that can return an instance of EntityProvider based on three parameters. Let me know if this is the intended way to use ProviderFactory and EntityProvider APIs.

public class ProviderFactoryImpl extends ProviderFactory {
   public <T> EntityProvider<T> createEntityProvider(Class<T> type, String[] requestedMineTypes,
                                                      boolean isConsumeMime) {

        for (EntityProvider<T> ep : entityProviders) {
            String[] supportedMimeTypes = {"*/*"};
            if (isConsumeMime) {
                ConsumeMime c = ep.getClass().getAnnotation(ConsumeMime.class);
                if (c != null) {
                    supportedMimeTypes = c.value();
            } else {
                ProduceMime c = ep.getClass().getAnnotation(ProduceMime.class);
                if (c != null) {
                    supportedMimeTypes = c.value();
            if (matchMineTypes(supportedMimeTypes, requestedMineTypes) && ep.supports(type)) {
                return ep;
        return null;

    private boolean matchMineTypes(String[] supportedMimeTypes, String[] requestedMimeTypes) {

Jervis Liu

IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland