Search in sources :

Example 21 with Inject

use of javax.inject.Inject in project OpenAM by OpenRock.

the class OAuth2GuiceModule method getOAuth2AuditContextProviders.

@Inject
@Provides
@Singleton
@Named(OAUTH2_AUDIT_CONTEXT_PROVIDERS)
Set<OAuth2AuditContextProvider> getOAuth2AuditContextProviders(TokenStore tokenStore, OAuth2RequestFactory<?, Request> requestFactory) {
    Set<OAuth2AuditContextProvider> set = new HashSet<>();
    set.add(new OAuth2AuditAccessTokenContextProvider(tokenStore, requestFactory));
    set.add(new OAuth2AuditRefreshTokenContextProvider(tokenStore, requestFactory));
    set.add(new OAuth2AuditSSOTokenContextProvider());
    return set;
}
Also used : OAuth2AuditRefreshTokenContextProvider(org.forgerock.openam.rest.audit.OAuth2AuditRefreshTokenContextProvider) OAuth2AuditContextProvider(org.forgerock.openam.rest.audit.OAuth2AuditContextProvider) OAuth2AuditAccessTokenContextProvider(org.forgerock.openam.rest.audit.OAuth2AuditAccessTokenContextProvider) OAuth2AuditSSOTokenContextProvider(org.forgerock.openam.rest.audit.OAuth2AuditSSOTokenContextProvider) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Named(javax.inject.Named) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 22 with Inject

use of javax.inject.Inject in project OpenAM by OpenRock.

the class CoreGuiceModule method getSessionBlacklist.

@Provides
@Singleton
@Inject
public static SessionBlacklist getSessionBlacklist(final CTSSessionBlacklist ctsBlacklist, final SessionServiceConfig serviceConfig) {
    if (!serviceConfig.isSessionBlacklistingEnabled()) {
        return NoOpSessionBlacklist.INSTANCE;
    }
    final long purgeDelayMs = serviceConfig.getSessionBlacklistPurgeDelay(TimeUnit.MILLISECONDS);
    final int cacheSize = serviceConfig.getSessionBlacklistCacheSize();
    final long pollIntervalMs = serviceConfig.getSessionBlacklistPollInterval(TimeUnit.MILLISECONDS);
    SessionBlacklist blacklist = ctsBlacklist;
    if (cacheSize > 0) {
        blacklist = new CachingSessionBlacklist(blacklist, cacheSize, purgeDelayMs);
    }
    if (pollIntervalMs > 0) {
        blacklist = new BloomFilterSessionBlacklist(blacklist, serviceConfig);
    }
    return blacklist;
}
Also used : BloomFilterSessionBlacklist(org.forgerock.openam.session.blacklist.BloomFilterSessionBlacklist) CachingSessionBlacklist(org.forgerock.openam.session.blacklist.CachingSessionBlacklist) CTSSessionBlacklist(org.forgerock.openam.session.blacklist.CTSSessionBlacklist) NoOpSessionBlacklist(org.forgerock.openam.session.blacklist.NoOpSessionBlacklist) SessionBlacklist(org.forgerock.openam.session.blacklist.SessionBlacklist) BloomFilterSessionBlacklist(org.forgerock.openam.session.blacklist.BloomFilterSessionBlacklist) CachingSessionBlacklist(org.forgerock.openam.session.blacklist.CachingSessionBlacklist) Inject(javax.inject.Inject) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 23 with Inject

use of javax.inject.Inject in project cloudstack by apache.

the class ActionEventUtilsTest method setup.

/**
     * This setup method injects the mocked beans into the ActionEventUtils class.
     * Because ActionEventUtils has static methods, we must also remember these fields
     * and restore them later, as otherwise strange behavior can result in other unit
     * tests due to the way the JVM handles static fields.
     * @throws Exception
     */
@Before
public void setup() throws Exception {
    publishedEvents = new ArrayList<>();
    staticFieldValues = new HashMap<>();
    setupCommonMocks();
    ActionEventUtils utils = new ActionEventUtils();
    for (Field field : ActionEventUtils.class.getDeclaredFields()) {
        if (field.getAnnotation(Inject.class) != null) {
            field.setAccessible(true);
            try {
                //Inject the mocked field from this class into the ActionEventUtils
                //and keep track of its original value.
                Field mockField = this.getClass().getDeclaredField(field.getName());
                field.set(utils, mockField.get(this));
                Field staticField = ActionEventUtils.class.getDeclaredField("s_" + field.getName());
                staticFieldValues.put(field.getName(), staticField.get(null));
            } catch (Exception e) {
            // ignore missing fields
            }
        }
    }
    utils.init();
}
Also used : Inject(javax.inject.Inject) Field(java.lang.reflect.Field) Before(org.junit.Before)

Example 24 with Inject

use of javax.inject.Inject in project drill by apache.

the class FunctionConverter method getHolder.

public <T extends DrillFunc> DrillFuncHolder getHolder(AnnotatedClassDescriptor func, ClassLoader classLoader) {
    FunctionTemplate template = func.getAnnotationProxy(FunctionTemplate.class);
    if (template == null) {
        return failure("Class does not declare FunctionTemplate annotation.", func);
    }
    String name = template.name();
    List<String> names = Arrays.asList(template.names());
    if (name.isEmpty() && names.isEmpty()) {
        // none set
        return failure("Must define 'name' or 'names'", func);
    }
    if (!name.isEmpty() && !names.isEmpty()) {
        // both are set
        return failure("Must use only one annotations 'name' or 'names', not both", func);
    }
    // start by getting field information.
    List<ValueReference> params = Lists.newArrayList();
    List<WorkspaceReference> workspaceFields = Lists.newArrayList();
    ValueReference outputField = null;
    for (FieldDescriptor field : func.getFields()) {
        Param param = field.getAnnotationProxy(Param.class);
        Output output = field.getAnnotationProxy(Output.class);
        Workspace workspace = field.getAnnotationProxy(Workspace.class);
        Inject inject = field.getAnnotationProxy(Inject.class);
        Annotation[] annotations = { param, output, workspace, inject };
        int annotationCount = 0;
        for (Annotation annotationDescriptor : annotations) {
            if (annotationDescriptor != null) {
                annotationCount += 1;
            }
        }
        if (annotationCount == 0) {
            return failure("The field must be either a @Param, @Output, @Inject or @Workspace field.", func, field);
        } else if (annotationCount > 1) {
            return failure("The field must be only one of @Param, @Output, @Inject or @Workspace. It currently has more than one of these annotations.", func, field);
        }
        // TODO(Julien): verify there are a few of those and we can load them
        Class<?> fieldClass = field.getFieldClass();
        if (param != null || output != null) {
            // Special processing for @Param FieldReader
            if (param != null && FieldReader.class.isAssignableFrom(fieldClass)) {
                params.add(ValueReference.createFieldReaderRef(field.getName()));
                continue;
            }
            // Special processing for @Output ComplexWriter
            if (output != null && ComplexWriter.class.isAssignableFrom(fieldClass)) {
                if (outputField != null) {
                    return failure("You've declared more than one @Output field.  You must declare one and only @Output field per Function class.", func, field);
                } else {
                    outputField = ValueReference.createComplexWriterRef(field.getName());
                }
                continue;
            }
            // check that param and output are value holders.
            if (!ValueHolder.class.isAssignableFrom(fieldClass)) {
                return failure(String.format("The field doesn't holds value of type %s which does not implement the ValueHolder interface.  All fields of type @Param or @Output must extend this interface..", fieldClass), func, field);
            }
            // get the type field from the value holder.
            MajorType type = null;
            try {
                type = getStaticFieldValue("TYPE", fieldClass, MajorType.class);
            } catch (Exception e) {
                return failure("Failure while trying to access the ValueHolder's TYPE static variable.  All ValueHolders must contain a static TYPE variable that defines their MajorType.", e, func, field);
            }
            ValueReference p = new ValueReference(type, field.getName());
            if (param != null) {
                p.setConstant(param.constant());
                params.add(p);
            } else {
                if (outputField != null) {
                    return failure("You've declared more than one @Output field.  You must declare one and only @Output field per Function class.", func, field);
                } else {
                    outputField = p;
                }
            }
        } else {
            // workspace work.
            boolean isInject = inject != null;
            if (isInject && UdfUtilities.INJECTABLE_GETTER_METHODS.get(fieldClass) == null) {
                return failure(String.format("A %s cannot be injected into a %s," + " available injectable classes are: %s.", fieldClass, DrillFunc.class.getSimpleName(), Joiner.on(",").join(UdfUtilities.INJECTABLE_GETTER_METHODS.keySet())), func, field);
            }
            WorkspaceReference wsReference = new WorkspaceReference(fieldClass, field.getName(), isInject);
            if (!isInject && template.scope() == FunctionScope.POINT_AGGREGATE && !ValueHolder.class.isAssignableFrom(fieldClass)) {
                return failure(String.format("Aggregate function '%s' workspace variable '%s' is of type '%s'. Please change it to Holder type.", func.getClassName(), field.getName(), fieldClass), func, field);
            }
            //If the workspace var is of Holder type, get its MajorType and assign to WorkspaceReference.
            if (ValueHolder.class.isAssignableFrom(fieldClass)) {
                MajorType majorType = null;
                try {
                    majorType = getStaticFieldValue("TYPE", fieldClass, MajorType.class);
                } catch (Exception e) {
                    return failure("Failure while trying to access the ValueHolder's TYPE static variable.  All ValueHolders must contain a static TYPE variable that defines their MajorType.", e, func, field);
                }
                wsReference.setMajorType(majorType);
            }
            workspaceFields.add(wsReference);
        }
    }
    if (outputField == null) {
        return failure("This function declares zero output fields.  A function must declare one output field.", func);
    }
    FunctionInitializer initializer = new FunctionInitializer(func.getClassName(), classLoader);
    try {
        // return holder
        ValueReference[] ps = params.toArray(new ValueReference[params.size()]);
        WorkspaceReference[] works = workspaceFields.toArray(new WorkspaceReference[workspaceFields.size()]);
        FunctionAttributes functionAttributes = new FunctionAttributes(template, ps, outputField, works);
        switch(template.scope()) {
            case POINT_AGGREGATE:
                return new DrillAggFuncHolder(functionAttributes, initializer);
            case SIMPLE:
                return outputField.isComplexWriter() ? new DrillComplexWriterFuncHolder(functionAttributes, initializer) : new DrillSimpleFuncHolder(functionAttributes, initializer);
            case HOLISTIC_AGGREGATE:
            case RANGE_AGGREGATE:
            default:
                return failure("Unsupported Function Type.", func);
        }
    } catch (Exception | NoSuchFieldError | AbstractMethodError ex) {
        return failure("Failure while creating function holder.", ex, func);
    }
}
Also used : ComplexWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter) FieldDescriptor(org.apache.drill.common.scanner.persistence.FieldDescriptor) FunctionTemplate(org.apache.drill.exec.expr.annotations.FunctionTemplate) Output(org.apache.drill.exec.expr.annotations.Output) Inject(javax.inject.Inject) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) ValueHolder(org.apache.drill.exec.expr.holders.ValueHolder) Annotation(java.lang.annotation.Annotation) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) Param(org.apache.drill.exec.expr.annotations.Param) FieldReader(org.apache.drill.exec.vector.complex.reader.FieldReader) Workspace(org.apache.drill.exec.expr.annotations.Workspace)

Example 25 with Inject

use of javax.inject.Inject in project deltaspike by apache.

the class TransactionStrategyHelper method collectEntityManagerQualifiersOnClass.

/**
     * Scan the given class and return all the injected EntityManager fields.
     * <p>Attention: we do only pick up EntityManagers which use &#064;Inject!</p>
     */
private void collectEntityManagerQualifiersOnClass(Set<Class<? extends Annotation>> emQualifiers, Class target) {
    // first scan all declared fields
    Field[] fields = target.getDeclaredFields();
    for (Field field : fields) {
        if (EntityManager.class.equals(field.getType())) {
            // also check if this is an injected EM
            if (field.getAnnotation(Inject.class) != null) {
                boolean qualifierFound = false;
                Class<? extends Annotation> qualifier = getFirstQualifierAnnotation(field.getAnnotations());
                if (qualifier != null) {
                    emQualifiers.add(qualifier);
                    qualifierFound = true;
                }
                if (!qualifierFound) {
                    // according to the CDI injection rules @Default is assumed
                    emQualifiers.add(Default.class);
                }
            }
        }
    }
    // finally recurse into the superclasses
    Class superClass = target.getSuperclass();
    if (!Object.class.equals(superClass)) {
        collectEntityManagerQualifiersOnClass(emQualifiers, superClass);
    }
}
Also used : Inject(javax.inject.Inject) Field(java.lang.reflect.Field)

Aggregations

Inject (javax.inject.Inject)25 Field (java.lang.reflect.Field)8 Provides (com.google.inject.Provides)6 ArrayList (java.util.ArrayList)6 Named (javax.inject.Named)5 Singleton (javax.inject.Singleton)3 Bundle (android.os.Bundle)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)2 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 PreferenceManager (android.preference.PreferenceManager)1 Nullable (android.support.annotation.Nullable)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 TabLayout (android.support.design.widget.TabLayout)1 Pair (android.support.v4.util.Pair)1 ViewCompat (android.support.v4.view.ViewCompat)1 ViewPager (android.support.v4.view.ViewPager)1 Toolbar (android.support.v7.widget.Toolbar)1 Transition (android.transition.Transition)1 TransitionInflater (android.transition.TransitionInflater)1