package xdi2.example.messaging;

import xdi2.client.XDIClient;
import xdi2.client.impl.local.XDILocalClient;
import xdi2.core.Graph;
import xdi2.core.impl.memory.MemoryGraphFactory;
import xdi2.core.io.XDIReader;
import xdi2.core.io.XDIReaderRegistry;
import xdi2.core.io.XDIWriter;
import xdi2.core.io.XDIWriterRegistry;
import xdi2.core.syntax.XDIAddress;
import xdi2.messaging.Message;
import xdi2.messaging.MessageCollection;
import xdi2.messaging.MessageEnvelope;
import xdi2.messaging.response.MessagingResponse;
import xdi2.messaging.target.impl.graph.GraphMessagingTarget;

public class SimpleMessagingSample {

    public static void main(String[] args) throws Exception {

        XDIReader reader = XDIReaderRegistry.forFormat("XDI DISPLAY", null);
        XDIWriter writer = XDIWriterRegistry.forFormat("XDI/JSON", null);

        // load an XDI graph and create a messaging target

        Graph graph = MemoryGraphFactory.getInstance().openGraph();
        reader.read(graph, SimpleMessagingSample.class.getResourceAsStream("simple.xdi"));
        GraphMessagingTarget graphMessagingTarget = new GraphMessagingTarget();
        graphMessagingTarget.setGraph(graph);

        // create a message

        MessageEnvelope messageEnvelope = new MessageEnvelope();
        MessageCollection messageCollection = messageEnvelope.getMessageCollection(XDIAddress.create("=sender"), true);
        Message message = messageCollection.createMessage();
        message.createGetOperation(XDIAddress.create("=markus"));

        // execute the message

        XDIClient xdiClient = new XDILocalClient(graphMessagingTarget);
        MessagingResponse messagingResponse = xdiClient.send(messageEnvelope);

        // serialize the result

        writer.write(messagingResponse.getGraph(), System.out);
    }
}
@@ -502,34 +502,52 @@
 ing.
-response.MessagingResponse
+container.impl.graph.GraphMessagingContainer
 ;%0D%0Ai
@@ -571,31 +571,17 @@
 ing.
-target.impl.graph.Graph
+response.
 Mess
@@ -585,22 +585,24 @@
 essaging
-Target
+Response
 ;%0D%0A%0D%0Apub
@@ -914,14 +914,17 @@
 ing 
-target
+container
 %0D%0A%0D%0A
@@ -1110,35 +1110,32 @@
 ging
-Target graphMessagingTarget
+Container graphContainer
  = n
@@ -1151,22 +1151,25 @@
 essaging
-Target
+Container
 ();%0D%0A   
@@ -1178,31 +1178,25 @@
    graph
-MessagingTarget
+Container
 .setGrap
@@ -1649,23 +1649,17 @@
 raph
-MessagingTarget
+Container
 );%0D%0A

update example