Java Code Examples for org.springframework.core.Conventions#attributeNameToPropertyName()

The following examples show how to use org.springframework.core.Conventions#attributeNameToPropertyName() . 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: RedissonNamespaceParserSupport.java    From redisson with Apache License 2.0 6 votes vote down vote up
public void parseAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    NamedNodeMap attributes = element.getAttributes();
    for (int x = 0; x < attributes.getLength(); x++) {
        Attr attribute = (Attr) attributes.item(x);
        if (isEligibleAttribute(attribute)) {
            String propertyName = attribute.getLocalName();
            if (propertyName.endsWith(REF_SUFFIX)) {
                propertyName = propertyName.substring(0, attribute.getLocalName().length() - REF_SUFFIX.length());
            }
            propertyName = Conventions
                    .attributeNameToPropertyName(propertyName);
            Assert.state(StringUtils.hasText(propertyName),
                    "Illegal property name returned from"
                            + " 'extractPropertyName(String)': cannot be"
                            + " null or empty.");
            if (attribute.getLocalName().endsWith(REF_SUFFIX)) {
                builder.addPropertyReference(propertyName,
                        attribute.getValue());
            } else {
                builder.addPropertyValue(propertyName, attribute.getValue());
            }
        }
    }
}
 
Example 2
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 3
Source File: RedissonGenericObjectDefinitionParser.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
protected Class<?> getBeanClass(Element element) {
    String elementName
            = Conventions.attributeNameToPropertyName(
                    element.getLocalName());
    try {
        String name = RedissonNamespaceParserSupport.API_CLASS_PATH_PREFIX;
        if (FAIL_LOCK.equals(elementName)) {
            name += StringUtils.capitalize("lock");
        } else {
            name += StringUtils.capitalize(elementName);
        }
        
        return Class.forName(name);
    } catch (ClassNotFoundException ex) {
        throw new IllegalArgumentException(ex);
    }
}
 
Example 4
Source File: RedissonGenericObjectDefinitionParser.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    bd.setFactoryBeanName(element.getAttribute(
            RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
    String typeName
            = Conventions.attributeNameToPropertyName(element.getLocalName());
    bd.setFactoryMethodName("get" + StringUtils.capitalize(typeName));
    
    helper.addConstructorArgs(element, KEY_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, TOPIC_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, PATTERN_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, SERVICE_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, CODEC_REF_ATTRIBUTE,
            Codec.class, builder);
    if (RDestroyable.class.isAssignableFrom(getBeanClass(element))) {
        ((AbstractBeanDefinition) bd).setDestroyMethodName("destroy");
    }
}
 
Example 5
Source File: RedissonReadAndWriteLockDefinitionParser.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    bd.setFactoryBeanName(element.getAttribute(
            RedissonNamespaceParserSupport.READ_WRITE_LOCK_REF_ATTRIBUTE));
    String typeName
            = Conventions.attributeNameToPropertyName(element.getLocalName());
    bd.setFactoryMethodName(typeName);
}
 
Example 6
Source File: RedissonMultiLockDefinitionParser.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected String getBeanClassName(Element element) {
    String elementName
            = Conventions.attributeNameToPropertyName(
                    element.getLocalName());
    return RedissonNamespaceParserSupport.IMPL_CLASS_PATH_PREFIX
            + StringUtils.capitalize(elementName);
}
 
Example 7
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 8
Source File: RedissonNamespaceParserSupport.java    From redisson with Apache License 2.0 4 votes vote down vote up
public String getName(Node node) {
    return Conventions.attributeNameToPropertyName(node.getLocalName());
}
 
Example 9
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;
}
 
Example 10
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 11
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 12
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 13
Source File: AbstractSimpleBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Extract a JavaBean property name from the supplied attribute name.
 * <p>The default implementation uses the
 * {@link Conventions#attributeNameToPropertyName(String)}
 * method to perform the extraction.
 * <p>The name returned must obey the standard JavaBean property name
 * conventions. For example for a class with a setter method
 * '{@code setBingoHallFavourite(String)}', the name returned had
 * better be '{@code bingoHallFavourite}' (with that exact casing).
 * @param attributeName the attribute name taken straight from the
 * XML element being parsed (never {@code null})
 * @return the extracted JavaBean property name (must never be {@code null})
 */
protected String extractPropertyName(String attributeName) {
	return Conventions.attributeNameToPropertyName(attributeName);
}
 
Example 14
Source File: AbstractSimpleBeanDefinitionParser.java    From blog_demos with Apache License 2.0 2 votes vote down vote up
/**
 * Extract a JavaBean property name from the supplied attribute name.
 * <p>The default implementation uses the
 * {@link Conventions#attributeNameToPropertyName(String)}
 * method to perform the extraction.
 * <p>The name returned must obey the standard JavaBean property name
 * conventions. For example for a class with a setter method
 * '{@code setBingoHallFavourite(String)}', the name returned had
 * better be '{@code bingoHallFavourite}' (with that exact casing).
 * @param attributeName the attribute name taken straight from the
 * XML element being parsed (never {@code null})
 * @return the extracted JavaBean property name (must never be {@code null})
 */
protected String extractPropertyName(String attributeName) {
	return Conventions.attributeNameToPropertyName(attributeName);
}
 
Example 15
Source File: AbstractSimpleBeanDefinitionParser.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Extract a JavaBean property name from the supplied attribute name.
 * <p>The default implementation uses the
 * {@link Conventions#attributeNameToPropertyName(String)}
 * method to perform the extraction.
 * <p>The name returned must obey the standard JavaBean property name
 * conventions. For example for a class with a setter method
 * '{@code setBingoHallFavourite(String)}', the name returned had
 * better be '{@code bingoHallFavourite}' (with that exact casing).
 * @param attributeName the attribute name taken straight from the
 * XML element being parsed (never {@code null})
 * @return the extracted JavaBean property name (must never be {@code null})
 */
protected String extractPropertyName(String attributeName) {
	return Conventions.attributeNameToPropertyName(attributeName);
}
 
Example 16
Source File: AbstractSimpleBeanDefinitionParser.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Extract a JavaBean property name from the supplied attribute name.
 * <p>The default implementation uses the
 * {@link Conventions#attributeNameToPropertyName(String)}
 * method to perform the extraction.
 * <p>The name returned must obey the standard JavaBean property name
 * conventions. For example for a class with a setter method
 * '{@code setBingoHallFavourite(String)}', the name returned had
 * better be '{@code bingoHallFavourite}' (with that exact casing).
 * @param attributeName the attribute name taken straight from the
 * XML element being parsed (never {@code null})
 * @return the extracted JavaBean property name (must never be {@code null})
 */
protected String extractPropertyName(String attributeName) {
	return Conventions.attributeNameToPropertyName(attributeName);
}
 
Example 17
Source File: AbstractSimpleBeanDefinitionParser.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Extract a JavaBean property name from the supplied attribute name.
 * <p>The default implementation uses the
 * {@link Conventions#attributeNameToPropertyName(String)}
 * method to perform the extraction.
 * <p>The name returned must obey the standard JavaBean property name
 * conventions. For example for a class with a setter method
 * '{@code setBingoHallFavourite(String)}', the name returned had
 * better be '{@code bingoHallFavourite}' (with that exact casing).
 * @param attributeName the attribute name taken straight from the
 * XML element being parsed (never {@code null})
 * @return the extracted JavaBean property name (must never be {@code null})
 */
protected String extractPropertyName(String attributeName) {
	return Conventions.attributeNameToPropertyName(attributeName);
}