Java 类javax.enterprise.inject.Produces 实例源码

项目:atbash-octopus    文件:ProducerBean.java   
@Produces
@RequestScoped
@Named("userPrincipal")
public UserPrincipal producePrincipal() {
    Object principal = SecurityUtils.getSubject().getPrincipal();
    UserPrincipal result = null;
    if (principal instanceof UserPrincipal) {

        result = (UserPrincipal) principal;
    }
    /*
    FIXME
    if (principal instanceof SystemAccountPrincipal) {
        SystemAccountPrincipal systemAccountPrincipal = (SystemAccountPrincipal) principal;
        String identifier = systemAccountPrincipal.getIdentifier();
        result = new UserPrincipal(identifier);
    }
    */
    if (principal == null) {
        result = new UserPrincipal();
    }
    return result;
}
项目:Biliomi    文件:VersionInfoProducer.java   
@Produces
public VersionInfo getVersionInfo() {
  VersionInfo versionInfo = new VersionInfo();

  try {
    versionInfo.setVersion(appVersion);
    versionInfo.setUserAgent(userAgent);
    versionInfo.setBuildDate(new DateTime(buildTimestamp));
  } catch (IllegalArgumentException e) {
    // In development mode no sources will be filtered yet
    versionInfo.setVersion("DEVELOPMENT");
    versionInfo.setUserAgent("DEVELOPMENT");
    versionInfo.setBuildDate(new DateTime());
  }

  return versionInfo;
}
项目:javaee8-jaxrs-sample    文件:PasswordEncoderProducer.java   
@Produces
@Crypto
public PasswordEncoder passwordEncoder(InjectionPoint ip) {
    Crypto crypto = ip.getAnnotated().getAnnotation(Crypto.class);
    Crypto.Type type = crypto.value();
    PasswordEncoder encoder;
    switch (type) {
        case PLAIN:
            encoder = new PlainPasswordEncoder();
            break;
        case BCRYPT:
            encoder = new BCryptPasswordEncoder();
            break;
        default:
            encoder = new PlainPasswordEncoder();
            break;
    }

    return encoder;
}
项目:Biliomi    文件:UserSettingsProducer.java   
@Produces
@CoreSetting("PRODUCER")
public String getUserSetting(InjectionPoint injectionPoint) {
  Annotated annotated = injectionPoint.getAnnotated();

  if (annotated.isAnnotationPresent(CoreSetting.class)) {
    String settingPath = annotated.getAnnotation(CoreSetting.class).value();
    Object object = yamlCoreSettings;
    String[] split = settingPath.split("\\.");
    int c = 0;

    while (c < split.length) {
      try {
        object = PropertyUtils.getProperty(object, split[c]);
        c++;
      } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        LogManager.getLogger(getClass()).error("Failed retrieving setting " + settingPath, e);
        return null;
      }
    }

    return String.valueOf(object);
  }

  return null;
}
项目:wildfly-microprofile-config    文件:ConfigProducer.java   
@SuppressWarnings("unchecked")
@Dependent
@Produces @ConfigProperty
<T> Optional<T> produceOptionalConfigValue(InjectionPoint injectionPoint) {
    Type type = injectionPoint.getAnnotated().getBaseType();
    final Class<T> valueType;
    if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;

        Type[] typeArguments = parameterizedType.getActualTypeArguments();
        valueType = unwrapType(typeArguments[0]);
    } else {
        valueType = (Class<T>) String.class;
    }
    return Optional.ofNullable(getValue(injectionPoint, valueType));
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:BankFactory.java   
@Produces
@BankProducer
public Bank createBank(@Any Instance<Bank> instance, InjectionPoint injectionPoint) {

    Annotated annotated = injectionPoint.getAnnotated();
    BankType bankTypeAnnotation = annotated.getAnnotation(BankType.class);
    Class<? extends Bank> bankType = bankTypeAnnotation.value().getBankType();
    return instance.select(bankType).get();
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:BookService.java   
@Draft
@Produces
public List<Book> getDraftBooks() {
    Book[] books = new Book[] { new Book("Glassfish", "Luca Stancapiano", DRAFT),
            new Book("Maven working", "Luca Stancapiano", DRAFT) };
    return asList(books);
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:PublishService.java   
@Published
@Produces
public List<Book> getPublishedBooks() {
    Book[] books = new Book[] {
            new Book("Mastering Java EE Development with WildFly 10", "Luca Stancapiano", PUBLISHED),
            new Book("Gatein Cookbook", "Luca Stancapiano", PUBLISHED) };
    return asList(books);
}
项目:willdfly-swarm-hello-world    文件:LiquibaseProducer.java   
@Produces
@LiquibaseType
public CDILiquibaseConfig createConfig() {
    final CDILiquibaseConfig config = new CDILiquibaseConfig();
    config.setChangeLog("liquibase/db.changelog.xml");
    return config;
}
项目:java-cdi    文件:SpanContextProducer.java   
@Produces
public SpanContext produceSpanContext() {
    SpanContext spanContext = (SpanContext) request.getAttribute(TracingFilter.SERVER_SPAN_CONTEXT);
    if (null == spanContext) {
        log.warning("A SpanContext has been requested, but none could be found on the HTTP request's " +
                "attributes. Make sure the Servlet integration is on the classpath!");
    }

    return spanContext;
}
项目:java-cdi    文件:SpanContextProducer.java   
@Produces
public Span produceSpan(InjectionPoint ip) {
    Scope scope = tracer.scopeManager().active();
    if (null == scope) {
        String spanName = ip.getMember().getName();
        return tracer.buildSpan(spanName).startActive().span();
    }

    return scope.span();
}
项目:java-cdi    文件:SpanContextProducer.java   
@Produces
public Scope produceScope(InjectionPoint ip) {
    Scope scope = tracer.scopeManager().active();
    if (null == scope) {
        String spanName = ip.getMember().getName();
        return tracer.buildSpan(spanName).startActive();
    }

    return scope;
}
项目:Hi-Framework    文件:MVCReqHandler.java   
@Produces
public HTMLizer getHTMLizer(){

    HTMLizer htmLizer = HTMLizer.getInstance();
    htmLizer.setGsonBuilder(appContext.getGsonBuilder());
    return htmLizer;

}
项目:atbash-octopus    文件:ProducerBean.java   
@Produces
@Named("loggedInUser")
public String produceUser() {
    Object principal = SecurityUtils.getSubject().getPrincipal();
    if (principal != null) {
        return principal.toString();
    } else {
        return null;
    }
}
项目:java-ml-projects    文件:Producers.java   
@Produces
@DatasetLabels
public List<String> produceLabels() {
    String labelsProperty = System.getProperty(LABELS_PROPERTY);
    if (labelsProperty == null) {
        throw new Error("Provide comma separated values for the dataset labels using the system property "
                + LABELS_PROPERTY);
    }
    return Stream.of(labelsProperty.split("\\,")).collect(Collectors.toList());
}
项目:java-ml-projects    文件:Producers.java   
@Produces
@OutputDir
public String produceOutputDir() {
    String outputDir = System.getProperty(OUTPUT_DIR);
    if (outputDir == null) {
        outputDir = System.getProperty("user.home");
        logger.info("Using user home dir since no output dir was set: " + outputDir);
    }
    return outputDir;
}
项目:lra-service    文件:BeanConfiguration.java   
@Produces
@Singleton
public Tracer tracer() {
    String jaegerURL = System.getenv("JAEGER_SERVER_HOSTNAME");
    if (jaegerURL != null) {
        log.info("Using Jaeger tracer");
        return jaegerTracer(jaegerURL);
    }

    log.info("Using Noop tracer");
    return NoopTracerFactory.create();

}
项目:poi    文件:ConfiguratorProducer.java   
/**
 * Define as system property
 * f.e.: connectionTimeout=500 and/or readTimeout=500
 */


@Produces
public long expose(InjectionPoint ip) {
    String fieldName = ip.getMember().getName();
    String configuredValue = System.getenv().getOrDefault(fieldName, "0");
    return Long.parseLong(configuredValue);
}
项目:xsharing-services-router    文件:TargetProducer.java   
@Produces
@ApplicationScoped
public IVRouterService produceWebTarget() {
    return new ResteasyClientBuilder()
            .connectionPoolSize(100)
            .maxPooledPerRoute(20)
            .asyncExecutor(executor)
            .build()
            .target(CONFIG.getIvRouterBaseUrl())
            .queryParam(IVRouterConfig.FORMAT, IVRouterConfig.REQUEST_FORMAT)
            .proxy(IVRouterService.class);
}
项目:scalable-coffee-shop    文件:KafkaConfigurator.java   
@Produces
@RequestScoped
public Properties exposeKafkaProperties() throws IOException {
    final Properties properties = new Properties();
    properties.putAll(kafkaProperties);
    return properties;
}
项目:scalable-coffee-shop    文件:KafkaConfigurator.java   
@Produces
@RequestScoped
public Properties exposeKafkaProperties() throws IOException {
    final Properties properties = new Properties();
    properties.putAll(kafkaProperties);
    return properties;
}
项目:scalable-coffee-shop    文件:KafkaConfigurator.java   
@Produces
@RequestScoped
public Properties exposeKafkaProperties() throws IOException {
    final Properties properties = new Properties();
    properties.putAll(kafkaProperties);
    return properties;
}
项目:crnk-framework    文件:MetaModuleProducer.java   
@Produces
@ApplicationScoped
public MetaModule createMetaModule() {
    MetaModuleConfig metaConfig = new MetaModuleConfig();
    metaConfig.addMetaProvider(new ResourceMetaProvider());
    MetaModule metaModule = MetaModule.createServerModule(metaConfig);
    return metaModule;
}
项目:crnk-framework    文件:MetaModuleProducer.java   
@Produces
@ApplicationScoped
public Module createRepositoryModule() {
    SimpleModule module = new SimpleModule("mock");
    module.addRepository(new ScheduleRepositoryImpl());
    module.addRepository(new ProjectRepository());
    module.addRepository(new TaskRepository());
    module.addRepository(new ProjectToTaskRepository());
    module.addRepository(new ScheduleToTaskRepository());
    module.addRepository(new TaskSubtypeRepository());
    module.addRepository(new TaskToProjectRepository());
    module.addRepository(new TaskToScheduleRepo());
    return module;
}
项目:testee.fi-examples    文件:WebDriverProducer.java   
@Produces
public WebDriver webDriver() {
    synchronized (WebDriverProducer.class) {
        if (webDriver == null) {
            webDriver = getWebDriverFactory().create();
            getRuntime().addShutdownHook(new Thread(webDriver::close));
        }
        return webDriver;
    }
}
项目:redis-cdi-example    文件:JedisProducer.java   
@Dependent
@Produces
public Jedis get(InjectionPoint ip) {
    System.out.println("injecting Jedis into " + ip.getMember().getDeclaringClass().getSimpleName());
    String redisHost = System.getenv().getOrDefault("REDIS_HOST", "192.168.99.100");
    String redisPort = System.getenv().getOrDefault("REDIS_PORT", "6379");

    Jedis jedis = new Jedis(redisHost, Integer.valueOf(redisPort), 10000);
    jedis.connect();
    System.out.println("Redis Connection obtained");
    return jedis;
}
项目:redis-cdi-example    文件:PooledJedisProducer.java   
@RequestScoped
@Produces
@FromJedisPool
public Jedis get() {
    Jedis jedis = pool.getResource();
    System.out.println("Got resource from Jedis pool");
    return jedis;
}
项目:apm-client    文件:HelloServiceConfiguration.java   
/**
 * Get the configuration.
 * @return The configuration
 */
@Produces
static TraceConfiguration getDefault() {
  return new TraceConfiguration(
    "greetings-server",
    "http://localhost:8126",
    TimeUnit.MINUTES.toMillis(1));
}
项目:apm-client    文件:TraceConfigurationFactory.java   
/**
 * Get the configuration.
 * @return The configuration
 */
@Produces
static TraceConfiguration getDefault() {
  return new TraceConfiguration(
    "greetings-client",
    "http://localhost:8126",
    TimeUnit.MINUTES.toMillis(1));
}
项目:apm-client    文件:TraceConfigurationFactory.java   
/**
 * Get the configuration.
 * @return The configuration
 */
@Produces
static TraceConfiguration getDefault() {
  return new TraceConfiguration(
    "greetings-client",
    "http://localhost:8126",
    TimeUnit.MINUTES.toMillis(1));
}
项目:microprofile-metrics    文件:MetricProducerMethodBean.java   
@Produces
@Metric(name = "cache-hits")
Gauge<Double> cacheHitRatioGauge(final @Metric(name = "hits") Meter hits, final @Metric(name = "calls") Timer calls) {
    return new Gauge<Double>() {

        @Override
        public Double getValue() {
            return (double) hits.getCount() / (double) calls.getCount();
        }
    };

}
项目:Biliomi    文件:LoggerProducer.java   
@Produces
public Logger getLogger(InjectionPoint injectionPoint) {
  Class loggerClass;

  if (injectionPoint.getAnnotated().isAnnotationPresent(LoggerFor.class)) {
    loggerClass = injectionPoint.getAnnotated().getAnnotation(LoggerFor.class).value();
  } else {
    loggerClass = injectionPoint.getBean().getBeanClass();
  }

  return LogManager.getLogger(loggerClass);
}
项目:payara-micro-docker-starter-kit    文件:ConfigProducer.java   
@Produces
@IConfig
public Config produce(InjectionPoint injectionPoint) throws IOException {
    Annotated annotated = injectionPoint.getAnnotated();
    IConfig iConfig = annotated.getAnnotation(IConfig.class);
    String key = iConfig.value();
    if (!configs.containsKey(key)) {
        Config config = new Config();
        config.load(key);
        configs.put(key, config);
    }
    return configs.get(key);
}
项目:Pedidex    文件:Resources.java   
@Produces
public <T extends Entidade> GenericDao<T> produceDao(InjectionPoint injectionPoint, EntityManager em) {
    Type[] args = ((ParameterizedType)injectionPoint.getType()).getActualTypeArguments();
    if (args.length == 0)
        throw new IllegalArgumentException("O GenericDao precisa de um tipo");
    Class<T> type = (Class<T>) args[0];
    return new GenericDao(em, type);
}
项目:Java-9-Programming-Blueprints    文件:Producers.java   
@Produces
private MongoDatabase getDatabase() {
    if (database == null) {
        database = getMongoClient().getDatabase("monumentum");
    }

    return database;
}
项目:Architecting-Modern-Java-EE-Applications    文件:ConfigurationExposer.java   
@Produces
@Config("")
public String exposeConfig(InjectionPoint injectionPoint) {
    final Config config = injectionPoint.getAnnotated().getAnnotation(Config.class);
    if (config != null)
        return properties.getProperty(config.value());
    return null;
}
项目:Architecting-Modern-Java-EE-Applications    文件:GreetingStrategySelector.java   
@Produces
public Function<String, String> exposeStrategy() {
    for (GreetingStrategy strategy : strategies) {
        if (strategy.isAppropriate(LocalTime.now()))
            return strategy::greet;
    }
    throw new IllegalStateException("Couldn't find an appropriate greeting");
}
项目:Architecting-Modern-Java-EE-Applications    文件:ConfigurationExposer.java   
@Produces
@Config("")
public String exposeConfig(InjectionPoint injectionPoint) {
    final Config config = injectionPoint.getAnnotated().getAnnotation(Config.class);
    if (config != null)
        return properties.getProperty(config.value());
    return null;
}
项目:javaee8-jsf-sample    文件:Resources.java   
@Produces
public Logger getLogger(InjectionPoint p) {
    return Logger.getLogger(p.getMember().getDeclaringClass().getName());
}
项目:launcher-backend    文件:BoosterCatalogFactory.java   
@Produces
@Singleton
public BoosterCatalog getDefaultCatalog() {
    return defaultBoosterCatalog;
}