• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Injectee类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.glassfish.hk2.api.Injectee的典型用法代码示例。如果您正苦于以下问题:Java Injectee类的具体用法?Java Injectee怎么用?Java Injectee使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Injectee类属于org.glassfish.hk2.api包,在下文中一共展示了Injectee类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: resolve

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) {

	if (injectee.getRequiredType() instanceof Class) {

		TypeLiteral<?> typeLiteral = TypeLiteral.get(injectee.getRequiredType());
		Errors errors = new Errors(injectee.getParent());
		Key<?> key;
		try {
			key = Annotations.getKey(typeLiteral, (Member) injectee.getParent(),
					injectee.getParent().getDeclaredAnnotations(), errors);
		} catch (ErrorsException e) {
			errors.merge(e.getErrors());
			throw new ConfigurationException(errors.getMessages());
		}

		return injector.getInstance(key);
	}

	throw new IllegalStateException("Can't process injection point: " + injectee.getRequiredType());
}
 
开发者ID:bootique,项目名称:bootique-jersey-client,代码行数:22,代码来源:ClientGuiceInjectInjector.java


示例2: buildName

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public MetricName buildName(MetricName metricName, AnnotatedElement injectionSite, Type metricType) {
    checkState(instantiationService != null, "instantiationService must be set");
    checkState(requestScope != null, "requestScope must be set");
    // Ensure we're inside a request scope
    Instance currentRequestScope = requestScope.suspendCurrent();
    if (currentRequestScope == null) {
        return metricName;
    } else {
        currentRequestScope.release();
    }
    // Verify that if we have injection information, we're not being injected into a singleton or per thread scoped object
    InstantiationData data = instantiationService.getInstantiationData();
    if (data != null) {
        Injectee injectee = data.getParentInjectee();
        if (injectee != null && injectee.getInjecteeDescriptor().getScopeAnnotation() != RequestScoped.class) {
            return metricName;
        }
    }
    return buildRequestScopedName(metricName, injectionSite, metricType);
}
 
开发者ID:baharclerode,项目名称:dropwizard-hk2,代码行数:22,代码来源:RequestScopedMetricNameFilter.java


示例3: provide

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
@PerLookup
@Visibility(DescriptorVisibility.LOCAL)
public T provide() {
    Injectee injectee = instantiationService.getInstantiationData().getParentInjectee();
    String   name;
    if (injectee == null) {
        log.warn("Creating metric with no injection context; Use the metric registry directly instead of dynamically creating it "
                 + "through HK2", new Exception());
        name = UUID.randomUUID().toString();
    } else {
        AnnotatedElement parent = injectee.getParent();
        if (parent instanceof Constructor) {
            parent = ((Constructor) parent).getParameters()[injectee.getPosition()];
        }
        if (parent instanceof Method) {
            parent = ((Method) parent).getParameters()[injectee.getPosition()];
        }
        name = nameService.getFormattedMetricName(parent, injectee.getInjecteeClass());
    }
    return metricSupplier.apply(name);
}
 
开发者ID:baharclerode,项目名称:dropwizard-hk2,代码行数:23,代码来源:MetricFactory.java


示例4: resolve

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
/**
 * @return RxWebTarget or Proxy client of specified injectee interface
 * @throws IllegalStateException if uri is not correct or there is no sufficient injection resolved
 */
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> root) {
    Remote remote = injectee.getParent().getAnnotation(Remote.class);
    UriInfo uriInfo = serviceLocator.getService(UriInfo.class);

    URI target = merge(remote.value(), uriInfo);
    WebTarget webTarget = client.target(target);
    Type type = injectee.getRequiredType();

    if (type instanceof Class) {
        Class<?> required = (Class) type;

        if (WebTarget.class.isAssignableFrom(required)) {
            return webTarget;
        }

        if (required.isInterface()) {
            return WebResourceFactory.newResource(required, webTarget, clientMethodInvoker);
        }
    }

    throw new IllegalStateException(format("Can't find proper injection for %s", type));
}
 
开发者ID:alex-shpak,项目名称:rx-jersey,代码行数:28,代码来源:RemoteResolver.java


示例5: resolve

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> root) {
  ActiveDescriptor<?> descriptor = locator.getInjecteeDescriptor(injectee);
  
  if (descriptor == null) {
    
    // Is it OK to return null?
    if (isNullable(injectee)) {
      return null;
    }
    
    throw new MultiException(new UnsatisfiedDependencyException(injectee));
  }
  
  return locator.getService(descriptor, root, injectee);
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:17,代码来源:GuiceThreeThirtyResolver.java


示例6: getQualifiers

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
/**
 * NOTE: There can be only one {@link Annotation} that is a {@link Qualifier} or {@link BindingAnnotation}. 
 * They're the same but HK2 does not know about {@link BindingAnnotation}.
 * 
 * @see Qualifier
 * @see BindingAnnotation
 * @see javax.inject.Named
 * @see com.google.inject.name.Named
 */
private static Set<Annotation> getQualifiers(Injectee injectee) {
  // JSR 330's @Qualifier
  Set<Annotation> qualifiers = injectee.getRequiredQualifiers();
  if (!qualifiers.isEmpty()) {
    return qualifiers;
  }
  
  AnnotatedElement element = injectee.getParent();
  int position = injectee.getPosition();
  
  // Guice's @BindingAnnotation is the same as @Qualifier
  Annotation annotation = getBindingAnnotation(element, position);
  if (annotation != null) {
    return Collections.singleton(annotation);
  }
  
  return Collections.emptySet();
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:28,代码来源:BindingUtils.java


示例7: justInTimeResolution

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public boolean justInTimeResolution(Injectee injectee) {
  Type type = injectee.getRequiredType();
  Class<?> clazz = MoreTypes.getRawType(type);
  
  if (clazz != null) {
    Binding<?> binding = findBinding(injectee);
    if (binding != null) {
      Key<?> key = binding.getKey();
      Set<Annotation> qualifiers = BindingUtils.getQualifiers(key);
      
      GuiceBindingDescriptor<?> descriptor = new GuiceBindingDescriptor<>(
          type, clazz, qualifiers, binding);
      ServiceLocatorUtilities.addOneDescriptor(locator, descriptor);
      return true;
    }
  }
  
  
  return false;
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:22,代码来源:GuiceJustInTimeResolver.java


示例8: findBinding

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
/**
 * Returns a {@link Guice} {@link Binding} for the given HK2 {@link Injectee}
 * or {@code null} if there is no such binding (i.e. Guice doesn't have it and
 * doesn't know how to build it).
 */
private Binding<?> findBinding(Injectee injectee) {
  Key<?> key = BindingUtils.toKey(injectee);
  if (key == null) {
    return null;
  }
  
  // We can't do anything about HK2 @Contracts
  if (BindingUtils.isHk2Contract(injectee)) {
    return null;
  }
  
  // Classes with a @Contract annotation are SPIs. They either exist or
  // not. They must be explicit bindings in the world of Guice.
  if (BindingUtils.isJerseyContract(injectee)) {
    return injector.getExistingBinding(key);
  }
  
  // We've to use Injector#getBinding() to cover Just-In-Time bindings
  // which may fail with an Exception because Guice doesn't know how to
  // construct the requested object.
  return injector.getBinding(key);
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:28,代码来源:GuiceJustInTimeResolver.java


示例9: getInjecteeName

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
public static String getInjecteeName(InstantiationService instantiationService) {
    InstantiationData instantiationData = instantiationService.getInstantiationData();
    Injectee parentInjectee = instantiationData.getParentInjectee();
    String name = null;
    Optional<Annotation> namedAnnotation = parentInjectee.getRequiredQualifiers().stream().filter(Named.class::isInstance).findFirst();
    if (namedAnnotation.isPresent()) {
        Named named = (Named) namedAnnotation.get();
        name = named.value();
    }

    if (name == null) {
        throw new RuntimeException("Named factory bound without name.");
    }
    return name;
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:16,代码来源:Hk2Helper.java


示例10: resolve

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> root) {
    ConfigProperty configProperty = injectee.getParent().getAnnotation(ConfigProperty.class);
    assert configProperty != null;

    if (StringUtils.isBlank(configProperty.name())) {
        throw new IllegalArgumentException("@ConfigProperty shouldn't have blank name");
    }

    if (configProperty.mustPresent() && !config.containsKey(configProperty.name())) {
        throw new IllegalArgumentException(configProperty.name() + " must be present in config properties");
    }

    String propValue = config.getString(configProperty.name(), configProperty.defaultValue()).trim();

    if (!configProperty.allowBlank() && StringUtils.isBlank(propValue)) {
        throw new IllegalArgumentException(configProperty.name() + " doesn't allow blank name");
    }

    if (injectee.getRequiredType().equals(String.class)) {
        return propValue;
    } else if (injectee.getRequiredType().equals(Integer.TYPE)) {
        return Integer.valueOf(propValue);
    } else if (injectee.getRequiredType().equals(Long.TYPE)) {
        return Long.valueOf(propValue);
    } else if (injectee.getRequiredType().equals(Boolean.TYPE)) {
        return Boolean.valueOf(propValue);
    }

    throw new IllegalArgumentException("Not acceptable injectin type : ${injectee.requiredType.typeName}");

}
 
开发者ID:protoxme,项目名称:protox-webapp-archetype,代码行数:33,代码来源:ConfigPropertyResolver.java


示例11: resolve

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) {
    Property annotation = injectee.getParent().getAnnotation(Property.class);

    String property = properties.get(annotation.value());
    if (isNull(property) || property.isEmpty()) {
        throw new HK2RuntimeException(String.format("Property %s does not exist.", property));
    }

    Function<String, ?> parser = parsers.get(injectee.getRequiredType());
    return parser.apply(property);
}
 
开发者ID:petrbouda,项目名称:joyrest,代码行数:13,代码来源:PropertyResolver.java


示例12: resolve

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> root)
{
    if ((injectee.getRequiredType() instanceof Class)
    && ((Class<?>)injectee.getRequiredType()).isAssignableFrom(logInject.getLoggerClass()))
    {
        Class<?> injecteeClass = injectee.getInjecteeClass();
        Class<?> implementationClass = injectee.getInjecteeDescriptor().getImplementationClass();
        Class<?> logger = (injecteeClass.isAssignableFrom(implementationClass))? implementationClass:injecteeClass;
        return logInject.createLogger(logger);
    }
    return systemResolver.resolve(injectee, root);
}
 
开发者ID:raner,项目名称:loginject,代码行数:14,代码来源:HK2LogInjectionResolver.java


示例13: resolve

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> handle) {
    Class requiredClass = (Class) injectee.getRequiredType();
    log.info("Asked to inject a " + requiredClass.getSimpleName());
    if (requiredClass == CouchbaseClientFactory.class) {
        return factory;
    }
    return AccessorFactory.getFactory().getAccessor(requiredClass, factory);
}
 
开发者ID:smartmachine,项目名称:dropwizard-couchbase,代码行数:10,代码来源:AccessorResolver.java


示例14: reifyDescriptor

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public ActiveDescriptor<?> reifyDescriptor(Descriptor descriptor, Injectee injectee) throws MultiException {
    throw new UnsupportedOperationException("Will not be supported!");
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:5,代码来源:OAuthServiceLocatorShim.java


示例15: getInjecteeDescriptor

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public ActiveDescriptor<?> getInjecteeDescriptor(Injectee injectee) throws MultiException {
    throw new UnsupportedOperationException("Will not be supported!");
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:5,代码来源:OAuthServiceLocatorShim.java


示例16: getServiceHandle

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public <T> ServiceHandle<T> getServiceHandle(ActiveDescriptor<T> activeDescriptor, Injectee injectee) throws MultiException {
    throw new UnsupportedOperationException("Will not be supported!");
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:5,代码来源:OAuthServiceLocatorShim.java


示例17: getService

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public <T> T getService(ActiveDescriptor<T> activeDescriptor,
    ServiceHandle<?> root, Injectee injectee) throws MultiException {
    throw new UnsupportedOperationException("Will not be supported!");
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:6,代码来源:OAuthServiceLocatorShim.java


示例18: resolve

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) {
	final Class<?> loggerClass = injectee.getInjecteeClass();

	return new DefaultLogger(loggerClass);
}
 
开发者ID:coolarch,项目名称:whaleunit,代码行数:6,代码来源:LoggerInjectionResolver.java


示例19: resolve

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> root) {
  InjectionResolver<?> resolver = descriptor.create(root);
  return resolver.resolve(injectee, root);
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:6,代码来源:GuiceInjectionResolver.java


示例20: toKey

import org.glassfish.hk2.api.Injectee; //导入依赖的package包/类
/**
 * Creates and returns a {@link Key} from the given {@link Injectee}.
 */
public static Key<?> toKey(Injectee injectee) {
  Type type = injectee.getRequiredType();
  Set<Annotation> qualifiers = getQualifiers(injectee);
  return newKey(type, qualifiers);
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:9,代码来源:BindingUtils.java



注:本文中的org.glassfish.hk2.api.Injectee类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StepScope类代码示例发布时间:2022-05-21
下一篇:
Java LiveRef类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap