Search in sources :

Example 51 with RawType

use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.

the class SchemaDebugUtil method prettyPrint.

public static String prettyPrint(ItemDeltaType change) throws SchemaException {
    if (change == null) {
        return "null";
    }
    StringBuilder sb = new StringBuilder("PropertyModification(");
    sb.append(change.getModificationType());
    sb.append(",");
    if (change.getPath() != null) {
        // todo ... with declarations?
        sb.append(change.getPath().getItemPath());
    } else {
        sb.append("xpath=null");
    }
    sb.append(",");
    List<RawType> values = change.getValue();
    for (RawType value : values) {
        // todo implement correctly...
        sb.append(prettyPrint(value.serializeToXNode()));
        sb.append(",");
    }
    return sb.toString();
}
Also used : RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 52 with RawType

use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.

the class StaticExpressionUtil method getRawType.

private static RawType getRawType(Object valueElement, String contextDescription) throws SchemaException {
    if (!(valueElement instanceof JAXBElement<?>)) {
        throw new SchemaException("Literal expression cannot handle element " + valueElement + " " + valueElement.getClass().getName() + " in " + contextDescription);
    }
    QName valueElementName = JAXBUtil.getElementQName(valueElement);
    if (!valueElementName.equals(SchemaConstants.C_VALUE)) {
        throw new SchemaException("Literal expression cannot handle element <" + valueElementName + "> in " + contextDescription);
    }
    JAXBElement<?> jaxbElement = (JAXBElement<?>) valueElement;
    // not checking declaredType because it may be Object.class instead ... but actual type must be of RawType
    if (jaxbElement.getValue() != null && !(jaxbElement.getValue() instanceof RawType)) {
        throw new SchemaException("Literal expression cannot handle JAXBElement value type " + jaxbElement.getValue().getClass() + " in " + contextDescription);
    }
    return (RawType) jaxbElement.getValue();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 53 with RawType

use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.

the class StaticExpressionUtil method deriveOutputDefinitionFromValueElements.

public static ItemDefinition<?> deriveOutputDefinitionFromValueElements(QName elementName, Collection<JAXBElement<?>> valueElements, String contextDescription, PrismContext prismContext) throws SchemaException {
    QName overallType = null;
    for (Object valueElement : valueElements) {
        RawType rawType = getRawType(valueElement, contextDescription);
        QName currentType = rawType.getExplicitTypeName();
        if (currentType != null) {
            QName unified = prismContext.getSchemaRegistry().unifyTypes(overallType, currentType);
            if (unified == null) {
                throw new SchemaException("Couldn't unify types " + overallType + " and " + currentType + " in " + contextDescription);
            }
            overallType = unified;
        }
    }
    if (overallType == null) {
        overallType = DOMUtil.XSD_STRING;
    }
    int maxOccurs = valueElements.size() > 1 ? -1 : 1;
    return prismContext.getSchemaRegistry().createAdHocDefinition(elementName, overallType, 0, maxOccurs);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 54 with RawType

use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.

the class ExpressionUtil method isShadowRefNodeExists.

public static boolean isShadowRefNodeExists(ExpressionType expression) {
    if (expression == null) {
        return false;
    }
    JAXBElement<?> element = ExpressionUtil.findFirstEvaluatorByName(expression, SchemaConstantsGenerated.C_VALUE);
    if (element == null) {
        return false;
    }
    if (element.getValue() instanceof RawType) {
        RawType raw = (RawType) element.getValue();
        PrismValue prismValue = raw.getAlreadyParsedValue();
        if (prismValue instanceof PrismContainerValue && ((PrismContainerValue<?>) prismValue).getComplexTypeDefinition() != null && ShadowAssociationType.class.equals(((PrismContainerValue<?>) prismValue).getComplexTypeDefinition().getCompileTimeClass())) {
            return true;
        }
    } else if (element.getValue() instanceof ShadowAssociationType) {
        return true;
    }
    return false;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 55 with RawType

use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.

the class ExpressionUtil method updateLiteralExpressionValue.

public static void updateLiteralExpressionValue(ExpressionType expression, List<String> values, PrismContext prismContext) {
    if (expression == null) {
        // TODO ??? this is thrown away
        expression = new ExpressionType();
    }
    removeEvaluatorByName(expression, SchemaConstantsGenerated.C_VALUE);
    for (String value : values) {
        PrimitiveXNode<String> newValueNode = prismContext.xnodeFactory().primitive(value);
        RawType raw = new RawType(newValueNode.frozen(), prismContext);
        JAXBElement element = new JAXBElement<>(SchemaConstantsGenerated.C_VALUE, RawType.class, raw);
        expression.expressionEvaluator(element);
    }
}
Also used : RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)62 QName (javax.xml.namespace.QName)22 Test (org.testng.annotations.Test)19 JAXBElement (javax.xml.bind.JAXBElement)18 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)16 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)10 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)9 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)9 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)9 ArrayList (java.util.ArrayList)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 Task (com.evolveum.midpoint.task.api.Task)8 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)6 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)6 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5