org.springframework.beans.factory.xml.ParserContext Java Examples

The following examples show how to use org.springframework.beans.factory.xml.ParserContext. 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: TilesConfigurerBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	List<Element> childElements = DomUtils.getChildElementsByTagName(element, "definitions");
	if (!childElements.isEmpty()) {
		List<String> locations = new ArrayList<>(childElements.size());
		for (Element childElement : childElements) {
			locations.add(childElement.getAttribute("location"));
		}
		builder.addPropertyValue("definitions", StringUtils.toStringArray(locations));
	}
	if (element.hasAttribute("check-refresh")) {
		builder.addPropertyValue("checkRefresh", element.getAttribute("check-refresh"));
	}
	if (element.hasAttribute("validate-definitions")) {
		builder.addPropertyValue("validateDefinitions", element.getAttribute("validate-definitions"));
	}
	if (element.hasAttribute("definitions-factory")) {
		builder.addPropertyValue("definitionsFactoryClass", element.getAttribute("definitions-factory"));
	}
	if (element.hasAttribute("preparer-factory")) {
		builder.addPropertyValue("preparerFactoryClass", element.getAttribute("preparer-factory"));
	}
}
 
Example #2
Source File: ViewControllerBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private BeanDefinition registerHandlerMapping(ParserContext context, @Nullable Object source) {
	if (context.getRegistry().containsBeanDefinition(HANDLER_MAPPING_BEAN_NAME)) {
		return context.getRegistry().getBeanDefinition(HANDLER_MAPPING_BEAN_NAME);
	}
	RootBeanDefinition beanDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
	beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	context.getRegistry().registerBeanDefinition(HANDLER_MAPPING_BEAN_NAME, beanDef);
	context.registerComponent(new BeanComponentDefinition(beanDef, HANDLER_MAPPING_BEAN_NAME));

	beanDef.setSource(source);
	beanDef.getPropertyValues().add("order", "1");
	beanDef.getPropertyValues().add("pathMatcher", MvcNamespaceUtils.registerPathMatcher(null, context, source));
	beanDef.getPropertyValues().add("urlPathHelper", MvcNamespaceUtils.registerUrlPathHelper(null, context, source));
	RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, context, source);
	beanDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef);

	return beanDef;
}
 
Example #3
Source File: ConfigBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link RootBeanDefinition} for the advisor described in the supplied. Does <strong>not</strong>
 * parse any associated '{@code pointcut}' or '{@code pointcut-ref}' attributes.
 */
private AbstractBeanDefinition createAdvisorBeanDefinition(Element advisorElement, ParserContext parserContext) {
	RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class);
	advisorDefinition.setSource(parserContext.extractSource(advisorElement));

	String adviceRef = advisorElement.getAttribute(ADVICE_REF);
	if (!StringUtils.hasText(adviceRef)) {
		parserContext.getReaderContext().error(
				"'advice-ref' attribute contains empty value.", advisorElement, this.parseState.snapshot());
	}
	else {
		advisorDefinition.getPropertyValues().add(
				ADVICE_BEAN_NAME, new RuntimeBeanNameReference(adviceRef));
	}

	if (advisorElement.hasAttribute(ORDER_PROPERTY)) {
		advisorDefinition.getPropertyValues().add(
				ORDER_PROPERTY, advisorElement.getAttribute(ORDER_PROPERTY));
	}

	return advisorDefinition;
}
 
Example #4
Source File: AnnotationConfigBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	// Obtain bean definitions for all relevant BeanPostProcessors.
	Set<BeanDefinitionHolder> processorDefinitions =
			AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);

	// Register component for the surrounding <context:annotation-config> element.
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	parserContext.pushContainingComponent(compDefinition);

	// Nest the concrete beans in the surrounding component.
	for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
		parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
	}

	// Finally register the composite component.
	parserContext.popAndRegisterContainingComponent();

	return null;
}
 
Example #5
Source File: HandlersBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, this.sockJsService, "SockJsService");
	cargs.addIndexedArgumentValue(1, handlerReference, "WebSocketHandler");

	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cargs, 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 #6
Source File: Jaxb2MarshallerBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
	String contextPath = element.getAttribute("context-path");
	if (StringUtils.hasText(contextPath)) {
		beanDefinitionBuilder.addPropertyValue("contextPath", contextPath);
	}

	List<Element> classes = DomUtils.getChildElementsByTagName(element, "class-to-be-bound");
	if (!classes.isEmpty()) {
		ManagedList<String> classesToBeBound = new ManagedList<>(classes.size());
		for (Element classToBeBound : classes) {
			String className = classToBeBound.getAttribute("name");
			classesToBeBound.add(className);
		}
		beanDefinitionBuilder.addPropertyValue("classesToBeBound", classesToBeBound);
	}
}
 
Example #7
Source File: PropertyPlaceholderBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	super.doParse(element, parserContext, builder);

	builder.addPropertyValue("ignoreUnresolvablePlaceholders",
			Boolean.valueOf(element.getAttribute("ignore-unresolvable")));

	String systemPropertiesModeName = element.getAttribute(SYSTEM_PROPERTIES_MODE_ATTRIBUTE);
	if (StringUtils.hasLength(systemPropertiesModeName) &&
			!systemPropertiesModeName.equals(SYSTEM_PROPERTIES_MODE_DEFAULT)) {
		builder.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_" + systemPropertiesModeName);
	}

	if (element.hasAttribute("value-separator")) {
		builder.addPropertyValue("valueSeparator", element.getAttribute("value-separator"));
	}
	if (element.hasAttribute("trim-values")) {
		builder.addPropertyValue("trimValues", element.getAttribute("trim-values"));
	}
	if (element.hasAttribute("null-value")) {
		builder.addPropertyValue("nullValue", element.getAttribute("null-value"));
	}
}
 
Example #8
Source File: RedissonDefinitionParser.java    From redisson with Apache License 2.0 6 votes vote down vote up
private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) {
    if (element.hasChildNodes()) {
        CompositeComponentDefinition compositeDef
                = new CompositeComponentDefinition(parentId,
                        parserContext.extractSource(element));
        parserContext.pushContainingComponent(compositeDef);
        List<Element> childElts = DomUtils.getChildElements(element);
        for (Element elt : childElts) {
            if (BeanDefinitionParserDelegate.QUALIFIER_ELEMENT.equals(elt.getLocalName())) {
                continue; //parsed elsewhere
            }
            String localName = parserContext.getDelegate().getLocalName(elt);
            localName = Conventions.attributeNameToPropertyName(localName);
            if (ConfigType.contains(localName)) {
                parseConfigTypes(elt, localName, redissonDef, parserContext);
            } else if (AddressType.contains(localName)) {
                parseAddressTypes(elt, localName, redissonDef, parserContext);
            } else if (helper.isRedissonNS(elt)) {
                elt.setAttribute(REDISSON_REF, redissonRef);
                parserContext.getDelegate().parseCustomElement(elt);
            }
        }
        parserContext.popContainingComponent();
    }
}
 
Example #9
Source File: TxAdviceBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	builder.addPropertyReference("transactionManager", TxNamespaceHandler.getTransactionManagerName(element));

	List<Element> txAttributes = DomUtils.getChildElementsByTagName(element, ATTRIBUTES_ELEMENT);
	if (txAttributes.size() > 1) {
		parserContext.getReaderContext().error(
				"Element <attributes> is allowed at most once inside element <advice>", element);
	}
	else if (txAttributes.size() == 1) {
		// Using attributes source.
		Element attributeSourceElement = txAttributes.get(0);
		RootBeanDefinition attributeSourceDefinition = parseAttributeSource(attributeSourceElement, parserContext);
		builder.addPropertyValue("transactionAttributeSource", attributeSourceDefinition);
	}
	else {
		// Assume annotations source.
		builder.addPropertyValue("transactionAttributeSource",
				new RootBeanDefinition("org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"));
	}
}
 
Example #10
Source File: ConfigBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Parse a '{@code declare-parents}' element and register the appropriate
 * DeclareParentsAdvisor with the BeanDefinitionRegistry encapsulated in the
 * supplied ParserContext.
 */
private AbstractBeanDefinition parseDeclareParents(Element declareParentsElement, ParserContext parserContext) {
	BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DeclareParentsAdvisor.class);
	builder.addConstructorArgValue(declareParentsElement.getAttribute(IMPLEMENT_INTERFACE));
	builder.addConstructorArgValue(declareParentsElement.getAttribute(TYPE_PATTERN));

	String defaultImpl = declareParentsElement.getAttribute(DEFAULT_IMPL);
	String delegateRef = declareParentsElement.getAttribute(DELEGATE_REF);

	if (StringUtils.hasText(defaultImpl) && !StringUtils.hasText(delegateRef)) {
		builder.addConstructorArgValue(defaultImpl);
	}
	else if (StringUtils.hasText(delegateRef) && !StringUtils.hasText(defaultImpl)) {
		builder.addConstructorArgReference(delegateRef);
	}
	else {
		parserContext.getReaderContext().error(
				"Exactly one of the " + DEFAULT_IMPL + " or " + DELEGATE_REF + " attributes must be specified",
				declareParentsElement, this.parseState.snapshot());
	}

	AbstractBeanDefinition definition = builder.getBeanDefinition();
	definition.setSource(parserContext.extractSource(declareParentsElement));
	parserContext.getReaderContext().registerWithGeneratedName(definition);
	return definition;
}
 
Example #11
Source File: DubboBeanDefinitionParser.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
private static void parseNested(Element element, ParserContext parserContext, Class<?> beanClass, boolean required, String tag, String property, String ref, BeanDefinition beanDefinition) {
    NodeList nodeList = element.getChildNodes();
    if (nodeList != null && nodeList.getLength() > 0) {
        boolean first = true;
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node instanceof Element) {
                if (tag.equals(node.getNodeName())
                        || tag.equals(node.getLocalName())) {
                    if (first) {
                        first = false;
                        String isDefault = element.getAttribute("default");
                        if (isDefault == null || isDefault.length() == 0) {
                            beanDefinition.getPropertyValues().addPropertyValue("default", "false");
                        }
                    }
                    BeanDefinition subDefinition = parse((Element) node, parserContext, beanClass, required);
                    if (subDefinition != null && ref != null && ref.length() > 0) {
                        subDefinition.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(ref));
                    }
                }
            }
        }
    }
}
 
Example #12
Source File: RedissonDefinitionParser.java    From redisson with Apache License 2.0 6 votes vote down vote up
private void parseConfigTypes(Element element, String configType, BeanDefinitionBuilder redissonDef, ParserContext parserContext) {
    BeanDefinitionBuilder builder
            = helper.createBeanDefinitionBuilder(element,
                    parserContext, null);
    //Use factory method on the Config bean
    AbstractBeanDefinition bd = builder.getRawBeanDefinition();
    bd.setFactoryMethodName("use" + StringUtils.capitalize(configType));
    bd.setFactoryBeanName(parserContext.getContainingComponent().getName());
    String id = parserContext.getReaderContext().generateBeanName(bd);
    helper.registerBeanDefinition(builder, id,
            helper.parseAliase(element), parserContext);
    helper.parseAttributes(element, parserContext, builder);
    redissonDef.addDependsOn(id);
    parseChildElements(element, id, null, redissonDef, parserContext);
    parserContext.getDelegate().parseQualifierElements(element, bd);
}
 
Example #13
Source File: TilesConfigurerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	List<Element> childElements = DomUtils.getChildElementsByTagName(element, "definitions");
	if (!childElements.isEmpty()) {
		List<String> locations = new ArrayList<String>(childElements.size());
		for (Element childElement : childElements) {
			locations.add(childElement.getAttribute("location"));
		}
		builder.addPropertyValue("definitions", locations.toArray(new String[locations.size()]));
	}
	if (element.hasAttribute("check-refresh")) {
		builder.addPropertyValue("checkRefresh", element.getAttribute("check-refresh"));
	}
	if (element.hasAttribute("validate-definitions")) {
		builder.addPropertyValue("validateDefinitions", element.getAttribute("validate-definitions"));
	}
	if (element.hasAttribute("definitions-factory")) {
		builder.addPropertyValue("definitionsFactoryClass", element.getAttribute("definitions-factory"));
	}
	if (element.hasAttribute("preparer-factory")) {
		builder.addPropertyValue("preparerFactoryClass", element.getAttribute("preparer-factory"));
	}
}
 
Example #14
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void registerAsyncExecutionAspect(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME)) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ASYNC_EXECUTION_ASPECT_CLASS_NAME);
		builder.setFactoryMethod("aspectOf");
		String executor = element.getAttribute("executor");
		if (StringUtils.hasText(executor)) {
			builder.addPropertyReference("executor", executor);
		}
		String exceptionHandler = element.getAttribute("exception-handler");
		if (StringUtils.hasText(exceptionHandler)) {
			builder.addPropertyReference("exceptionHandler", exceptionHandler);
		}
		parserContext.registerBeanComponent(new BeanComponentDefinition(builder.getBeanDefinition(),
				TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME));
	}
}
 
Example #15
Source File: Jaxb2MarshallerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
	String contextPath = element.getAttribute("context-path");
	if (!StringUtils.hasText(contextPath)) {
		// Backwards compatibility with 3.x version of the xsd
		contextPath = element.getAttribute("contextPath");
	}
	if (StringUtils.hasText(contextPath)) {
		beanDefinitionBuilder.addPropertyValue("contextPath", contextPath);
	}

	List<Element> classes = DomUtils.getChildElementsByTagName(element, "class-to-be-bound");
	if (!classes.isEmpty()) {
		ManagedList<String> classesToBeBound = new ManagedList<String>(classes.size());
		for (Element classToBeBound : classes) {
			String className = classToBeBound.getAttribute("name");
			classesToBeBound.add(className);
		}
		beanDefinitionBuilder.addPropertyValue("classesToBeBound", classesToBeBound);
	}
}
 
Example #16
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ManagedList<?> getDeferredResultInterceptors(Element element, Object source, ParserContext parserContext) {
	ManagedList<? super Object> interceptors = new ManagedList<Object>();
	Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
	if (asyncElement != null) {
		Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "deferred-result-interceptors");
		if (interceptorsElement != null) {
			interceptors.setSource(source);
			for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {
				BeanDefinitionHolder beanDef = parserContext.getDelegate().parseBeanDefinitionElement(converter);
				beanDef = parserContext.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
				interceptors.add(beanDef);
			}
		}
	}
	return interceptors;
}
 
Example #17
Source File: MessageBrokerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private RuntimeBeanReference registerUserDestHandler(Element brokerElem,
		RuntimeBeanReference userRegistry, RuntimeBeanReference inChannel,
		RuntimeBeanReference brokerChannel, ParserContext context, Object source) {

	Object userDestResolver = registerUserDestResolver(brokerElem, userRegistry, context, source);

	RootBeanDefinition beanDef = new RootBeanDefinition(UserDestinationMessageHandler.class);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(0, inChannel);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(1, brokerChannel);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(2, userDestResolver);

	Element relayElement = DomUtils.getChildElementByTagName(brokerElem, "stomp-broker-relay");
	if (relayElement != null && relayElement.hasAttribute("user-destination-broadcast")) {
		String destination = relayElement.getAttribute("user-destination-broadcast");
		beanDef.getPropertyValues().add("broadcastDestination", destination);
	}

	String beanName = registerBeanDef(beanDef, context, source);
	return new RuntimeBeanReference(beanName);
}
 
Example #18
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private RuntimeBeanReference getValidator(Element element, Object source, ParserContext parserContext) {
	if (element.hasAttribute("validator")) {
		return new RuntimeBeanReference(element.getAttribute("validator"));
	}
	else if (javaxValidationPresent) {
		RootBeanDefinition validatorDef = new RootBeanDefinition(
				"org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean");
		validatorDef.setSource(source);
		validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String validatorName = parserContext.getReaderContext().registerWithGeneratedName(validatorDef);
		parserContext.registerComponent(new BeanComponentDefinition(validatorDef, validatorName));
		return new RuntimeBeanReference(validatorName);
	}
	else {
		return null;
	}
}
 
Example #19
Source File: ZmqContextManagerParser.java    From spring-integration-zmq with Apache License 2.0 5 votes vote down vote up
protected AbstractBeanDefinition parseInternal(Element element,
		ParserContext context) {
	BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
			"com.github.moonkev.spring.integration.zmq.ZmqContextManager");
	builder.addConstructorArgValue(element.getAttribute("io-threads"));
	return builder.getBeanDefinition();
}
 
Example #20
Source File: MessageBrokerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private RuntimeBeanReference registerMessagingTemplate(Element element, RuntimeBeanReference brokerChannel,
		RuntimeBeanReference messageConverter, ParserContext context, Object source) {

	ConstructorArgumentValues cavs = new ConstructorArgumentValues();
	cavs.addIndexedArgumentValue(0, brokerChannel);
	RootBeanDefinition beanDef = new RootBeanDefinition(SimpMessagingTemplate.class,cavs, null);
	if (element.hasAttribute("user-destination-prefix")) {
		beanDef.getPropertyValues().add("userDestinationPrefix", element.getAttribute("user-destination-prefix"));
	}
	beanDef.getPropertyValues().add("messageConverter", messageConverter);
	return new RuntimeBeanReference(registerBeanDef(beanDef,context, source));
}
 
Example #21
Source File: BusDefinitionParser.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void mapElement(ParserContext ctx,
                          BeanDefinitionBuilder bean,
                          Element e,
                          String name) {
    if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name)
        || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name)
        || "features".equals(name)) {
        List<?> list = ctx.getDelegate().parseListElement(e, bean.getBeanDefinition());
        bean.addPropertyValue(name, list);
    } else if ("properties".equals(name)) {
        Map<?, ?> map = ctx.getDelegate().parseMapElement(e, bean.getBeanDefinition());
        bean.addPropertyValue("properties", map);
    }
}
 
Example #22
Source File: ComponentScanBeanDefinitionParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected TypeFilter createTypeFilter(Element element, @Nullable ClassLoader classLoader,
		ParserContext parserContext) throws ClassNotFoundException {

	String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE);
	String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE);
	expression = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(expression);
	if ("annotation".equals(filterType)) {
		return new AnnotationTypeFilter((Class<Annotation>) ClassUtils.forName(expression, classLoader));
	}
	else if ("assignable".equals(filterType)) {
		return new AssignableTypeFilter(ClassUtils.forName(expression, classLoader));
	}
	else if ("aspectj".equals(filterType)) {
		return new AspectJTypeFilter(expression, classLoader);
	}
	else if ("regex".equals(filterType)) {
		return new RegexPatternTypeFilter(Pattern.compile(expression));
	}
	else if ("custom".equals(filterType)) {
		Class<?> filterClass = ClassUtils.forName(expression, classLoader);
		if (!TypeFilter.class.isAssignableFrom(filterClass)) {
			throw new IllegalArgumentException(
					"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
		}
		return (TypeFilter) BeanUtils.instantiateClass(filterClass);
	}
	else {
		throw new IllegalArgumentException("Unsupported filter type: " + filterType);
	}
}
 
Example #23
Source File: AbstractCloudServiceFactoryParser.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	String serviceId = element.getAttribute("service-name");
	builder.addConstructorArgValue(serviceConnectorFactoryType);
	builder.addConstructorArgValue(element.getAttribute(ID_ATTRIBUTE));
	builder.addConstructorArgValue(serviceId);
	// subclasses should add one more constructor parameter for ServiceConnectorConfig
}
 
Example #24
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the {@code <tx:annotation-driven/>} tag. Will
 * {@link AopNamespaceUtils#registerAutoProxyCreatorIfNecessary register an AutoProxyCreator}
 * with the container as necessary.
 */
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	registerTransactionalEventListenerFactory(parserContext);
	String mode = element.getAttribute("mode");
	if ("aspectj".equals(mode)) {
		// mode="aspectj"
		registerTransactionAspect(element, parserContext);
	}
	else {
		// mode="proxy"
		AopAutoProxyConfigurer.configureAutoProxyCreator(element, parserContext);
	}
	return null;
}
 
Example #25
Source File: ScheduledTasksBeanDefinitionParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private RuntimeBeanReference beanReference(Element taskElement,
		ParserContext parserContext, BeanDefinitionBuilder builder) {
	// Extract the source of the current task
	builder.getRawBeanDefinition().setSource(parserContext.extractSource(taskElement));
	String generatedName = parserContext.getReaderContext().generateBeanName(builder.getRawBeanDefinition());
	parserContext.registerBeanComponent(new BeanComponentDefinition(builder.getBeanDefinition(), generatedName));
	return new RuntimeBeanReference(generatedName);
}
 
Example #26
Source File: AbstractBeanDefinitionParser.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected boolean parseAttribute(Element element, Attr node,
                                 ParserContext ctx, BeanDefinitionBuilder bean) {
    String val = node.getValue();
    String pre = node.getPrefix();
    String name = node.getLocalName();
    String prefix = node.getPrefix();

    // Don't process namespaces
    if (isNamespace(name, prefix)) {
        return false;
    }

    if ("createdFromAPI".equals(name)) {
        bean.setAbstract(true);
    } else if ("abstract".equals(name)) {
        bean.setAbstract(true);
    } else if ("depends-on".equals(name)) {
        bean.addDependsOn(val);
    } else if ("name".equals(name)) {
        processNameAttribute(element, ctx, bean, val);
    } else if ("bus".equals(name)) {
        return processBusAttribute(element, ctx, bean, val);
    } else if (!"id".equals(name) && isAttribute(pre, name)) {
        mapAttribute(bean, element, name, val);
    }
    return false;
}
 
Example #27
Source File: MessageBrokerBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private RuntimeBeanReference registerUserRegistryMessageHandler(
		RuntimeBeanReference userRegistry, RuntimeBeanReference brokerTemplate,
		String destination, ParserContext context, @Nullable Object source) {

	Object scheduler = WebSocketNamespaceUtils.registerScheduler(SCHEDULER_BEAN_NAME, context, source);

	RootBeanDefinition beanDef = new RootBeanDefinition(UserRegistryMessageHandler.class);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(0, userRegistry);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(1, brokerTemplate);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(2, destination);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(3, scheduler);

	String beanName = registerBeanDef(beanDef, context, source);
	return new RuntimeBeanReference(beanName);
}
 
Example #28
Source File: ScheduledTasksBeanDefinitionParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private RuntimeBeanReference runnableReference(String ref, String method, Element taskElement, ParserContext parserContext) {
	BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
			"org.springframework.scheduling.support.ScheduledMethodRunnable");
	builder.addConstructorArgReference(ref);
	builder.addConstructorArgValue(method);
	return beanReference(taskElement, parserContext, builder);
}
 
Example #29
Source File: MqClientParser.java    From zxl with Apache License 2.0 5 votes vote down vote up
@Override
protected void doParseOther(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	if (!NamespaceUtils.isAttributeDefined(element, ID_ATTRIBUTE) || !NamespaceUtils.isAttributeDefined(element, ROUTING_KEY_NAME)) {
		parserContext.getReaderContext().error("MqClientParser must have id and routing-key", element);
	}
	builder.getBeanDefinition().setBeanClass(CLASS);
	builder.addPropertyValue("routingKey", element.getAttribute(ROUTING_KEY_NAME));
	if (element.hasAttribute(EXCHANGE_NAME)) {
		builder.addPropertyValue("exchange", element.getAttribute(EXCHANGE_NAME));
	}
}
 
Example #30
Source File: Parsers.java    From krpc with Apache License 2.0 5 votes vote down vote up
void registerAsyncReferer(String beanName, String interfaceName, ParserContext parserContext) {
    //log.info("register referer "+interfaceName+", beanName="+beanName);
    BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(RefererFactory.class);
    beanDefinitionBuilder.addConstructorArgValue(beanName);
    beanDefinitionBuilder.addConstructorArgValue(interfaceName);
    beanDefinitionBuilder.addDependsOn("rpcApp");
    beanDefinitionBuilder.setLazyInit(true);
    parserContext.getRegistry().registerBeanDefinition(beanName, beanDefinitionBuilder.getRawBeanDefinition());
}