use of com.evolveum.midpoint.util.DebugDumpable in project midpoint by Evolveum.
the class LazyXPathVariableResolver method convertToXml.
// May return primitive types or DOM Node
public static Object convertToXml(Object variableValue, QName variableName, final PrismContext prismContext, String contextDescription) throws SchemaException {
try {
if (variableValue instanceof Objectable) {
variableValue = ((Objectable) variableValue).asPrismObject();
}
if (variableValue instanceof PrismObject) {
PrismObject<?> prismObject = (PrismObject<?>) variableValue;
variableValue = prismObject.getPrismContext().domSerializer().serialize(prismObject);
} else if (variableValue instanceof PrismProperty<?>) {
PrismProperty<?> prismProperty = (PrismProperty<?>) variableValue;
final List<Element> elementList = new ArrayList<Element>();
for (PrismPropertyValue<?> value : prismProperty.getValues()) {
Element valueElement = prismContext.domSerializer().serialize(value, prismProperty.getElementName());
elementList.add(valueElement);
}
NodeList nodeList = new AdHocNodeList(elementList);
variableValue = nodeList;
} else if (variableValue instanceof PrismValue) {
PrismValue pval = (PrismValue) variableValue;
if (pval.getParent() == null) {
// Set a fake parent to allow serialization
pval.setParent(new AdHocItemable(prismContext));
}
variableValue = prismContext.domSerializer().serialize(pval, variableName);
}
if (!((variableValue instanceof Node) || variableValue instanceof NodeList) && !(variableValue.getClass().getPackage().getName().startsWith("java."))) {
throw new SchemaException("Unable to convert value of variable " + variableName + " to XML, still got " + variableValue.getClass().getName() + ":" + variableValue + " value at the end");
}
return variableValue;
} catch (SchemaException e) {
if (variableValue != null && variableValue instanceof DebugDumpable) {
LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
}
throw new SchemaException(e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
} catch (RuntimeException e) {
if (variableValue != null && variableValue instanceof DebugDumpable) {
LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
}
throw new RuntimeException(e.getClass().getName() + ": " + e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
}
}
use of com.evolveum.midpoint.util.DebugDumpable in project midpoint by Evolveum.
the class VariablesMap method formatVariables.
public String formatVariables() {
StringBuilder sb = new StringBuilder();
Iterator<Entry<String, TypedValue>> i = entrySet().iterator();
while (i.hasNext()) {
Entry<String, TypedValue> entry = i.next();
if (!isAlias(entry.getKey())) {
SchemaDebugUtil.indentDebugDump(sb, 1);
sb.append(entry.getKey());
sb.append(getAliasesListFormatted(entry.getKey()));
sb.append(": ");
TypedValue valueDef = entry.getValue();
Object value = valueDef.getValue();
// TODO: dump definitions?
if (value instanceof DebugDumpable) {
sb.append("\n");
sb.append(((DebugDumpable) value).debugDump(2));
} else if (value instanceof Element) {
sb.append("\n");
sb.append(DOMUtil.serializeDOMToString(((Element) value)));
} else {
sb.append(SchemaDebugUtil.prettyPrint(value));
}
if (i.hasNext()) {
sb.append("\n");
}
}
}
return sb.toString();
}
use of com.evolveum.midpoint.util.DebugDumpable in project midpoint by Evolveum.
the class ExpressionVariables method formatVariables.
public String formatVariables() {
StringBuilder sb = new StringBuilder();
Iterator<Entry<QName, Object>> i = variables.entrySet().iterator();
while (i.hasNext()) {
Entry<QName, Object> entry = i.next();
SchemaDebugUtil.indentDebugDump(sb, 1);
sb.append(SchemaDebugUtil.prettyPrint(entry.getKey())).append(": ");
Object value = entry.getValue();
if (value instanceof DebugDumpable) {
sb.append("\n");
sb.append(((DebugDumpable) value).debugDump(2));
} else if (value instanceof Element) {
sb.append("\n");
sb.append(DOMUtil.serializeDOMToString(((Element) value)));
} else {
sb.append(SchemaDebugUtil.prettyPrint(value));
}
if (i.hasNext()) {
sb.append("\n");
}
}
return sb.toString();
}
use of com.evolveum.midpoint.util.DebugDumpable in project midpoint by Evolveum.
the class SchemaDebugUtil method debugDump.
public static String debugDump(Collection<? extends DebugDumpable> dumpables, int indent) {
StringBuilder sb = new StringBuilder();
indentDebugDump(sb, indent);
sb.append(getCollectionOpeningSymbol(dumpables));
if (!dumpables.isEmpty()) {
sb.append("\n");
for (DebugDumpable dd : dumpables) {
if (dd == null) {
indentDebugDump(sb, indent + 1);
sb.append("null");
} else {
sb.append(dd.debugDump(indent + 1));
}
sb.append("\n");
}
indentDebugDump(sb, indent);
}
sb.append(getCollectionClosingSymbol(dumpables));
return sb.toString();
}
use of com.evolveum.midpoint.util.DebugDumpable in project midpoint by Evolveum.
the class IntegrationTestTools method displayCollection.
public static void displayCollection(String message, Collection<? extends DebugDumpable> collection) {
println(OBJECT_TITLE_OUT_PREFIX + message);
LOGGER.debug(OBJECT_TITLE_LOG_PREFIX + message);
for (DebugDumpable c : CollectionUtils.emptyIfNull(collection)) {
String s = DebugUtil.debugDump(c);
println(s);
LOGGER.debug("{}", s);
println(OBJECT_LIST_SEPARATOR);
LOGGER.debug(OBJECT_LIST_SEPARATOR);
}
}
Aggregations