All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jvnet.annox.model.annotation.value.XArrayClassAnnotationValue Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package org.jvnet.annox.model.annotation.value;

import java.lang.reflect.Array;
import java.util.Arrays;

import org.apache.commons.lang3.Validate;

public class XArrayClassAnnotationValue extends
		XDynamicAnnotationValue> {

	private final XClassByNameAnnotationValue itemClassByNameAnnotationValue;
	private final int dimension;
	private final String arrayClassName;

	public XArrayClassAnnotationValue(
			XClassByNameAnnotationValue itemClassByNameAnnotationValue,
			int dimension) {
		this.itemClassByNameAnnotationValue = Validate
				.notNull(itemClassByNameAnnotationValue);
		Validate.isTrue(dimension > 0);
		this.dimension = dimension;
		String arrayClassName = itemClassByNameAnnotationValue.getClassName();
		for (int index = 0; index < dimension; index++) {
			arrayClassName = arrayClassName + "[]";
		}
		this.arrayClassName = arrayClassName;
	}

	public XClassByNameAnnotationValue getItemClassByNameAnnotationValue() {
		return itemClassByNameAnnotationValue;
	}

	public String getItemClassName() {
		return itemClassByNameAnnotationValue.getClassName();
	}

	public int getDimension() {
		return dimension;
	}

	@Override
	protected Object getInternalValue() {
		return this.arrayClassName;
	}

	@Override
	public 

P accept(XAnnotationValueVisitor

visitor) { return visitor.visit(this); } @Override public Class getValue() { final Class componentType = this.itemClassByNameAnnotationValue .getValue(); final int[] dimensions = new int[this.dimension]; Arrays.fill(dimensions, 0); final Object array = Array.newInstance(componentType, dimensions); @SuppressWarnings("unchecked") final Class arrayClass = (Class) array.getClass(); return arrayClass; } }