TypeTypeManufacturerImpl.java

  1. package uk.co.jemos.podam.typeManufacturers;

  2. import uk.co.jemos.podam.api.AttributeMetadata;
  3. import uk.co.jemos.podam.api.DataProviderStrategy;
  4. import uk.co.jemos.podam.common.ManufacturingContext;
  5. import uk.co.jemos.podam.common.PodamConstants;

  6. import java.lang.reflect.Type;
  7. import java.util.Map;
  8. import java.util.concurrent.atomic.AtomicReference;

  9. /**
  10.  * Default generic type type manufacturer.
  11.  *
  12.  * Created by tedonema on 17/05/2015.
  13.  *
  14.  * @since 6.0.0.RELEASE
  15.  */
  16. public class TypeTypeManufacturerImpl extends AbstractTypeManufacturer<Object> {

  17.     @Override
  18.     public Object getType(DataProviderStrategy strategy,
  19.             AttributeMetadata attributeMetadata,
  20.             ManufacturingContext manufacturingCtx) {

  21.         Type genericAttributeType = attributeMetadata.getAttributeGenericType();
  22.         AtomicReference<Type[]> elementGenericTypeArgs
  23.                 = new AtomicReference<Type[]>(PodamConstants.NO_TYPES);
  24.         TypeManufacturerUtil.resolveGenericParameter(genericAttributeType,
  25.                 manufacturingCtx, elementGenericTypeArgs);

  26.         if (elementGenericTypeArgs.get().length > 0) {

  27.             Type resolvedType = elementGenericTypeArgs.get()[0];
  28.             return TypeManufacturerUtil.resolveGenericParameter(resolvedType,
  29.                     manufacturingCtx, elementGenericTypeArgs);
  30.         } else {

  31.             return attributeMetadata.getAttributeType();
  32.         }

  33.     }
  34. }