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

com.sun.jersey.server.impl.inject.InjectableValuesProvider Maven / Gradle / Ivy

Go to download

A bundle containing code of all jar-based modules that provide JAX-RS and Jersey-related features. Such a bundle is *only intended* for developers that do not use Maven's dependency system. The bundle does not include code for contributes, tests and samples.

There is a newer version: 1.19.4
Show newest version
package com.sun.jersey.server.impl.inject;

import com.sun.jersey.api.container.ContainerException;
import com.sun.jersey.api.core.HttpContext;
import com.sun.jersey.spi.inject.Injectable;
import java.util.List;
import javax.ws.rs.WebApplicationException;


/**
 * A hold of a list of injectable that obtains the injectable values
 * from that list.
 *
 * @author [email protected]
 */
public class InjectableValuesProvider {

    private final List is;

    /**
     * Create a new instance given a list of injectable.
     * 
     * @param is the list of injectable.
     */
    public InjectableValuesProvider(List is) {
        this.is = AbstractHttpContextInjectable.transform(is);
    }

    public List getInjectables() {
        return is;
    }

    /**
     * Get the injectable values.
     *
     * @param context the http contest.
     * @return the injectable values. Each element in the object array
     *         is a value obtained from the injectable at the list index
     *         that is the element index.
     */
    public Object[] getInjectableValues(HttpContext context) {
        final Object[] params = new Object[is.size()];
        try {
            int index = 0;
            for (AbstractHttpContextInjectable i : is) {
                params[index++] = i.getValue(context);
            }
            return params;
        } catch (WebApplicationException e) {
            throw e;
        } catch (ContainerException e) {
            throw e;
        } catch (RuntimeException e) {
            throw new ContainerException("Exception obtaining parameters", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy