@Test public void testSerialize() throws IOException, ParsingFailureException { System.out.println("serialize"); StandaloneResource resource = StandaloneResourceProvider.instance().acmeResourceForString( "ZNewsSys.acme"); AcmeSystem sys = resource.getModel().getSystems().iterator().next(); IModelInstance<IAcmeSystem> instance = new AcmeInternalModelInstance(sys, "Acme"); AcmeModelSerializer serializer = new AcmeModelSerializer(); String result = serializer.serialize(instance); IModelInstance<IAcmeSystem> instanceResult = serializer.deserialize(result); assertEquals(instance.getModelName(), instanceResult.getModelName()); assertEquals(instance.getModelType(), instanceResult.getModelType()); assertEquals(instance.getOriginalSource(), instanceResult.getOriginalSource()); String result2 = serializer.serialize(instance); assertEquals(result, result2); }
public String serialize(IModelInstance<IAcmeSystem> instance) { String serial = null; try { DataValue value = converter.from_java(instance, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); encoding.encode(value, new DataOutputStream(baos)); serial = baos.toString(); } catch (ValueConversionException | IOException ex) { Logger.getLogger(AcmeModelSerializer.class.getName()).log(Level.SEVERE, null, ex); } return serial; }
AcmeModelSerializer { public String serialize(IModelInstance<IAcmeSystem> instance) { String serial = null; try { DataValue value = converter.from_java(instance, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); encoding.encode(value, new DataOutputStream(baos)); serial = baos.toString(); } catch (ValueConversionException | IOException ex) { Logger.getLogger(AcmeModelSerializer.class.getName()).log(Level.SEVERE, null, ex); } return serial; } }
AcmeModelSerializer { public String serialize(IModelInstance<IAcmeSystem> instance) { String serial = null; try { DataValue value = converter.from_java(instance, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); encoding.encode(value, new DataOutputStream(baos)); serial = baos.toString(); } catch (ValueConversionException | IOException ex) { Logger.getLogger(AcmeModelSerializer.class.getName()).log(Level.SEVERE, null, ex); } return serial; } AcmeModelSerializer(); }
AcmeModelSerializer { public String serialize(IModelInstance<IAcmeSystem> instance) { String serial = null; try { DataValue value = converter.from_java(instance, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); encoding.encode(value, new DataOutputStream(baos)); serial = baos.toString(); } catch (ValueConversionException | IOException ex) { Logger.getLogger(AcmeModelSerializer.class.getName()).log(Level.SEVERE, null, ex); } return serial; } AcmeModelSerializer(); String serialize(IModelInstance<IAcmeSystem> instance); IModelInstance<IAcmeSystem> deserialize(String serial); }
AcmeModelSerializer { public String serialize(IModelInstance<IAcmeSystem> instance) { String serial = null; try { DataValue value = converter.from_java(instance, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); encoding.encode(value, new DataOutputStream(baos)); serial = baos.toString(); } catch (ValueConversionException | IOException ex) { Logger.getLogger(AcmeModelSerializer.class.getName()).log(Level.SEVERE, null, ex); } return serial; } AcmeModelSerializer(); String serialize(IModelInstance<IAcmeSystem> instance); IModelInstance<IAcmeSystem> deserialize(String serial);  }