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

org.jboss.resteasy.core.QueryInjector Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package org.jboss.resteasy.core;

import org.jboss.resteasy.spi.*;

import java.lang.reflect.Constructor;

/**
 * Created by Simon Ström on 7/17/14.
 */
public class QueryInjector implements ValueInjector {

   private Class type;
   private ConstructorInjector constructorInjector;
   private PropertyInjector propertyInjector;

   public QueryInjector(Class type, ResteasyProviderFactory factory) {
      this.type = type;
      Constructor constructor;

      try
      {
         constructor = type.getConstructor();
      }
      catch (NoSuchMethodException e)
      {
         throw new RuntimeException("Unable to instantiate @Query class. No no-arg constructor.");
      }

      constructorInjector = factory.getInjectorFactory().createConstructor(constructor, factory);
      propertyInjector = factory.getInjectorFactory().createPropertyInjector(type, factory);
   }

   @Override
   public Object inject() {
      throw new IllegalStateException("You cannot inject outside the scope of an HTTP request");
   }

   @Override
   public Object inject(HttpRequest request, HttpResponse response) {
      Object target = constructorInjector.construct();
      propertyInjector.inject(request, response, target);
      return target;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy