Exemplo n.º 1
0
  public <T> ModelSchemaExtractionResult<T> extract(
      ModelSchemaExtractionContext<T> extractionContext,
      ModelSchemaStore store,
      final ModelSchemaCache cache) {
    ModelType<T> type = extractionContext.getType();
    if (MODEL_MAP_MODEL_TYPE.isAssignableFrom(type)) {
      if (!type.getRawClass().equals(ModelMap.class)) {
        throw new InvalidManagedModelElementTypeException(
            extractionContext,
            String.format("subtyping %s is not supported.", ModelMap.class.getName()));
      }
      if (type.isHasWildcardTypeVariables()) {
        throw new InvalidManagedModelElementTypeException(
            extractionContext,
            String.format("type parameter of %s cannot be a wildcard.", ModelMap.class.getName()));
      }

      List<ModelType<?>> typeVariables = type.getTypeVariables();
      if (typeVariables.isEmpty()) {
        throw new InvalidManagedModelElementTypeException(
            extractionContext,
            String.format("type parameter of %s has to be specified.", ModelMap.class.getName()));
      }

      ModelType<?> elementType = typeVariables.get(0);

      if (MODEL_MAP_MODEL_TYPE.isAssignableFrom(elementType)) {
        throw new InvalidManagedModelElementTypeException(
            extractionContext,
            String.format(
                "%1$s cannot be used as type parameter of %1$s.", ModelMap.class.getName()));
      }

      return gettModelSchemaExtractionResult(extractionContext, cache, elementType, store);
    } else {
      return null;
    }
  }