@Override
  public void setValue(T value) {
    this.actualValue = value;

    checkPrismContext();
    if (value != null && prismContext.canSerialize(value)) {
      try {
        this.valueForStorageWhenEncoded =
            prismContext.xmlSerializer().serializeAnyData(value, new QName("value"));
      } catch (SchemaException e) {
        throw new SystemException(
            "Couldn't serialize value of type " + value.getClass() + ": " + e.getMessage(), e);
      }
      this.valueForStorageWhenNotEncoded = null;
      encodingScheme = EncodingScheme.PRISM;
    } else if (value == null || value instanceof Serializable) {
      this.valueForStorageWhenNotEncoded = value;
      this.valueForStorageWhenEncoded = null;
      encodingScheme = EncodingScheme.NONE;
      if (value instanceof Itemable) {
        throw new IllegalStateException(
            "Itemable value is used as not-encoded serializable item; value = " + value);
      }
    } else {
      throw new IllegalStateException(
          "Attempt to put non-serializable item "
              + value.getClass()
              + " into "
              + this.getClass().getSimpleName());
    }
  }
 private void debugDumpValue(int indent, StringBuilder sb, T value) {
   if (value instanceof DebugDumpable) {
     DebugUtil.debugDumpWithLabel(sb, "value", (DebugDumpable) value, indent);
     return;
   }
   String stringValue = null;
   if (value instanceof ExpressionType) {
     // brutal hack...
     String xml = null;
     try {
       xml =
           prismContext
               .xmlSerializer()
               .serializeRealValue(value, SchemaConstantsGenerated.C_EXPRESSION);
       stringValue = DebugUtil.fixIndentInMultiline(indent, DebugDumpable.INDENT_STRING, xml);
     } catch (SchemaException e) {
       LOGGER.warn("Couldn't serialize an expression: {}", value, e);
     }
   }
   if (stringValue == null) {
     stringValue = String.valueOf(value);
   }
   DebugUtil.debugDumpWithLabel(sb, "value", stringValue, indent);
 }