Java Code Examples for org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder#setSource()

The following examples show how to use org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder#setSource() . 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: SimpleConstructorNamespaceHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@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;
}
 
Example 2
Source File: SimpleConstructorNamespaceHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
@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;
}
 
Example 3
Source File: SimpleConstructorNamespaceHandler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@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;
}
 
Example 4
Source File: SimpleConstructorNamespaceHandler.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 5
Source File: SimpleConstructorNamespaceHandler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@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;
}