/** * Utility method that encodes an object that is not an expression Node to * String. */ protected static void appendScalarAsString(Appendable out, Object scalar, char quoteChar) throws IOException { boolean quote = scalar instanceof String; if (quote) { out.append(quoteChar); } // encode only ObjectId for Persistent, ensure that the order of keys is predictable.... // TODO: should we use UUID here? if (scalar instanceof Persistent) { ObjectId id = ((Persistent) scalar).getObjectId(); Object encode = (id != null) ? id : scalar; appendAsEscapedString(out, String.valueOf(encode)); } else if (scalar instanceof Enum<?>) { Enum<?> e = (Enum<?>) scalar; out.append("enum:"); out.append(e.getClass().getName()).append(".").append(e.name()); } else { appendAsEscapedString(out, String.valueOf(scalar)); } if (quote) { out.append(quoteChar); } }
ObjectId id = ((Persistent) scalar).getObjectId(); Object encode = (id != null) ? id : scalar; appendAsEscapedString(out, String.valueOf(encode)); return; appendAsEscapedString(out, scalar.toString()); out.append('\''); return;