javax.enterprise.inject.New Java Examples

The following examples show how to use javax.enterprise.inject.New. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ManagerApiMicroServiceCdiFactory.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Produces
@ApplicationScoped
public static IStorage provideStorage(ManagerApiMicroServiceConfig config, @New JpaStorage jpaStorage,
        @New EsStorage esStorage, IPluginRegistry pluginRegistry) {
    IStorage storage;
    if ("jpa".equals(config.getStorageType())) { //$NON-NLS-1$
        storage = initJpaStorage(config, jpaStorage);
    } else if ("es".equals(config.getStorageType())) { //$NON-NLS-1$
        storage = initES(config, esStorage);
    } else {
        try {
            storage = createCustomComponent(IStorage.class, config.getStorageType(),
                    config.getStorageProperties(), pluginRegistry);
        } catch (Throwable t) {
            throw new RuntimeException("Error or unknown storage type: " + config.getStorageType(), t); //$NON-NLS-1$
        }
    }
    return storage;
}
 
Example #2
Source File: WarCdiFactory.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Produces @ApplicationScoped
public static IApiKeyGenerator provideApiKeyGenerator(WarApiManagerConfig config,
        @New UuidApiKeyGenerator uuidApiKeyGen, IPluginRegistry pluginRegistry) {
    IApiKeyGenerator apiKeyGenerator;
    String type = config.getApiKeyGeneratorType();
    if ("uuid".equals(type)) { //$NON-NLS-1$
        apiKeyGenerator = uuidApiKeyGen;
    } else {
        try {
            apiKeyGenerator = createCustomComponent(IApiKeyGenerator.class, type,
                    config.getApiKeyGeneratorProperties(), pluginRegistry);
        } catch (Exception e) {
            System.err.println("Unknown apiman API key generator type: " + type); //$NON-NLS-1$
            System.err.println("Automatically falling back to UUID style API Keys."); //$NON-NLS-1$
            apiKeyGenerator = uuidApiKeyGen;
        }
    }
    return apiKeyGenerator;
}
 
Example #3
Source File: WarCdiFactory.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Produces @ApplicationScoped
public static IMetricsAccessor provideMetricsAccessor(WarApiManagerConfig config,
        @New NoOpMetricsAccessor noopMetrics, @New ESMetricsAccessor esMetrics, IPluginRegistry pluginRegistry) {
    IMetricsAccessor metrics;
    if ("es".equals(config.getMetricsType())) { //$NON-NLS-1$
        metrics = esMetrics;
    } else if (config.getMetricsType().equals(ESMetricsAccessor.class.getName())) {
        metrics = esMetrics;
    } else if ("noop".equals(config.getMetricsType())) { //$NON-NLS-1$
        metrics = noopMetrics;
    } else if (config.getMetricsType().equals(NoOpMetricsAccessor.class.getName())) {
        metrics = noopMetrics;
    } else {
        try {
            metrics = createCustomComponent(IMetricsAccessor.class, config.getMetricsType(),
                    config.getMetricsProperties(), pluginRegistry);
        } catch (Throwable t) {
            System.err.println("Unknown apiman metrics accessor type: " + config.getMetricsType()); //$NON-NLS-1$
            metrics = noopMetrics;
        }
    }
    return metrics;
}
 
Example #4
Source File: WarCdiFactory.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Produces @ApplicationScoped
public static IStorageQuery provideStorageQuery(WarApiManagerConfig config, @New JpaStorage jpaStorage,
        @New EsStorage esStorage, IStorage storage, IPluginRegistry pluginRegistry) {
    if ("jpa".equals(config.getStorageType())) { //$NON-NLS-1$
        return initJpaStorage(config, jpaStorage);
    } else if ("es".equals(config.getStorageType())) { //$NON-NLS-1$
        return initEsStorage(config, esStorage);
    } else if (storage != null && storage instanceof IStorageQuery) {
        return (IStorageQuery) storage;
    } else {
        try {
            return createCustomComponent(IStorageQuery.class, config.getStorageQueryType(),
                    config.getStorageQueryProperties(), pluginRegistry);
        } catch (Throwable t) {
            throw new RuntimeException("Error or unknown storage query type: " + config.getStorageType(), t); //$NON-NLS-1$
        }
    }
}
 
Example #5
Source File: WarCdiFactory.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Produces @ApplicationScoped
public static IStorage provideStorage(WarApiManagerConfig config, @New JpaStorage jpaStorage,
        @New EsStorage esStorage, IPluginRegistry pluginRegistry) {
    IStorage storage;
    if ("jpa".equals(config.getStorageType())) { //$NON-NLS-1$
        storage = initJpaStorage(config, jpaStorage);
    } else if ("es".equals(config.getStorageType())) { //$NON-NLS-1$
        storage = initEsStorage(config, esStorage);
    } else {
        try {
            storage = createCustomComponent(IStorage.class, config.getStorageType(),
                    config.getStorageProperties(), pluginRegistry);
        } catch (Throwable t) {
            throw new RuntimeException("Error or unknown storage type: " + config.getStorageType(), t); //$NON-NLS-1$
        }
    }
    return storage;
}
 
Example #6
Source File: ManagerApiMicroServiceCdiFactory.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Produces @ApplicationScoped
public static IApiKeyGenerator provideApiKeyGenerator(ManagerApiMicroServiceConfig config,
        IPluginRegistry pluginRegistry, @New UuidApiKeyGenerator uuidApiKeyGen) {
    IApiKeyGenerator apiKeyGenerator;
    String type = config.getApiKeyGeneratorType();
    if ("uuid".equals(type)) { //$NON-NLS-1$
        apiKeyGenerator = uuidApiKeyGen;
    } else {
        try {
            apiKeyGenerator = createCustomComponent(IApiKeyGenerator.class, type,
                    config.getApiKeyGeneratorProperties(), pluginRegistry);
        } catch (Exception e) {
            System.err.println("Unknown apiman API key generator type: " + type); //$NON-NLS-1$
            System.err.println("Automatically falling back to UUID style API Keys."); //$NON-NLS-1$
            apiKeyGenerator = uuidApiKeyGen;
        }
    }
    return apiKeyGenerator;
}
 
Example #7
Source File: ManagerApiMicroServiceCdiFactory.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Produces @ApplicationScoped
public static IMetricsAccessor provideMetricsAccessor(ManagerApiMicroServiceConfig config,
        @New NoOpMetricsAccessor noopMetrics, @New ESMetricsAccessor esMetrics, IPluginRegistry pluginRegistry) {
    IMetricsAccessor metrics;
    if ("es".equals(config.getMetricsType())) { //$NON-NLS-1$
        metrics = esMetrics;
    } else {
        try {
            metrics = createCustomComponent(IMetricsAccessor.class, config.getMetricsType(),
                    config.getMetricsProperties(), pluginRegistry);
        } catch (Throwable t) {
            System.err.println("Unknown apiman metrics accessor type: " + config.getMetricsType()); //$NON-NLS-1$
            metrics = noopMetrics;
        }
    }
    return metrics;
}
 
Example #8
Source File: ManagerApiMicroServiceCdiFactory.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Produces @ApplicationScoped
public static IStorageQuery provideStorageQuery(ManagerApiMicroServiceConfig config, @New JpaStorage jpaStorage,
        @New EsStorage esStorage, IPluginRegistry pluginRegistry) {
    if ("jpa".equals(config.getStorageQueryType())) { //$NON-NLS-1$
        return initJpaStorage(config, jpaStorage);
    } else if ("es".equals(config.getStorageQueryType())) { //$NON-NLS-1$
        return initES(config, esStorage);
    } else {
        try {
            return createCustomComponent(IStorageQuery.class, config.getStorageQueryType(),
                    config.getStorageQueryProperties(), pluginRegistry);
        } catch (Throwable t) {
            throw new RuntimeException("Error or unknown storage query type: " + config.getStorageType(), t); //$NON-NLS-1$
        }
    }
}
 
Example #9
Source File: ManagerApiMicroServiceCdiFactory.java    From apiman with Apache License 2.0 5 votes vote down vote up
@Produces @ApplicationScoped
public static IDataEncrypter provideDataEncrypter(ManagerApiMicroServiceConfig config,
        IPluginRegistry pluginRegistry, @New DefaultDataEncrypter defaultEncrypter) {
    try {
        IDataEncrypter encrypter = createCustomComponent(IDataEncrypter.class, config.getDataEncrypterType(),
                config.getDataEncrypterProperties(), pluginRegistry, defaultEncrypter);
        CurrentDataEncrypter.instance = encrypter;
        return encrypter;
    } catch (Throwable t) {
        throw new RuntimeException("Error or unknown data encrypter type: " + config.getDataEncrypterType(), t); //$NON-NLS-1$
    }
}
 
Example #10
Source File: WarCdiFactory.java    From apiman with Apache License 2.0 5 votes vote down vote up
@Produces @ApplicationScoped
public static ISecurityContext provideSecurityContext(WarApiManagerConfig config,
        @New DefaultSecurityContext defaultSC, @New KeycloakSecurityContext keycloakSC) {
    if ("default".equals(config.getSecurityContextType())) { //$NON-NLS-1$
        return defaultSC;
    } else if ("keycloak".equals(config.getSecurityContextType())) { //$NON-NLS-1$
        return keycloakSC;
    } else {
        throw new RuntimeException("Unknown security context type: " + config.getSecurityContextType()); //$NON-NLS-1$
    }
}
 
Example #11
Source File: ParamValueLoaderService.java    From actframework with Apache License 2.0 5 votes vote down vote up
private static ScopeCacheSupport scopeCacheSupport(BeanSpec spec) {
    if (spec.hasAnnotation(RequestScoped.class) || spec.hasAnnotation(org.osgl.inject.annotation.RequestScoped.class)) {
        return RequestScope.INSTANCE;
    } else if (sessionScoped(spec)) {
        return SessionScope.INSTANCE;
    } else if (spec.hasAnnotation(Dependent.class) || spec.hasAnnotation(New.class)) {
        return DependentScope.INSTANCE;
    }
    // Default to Request Scope
    return RequestScope.INSTANCE;
}
 
Example #12
Source File: WarCdiFactory.java    From apiman with Apache License 2.0 5 votes vote down vote up
@Produces @ApplicationScoped
public static IDataEncrypter provideDataEncrypter(@New DefaultDataEncrypter defaultEncrypter,
        WarApiManagerConfig config, IPluginRegistry pluginRegistry) {
    try {
        IDataEncrypter encrypter = createCustomComponent(IDataEncrypter.class, config.getDataEncrypterType(),
                config.getDataEncrypterProperties(), pluginRegistry, defaultEncrypter);
        CurrentDataEncrypter.instance = encrypter;
        return encrypter;
    } catch (Throwable t) {
        throw new RuntimeException("Error or unknown data encrypter type: " + config.getDataEncrypterType(), t); //$NON-NLS-1$
    }
}
 
Example #13
Source File: TestCdiFactory.java    From apiman with Apache License 2.0 5 votes vote down vote up
@Produces @ApplicationScoped
public static IStorage provideStorage(@New JpaStorage jpaStorage, @New EsStorage esStorage) {
    TestType testType = ManagerTestUtils.getTestType();
    if (testType == TestType.jpa) {
        return jpaStorage;
    } else if (testType == TestType.es) {
        esStorage.initialize();
        return new TestEsStorageWrapper(ManagerApiTestServer.ES_CLIENT, esStorage);
    } else {
        throw new RuntimeException("Unexpected test type: " + testType);
    }
}
 
Example #14
Source File: TestCdiFactory.java    From apiman with Apache License 2.0 5 votes vote down vote up
@Produces @ApplicationScoped
public static IStorageQuery provideStorageQuery(@New JpaStorage jpaStorage, @New EsStorage esStorage) {
    TestType testType = ManagerTestUtils.getTestType();
    if (testType == TestType.jpa) {
        return jpaStorage;
    } else if (testType == TestType.es) {
        esStorage.initialize();
        return new TestEsStorageQueryWrapper(ManagerApiTestServer.ES_CLIENT, esStorage);
    } else {
        throw new RuntimeException("Unexpected test type: " + testType);
    }
}
 
Example #15
Source File: TestCdiFactory.java    From apiman with Apache License 2.0 5 votes vote down vote up
@Produces @ApplicationScoped
public static IMetricsAccessor provideMetricsAccessor(@New TestMetricsAccessor testMetrics, @New ESMetricsAccessor esMetrics) {
    boolean enableESMetrics = "true".equals(System.getProperty("apiman-test.es-metrics", "false"));
    if (enableESMetrics) {
        return esMetrics;
    } else {
        return testMetrics;
    }
}
 
Example #16
Source File: ManagerApiMicroServiceCdiFactory.java    From apiman with Apache License 2.0 4 votes vote down vote up
@Produces @ApplicationScoped
public static ISecurityContext provideSecurityContext(@New DefaultSecurityContext defaultSC) {
    return defaultSC;
}
 
Example #17
Source File: TestCdiFactory.java    From apiman with Apache License 2.0 4 votes vote down vote up
@Produces @ApplicationScoped
public static ISecurityContext provideSecurityContext(@New DefaultSecurityContext defaultSC) {
    return defaultSC;
}
 
Example #18
Source File: TestCdiFactory.java    From apiman with Apache License 2.0 4 votes vote down vote up
@Produces @ApplicationScoped
public static IApiKeyGenerator provideApiKeyGenerator(@New UuidApiKeyGenerator uuidApiKeyGen) {
    return uuidApiKeyGen;
}
 
Example #19
Source File: TestCdiFactory.java    From apiman with Apache License 2.0 4 votes vote down vote up
@Produces @ApplicationScoped
public static IDataEncrypter provideDataEncrypter(@New DefaultDataEncrypter defaultEncrypter) {
    CurrentDataEncrypter.instance = defaultEncrypter;
    return defaultEncrypter;
}
 
Example #20
Source File: NewLiteral.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public NewLiteral()
{
    this(New.class);
}