Search in sources :

Example 1 with DebugDumpable

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) DebugDumpable(com.evolveum.midpoint.util.DebugDumpable) PrismValue(com.evolveum.midpoint.prism.PrismValue) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) Objectable(com.evolveum.midpoint.prism.Objectable) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 2 with DebugDumpable

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();
}
Also used : Element(org.w3c.dom.Element) ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) DebugDumpable(com.evolveum.midpoint.util.DebugDumpable)

Example 3 with DebugDumpable

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();
}
Also used : Entry(java.util.Map.Entry) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) PrismObject(com.evolveum.midpoint.prism.PrismObject) DebugDumpable(com.evolveum.midpoint.util.DebugDumpable)

Example 4 with DebugDumpable

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();
}
Also used : DebugDumpable(com.evolveum.midpoint.util.DebugDumpable)

Example 5 with DebugDumpable

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);
    }
}
Also used : DebugDumpable(com.evolveum.midpoint.util.DebugDumpable) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

DebugDumpable (com.evolveum.midpoint.util.DebugDumpable)5 Element (org.w3c.dom.Element)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 Objectable (com.evolveum.midpoint.prism.Objectable)1 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)1 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 PrismValue (com.evolveum.midpoint.prism.PrismValue)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ObjectDeltaObject (com.evolveum.midpoint.prism.util.ObjectDeltaObject)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 QName (javax.xml.namespace.QName)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1