org.springframework.beans.factory.support.ManagedArray Java Examples

The following examples show how to use org.springframework.beans.factory.support.ManagedArray. 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: JupiterBeanDefinitionParser.java    From Jupiter with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("SameParameterValue")
private static void addPropertyReferenceArray(
        RootBeanDefinition definition, Element element, String elementTypeName, String propertyName, boolean required) {
    String[] refArray = Strings.split(element.getAttribute(propertyName), ',');
    List<RuntimeBeanReference> refBeanList = Lists.newArrayListWithCapacity(refArray.length);
    for (String ref : refArray) {
        ref = ref.trim();
        if (required) {
            checkAttribute(propertyName, ref);
        }
        if (!Strings.isNullOrEmpty(ref)) {
            refBeanList.add(new RuntimeBeanReference(ref));
        }
    }

    if (!refBeanList.isEmpty()) {
        ManagedArray managedArray = new ManagedArray(elementTypeName, refBeanList.size());
        managedArray.addAll(refBeanList);
        definition.getPropertyValues().addPropertyValue(propertyName, managedArray);
    }
}
 
Example #2
Source File: BeanDefinitionWriterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
private XStream createStream() {
	XStream stream = new XStream();
	stream.registerConverter(new BeanDefinitionConverter(stream.getMapper()));
	stream.registerConverter(new BeanDefinitionHolderConverter(stream.getMapper()));
	stream.registerConverter(new TypedStringValueConverter());
	stream.registerConverter(new ManagedCollectionConverter(stream.getMapper()));
	stream.registerConverter(new ManagedMapConverter(stream.getMapper()));
	stream.registerConverter(new RuntimeBeanReferenceConverter());
	stream.alias("map", ManagedMap.class);
	stream.alias("list", ManagedList.class);
	stream.alias("set", ManagedSet.class);
	stream.alias("array", ManagedArray.class);
	stream.aliasType("bean", BeanDefinition.class);
	stream.alias("bean", BeanDefinitionHolder.class);
	stream.alias("ref", RuntimeBeanReference.class);
	return stream;
}
 
Example #3
Source File: BeanDefinitionParserDelegate.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Parse an array element.
 */
public Object parseArrayElement(Element arrayEle, @Nullable BeanDefinition bd) {
	String elementType = arrayEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
	NodeList nl = arrayEle.getChildNodes();
	ManagedArray target = new ManagedArray(elementType, nl.getLength());
	target.setSource(extractSource(arrayEle));
	target.setElementTypeName(elementType);
	target.setMergeEnabled(parseMergeAttribute(arrayEle));
	parseCollectionElements(nl, target, bd, elementType);
	return target;
}
 
Example #4
Source File: BeanDefinitionParserDelegate.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Parse an array element.
 */
public Object parseArrayElement(Element arrayEle, @Nullable BeanDefinition bd) {
	String elementType = arrayEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
	NodeList nl = arrayEle.getChildNodes();
	ManagedArray target = new ManagedArray(elementType, nl.getLength());
	target.setSource(extractSource(arrayEle));
	target.setElementTypeName(elementType);
	target.setMergeEnabled(parseMergeAttribute(arrayEle));
	parseCollectionElements(nl, target, bd, elementType);
	return target;
}
 
Example #5
Source File: BeanDefinitionParserDelegate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse an array element.
 */
public Object parseArrayElement(Element arrayEle, BeanDefinition bd) {
	String elementType = arrayEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
	NodeList nl = arrayEle.getChildNodes();
	ManagedArray target = new ManagedArray(elementType, nl.getLength());
	target.setSource(extractSource(arrayEle));
	target.setElementTypeName(elementType);
	target.setMergeEnabled(parseMergeAttribute(arrayEle));
	parseCollectionElements(nl, target, bd, elementType);
	return target;
}
 
Example #6
Source File: BeanDefinitionParserDelegate.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Parse an array element.
 */
public Object parseArrayElement(Element arrayEle, BeanDefinition bd) {
	String elementType = arrayEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
	NodeList nl = arrayEle.getChildNodes();
	ManagedArray target = new ManagedArray(elementType, nl.getLength());
	target.setSource(extractSource(arrayEle));
	target.setElementTypeName(elementType);
	target.setMergeEnabled(parseMergeAttribute(arrayEle));
	parseCollectionElements(nl, target, bd, elementType);
	return target;
}
 
Example #7
Source File: BeanDefinitionParserDelegate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Parse an array element.
 */
public Object parseArrayElement(Element arrayEle, BeanDefinition bd) {
	String elementType = arrayEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
	NodeList nl = arrayEle.getChildNodes();
	ManagedArray target = new ManagedArray(elementType, nl.getLength());
	target.setSource(extractSource(arrayEle));
	target.setElementTypeName(elementType);
	target.setMergeEnabled(parseMergeAttribute(arrayEle));
	parseCollectionElements(nl, target, bd, elementType);
	return target;
}
 
Example #8
Source File: DictionaryBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Determines what kind of collection (or array) the given value is and call handlers based on the determined type
 *
 * @param value collection value to process
 * @param propertyName name of the property which has the collection value
 * @param nestedBeanStack stack of bean containers which contains the collection property
 */
protected void visitCollection(Object value, String propertyName, Stack<BeanDefinitionHolder> nestedBeanStack) {
    if (value instanceof Object[] || (value instanceof ManagedArray)) {
        visitArray(value, propertyName, nestedBeanStack);
    } else if (value instanceof List) {
        visitList((List<?>) value, propertyName, nestedBeanStack);
    } else if (value instanceof Set) {
        visitSet((Set<?>) value, propertyName, nestedBeanStack);
    } else if (value instanceof Map) {
        visitMap((Map<?, ?>) value, propertyName, nestedBeanStack);
    }
}
 
Example #9
Source File: DictionaryBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Iterates through the array values and calls helpers to process the value
 *
 * @param array the array to process
 * @param propertyName name of the property which has the array value
 * @param nestedBeanStack stack of bean containers which contains the array property
 */
protected void visitArray(Object array, String propertyName, Stack<BeanDefinitionHolder> nestedBeanStack) {
    Object[] arrayVal = null;
    if (array instanceof ManagedArray) {
        arrayVal = (Object[]) ((ManagedArray) array).getSource();
    } else {
        arrayVal = (Object[]) array;
    }

    Object[] newArray = new Object[arrayVal.length];
    for (int i = 0; i < arrayVal.length; i++) {
        Object elem = arrayVal[i];

        if (isStringValue(elem)) {
            elem = processArrayStringPropertyValue(propertyName, arrayVal, getString(elem), i, nestedBeanStack,
                    beanProcessors);
        } else {
            elem = visitPropertyValue(propertyName, elem, nestedBeanStack);
        }

        newArray[i] = elem;
    }

    if (array instanceof ManagedArray) {
        ((ManagedArray) array).setSource(newArray);
    } else {
        array = newArray;
    }
}
 
Example #10
Source File: DictionaryBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Indicate whether the given value is a collection
 *
 * @param value value to test
 * @return boolean true if the value is a collection, false if not
 */
protected boolean isCollectionValue(Object value) {
    boolean isCollection = false;

    if (value instanceof Object[] || (value instanceof ManagedArray) || (value instanceof List) ||
            (value instanceof Set) || (value instanceof Map)) {
        isCollection = true;
    }

    return isCollection;
}
 
Example #11
Source File: BeanDefinitionWriterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean canConvert(Class type) {
	return type.equals(ManagedList.class) || type.equals(ManagedArray.class) || type.equals(ManagedSet.class);
}