Examples of XStream


Examples of com.thoughtworks.xstream.XStream

        FileUtils.cleanDirectory(colDir);
    }

    @Test
    public void addingAuthors1() {
        XStream xstream = XBirdCollectionStrategy.getAnnotationProcessableXStreamInstance();
        XBirdCollectionStrategy<String, Object> strategy = new XBirdCollectionStrategy<String, Object>(COLLECTION_NAME, xstream);

        //xstream.processAnnotations(Author.class);

        List<Author> list = new XmlArrayList(strategy);
View Full Code Here

Examples of com.thoughtworks.xstream.XStream

        list2.clear();
    }

    //@Test
    public void addingRendezvousMessages1() throws DbException, XQueryException {
        XStream xstream = new XStream();
        XBirdCollectionStrategy<String, Object> strategy = new XBirdCollectionStrategy<String, Object>(COLLECTION_NAME, xstream);
        xstream.processAnnotations(RendezvousMessage.class);

        RendezvousMessage msg1 = new RendezvousMessage(15, Arrays.asList(new Author("anonymous"), new Author("makoto")));
        System.out.println(xstream.toXML(msg1));
        System.out.println();

        RendezvousMessage msg2 = new RendezvousMessage(15, Arrays.asList(new Author("anonymous")), "firstPart", "secondPart");
        System.out.println(xstream.toXML(msg2));
        System.out.println();

        List<RendezvousMessage> list = new XmlArrayList(strategy);
        list.add(msg1);
        list.add(msg2);
        Assert.assertEquals(2, list.size());

        String query1 = "fn:collection('/" + COLLECTION_NAME + "/1.xml')//author[1]";
        XQueryProcessor proc = new XQueryProcessor();
        XQueryModule compiled1 = proc.parse(query1);
        StringWriter sw = new StringWriter();
        SAXWriter handler = new SAXWriter(sw);
        SAXSerializer ser = new SAXSerializer(handler);

        proc.execute(compiled1, ser);
        handler.flush();
        String result1 = sw.toString();

        System.err.println(result1);

        Author author1 = (Author) xstream.fromXML(result1);
        Assert.assertEquals("anonymous", author1.getName());
    }
View Full Code Here

Examples of com.thoughtworks.xstream.XStream

        Assert.assertEquals("anonymous", author1.getName());
    }

    //@Test
    public void addingRendezvousMessages2() throws DbException, XQueryException {
        XStream xstream = new XStream();
        XBirdCollectionStrategy<String, Object> strategy = new XBirdCollectionStrategy<String, Object>(COLLECTION_NAME, xstream);
        xstream.processAnnotations(RendezvousMessage.class);
        xstream.processAnnotations(Author.class);

        List<Author> author1 = Arrays.asList(new Author("anonymous"));
        RendezvousMessage msg1 = new RendezvousMessage(15, author1);
        System.out.println(xstream.toXML(msg1));
        System.out.println();

        List<Author> author2 = Arrays.asList(new Author("makoto"), new Author("leo"), new Author("grun"));
        RendezvousMessage msg2 = new RendezvousMessage(15, author2, "firstPart", "secondPart");
        System.out.println(xstream.toXML(msg2));
        System.out.println();

        List<RendezvousMessage> list = new XmlArrayList(strategy);
        list.add(msg1);
        list.add(msg2);
        Assert.assertEquals(2, list.size());

        String query1 = "fn:collection('/" + COLLECTION_NAME + "/.*.xml')//author";
        XQueryProcessor proc = new XQueryProcessor();
        XQueryModule compiled1 = proc.parse(query1);
        Sequence<? extends Item> items = proc.execute(compiled1);
        INodeSequence<DTMElement> nodes = ProxyNodeSequence.wrap(items, DynamicContext.DUMMY);

        for(DTMElement node : nodes) {
            Object unmarshalled = xstream.unmarshal(new DTMReader(node));
            Author author = (Author) unmarshalled;
            System.out.println("author: " + author.getName());
        }
    }
View Full Code Here

Examples of com.thoughtworks.xstream.XStream

    public XBirdCollectionStrategy(String collectionName) {
        this(collectionName, getAnnotationProcessableXStreamInstance());
    }

    public static XStream getAnnotationProcessableXStreamInstance() {
        final XStream xstream;
        if(ClassResolver.isPresent(XPP_CLASS)) {
            xstream = new XStream();
        } else {
            xstream = new XStream(new DomDriver());
        }
        xstream.autodetectAnnotations(true);
        return xstream;
    }
View Full Code Here

Examples of com.thoughtworks.xstream.XStream

    }

    // Implementation methods
    // -------------------------------------------------------------------------
    protected XStream createXStream() {
        XStream answer = new XStream();
        answer.alias("invoke", LingoInvocation.class);
        answer.alias("result", RemoteInvocationResult.class);
        return answer;
    }
View Full Code Here

Examples of com.thoughtworks.xstream.XStream

        catch(JSONException je){
          throw new IOException(je.getMessage());
        }
      }
      else{
        XStream xstream=XStreamDispenser.getXMLXStream();
        writer.write(xstream.toXML(result));
      }
      return null;
    } catch (BrowseException e) {
      throw new ServletException(e.getMessage(),e);
    }
View Full Code Here

Examples of com.thoughtworks.xstream.XStream

        catch(JSONException je){
          throw new IOException(je.getMessage());
        }
      }
      else{
        XStream xstream=XStreamDispenser.getXMLXStream();
        writer.write(xstream.toXML(result));
      }
     
     
     
    } catch (BrowseException e) {
View Full Code Here

Examples of com.thoughtworks.xstream.XStream

     * serializing abitary objects to JSON.
     */
    public XStreamJsonAdapter()
    {
        super();
        _xstream = new XStream( new JsonHierarchicalStreamDriver() );
        _strAdapter = new UTF8StringAdapter();
    }
View Full Code Here

Examples of com.thoughtworks.xstream.XStream

     * @see com.thoughtworks.xstream.io.xml.CompactWriter
     */
    public XStreamAdapter(boolean isCompact)
    {
        this._isCompact = isCompact;
        this._xstream = new XStream();
    }
View Full Code Here

Examples of com.thoughtworks.xstream.XStream

    /**
     * Creates a new instance of XStreamAdapter using the given HierarchicalStreamDriver
     */
    public XStreamAdapter(HierarchicalStreamDriver driver)
    {
        this._xstream = new XStream( driver );
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.