Java Code Examples for org.springframework.beans.factory.config.BeanDefinition#getConstructorArgumentValues()

The following examples show how to use org.springframework.beans.factory.config.BeanDefinition#getConstructorArgumentValues() . 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: JPAPersistenceSupportBeanFactory.java    From statefulj with Apache License 2.0 6 votes vote down vote up
@Override
public BeanDefinition buildFSMHarnessBean(
		Class<?> statefulClass,
		String fsmBeanId,
		String factoryId, 
		String finderId,
		BeanDefinition repoBeanDefinitionFactory) {
	String tmId = (String)repoBeanDefinitionFactory.getPropertyValues().getPropertyValue("transactionManager").getValue();
	
	BeanDefinition fsmHarness = BeanDefinitionBuilder
			.genericBeanDefinition(JPAFSMHarnessImpl.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = fsmHarness.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, new RuntimeBeanReference(fsmBeanId));
	args.addIndexedArgumentValue(1, statefulClass);
	args.addIndexedArgumentValue(2, new RuntimeBeanReference(factoryId));
	args.addIndexedArgumentValue(3, new RuntimeBeanReference(finderId));
	args.addIndexedArgumentValue(4, new RuntimeBeanReference(tmId));
	return fsmHarness;
}
 
Example 2
Source File: JPAPersistenceSupportBeanFactory.java    From statefulj with Apache License 2.0 6 votes vote down vote up
@Override
public BeanDefinition buildPersisterBean(
		Class<?> statefulClass,
		String repoBeanId,
		BeanDefinition repoBeanDefinitionFactory,
		String stateFieldName,
		String startStateId, 
		List<RuntimeBeanReference> stateBeans) {
	BeanDefinition entityMgr = (BeanDefinition)repoBeanDefinitionFactory.getPropertyValues().getPropertyValue("entityManager").getValue();
	String tmId = (String)repoBeanDefinitionFactory.getPropertyValues().getPropertyValue("transactionManager").getValue();
	BeanDefinition persisterBean = BeanDefinitionBuilder
			.genericBeanDefinition(JPAPerister.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = persisterBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, stateBeans);
	args.addIndexedArgumentValue(1, stateFieldName);
	args.addIndexedArgumentValue(2, new RuntimeBeanReference(startStateId));
	args.addIndexedArgumentValue(3, statefulClass);
	args.addIndexedArgumentValue(4, entityMgr);
	args.addIndexedArgumentValue(5, new RuntimeBeanReference(tmId));
	return persisterBean;
}
 
Example 3
Source File: MemoryPersistenceSupportBeanFactoryImpl.java    From statefulj with Apache License 2.0 6 votes vote down vote up
@Override
public BeanDefinition buildPersisterBean(
		Class<?> statefulClass,
		String repoBeanId, 
		BeanDefinition repoBeanDefinitionFactory,
		String stateFieldName, 
		String startStateId,
		List<RuntimeBeanReference> stateBeans) {
	BeanDefinition persisterBean = BeanDefinitionBuilder
			.genericBeanDefinition(MemoryPersisterImpl.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = persisterBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, stateBeans);
	args.addIndexedArgumentValue(1, new RuntimeBeanReference(startStateId));
	args.addIndexedArgumentValue(2, stateFieldName);
	return persisterBean;
}
 
Example 4
Source File: StatefulFactory.java    From statefulj with Apache License 2.0 6 votes vote down vote up
/**
 * @param referenceFactory
 * @param from
 * @param to
 * @param reload
 * @param transition
 * @param transitionId
 * @param reg
 * @param actionRef
 */
private void registerTransition(ReferenceFactory referenceFactory,
		String from, String to, boolean reload, Transition transition,
		String transitionId, BeanDefinitionRegistry reg,
		RuntimeBeanReference actionRef) {
	// Build the Transition Bean
	//
	BeanDefinition transitionBean = BeanDefinitionBuilder
			.genericBeanDefinition(TransitionImpl.class)
			.getBeanDefinition();

	String fromId = referenceFactory.getStateId(from);
	String toId = referenceFactory.getStateId(to);
	Pair<String, String> providerEvent = parseEvent(transition.event());

	ConstructorArgumentValues args = transitionBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, new RuntimeBeanReference(fromId));
	args.addIndexedArgumentValue(1, new RuntimeBeanReference(toId));
	args.addIndexedArgumentValue(2, providerEvent.getRight());
	args.addIndexedArgumentValue(3, actionRef);
	args.addIndexedArgumentValue(4,
			(transition.from().equals(Transition.ANY_STATE) &&
			 transition.to().equals(Transition.ANY_STATE)));
	args.addIndexedArgumentValue(5, reload);
	reg.registerBeanDefinition(transitionId, transitionBean);
}
 
Example 5
Source File: StatefulFactory.java    From statefulj with Apache License 2.0 6 votes vote down vote up
private String registerState(
		ReferenceFactory referenceFactory,
		Class<?> statefulControllerClass,
		String state,
		boolean isBlocking,
		BeanDefinitionRegistry reg) {

	String stateId = referenceFactory.getStateId(state);
	BeanDefinition stateBean = BeanDefinitionBuilder
			.genericBeanDefinition(StateImpl.class)
			.getBeanDefinition();

	ConstructorArgumentValues args = stateBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, state);
	args.addIndexedArgumentValue(1, false);
	args.addIndexedArgumentValue(2, isBlocking);

	reg.registerBeanDefinition(stateId, stateBean);

	return stateId;
}
 
Example 6
Source File: MongoPersistenceSupportBeanFactory.java    From statefulj with Apache License 2.0 6 votes vote down vote up
@Override
public BeanDefinition buildFSMHarnessBean(
		Class<?> statefulClass,
		String fsmBeanId,
		String factoryId, 
		String finderId,
		BeanDefinition repoBeanDefinitionFactory) {

	BeanDefinition fsmHarness = BeanDefinitionBuilder
			.genericBeanDefinition(FSMHarnessImpl.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = fsmHarness.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, new RuntimeBeanReference(fsmBeanId));
	args.addIndexedArgumentValue(1, statefulClass);
	args.addIndexedArgumentValue(2, new RuntimeBeanReference(factoryId));
	args.addIndexedArgumentValue(3, new RuntimeBeanReference(finderId));
	return fsmHarness;
}
 
Example 7
Source File: StatefulFactory.java    From statefulj with Apache License 2.0 6 votes vote down vote up
private String registerStatefulFSMBean(
		ReferenceFactory referenceFactory,
		Class<?> statefulClass,
		String fsmBeanId,
		String factoryId,
		List<String> transitionIds,
		BeanDefinitionRegistry reg) {
	String statefulFSMBeanId = referenceFactory.getStatefulFSMId();
	BeanDefinition statefulFSMBean = BeanDefinitionBuilder
			.genericBeanDefinition(StatefulFSMImpl.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = statefulFSMBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, new RuntimeBeanReference(fsmBeanId));
	args.addIndexedArgumentValue(1, statefulClass);
	args.addIndexedArgumentValue(2, new RuntimeBeanReference(factoryId));
	reg.registerBeanDefinition(statefulFSMBeanId, statefulFSMBean);
	statefulFSMBean.setDependsOn(transitionIds.toArray(new String[]{}));
	return statefulFSMBeanId;
}
 
Example 8
Source File: MongoPersistenceSupportBeanFactory.java    From statefulj with Apache License 2.0 6 votes vote down vote up
@Override
public BeanDefinition buildPersisterBean(
		Class<?> statefulClass,
		String repoBeanId,
		BeanDefinition repoBeanDefinitionFactory,
		String stateFieldName,
		String startStateId,
		List<RuntimeBeanReference> stateBeans) {
	BeanDefinition persisterBean = BeanDefinitionBuilder
			.genericBeanDefinition(MongoPersister.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = persisterBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, stateBeans);
	args.addIndexedArgumentValue(1, stateFieldName);
	args.addIndexedArgumentValue(2, new RuntimeBeanReference(startStateId));
	args.addIndexedArgumentValue(3, statefulClass);
	args.addIndexedArgumentValue(4, repoBeanId);
	return persisterBean;
}
 
Example 9
Source File: StatefulFactory.java    From statefulj with Apache License 2.0 5 votes vote down vote up
private String registerFSM(
		ReferenceFactory referenceFactory,
		Class<?> statefulControllerClass,
		StatefulController scAnnotation,
		String persisterId,
		Class<?> managedClass,
		String finderId,
		Class<? extends Annotation> idAnnotationType,
		BeanDefinitionRegistry reg) {
	int retryAttempts = scAnnotation.retryAttempts();
	int retryInterval = scAnnotation.retryInterval();

	String fsmBeanId = referenceFactory.getFSMId();
	BeanDefinition fsmBean = BeanDefinitionBuilder
			.genericBeanDefinition(FSM.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = fsmBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, fsmBeanId);
	args.addIndexedArgumentValue(1, new RuntimeBeanReference(persisterId));
	args.addIndexedArgumentValue(2, retryAttempts);
	args.addIndexedArgumentValue(3, retryInterval);
	args.addIndexedArgumentValue(4, managedClass);
	args.addIndexedArgumentValue(5, idAnnotationType);
	args.addIndexedArgumentValue(6, this.appContext);

	if (finderId != null) {
		args.addIndexedArgumentValue(7, new RuntimeBeanReference(finderId));
	}

	reg.registerBeanDefinition(fsmBeanId, fsmBean);
	return fsmBeanId;
}
 
Example 10
Source File: MongoPersister.java    From statefulj with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeanDefinitionRegistry(
		BeanDefinitionRegistry registry) throws BeansException {

	if (this.mongoTemplate == null) {

		if (this.repoId != null) {

			// Fetch the MongoTemplate Bean Id
			//
			BeanDefinition repo = registry.getBeanDefinition(this.repoId);
			this.templateId = ((BeanReference)repo.getPropertyValues().get("mongoOperations")).getBeanName();
		}

		// Check to make sure we have a reference to the MongoTemplate
		//
		if (this.templateId == null) {
			throw new RuntimeException("Unable to obtain a reference to a MongoTemplate");
		}
	}


	// Add in CascadeSupport
	//
	BeanDefinition mongoCascadeSupportBean = BeanDefinitionBuilder
			.genericBeanDefinition(MongoCascadeSupport.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = mongoCascadeSupportBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, this);
	registry.registerBeanDefinition(Long.toString((new Random()).nextLong()), mongoCascadeSupportBean);
}
 
Example 11
Source File: JPAPersistenceSupportBeanFactory.java    From statefulj with Apache License 2.0 5 votes vote down vote up
@Override
public BeanDefinition buildFinderBean(String repoFactoryBeanId) {
	BeanDefinition finderBean = BeanDefinitionBuilder
			.genericBeanDefinition(CrudRepositoryFinderImpl.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = finderBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, new RuntimeBeanReference(repoFactoryBeanId));
	return finderBean;
}
 
Example 12
Source File: MongoPersistenceSupportBeanFactory.java    From statefulj with Apache License 2.0 5 votes vote down vote up
@Override
public BeanDefinition buildFinderBean(String repoFactoryBeanId) {
	BeanDefinition finderBean = BeanDefinitionBuilder
			.genericBeanDefinition(CrudRepositoryFinderImpl.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = finderBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, new RuntimeBeanReference(repoFactoryBeanId));
	return finderBean;
}
 
Example 13
Source File: DasTransactionalEnabler.java    From das with Apache License 2.0 5 votes vote down vote up
private void replaceBeanDefinition() {
    for(String beanName: getBeanDefinitionNames()) {
        BeanDefinition beanDef = getBeanDefinition(beanName);
        String beanClassName = beanDef.getBeanClassName();

        if(beanClassName == null || beanClassName.equals(BEAN_FACTORY_NAME) || isSpringSmartClassLoader(beanDef)) {
            continue;
        }

        Class beanClass;
        try {
            beanClass = Class.forName(beanDef.getBeanClassName());
        } catch (ClassNotFoundException e) {
            throw new BeanDefinitionValidationException("Cannot validate bean: " + beanName, e);
        }

        boolean annotated = false;
        for (Method method : beanClass.getMethods()) {
            if(isTransactionAnnotated(method)) {
                annotated = true;
                break;
            }
        }

        if(!annotated) {
            continue;
        }

        beanDef.setBeanClassName(BEAN_FACTORY_NAME);
        beanDef.setFactoryMethodName(FACTORY_METHOD_NAME);

        ConstructorArgumentValues cav = beanDef.getConstructorArgumentValues();

        if(cav.getArgumentCount() != 0) {
            throw new BeanDefinitionValidationException("The transactional bean can only be instantiated with default constructor.");
        }

        cav.addGenericArgumentValue(beanClass.getName());
    }
}
 
Example 14
Source File: StatefulFactory.java    From statefulj with Apache License 2.0 5 votes vote down vote up
/**
 * @param referenceFactory
 * @param method
 * @param isDomainEntity
 * @param controllerRef
 * @param reg
 * @param actionId
 */
private void registerMethodInvocationAction(
		ReferenceFactory referenceFactory, Method method,
		boolean isDomainEntity, RuntimeBeanReference controllerRef,
		BeanDefinitionRegistry reg, String actionId) {
	// Choose the type of invocationAction based off of
	// whether the controller is a DomainEntity
	//
	Class<?> methodInvocationAction = (isDomainEntity) ?
			DomainEntityMethodInvocationAction.class :
			MethodInvocationAction.class;

	BeanDefinition actionBean = BeanDefinitionBuilder
			.genericBeanDefinition(methodInvocationAction)
			.getBeanDefinition();

	ConstructorArgumentValues args = actionBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, method.getName());
	args.addIndexedArgumentValue(1, method.getParameterTypes());
	args.addIndexedArgumentValue(2, new RuntimeBeanReference(referenceFactory.getFSMId()));

	if (!isDomainEntity) {
		args.addIndexedArgumentValue(3, controllerRef);
	}

	reg.registerBeanDefinition(actionId, actionBean);
}
 
Example 15
Source File: RedissonNamespaceParserSupport.java    From redisson with Apache License 2.0 5 votes vote down vote up
public void addConstructorArgs(Object value, Class<?> type, BeanDefinition bd) {
    ConstructorArgumentValues.ValueHolder vHolder
            = new ConstructorArgumentValues.ValueHolder(value, type.getName());
    ConstructorArgumentValues args
            = bd.getConstructorArgumentValues();
    args.addIndexedArgumentValue(args.getArgumentCount(), vHolder);
}
 
Example 16
Source File: BusWiringBeanFactoryPostProcessor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) {
    Object inject = bus;
    if (inject == null) {
        inject = getBusForName(Bus.DEFAULT_BUS_ID, factory, true, null);
    } else {
        if (!factory.containsBeanDefinition(Bus.DEFAULT_BUS_ID)
            && !factory.containsSingleton(Bus.DEFAULT_BUS_ID)) {
            factory.registerSingleton(Bus.DEFAULT_BUS_ID, bus);
        }
    }
    for (String beanName : factory.getBeanDefinitionNames()) {
        BeanDefinition beanDefinition = factory.getBeanDefinition(beanName);
        BusWiringType type
            = (BusWiringType)beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE);
        if (type == null) {
            continue;
        }
        String busname = (String)beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_NAME);
        String create = (String)beanDefinition
            .getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_CREATE);
        Object inj = inject;
        if (busname != null) {
            if (bus != null) {
                continue;
            }
            inj = getBusForName(busname, factory, create != null, create);
        }
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_NAME);
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE);
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_CREATE);
        if (create == null) {
            if (BusWiringType.PROPERTY == type) {
                beanDefinition.getPropertyValues()
                    .addPropertyValue("bus", inj);
            } else if (BusWiringType.CONSTRUCTOR == type) {
                ConstructorArgumentValues constructorArgs = beanDefinition.getConstructorArgumentValues();
                insertConstructorArg(constructorArgs, inj);
            }
        }
    }
}
 
Example 17
Source File: DalTransactionalEnabler.java    From dal with Apache License 2.0 4 votes vote down vote up
private void replaceBeanDefinition() {
    for (String beanName : getBeanDefinitionNames()) {
        BeanDefinition beanDef = getBeanDefinition(beanName);
        String beanClassName = beanDef.getBeanClassName();

        if (beanClassName == null || beanClassName.equals(BEAN_FACTORY_NAME))
            continue;

        Class beanClass;
        try {
            beanClass = Class.forName(beanDef.getBeanClassName());
        } catch (ClassNotFoundException e) {
            throw new BeanDefinitionValidationException("Cannot validate bean: " + beanName, e);
        }

        boolean annotated = false;

        List<Method> methods = new ArrayList<>();
        ReflectUtils.addAllMethods(beanClass, methods);
        List<Method> unsupportedMethods = new ArrayList<>();

        for (int i = 0; i < methods.size(); i++) {
            Method currentMethod = methods.get(i);

            if (isTransactionAnnotated(currentMethod)) {
                if (Modifier.isFinal(currentMethod.getModifiers()) || Modifier.isStatic(currentMethod.getModifiers()) || Modifier.isPrivate(currentMethod.getModifiers()))
                    unsupportedMethods.add(currentMethod);
                annotated = true;
            }
        }

        if (!unsupportedMethods.isEmpty()){
            StringBuilder errMsg=new StringBuilder();
            errMsg.append(String.format("The Methods below are not supported in dal transaction due to private, final or static modifier, please use public,protected or default modifier instead:"));
            errMsg.append("\n");
            int index=1;
            for (Method method : unsupportedMethods) {
                errMsg.append(String.format("%d. %s", index, method.toString()));
                errMsg.append("\n");
                index++;
            }
            throw new DalRuntimeException(errMsg.toString());
        }

        if (!annotated)
            continue;

        beanDef.setBeanClassName(BEAN_FACTORY_NAME);
        beanDef.setFactoryMethodName(FACTORY_METHOD_NAME);

        ConstructorArgumentValues cav = beanDef.getConstructorArgumentValues();

        if (cav.getArgumentCount() != 0)
            throw new BeanDefinitionValidationException("The transactional bean can only be instantiated with default constructor.");

        cav.addGenericArgumentValue(beanClass.getName());
    }
}