private void processAttributes()

in scim-server/src/main/java/org/apache/directory/scim/server/rest/AttributeUtil.java [188:247]


  private void processAttributes(Object object, AttributeContainer attributeContainer, Function<Attribute, Boolean> function) throws AttributeException {
    try {
      if (attributeContainer != null && object != null) {
        for (Attribute attribute : attributeContainer.getAttributes()) {

          Schema.AttributeAccessor accessor = attribute.getAccessor();

          if (function.apply(attribute)) {
            if (!accessor.getType().isPrimitive()) {
              Object obj = accessor.get(object);
              if (obj == null) {
                continue;
              }

              log.info("field to be set to null = " + accessor.getType().getName());
              accessor.set(object, null);
            }
          } else if (!attribute.isMultiValued() && attribute.getType() == Type.COMPLEX) {
            log.debug("### Processing single value complex field " + attribute.getName());
            Object subObject = accessor.get(object);

            if (subObject == null) {
              continue;
            }

            Attribute subAttribute = attributeContainer.getAttribute(attribute.getName());
            log.debug("### container type = " + attributeContainer.getClass().getName());
            if (subAttribute == null) {
              log.debug("#### subattribute == null");
            }
            processAttributes(subObject, subAttribute, function);
          } else if (attribute.isMultiValued() && attribute.getType() == Type.COMPLEX) {
            log.debug("### Processing multi-valued complex field " + attribute.getName());
            Object subObject = accessor.get(object);

            if (subObject == null) {
              continue;
            }

            if (Collection.class.isAssignableFrom(subObject.getClass())) {
              Collection<?> collection = (Collection<?>) subObject;
              for (Object o : collection) {
                Attribute subAttribute = attributeContainer.getAttribute(attribute.getName());
                processAttributes(o, subAttribute, function);
              }
            } else if (accessor.getType().isArray()) {
              Object[] array = (Object[]) subObject;

              for (Object o : array) {
                Attribute subAttribute = attributeContainer.getAttribute(attribute.getName());
                processAttributes(o, subAttribute, function);
              }
            }
          }
        }
      }
    } catch (IllegalArgumentException e) {
      throw new AttributeException(e);
    }
  }