Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2004-2008 the original author or authors.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package org.springframework.binding.convert.converters;
Special one-way converter that converts from a source array to a target array. Supports type conversion of the individual array elements; for example, the ability to convert a String[] to an Integer[]. Mainly used internally by org.springframework.binding.convert.ConversionService implementations.

Keith Donald
public class ArrayToArray implements Converter {
Creates a new array-to-array converter.

conversionService the service to use to lookup conversion executors for individual array elements
	public ArrayToArray(ConversionService conversionService) {
		this. = conversionService;
	public Class getSourceClass() {
		return Object[].class;
	public Class getTargetClass() {
		return Object[].class;
	public Object convertSourceToTargetClass(Object sourceClass targetClassthrows Exception {
		if (source == null) {
			return null;
		Class sourceComponentType = source.getClass().getComponentType();
		Class targetComponentType = targetClass.getComponentType();
		int length = Array.getLength(source);
		Object targetArray = Array.newInstance(targetComponentTypelength);
		for (int i = 0; i < lengthi++) {
			Object value = Array.get(sourcei);
		return targetArray;
New to GrepCode? Check out our FAQ X