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
  * 
  *      http://www.apache.org/licenses/LICENSE-2.0
  * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * 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.

Author(s):
Keith Donald
public class ArrayToArray implements Converter {
Creates a new array-to-array converter.

Parameters:
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);
				.getConversionExecutor(sourceComponentTypetargetComponentType);
		for (int i = 0; i < lengthi++) {
			Object value = Array.get(sourcei);
			Array.set(targetArrayiconverter.execute(value));
		}
		return targetArray;
	}
New to GrepCode? Check out our FAQ X