Java Code Examples for org.springframework.util.ObjectUtils#addObjectToArray()

The following examples show how to use org.springframework.util.ObjectUtils#addObjectToArray() . 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: RecursiveAnnotationArrayVisitor.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void visit(String attributeName, Object attributeValue) {
	Object newValue = attributeValue;
	Object existingValue = this.attributes.get(this.attributeName);
	if (existingValue != null) {
		newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue);
	}
	else {
		Class<?> arrayClass = newValue.getClass();
		if (Enum.class.isAssignableFrom(arrayClass)) {
			while (arrayClass.getSuperclass() != null && !arrayClass.isEnum()) {
				arrayClass = arrayClass.getSuperclass();
			}
		}
		Object[] newArray = (Object[]) Array.newInstance(arrayClass, 1);
		newArray[0] = newValue;
		newValue = newArray;
	}
	this.attributes.put(this.attributeName, newValue);
}
 
Example 2
Source File: RecursiveAnnotationArrayVisitor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(String attributeName, Object attributeValue) {
	Object newValue = attributeValue;
	Object existingValue = this.attributes.get(this.attributeName);
	if (existingValue != null) {
		newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue);
	}
	else {
		Class<?> arrayClass = newValue.getClass();
		if (Enum.class.isAssignableFrom(arrayClass)) {
			while (arrayClass.getSuperclass() != null && !arrayClass.isEnum()) {
				arrayClass = arrayClass.getSuperclass();
			}
		}
		Object[] newArray = (Object[]) Array.newInstance(arrayClass, 1);
		newArray[0] = newValue;
		newValue = newArray;
	}
	this.attributes.put(this.attributeName, newValue);
}
 
Example 3
Source File: RecursiveAnnotationArrayVisitor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visit(String attributeName, Object attributeValue) {
	Object newValue = attributeValue;
	Object existingValue = this.attributes.get(this.attributeName);
	if (existingValue != null) {
		newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue);
	}
	else {
		Class<?> arrayClass = newValue.getClass();
		if (Enum.class.isAssignableFrom(arrayClass)) {
			while (arrayClass.getSuperclass() != null && !arrayClass.isEnum()) {
				arrayClass = arrayClass.getSuperclass();
			}
		}
		Object[] newArray = (Object[]) Array.newInstance(arrayClass, 1);
		newArray[0] = newValue;
		newValue = newArray;
	}
	this.attributes.put(this.attributeName, newValue);
}
 
Example 4
Source File: BeanDefinitionBuilder.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Append the specified bean name to the list of beans that this definition
 * depends on.
 */
public BeanDefinitionBuilder addDependsOn(String beanName) {
	if (this.beanDefinition.getDependsOn() == null) {
		this.beanDefinition.setDependsOn(beanName);
	}
	else {
		String[] added = ObjectUtils.addObjectToArray(this.beanDefinition.getDependsOn(), beanName);
		this.beanDefinition.setDependsOn(added);
	}
	return this;
}
 
Example 5
Source File: BeanDefinitionBuilder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Append the specified bean name to the list of beans that this definition
 * depends on.
 */
public BeanDefinitionBuilder addDependsOn(String beanName) {
	if (this.beanDefinition.getDependsOn() == null) {
		this.beanDefinition.setDependsOn(beanName);
	}
	else {
		String[] added = ObjectUtils.addObjectToArray(this.beanDefinition.getDependsOn(), beanName);
		this.beanDefinition.setDependsOn(added);
	}
	return this;
}
 
Example 6
Source File: ScriptFactoryPostProcessor.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Prepare the script beans in the internal BeanFactory that this
 * post-processor uses. Each original bean definition will be split
 * into a ScriptFactory definition and a scripted object definition.
 * @param bd the original bean definition in the main BeanFactory
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptedObjectBeanName the name of the internal scripted object bean
 */
protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) {
	// Avoid recreation of the script bean definition in case of a prototype.
	synchronized (this.scriptBeanFactory) {
		if (!this.scriptBeanFactory.containsBeanDefinition(scriptedObjectBeanName)) {

			this.scriptBeanFactory.registerBeanDefinition(
					scriptFactoryBeanName, createScriptFactoryBeanDefinition(bd));
			ScriptFactory scriptFactory =
					this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
			ScriptSource scriptSource =
					getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
			Class<?>[] interfaces = scriptFactory.getScriptInterfaces();

			Class<?>[] scriptedInterfaces = interfaces;
			if (scriptFactory.requiresConfigInterface() && !bd.getPropertyValues().isEmpty()) {
				Class<?> configInterface = createConfigInterface(bd, interfaces);
				scriptedInterfaces = ObjectUtils.addObjectToArray(interfaces, configInterface);
			}

			BeanDefinition objectBd = createScriptedObjectBeanDefinition(
					bd, scriptFactoryBeanName, scriptSource, scriptedInterfaces);
			long refreshCheckDelay = resolveRefreshCheckDelay(bd);
			if (refreshCheckDelay >= 0) {
				objectBd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
			}

			this.scriptBeanFactory.registerBeanDefinition(scriptedObjectBeanName, objectBd);
		}
	}
}
 
Example 7
Source File: ScriptFactoryPostProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Prepare the script beans in the internal BeanFactory that this
 * post-processor uses. Each original bean definition will be split
 * into a ScriptFactory definition and a scripted object definition.
 * @param bd the original bean definition in the main BeanFactory
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptedObjectBeanName the name of the internal scripted object bean
 */
protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) {
	// Avoid recreation of the script bean definition in case of a prototype.
	synchronized (this.scriptBeanFactory) {
		if (!this.scriptBeanFactory.containsBeanDefinition(scriptedObjectBeanName)) {

			this.scriptBeanFactory.registerBeanDefinition(
					scriptFactoryBeanName, createScriptFactoryBeanDefinition(bd));
			ScriptFactory scriptFactory =
					this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
			ScriptSource scriptSource =
					getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
			Class<?>[] interfaces = scriptFactory.getScriptInterfaces();

			Class<?>[] scriptedInterfaces = interfaces;
			if (scriptFactory.requiresConfigInterface() && !bd.getPropertyValues().isEmpty()) {
				Class<?> configInterface = createConfigInterface(bd, interfaces);
				scriptedInterfaces = ObjectUtils.addObjectToArray(interfaces, configInterface);
			}

			BeanDefinition objectBd = createScriptedObjectBeanDefinition(
					bd, scriptFactoryBeanName, scriptSource, scriptedInterfaces);
			long refreshCheckDelay = resolveRefreshCheckDelay(bd);
			if (refreshCheckDelay >= 0) {
				objectBd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
			}

			this.scriptBeanFactory.registerBeanDefinition(scriptedObjectBeanName, objectBd);
		}
	}
}
 
Example 8
Source File: BeanDefinitionBuilder.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Append the specified bean name to the list of beans that this definition
 * depends on.
 */
public BeanDefinitionBuilder addDependsOn(String beanName) {
	if (this.beanDefinition.getDependsOn() == null) {
		this.beanDefinition.setDependsOn(beanName);
	}
	else {
		String[] added = ObjectUtils.addObjectToArray(this.beanDefinition.getDependsOn(), beanName);
		this.beanDefinition.setDependsOn(added);
	}
	return this;
}
 
Example 9
Source File: ScriptFactoryPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Prepare the script beans in the internal BeanFactory that this
 * post-processor uses. Each original bean definition will be split
 * into a ScriptFactory definition and a scripted object definition.
 * @param bd the original bean definition in the main BeanFactory
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptedObjectBeanName the name of the internal scripted object bean
 */
protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) {
	// Avoid recreation of the script bean definition in case of a prototype.
	synchronized (this.scriptBeanFactory) {
		if (!this.scriptBeanFactory.containsBeanDefinition(scriptedObjectBeanName)) {

			this.scriptBeanFactory.registerBeanDefinition(
					scriptFactoryBeanName, createScriptFactoryBeanDefinition(bd));
			ScriptFactory scriptFactory =
					this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
			ScriptSource scriptSource =
					getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
			Class<?>[] interfaces = scriptFactory.getScriptInterfaces();

			Class<?>[] scriptedInterfaces = interfaces;
			if (scriptFactory.requiresConfigInterface() && !bd.getPropertyValues().isEmpty()) {
				Class<?> configInterface = createConfigInterface(bd, interfaces);
				scriptedInterfaces = ObjectUtils.addObjectToArray(interfaces, configInterface);
			}

			BeanDefinition objectBd = createScriptedObjectBeanDefinition(
					bd, scriptFactoryBeanName, scriptSource, scriptedInterfaces);
			long refreshCheckDelay = resolveRefreshCheckDelay(bd);
			if (refreshCheckDelay >= 0) {
				objectBd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
			}

			this.scriptBeanFactory.registerBeanDefinition(scriptedObjectBeanName, objectBd);
		}
	}
}
 
Example 10
Source File: ScriptFactoryPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prepare the script beans in the internal BeanFactory that this
 * post-processor uses. Each original bean definition will be split
 * into a ScriptFactory definition and a scripted object definition.
 * @param bd the original bean definition in the main BeanFactory
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptedObjectBeanName the name of the internal scripted object bean
 */
protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) {
	// Avoid recreation of the script bean definition in case of a prototype.
	synchronized (this.scriptBeanFactory) {
		if (!this.scriptBeanFactory.containsBeanDefinition(scriptedObjectBeanName)) {

			this.scriptBeanFactory.registerBeanDefinition(
					scriptFactoryBeanName, createScriptFactoryBeanDefinition(bd));
			ScriptFactory scriptFactory =
					this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
			ScriptSource scriptSource =
					getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
			Class<?>[] interfaces = scriptFactory.getScriptInterfaces();

			Class<?>[] scriptedInterfaces = interfaces;
			if (scriptFactory.requiresConfigInterface() && !bd.getPropertyValues().isEmpty()) {
				Class<?> configInterface = createConfigInterface(bd, interfaces);
				scriptedInterfaces = ObjectUtils.addObjectToArray(interfaces, configInterface);
			}

			BeanDefinition objectBd = createScriptedObjectBeanDefinition(
					bd, scriptFactoryBeanName, scriptSource, scriptedInterfaces);
			long refreshCheckDelay = resolveRefreshCheckDelay(bd);
			if (refreshCheckDelay >= 0) {
				objectBd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
			}

			this.scriptBeanFactory.registerBeanDefinition(scriptedObjectBeanName, objectBd);
		}
	}
}
 
Example 11
Source File: BeanDefinitionBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Append the specified bean name to the list of beans that this definition
 * depends on.
 */
public BeanDefinitionBuilder addDependsOn(String beanName) {
	if (this.beanDefinition.getDependsOn() == null) {
		this.beanDefinition.setDependsOn(beanName);
	}
	else {
		String[] added = ObjectUtils.addObjectToArray(this.beanDefinition.getDependsOn(), beanName);
		this.beanDefinition.setDependsOn(added);
	}
	return this;
}
 
Example 12
Source File: BeanDefinitionBuilder.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Append the specified bean name to the list of beans that this definition
 * depends on.
 */
public BeanDefinitionBuilder addDependsOn(String beanName) {
	if (this.beanDefinition.getDependsOn() == null) {
		this.beanDefinition.setDependsOn(new String[] {beanName});
	}
	else {
		String[] added = ObjectUtils.addObjectToArray(this.beanDefinition.getDependsOn(), beanName);
		this.beanDefinition.setDependsOn(added);
	}
	return this;
}
 
Example 13
Source File: Result.java    From albedo with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void addMessage(String message) {
	this.messages = ObjectUtils.addObjectToArray(messages, message);
}
 
Example 14
Source File: MockFilterChain.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private static List<Filter> initFilterList(Servlet servlet, Filter... filters) {
	Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet));
	return Arrays.asList(allFilters);
}
 
Example 15
Source File: MockFilterChain.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private static List<Filter> initFilterList(Servlet servlet, Filter... filters) {
	Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet));
	return Arrays.asList(allFilters);
}
 
Example 16
Source File: MockFilterChain.java    From java-technology-stack with MIT License 4 votes vote down vote up
private static List<Filter> initFilterList(Servlet servlet, Filter... filters) {
	Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet));
	return Arrays.asList(allFilters);
}
 
Example 17
Source File: MockFilterChain.java    From java-technology-stack with MIT License 4 votes vote down vote up
private static List<Filter> initFilterList(Servlet servlet, Filter... filters) {
	Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet));
	return Arrays.asList(allFilters);
}
 
Example 18
Source File: MockFilterChain.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private static List<Filter> initFilterList(Servlet servlet, Filter... filters) {
	Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet));
	return Arrays.asList(allFilters);
}
 
Example 19
Source File: MockFilterChain.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private static List<Filter> initFilterList(Servlet servlet, Filter... filters) {
	Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet));
	return Arrays.asList(allFilters);
}
 
Example 20
Source File: MockFilterChain.java    From gocd with Apache License 2.0 4 votes vote down vote up
private static List<Filter> initFilterList(Servlet servlet, Filter... filters) {
	Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet));
	return Arrays.asList(allFilters);
}