Java Code Examples for org.springframework.beans.factory.config.ConstructorArgumentValues#addIndexedArgumentValue()
The following examples show how to use
org.springframework.beans.factory.config.ConstructorArgumentValues#addIndexedArgumentValue() .
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: StatefulFactory.java From statefulj with Apache License 2.0 | 6 votes |
/** * @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 2
Source File: StatefulFactory.java From statefulj with Apache License 2.0 | 6 votes |
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 3
Source File: MongoPersistenceSupportBeanFactory.java From statefulj with Apache License 2.0 | 6 votes |
@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 4
Source File: HandlersBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) { String pathAttribute = element.getAttribute("path"); List<String> mappings = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ",")); RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler")); ConstructorArgumentValues cavs = new ConstructorArgumentValues(); cavs.addIndexedArgumentValue(0, this.sockJsService, "SockJsService"); cavs.addIndexedArgumentValue(1, handlerReference, "WebSocketHandler"); RootBeanDefinition requestHandlerDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cavs, null); requestHandlerDef.setSource(context.extractSource(element)); requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef); RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName); for (String mapping : mappings) { String pathPattern = (mapping.endsWith("/") ? mapping + "**" : mapping + "/**"); urlMap.put(pathPattern, requestHandlerRef); } }
Example 5
Source File: JPAPersistenceSupportBeanFactory.java From statefulj with Apache License 2.0 | 6 votes |
@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 6
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testCustomTypeConverterWithBeanReference() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN); lbf.setTypeConverter(new CustomTypeConverter(nf)); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("myFloat", new RuntimeBeanReference("myFloat")); ConstructorArgumentValues cav = new ConstructorArgumentValues(); cav.addIndexedArgumentValue(0, "myName"); cav.addIndexedArgumentValue(1, "myAge"); lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, cav, pvs)); lbf.registerSingleton("myFloat", "1,1"); TestBean testBean = (TestBean) lbf.getBean("testBean"); assertEquals("myName", testBean.getName()); assertEquals(5, testBean.getAge()); assertTrue(testBean.getMyFloat().floatValue() == 1.1f); }
Example 7
Source File: StatefulFactory.java From statefulj with Apache License 2.0 | 6 votes |
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: ResourcesBeanDefinitionParser.java From spring-analysis-note with MIT License | 5 votes |
private void parseResourceCache(ManagedList<Object> resourceResolvers, ManagedList<Object> resourceTransformers, Element element, @Nullable Object source) { String resourceCache = element.getAttribute("resource-cache"); if ("true".equals(resourceCache)) { ConstructorArgumentValues cargs = new ConstructorArgumentValues(); RootBeanDefinition cachingResolverDef = new RootBeanDefinition(CachingResourceResolver.class); cachingResolverDef.setSource(source); cachingResolverDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cachingResolverDef.setConstructorArgumentValues(cargs); RootBeanDefinition cachingTransformerDef = new RootBeanDefinition(CachingResourceTransformer.class); cachingTransformerDef.setSource(source); cachingTransformerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cachingTransformerDef.setConstructorArgumentValues(cargs); String cacheManagerName = element.getAttribute("cache-manager"); String cacheName = element.getAttribute("cache-name"); if (StringUtils.hasText(cacheManagerName) && StringUtils.hasText(cacheName)) { RuntimeBeanReference cacheManagerRef = new RuntimeBeanReference(cacheManagerName); cargs.addIndexedArgumentValue(0, cacheManagerRef); cargs.addIndexedArgumentValue(1, cacheName); } else { ConstructorArgumentValues cacheCavs = new ConstructorArgumentValues(); cacheCavs.addIndexedArgumentValue(0, RESOURCE_CHAIN_CACHE); RootBeanDefinition cacheDef = new RootBeanDefinition(ConcurrentMapCache.class); cacheDef.setSource(source); cacheDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); cacheDef.setConstructorArgumentValues(cacheCavs); cargs.addIndexedArgumentValue(0, cacheDef); } resourceResolvers.add(cachingResolverDef); resourceTransformers.add(cachingTransformerDef); } }
Example 9
Source File: MessageBrokerBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
private void registerAnnotationMethodMessageHandler(Element messageBrokerElement, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, RuntimeBeanReference converter, RuntimeBeanReference messagingTemplate, ParserContext context, @Nullable Object source) { ConstructorArgumentValues cargs = new ConstructorArgumentValues(); cargs.addIndexedArgumentValue(0, inChannel); cargs.addIndexedArgumentValue(1, outChannel); cargs.addIndexedArgumentValue(2, messagingTemplate); MutablePropertyValues values = new MutablePropertyValues(); String prefixAttribute = messageBrokerElement.getAttribute("application-destination-prefix"); values.add("destinationPrefixes", Arrays.asList(StringUtils.tokenizeToStringArray(prefixAttribute, ","))); values.add("messageConverter", converter); RootBeanDefinition beanDef = new RootBeanDefinition(WebSocketAnnotationMethodMessageHandler.class, cargs, values); if (messageBrokerElement.hasAttribute("path-matcher")) { String pathMatcherRef = messageBrokerElement.getAttribute("path-matcher"); beanDef.getPropertyValues().add("pathMatcher", new RuntimeBeanReference(pathMatcherRef)); } RuntimeBeanReference validatorRef = getValidator(messageBrokerElement, source, context); if (validatorRef != null) { beanDef.getPropertyValues().add("validator", validatorRef); } Element resolversElement = DomUtils.getChildElementByTagName(messageBrokerElement, "argument-resolvers"); if (resolversElement != null) { values.add("customArgumentResolvers", extractBeanSubElements(resolversElement, context)); } Element handlersElement = DomUtils.getChildElementByTagName(messageBrokerElement, "return-value-handlers"); if (handlersElement != null) { values.add("customReturnValueHandlers", extractBeanSubElements(handlersElement, context)); } registerBeanDef(beanDef, context, source); }
Example 10
Source File: Spr5475Tests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void noArgFactoryMethodInvokedWithTwoArgsAndTypesSpecified() { RootBeanDefinition def = new RootBeanDefinition(Foo.class); def.setFactoryMethodName("noArgFactory"); ConstructorArgumentValues cav = new ConstructorArgumentValues(); cav.addIndexedArgumentValue(0, "bogusArg1", CharSequence.class.getName()); cav.addIndexedArgumentValue(1, "bogusArg2".getBytes()); def.setConstructorArgumentValues(cav); assertExceptionMessageForMisconfiguredFactoryMethod( def, "Error creating bean with name 'foo': No matching factory method found: factory method 'noArgFactory(CharSequence,byte[])'. " + "Check that a method with the specified name and arguments exists and that it is static."); }
Example 11
Source File: StatefulFactory.java From statefulj with Apache License 2.0 | 5 votes |
/** * @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 12
Source File: MessageBrokerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
private RuntimeBeanReference registerMessageConverter(Element element, ParserContext context, Object source) { Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters"); ManagedList<? super Object> converters = new ManagedList<Object>(); if (convertersElement != null) { converters.setSource(source); for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) { Object object = context.getDelegate().parsePropertySubElement(beanElement, null); converters.add(object); } } if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) { converters.setSource(source); converters.add(new RootBeanDefinition(StringMessageConverter.class)); converters.add(new RootBeanDefinition(ByteArrayMessageConverter.class)); if (jackson2Present) { RootBeanDefinition jacksonConverterDef = new RootBeanDefinition(MappingJackson2MessageConverter.class); RootBeanDefinition resolverDef = new RootBeanDefinition(DefaultContentTypeResolver.class); resolverDef.getPropertyValues().add("defaultMimeType", MimeTypeUtils.APPLICATION_JSON); jacksonConverterDef.getPropertyValues().add("contentTypeResolver", resolverDef); // Use Jackson factory in order to have JSR-310 and Joda-Time modules registered automatically GenericBeanDefinition jacksonFactoryDef = new GenericBeanDefinition(); jacksonFactoryDef.setBeanClass(Jackson2ObjectMapperFactoryBean.class); jacksonFactoryDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); jacksonFactoryDef.setSource(source); jacksonConverterDef.getPropertyValues().add("objectMapper", jacksonFactoryDef); converters.add(jacksonConverterDef); } } ConstructorArgumentValues cavs = new ConstructorArgumentValues(); cavs.addIndexedArgumentValue(0, converters); RootBeanDefinition messageConverterDef = new RootBeanDefinition(CompositeMessageConverter.class, cavs, null); return new RuntimeBeanReference(registerBeanDef(messageConverterDef, context, source)); }
Example 13
Source File: MessageBrokerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void registerAnnotationMethodMessageHandler(Element messageBrokerElement, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, RuntimeBeanReference converter, RuntimeBeanReference messagingTemplate, ParserContext context, Object source) { ConstructorArgumentValues cavs = new ConstructorArgumentValues(); cavs.addIndexedArgumentValue(0, inChannel); cavs.addIndexedArgumentValue(1, outChannel); cavs.addIndexedArgumentValue(2, messagingTemplate); MutablePropertyValues values = new MutablePropertyValues(); String prefixAttribute = messageBrokerElement.getAttribute("application-destination-prefix"); values.add("destinationPrefixes", Arrays.asList(StringUtils.tokenizeToStringArray(prefixAttribute, ","))); values.add("messageConverter", converter); RootBeanDefinition beanDef = new RootBeanDefinition(WebSocketAnnotationMethodMessageHandler.class, cavs, values); if (messageBrokerElement.hasAttribute("path-matcher")) { String pathMatcherRef = messageBrokerElement.getAttribute("path-matcher"); beanDef.getPropertyValues().add("pathMatcher", new RuntimeBeanReference(pathMatcherRef)); } Element resolversElement = DomUtils.getChildElementByTagName(messageBrokerElement, "argument-resolvers"); if (resolversElement != null) { values.add("customArgumentResolvers", extractBeanSubElements(resolversElement, context)); } Element handlersElement = DomUtils.getChildElementByTagName(messageBrokerElement, "return-value-handlers"); if (handlersElement != null) { values.add("customReturnValueHandlers", extractBeanSubElements(handlersElement, context)); } registerBeanDef(beanDef, context, source); }
Example 14
Source File: MulCommonBaseServiceParser.java From zxl with Apache License 2.0 | 5 votes |
private BeanDefinition buildSqlSessionTemplateBeanDefinition(Element element, String name) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setAttribute(ID_ATTRIBUTE, name + SQL_SESSION_TEMPLATE_SUFFIX); beanDefinition.setBeanClass(SqlSessionTemplate.class); ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues(); constructorArgumentValues.addIndexedArgumentValue(0, new RuntimeBeanReference(name + SQL_SESSION_FACTORY_SUFFIX)); beanDefinition.setConstructorArgumentValues(constructorArgumentValues); return beanDefinition; }
Example 15
Source File: StatefulFactory.java From statefulj with Apache License 2.0 | 5 votes |
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 16
Source File: MessageBrokerBeanDefinitionParser.java From spring-analysis-note with MIT License | 5 votes |
private void registerAnnotationMethodMessageHandler(Element messageBrokerElement, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, RuntimeBeanReference converter, RuntimeBeanReference messagingTemplate, ParserContext context, @Nullable Object source) { ConstructorArgumentValues cargs = new ConstructorArgumentValues(); cargs.addIndexedArgumentValue(0, inChannel); cargs.addIndexedArgumentValue(1, outChannel); cargs.addIndexedArgumentValue(2, messagingTemplate); MutablePropertyValues values = new MutablePropertyValues(); String prefixAttribute = messageBrokerElement.getAttribute("application-destination-prefix"); values.add("destinationPrefixes", Arrays.asList(StringUtils.tokenizeToStringArray(prefixAttribute, ","))); values.add("messageConverter", converter); RootBeanDefinition beanDef = new RootBeanDefinition(WebSocketAnnotationMethodMessageHandler.class, cargs, values); if (messageBrokerElement.hasAttribute("path-matcher")) { String pathMatcherRef = messageBrokerElement.getAttribute("path-matcher"); beanDef.getPropertyValues().add("pathMatcher", new RuntimeBeanReference(pathMatcherRef)); } RuntimeBeanReference validatorRef = getValidator(messageBrokerElement, source, context); if (validatorRef != null) { beanDef.getPropertyValues().add("validator", validatorRef); } Element resolversElement = DomUtils.getChildElementByTagName(messageBrokerElement, "argument-resolvers"); if (resolversElement != null) { values.add("customArgumentResolvers", extractBeanSubElements(resolversElement, context)); } Element handlersElement = DomUtils.getChildElementByTagName(messageBrokerElement, "return-value-handlers"); if (handlersElement != null) { values.add("customReturnValueHandlers", extractBeanSubElements(handlersElement, context)); } registerBeanDef(beanDef, context, source); }
Example 17
Source File: MessageBrokerBeanDefinitionParser.java From spring-analysis-note with MIT License | 5 votes |
private RuntimeBeanReference registerMessagingTemplate(Element element, RuntimeBeanReference brokerChannel, RuntimeBeanReference messageConverter, ParserContext context, @Nullable Object source) { ConstructorArgumentValues cargs = new ConstructorArgumentValues(); cargs.addIndexedArgumentValue(0, brokerChannel); RootBeanDefinition beanDef = new RootBeanDefinition(SimpMessagingTemplate.class, cargs, null); if (element.hasAttribute("user-destination-prefix")) { beanDef.getPropertyValues().add("userDestinationPrefix", element.getAttribute("user-destination-prefix")); } beanDef.getPropertyValues().add("messageConverter", messageConverter); String name = MESSAGING_TEMPLATE_BEAN_NAME; registerBeanDefByName(name, beanDef, context, source); return new RuntimeBeanReference(name); }
Example 18
Source File: MqBeanParser.java From zxl with Apache License 2.0 | 5 votes |
protected void buildRabbitTemplateBeanDefinition(String beanName, String connectionFactoryBeanName, BeanDefinitionRegistry beanDefinitionRegistry) { AbstractBeanDefinition rabbitTemplateBeanDefinition = new GenericBeanDefinition(); rabbitTemplateBeanDefinition.setBeanClass(RabbitTemplate.class); ConstructorArgumentValues rabbitTemplateConstructorArgumentValues = new ConstructorArgumentValues(); rabbitTemplateConstructorArgumentValues.addIndexedArgumentValue(0, new RuntimeBeanReference(connectionFactoryBeanName)); rabbitTemplateBeanDefinition.setConstructorArgumentValues(rabbitTemplateConstructorArgumentValues); beanDefinitionRegistry.registerBeanDefinition(beanName, rabbitTemplateBeanDefinition); }
Example 19
Source File: ConfigBeanDefinitionParser.java From spring-analysis-note with MIT License | 4 votes |
/** * Creates the RootBeanDefinition for a POJO advice bean. Also causes pointcut * parsing to occur so that the pointcut may be associate with the advice bean. * This same pointcut is also configured as the pointcut for the enclosing * Advisor definition using the supplied MutablePropertyValues. */ private AbstractBeanDefinition createAdviceDefinition( Element adviceElement, ParserContext parserContext, String aspectName, int order, RootBeanDefinition methodDef, RootBeanDefinition aspectFactoryDef, List<BeanDefinition> beanDefinitions, List<BeanReference> beanReferences) { RootBeanDefinition adviceDefinition = new RootBeanDefinition(getAdviceClass(adviceElement, parserContext)); adviceDefinition.setSource(parserContext.extractSource(adviceElement)); adviceDefinition.getPropertyValues().add(ASPECT_NAME_PROPERTY, aspectName); adviceDefinition.getPropertyValues().add(DECLARATION_ORDER_PROPERTY, order); if (adviceElement.hasAttribute(RETURNING)) { adviceDefinition.getPropertyValues().add( RETURNING_PROPERTY, adviceElement.getAttribute(RETURNING)); } if (adviceElement.hasAttribute(THROWING)) { adviceDefinition.getPropertyValues().add( THROWING_PROPERTY, adviceElement.getAttribute(THROWING)); } if (adviceElement.hasAttribute(ARG_NAMES)) { adviceDefinition.getPropertyValues().add( ARG_NAMES_PROPERTY, adviceElement.getAttribute(ARG_NAMES)); } ConstructorArgumentValues cav = adviceDefinition.getConstructorArgumentValues(); cav.addIndexedArgumentValue(METHOD_INDEX, methodDef); Object pointcut = parsePointcutProperty(adviceElement, parserContext); if (pointcut instanceof BeanDefinition) { cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcut); beanDefinitions.add((BeanDefinition) pointcut); } else if (pointcut instanceof String) { RuntimeBeanReference pointcutRef = new RuntimeBeanReference((String) pointcut); cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcutRef); beanReferences.add(pointcutRef); } cav.addIndexedArgumentValue(ASPECT_INSTANCE_FACTORY_INDEX, aspectFactoryDef); return adviceDefinition; }
Example 20
Source File: SimpleConstructorNamespaceHandler.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { if (node instanceof Attr) { Attr attr = (Attr) node; String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr)); String argValue = StringUtils.trimWhitespace(attr.getValue()); ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues(); boolean ref = false; // handle -ref arguments if (argName.endsWith(REF_SUFFIX)) { ref = true; argName = argName.substring(0, argName.length() - REF_SUFFIX.length()); } ValueHolder valueHolder = new ValueHolder(ref ? new RuntimeBeanReference(argValue) : argValue); valueHolder.setSource(parserContext.getReaderContext().extractSource(attr)); // handle "escaped"/"_" arguments if (argName.startsWith(DELIMITER_PREFIX)) { String arg = argName.substring(1).trim(); // fast default check if (!StringUtils.hasText(arg)) { cvs.addGenericArgumentValue(valueHolder); } // assume an index otherwise else { int index = -1; try { index = Integer.parseInt(arg); } catch (NumberFormatException ex) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies an invalid integer", attr); } if (index < 0) { parserContext.getReaderContext().error( "Constructor argument '" + argName + "' specifies a negative index", attr); } if (cvs.hasIndexedArgumentValue(index)){ parserContext.getReaderContext().error( "Constructor argument '" + argName + "' with index "+ index+" already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } cvs.addIndexedArgumentValue(index, valueHolder); } } // no escaping -> ctr name else { String name = Conventions.attributeNameToPropertyName(argName); if (containsArgWithName(name, cvs)){ parserContext.getReaderContext().error( "Constructor argument '" + argName + "' already defined using <constructor-arg>." + " Only one approach may be used per argument.", attr); } valueHolder.setName(Conventions.attributeNameToPropertyName(argName)); cvs.addGenericArgumentValue(valueHolder); } } return definition; }