@Override
  public void propertyOrder(JDefinedClass clazz, JsonNode propertiesNode) {
    JAnnotationArrayMember annotationValue =
        clazz.annotate(JsonPropertyOrder.class).paramArray("value");

    for (Iterator<String> properties = propertiesNode.fieldNames(); properties.hasNext(); ) {
      annotationValue.param(properties.next());
    }
  }
  private void addProducesAnnotation(
      final Collection<MimeType> uniqueResponseMimeTypes, final JMethod method) {
    if (uniqueResponseMimeTypes.isEmpty()) {
      return;
    }

    final JAnnotationArrayMember paramArray =
        method.annotate(Produces.class).paramArray(DEFAULT_ANNOTATION_PARAMETER);

    for (final MimeType responseMimeType : uniqueResponseMimeTypes) {
      paramArray.param(responseMimeType.getType());
    }
  }
 @Override
 public Void visitEnumConstant(VariableElement c, JAnnotationArrayMember p) {
   JClass annotationClass = helper.typeMirrorToJClass(c.asType(), holder);
   JExpression expression = JExpr.direct(annotationClass.fullName() + "." + c.getSimpleName());
   p.param(expression);
   return null;
 }
 @Override
 public Void visitType(TypeMirror t, JAnnotationArrayMember p) {
   JClass annotationClass = helper.typeMirrorToJClass(t, holder);
   JExpression dotclass = JExpr.dotclass(annotationClass);
   p.param(dotclass);
   return null;
 }
示例#5
0
  /**
   * 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);
    }
  }
 @Override
 public Void visitString(String s, JAnnotationArrayMember p) {
   p.param(s);
   return null;
 }
 @Override
 public Void visitShort(short s, JAnnotationArrayMember p) {
   p.param(s);
   return null;
 }
 @Override
 public Void visitLong(long i, JAnnotationArrayMember p) {
   p.param(i);
   return null;
 }
 @Override
 public Void visitInt(int i, JAnnotationArrayMember p) {
   p.param(i);
   return null;
 }
 @Override
 public Void visitFloat(float f, JAnnotationArrayMember p) {
   p.param(f);
   return null;
 }
 @Override
 public Void visitDouble(double d, JAnnotationArrayMember p) {
   p.param(d);
   return null;
 }
 @Override
 public Void visitChar(char c, JAnnotationArrayMember p) {
   p.param(c);
   return null;
 }
 @Override
 public Void visitByte(byte b, JAnnotationArrayMember p) {
   p.param(b);
   return null;
 }
 @Override
 public Void visitBoolean(boolean b, JAnnotationArrayMember p) {
   p.param(b);
   return null;
 }