Example usage for org.springframework.beans.factory.support AbstractBeanDefinition AUTOWIRE_BY_NAME

List of usage examples for org.springframework.beans.factory.support AbstractBeanDefinition AUTOWIRE_BY_NAME

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support AbstractBeanDefinition AUTOWIRE_BY_NAME.

Prototype

int AUTOWIRE_BY_NAME

To view the source code for org.springframework.beans.factory.support AbstractBeanDefinition AUTOWIRE_BY_NAME.

Click Source Link

Document

Constant that indicates autowiring bean properties by name.

Usage

From source file:com.taobao.itest.spring.context.SpringContextManager.java

public static void registerBeanDefinition(Field field, ApplicationContext applicationContext) {
    @SuppressWarnings("deprecation")
    RootBeanDefinition beanDefinition = new RootBeanDefinition(field.getType(), true);
    beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
    DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) (applicationContext
            .getAutowireCapableBeanFactory());
    defaultListableBeanFactory.registerBeanDefinition(field.getName(), beanDefinition);
}

From source file:me.springframework.di.spring.AutowiringAugmentation.java

private void attribute(final MutableInstance instance, final MutableContext context) {
    if (instance.getAutowireMode() == AbstractBeanDefinition.AUTOWIRE_BY_NAME
            || instance.getAutowireMode() == AbstractBeanDefinition.AUTOWIRE_BY_TYPE) {
        attributeProperties(instance, context);
    } else if (instance.getAutowireMode() == AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR) {
        attributeConstructor(instance, context);
    }/*from  ww w.j a  v  a  2s.c  om*/
}

From source file:me.springframework.di.spring.AutowiringAugmentation.java

/**
 * Autowires {@link MutableInstance} passed in, accepting
 * <code>context</code> for resolving references.
 *///from  w w  w  .java 2 s . co  m
private void attributeProperties(final MutableInstance instance, final MutableContext context) {
    final JavaClass cl = builder.getClassByName(instance.getType());
    for (final BeanProperty beanProperty : cl.getBeanProperties()) {
        // don't do autowiring by type for primitive types
        if (beanProperty.getType().isPrimitive()) {
            continue;
        }

        // check if property not set already
        if (hasSetter(instance, beanProperty.getName())) {
            continue;
        }
        final MutableInstance newInstance;
        if (instance.getAutowireMode() == AbstractBeanDefinition.AUTOWIRE_BY_NAME) {
            // try to find an instance by name
            newInstance = context.getByName(beanProperty.getName());
            if (newInstance == null || !newInstance.isAutowireCandidate()) {
                continue;
            }
        } else {
            // try to find an instance by type
            newInstance = findInstanceByType(context, instance.getName(), beanProperty.getName(),
                    beanProperty.getType().getValue());
            if (newInstance == null || !newInstance.isAutowireCandidate()) {
                continue;
            }
        }

        // add new setter
        final MutablePropertySetter newSetter = new MutablePropertySetter(instance);
        final MutableInstanceReference ref = new MutableInstanceReference(newSetter, newInstance.getName());
        ref.setReferencedId(newInstance.getId());
        ref.setId("source_autowire" + counter++);
        newSetter.setName(beanProperty.getName());
        newSetter.setPrimitive(false);
        newSetter.setSource(ref);
        newSetter.setType(newInstance.getType());
        newSetter.setInstance(instance);
        instance.getSetters().add(newSetter);
    }

}

From source file:hudson.util.spring.DefaultBeanConfiguration.java

public BeanConfiguration setAutowire(String type) {
    if ("byName".equals(type)) {
        getBeanDefinition().setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
    } else if ("byType".equals(type)) {
        getBeanDefinition().setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
    }/*  ww  w .j  a v a 2  s.c  o  m*/
    return this;
}

From source file:org.apache.syncope.core.misc.utils.MappingUtils.java

public static List<MappingItemTransformer> getMappingItemTransformers(final MappingItem mappingItem) {
    List<MappingItemTransformer> result = new ArrayList<>();

    for (String className : mappingItem.getMappingItemTransformerClassNames()) {
        try {//from   www.ja v  a2 s  .  c  om
            Class<?> transformerClass = ClassUtils.getClass(className);

            result.add((MappingItemTransformer) ApplicationContextProvider.getBeanFactory()
                    .createBean(transformerClass, AbstractBeanDefinition.AUTOWIRE_BY_NAME, false));
        } catch (Exception e) {
            LOG.error("Could not instantiate {}, ignoring...", className, e);
        }
    }

    return result;
}

From source file:org.apache.syncope.core.provisioning.java.job.TaskJob.java

@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
    super.execute(context);

    try {/*  w  w w. ja  v  a 2 s.co m*/
        AuthContextUtils.execWithAuthContext(context.getMergedJobDataMap().getString(JobManager.DOMAIN_KEY),
                new AuthContextUtils.Executable<Void>() {

                    @Override
                    public Void exec() {
                        try {
                            Class<?> delegateClass = ClassUtils
                                    .getClass(context.getMergedJobDataMap().getString(DELEGATE_CLASS_KEY));

                            ((SchedTaskJobDelegate) ApplicationContextProvider.getBeanFactory()
                                    .createBean(delegateClass, AbstractBeanDefinition.AUTOWIRE_BY_NAME, false))
                                            .execute(taskKey, context.getMergedJobDataMap()
                                                    .getBoolean(DRY_RUN_JOBDETAIL_KEY), context);
                        } catch (Exception e) {
                            LOG.error("While executing task {}", taskKey, e);
                            throw new RuntimeException(e);
                        }

                        return null;
                    }
                });
    } catch (RuntimeException e) {
        LOG.error("While executing task {}", taskKey, e);
        throw new JobExecutionException("While executing task " + taskKey, e);
    }
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate.java

protected RealmPullResultHandler buildRealmHandler() {
    RealmPullResultHandler handler = (RealmPullResultHandler) ApplicationContextProvider.getBeanFactory()
            .createBean(DefaultRealmPullResultHandler.class, AbstractBeanDefinition.AUTOWIRE_BY_NAME, false);
    handler.setProfile(profile);/*  w w  w.ja va2 s .  co m*/
    handler.setPullExecutor(this);

    return handler;
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate.java

protected AnyObjectPullResultHandler buildAnyObjectHandler() {
    AnyObjectPullResultHandler handler = (AnyObjectPullResultHandler) ApplicationContextProvider
            .getBeanFactory().createBean(DefaultAnyObjectPullResultHandler.class,
                    AbstractBeanDefinition.AUTOWIRE_BY_NAME, false);
    handler.setProfile(profile);/*from w w w.java 2 s.c om*/
    handler.setPullExecutor(this);

    return handler;
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate.java

protected UserPullResultHandler buildUserHandler() {
    UserPullResultHandler handler = (UserPullResultHandler) ApplicationContextProvider.getBeanFactory()
            .createBean(DefaultUserPullResultHandler.class, AbstractBeanDefinition.AUTOWIRE_BY_NAME, false);
    handler.setProfile(profile);//  w  w w  .  ja va 2s .c  om
    handler.setPullExecutor(this);

    return handler;
}

From source file:org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate.java

protected GroupPullResultHandler buildGroupHandler() {
    GroupPullResultHandler handler = (GroupPullResultHandler) ApplicationContextProvider.getBeanFactory()
            .createBean(DefaultGroupPullResultHandler.class, AbstractBeanDefinition.AUTOWIRE_BY_NAME, false);
    handler.setProfile(profile);/*from   ww w. ja va2  s  .  co m*/
    handler.setPullExecutor(this);

    return handler;
}