@Test public void testParseRoundTripAsPO() throws Exception{ displayTestTitle("testParseRoundTripAsPO"); SerializationOptions o = SerializationOptions.createSerializeReferenceNames(); processParsingsPO(v -> getPrismContext().serializerFor(language).options(o).serialize(v), "s0", true); processParsingsPO(v -> getPrismContext().serializerFor(language).options(o).root(new QName("dummy")).serialize(v), "s1", false); processParsingsPO(v -> getPrismContext().serializerFor(language).options(o).root(SchemaConstantsGenerated.C_SYSTEM_CONFIGURATION).serialize(v), "s2", false); // misleading item name processParsingsPO(v -> getPrismContext().serializerFor(language).options(o).serializeRealValue(v.asObjectable()), "s3", false); processParsingsPO(v -> getPrismContext().serializerFor(language).options(o).root(new QName("dummy")).serializeAnyData(v.asObjectable()), "s4", false); }
@Nullable public <T> XNodeImpl marshall(@Nullable T bean, @Nullable SerializationContext ctx) throws SchemaException { if (bean == null) { return null; } Marshaller marshaller = specialMarshallers.get(bean.getClass()); if (marshaller != null) { return marshaller.marshal(bean, ctx); } // avoiding chatty PolyString serializations (namespace declaration + orig + norm) if (bean instanceof PolyString) { bean = (T) ((PolyString) bean).getOrig(); } else if (bean instanceof PolyStringType) { bean = (T) ((PolyStringType) bean).getOrig(); } if (bean instanceof Containerable) { return (XNodeImpl) prismContext.xnodeSerializer().context(ctx).serializeRealValue(bean, new QName("dummy")).getSubnode(); } else if (bean instanceof Enum) { return marshalEnum((Enum) bean, ctx); } else if (bean.getClass().getAnnotation(XmlType.class) != null) { return marshalXmlType(bean, ctx); } else { return marshalToPrimitive(bean, ctx); } }
public static String serializeQuietly(PrismContext prismContext, Object object) { if (object == null) { return null; } if (object instanceof Collection) { return ((Collection<?>) object).stream() .map(o -> serializeQuietly(prismContext, o)) .collect(Collectors.joining("; ")); } try { PrismSerializer<String> serializer = prismContext.xmlSerializer(); if (object instanceof Item) { return serializer.serialize((Item) object); } else { return serializer.serializeRealValue(object, new QName("value")); } } catch (Throwable t) { return "Couldn't serialize (" + t.getMessage() + "): " + object; } }
private static XNode toXNode(ItemDelta delta, @NotNull PrismValue value, DeltaConversionOptions options) throws SchemaException{ return delta.getPrismContext().xnodeSerializer() .definition(delta.getDefinition()) .options(DeltaConversionOptions.isSerializeReferenceNames(options) ? SerializationOptions.createSerializeReferenceNames() : null) .serialize(value) .getSubnode(); }
.options(SerializationOptions.createSerializeReferenceNames()); xml = serializer.serialize((PrismObject<?>) object); } else if (object instanceof OperationResult) { xml = serializer.serializeAnyData(operationResultType, fakeQName); } else { xml = serializer.serializeAnyData(object, fakeQName);
@Override protected <O extends ObjectType> void write(Writer writer, PrismObject<O> object) throws SchemaException, IOException { String xml = serializer.serialize(object); writer.write(xml); }
private void dumpOutput(ExecutionContext output, OperationResult result) throws JAXBException, SchemaException { display("output", output.getFinalOutput()); display("stdout", output.getConsoleOutput()); display(result); if (output.getFinalOutput() != null) { PipelineDataType bean = ModelWebService.prepareXmlData(output.getFinalOutput().getData(), null); display("output in XML", prismContext.xmlSerializer().root(new QName("output")).serializeRealValue(bean)); } }
public static String toObjectTreeDeltasTypeXml(ObjectTreeDeltasType objectTreeDeltasType, PrismContext prismContext) throws SchemaException { if (objectTreeDeltasType != null) { return prismContext.xmlSerializer().serializeRealValue(objectTreeDeltasType, SchemaConstantsGenerated.C_OBJECT_TREE_DELTAS); } else { return null; } }
public XNode serializeToXNode() throws SchemaException { if (xnode != null) { // QName type = xnode.getTypeQName(); // if (xnode instanceof PrimitiveXNode && type != null){ // if (!((PrimitiveXNode)xnode).isParsed()){ // Object realValue = PrismUtil.getXnodeProcessor(prismContext).parseAnyValue(xnode, ParsingContext.createDefault()); // ((PrimitiveXNode)xnode).setValue(realValue, type); // } // } return xnode; } else if (parsed != null) { checkPrismContext(); XNode rv = prismContext.xnodeSerializer().root(new QName("dummy")).serialize(parsed).getSubnode(); prismContext.xnodeMutator().setXNodeType(rv, explicitTypeName, explicitTypeDeclaration); return rv; } else { return null; // or an exception here? } } //endregion
public static String toObjectDeltaTypeXml(ObjectDelta<? extends ObjectType> delta, DeltaConversionOptions options) throws SchemaException, JAXBException { Validate.notNull(delta.getPrismContext(), "ObjectDelta without prismContext cannot be converted to XML"); ObjectDeltaType objectDeltaType = toObjectDeltaType(delta, options); SerializationOptions serializationOptions = new SerializationOptions(); serializationOptions.setSerializeReferenceNames(DeltaConversionOptions.isSerializeReferenceNames(options)); return delta.getPrismContext().xmlSerializer().options(serializationOptions).serializeRealValue(objectDeltaType, SchemaConstants.T_OBJECT_DELTA); }
public static String serializeAnyData(Object o, QName defaultRootElementName) throws SchemaException { return getPrismContext().xmlSerializer().serializeAnyData(o, defaultRootElementName); }
val.setParent(filter); XNodeImpl valNode = (XNodeImpl) xnodeSerializer.definition(filter.getDefinition()).serialize(val).getSubnode(); if (filter instanceof RefFilter) { // TODO shouldn't we do this in all cases? valNode.setExplicitTypeDeclaration(true);
try { PrismSerializer<Element> serializer = prismContext.domSerializer() .options(SerializationOptions.createSerializeReferenceNames()); if (requestObject instanceof GetObjectType) { GetObjectType g = (GetObjectType) requestObject; gr.setObject(objectTypeHolder.value); gr.setResult(operationResultTypeHolder.value); response = serializer.serializeAnyData(gr, ModelPort.GET_OBJECT_RESPONSE); } else if (requestObject instanceof SearchObjectsType) { SearchObjectsType s = (SearchObjectsType) requestObject; sr.setObjectList(objectListTypeHolder.value); sr.setResult(operationResultTypeHolder.value); response = serializer.serializeAnyData(sr, ModelPort.SEARCH_OBJECTS_RESPONSE); } else if (requestObject instanceof ExecuteChangesType) { ExecuteChangesType e = (ExecuteChangesType) requestObject; ExecuteChangesResponseType er = new ExecuteChangesResponseType(); er.setDeltaOperationList(objectDeltaOperationListType); response = serializer.serializeAnyData(er, ModelPort.EXECUTE_CHANGES_RESPONSE); } else if (requestObject instanceof FindShadowOwnerType) { FindShadowOwnerType f = (FindShadowOwnerType) requestObject; fsr.setUser(userTypeHolder.value); fsr.setResult(operationResultTypeHolder.value); response = serializer.serializeAnyData(fsr, ModelPort.FIND_SHADOW_OWNER_RESPONSE); } else if (requestObject instanceof TestResourceType) { TestResourceType tr = (TestResourceType) requestObject;
EvaluateScriptResponseType sr = new EvaluateScriptResponseType(); sr.setObjectList(olt); response = prismContext.domSerializer().context(ctx).serializeAnyData(sr, ReportPort.EVALUATE_SCRIPT_RESPONSE); } else if (requestObject instanceof EvaluateAuditScriptType){ EvaluateAuditScriptType s = (EvaluateAuditScriptType) requestObject; EvaluateAuditScriptResponseType sr = new EvaluateAuditScriptResponseType(); sr.setObjectList(olt); response = prismContext.domSerializer().context(ctx).serializeAnyData(sr, ReportPort.EVALUATE_AUDIT_SCRIPT_RESPONSE); } else if (requestObject instanceof ProcessReportType){ ProcessReportType p = (ProcessReportType) requestObject; ProcessReportResponseType pr = new ProcessReportResponseType(); pr.setObjectList(olt); response = prismContext.domSerializer().context(ctx).serializeAnyData(pr, ReportPort.PROCESS_REPORT_RESPONSE); } else { throw new FaultMessage("Unsupported request type: " + requestObject);
@Override protected void init() { serializer = context.getPrismContext() .xmlSerializer() .options(SerializationOptions.createSerializeForExport()); }
@Override public <O extends Objectable> String serializeObjectToString(PrismObject<O> object, String language) throws SchemaException { return serializerFor(language).serialize(object); }
@Test public void testAccountRefDelta() throws Exception { System.out.println("===[ testAccountRefDelta ]===="); // GIVEN ObjectModificationType objectChange = new ObjectModificationType(); objectChange.setOid("12345"); ItemDeltaType modificationDeleteAccountRef = new ItemDeltaType(); modificationDeleteAccountRef.setModificationType(ModificationTypeType.DELETE); ObjectReferenceType accountRefToDelete = new ObjectReferenceType(); accountRefToDelete.setOid("54321"); PrismContext prismContext = getPrismContext(); RawType modificationValue = new RawType(prismContext.xnodeSerializer().root(new QName("dummy")).serializeRealValue(accountRefToDelete).getSubnode(), prismContext); modificationDeleteAccountRef.getValue().add(modificationValue); objectChange.getItemDelta().add(modificationDeleteAccountRef); ItemPathType itemPathType = new ItemPathType(UserType.F_LINK_REF); modificationDeleteAccountRef.setPath(itemPathType); PrismObjectDefinition<UserType> objDef = PrismTestUtil.getObjectDefinition(UserType.class); // WHEN Collection<? extends ItemDelta> modifications = DeltaConvertor.toModifications(objectChange, objDef); // THEN assertNotNull("Null modifications", modifications); assertFalse("Empty modifications", modifications.isEmpty()); // TODO: more asserts }
public String toObjectTreeDeltasTypeXml() throws SchemaException { ObjectTreeDeltasType jaxb = toObjectTreeDeltasType(); return prismContext.xmlSerializer().serializeRealValue(jaxb, SchemaConstantsGenerated.C_OBJECT_TREE_DELTAS); }