コード例 #1
0
 private void addJsonTypeInfoAnnotation(JDefinedClass jclass, JsonNode node) {
   if (this.ruleFactory.getGenerationConfig().getAnnotationStyle() == AnnotationStyle.JACKSON2) {
     String annotationName = node.get("deserializationClassProperty").asText();
     JAnnotationUse jsonTypeInfo = jclass.annotate(JsonTypeInfo.class);
     jsonTypeInfo.param("use", JsonTypeInfo.Id.CLASS);
     jsonTypeInfo.param("include", JsonTypeInfo.As.PROPERTY);
     jsonTypeInfo.param("property", annotationName);
   }
 }
  @Override
  public JAnnotationUse apply(
      ApiResourceMetadata controllerMetadata, JDefinedClass generatableType) {
    JAnnotationUse feignClient = generatableType.annotate(FeignClient.class);

    feignClient.param("url", controllerMetadata.getControllerUrl());
    feignClient.param("name", getClientName(controllerMetadata));

    return feignClient;
  }
コード例 #3
0
  private void addGenerated(final JDefinedClass type) {
    assert type != null;

    JAnnotationUse anno = type.annotate(Generated.class);
    anno.param("value", String.format("XJC %s", Driver.getBuildID()));

    Date now = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat(ISO_8601_FORMAT);
    anno.param("date", sdf.format(now));

    // TODO: Maybe support customized comments?
  }
コード例 #4
0
  private void addJsr303Annotations(final AbstractParam parameter, final JVar argumentVariable) {
    if (isNotBlank(parameter.getPattern())) {
      LOGGER.info(
          "Pattern constraint ignored for parameter: "
              + ToStringBuilder.reflectionToString(parameter, SHORT_PREFIX_STYLE));
    }

    final Integer minLength = parameter.getMinLength();
    final Integer maxLength = parameter.getMaxLength();
    if ((minLength != null) || (maxLength != null)) {
      final JAnnotationUse sizeAnnotation = argumentVariable.annotate(Size.class);

      if (minLength != null) {
        sizeAnnotation.param("min", minLength);
      }

      if (maxLength != null) {
        sizeAnnotation.param("max", maxLength);
      }
    }

    final BigDecimal minimum =
        parameter.getMinimum() == null ? null : BigDecimal.valueOf(parameter.getMinimum());
    if (minimum != null) {
      addMinMaxConstraint(parameter, "minimum", Min.class, minimum, argumentVariable);
    }

    final BigDecimal maximum =
        parameter.getMaximum() == null ? null : BigDecimal.valueOf(parameter.getMaximum());

    if (maximum != null) {
      addMinMaxConstraint(parameter, "maximum", Max.class, maximum, argumentVariable);
    }

    if (parameter.isRequired()) {
      argumentVariable.annotate(NotNull.class);
    }
  }
コード例 #5
0
ファイル: BeanGenerator.java プロジェクト: tduehr/ldaptive
  /**
   * Generates a class for each configured object class. See {@link #objectClasses}. {@link
   * #write(String)} must be invoked to write the classes to disk.
   */
  public void generate() {
    for (String objectClass : objectClasses) {
      final JDefinedClass definedClass = createClass(packageName, objectClass);
      final JDocComment jDocComment = definedClass.javadoc();
      jDocComment.add(String.format("Ldaptive generated bean for objectClass '%s'", objectClass));

      final ObjectClass oc = schema.getObjectClass(objectClass);
      final Set<String> attributeNames = getAttributeNames(oc);
      if (useOperationalAttributes) {
        for (AttributeType type : schema.getAttributeTypes()) {
          if (AttributeUsage.DIRECTORY_OPERATION.equals(type.getUsage())) {
            attributeNames.add(type.getName());
          }
        }
      }

      final Map<String, AttributeType> mutators = new TreeMap<>();
      for (String name : attributeNames) {
        final AttributeType type = schema.getAttributeType(name);
        if (!isNameExcluded(type)) {
          if (nameMappings.containsKey(type.getName())) {
            mutators.put(nameMappings.get(type.getName()), type);
          } else {
            mutators.put(formatAttributeName(type.getName()), type);
          }
        }
      }

      // add entry annotation
      final JAnnotationUse entryAnnotation =
          definedClass.annotate(codeModel.ref(org.ldaptive.beans.Entry.class));
      entryAnnotation.param("dn", "dn");

      final JAnnotationArrayMember attrArray = entryAnnotation.paramArray("attributes");

      // add mutator for the DN
      createMutators(definedClass, "dn", String.class, false);

      // add mutators for each attribute
      for (Map.Entry<String, AttributeType> mutator : mutators.entrySet()) {
        final Class<?> syntaxType =
            getSyntaxType(
                mutator.getValue(), schema.getSyntax(mutator.getValue().getSyntaxOID(false)));
        if (mutator.getValue().isSingleValued()) {
          createMutators(definedClass, mutator.getKey(), syntaxType, false);
        } else {
          createMutators(definedClass, mutator.getKey(), syntaxType, true);
        }

        // add attribute annotation
        final JAnnotationUse attrAnnotation =
            attrArray.annotate(org.ldaptive.beans.Attribute.class);
        attrAnnotation.param("name", mutator.getValue().getName());
        if (!mutator.getKey().equals(mutator.getValue().getName())) {
          attrAnnotation.param("property", mutator.getKey());
        }
        if (byte[].class.equals(syntaxType)) {
          attrAnnotation.param("binary", true);
        }
      }

      // create additional methods
      createHashCode(definedClass);
      createEquals(definedClass);
      createToString(definedClass);
    }
  }
コード例 #6
0
 private void addGeneratedAnnotation(JDefinedClass jclass) {
   JAnnotationUse generated = jclass.annotate(Generated.class);
   generated.param("value", SchemaMapper.class.getPackage().getName());
 }