Package com.thoughtworks.xstream

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


    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

    }

    // 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

        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

        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

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

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

    /**
     * Creates a new instance of XStreamAdapter using the given HierarchicalStreamDriver
     */
    public XStreamAdapter(HierarchicalStreamDriver driver)
    {
        this._xstream = new XStream( driver );
    }
View Full Code Here

        // now query both addresses
        System.out.println( "querying Jimmys address..." );
        Address adrJimmy = addressBook.getAddressFromName( "Jimmy Who" );
        System.out.println( "Jimmys address: " );
        XStream xstream = new XStream();
        System.out.println( xstream.toXML( adrJimmy ) );

        System.out.println( "" );

        System.out.println( "querying Janes address..." );
        Address adrJane = addressBook.getAddressFromName( "Jane Who" );
        System.out.println( "Janes address: " );
        System.out.println( xstream.toXML( adrJane ) );
    }
View Full Code Here

           
            request.setArgs( new Object[] { "Jimmy Who" } );
            System.out.println("querying Jimmys address...");
            Address adrJimmy = (Address) client.execute( request );           
            System.out.println("Jimmys address: ");
            XStream xstream = new XStream();
            System.out.println( xstream.toXML( adrJimmy ));
           
            System.out.println("");
           
            request.setArgs( new Object[] { "Jane Who" } );
            System.out.println("querying Janes address...");
            Address adrJane = (Address) client.execute( request );
            System.out.println("Janes address: ");
            System.out.println( xstream.toXML( adrJane ));
        }
        catch ( IOException e )
        {
            e.printStackTrace();
        }   
View Full Code Here

TOP

Related Classes of com.thoughtworks.xstream.XStream

Copyright © 2018 www.massapicom. 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.