Package com.thoughtworks.xstream

Examples of com.thoughtworks.xstream.XStream


        }
        return ids;
    }

    private String serialize(Object task) {
        XStream xStream = new XStream();
        return xStream.toXML(task);
    }
View Full Code Here


        XStream xStream = new XStream();
        return xStream.toXML(task);
    }

    private Object deserialize(String serializedRunnable) {
        XStream xStream = new XStream();
        return xStream.fromXML(serializedRunnable);
    }
View Full Code Here

            ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
            try {
                Thread.currentThread().setContextClassLoader(classLoader);

                DomReader reader = new DomReader(element);
                XStream xstream = XStreamUtil.createXStream();
                xstream.setClassLoader(classLoader);
                Object o = xstream.unmarshal(reader);
                GBeanData[] gbeanDatas = (GBeanData[]) o;
                return Arrays.asList(gbeanDatas);
            } catch (Exception e) {
                throw new InvalidConfigException("Unable to load gbeans", e);
            } finally {
View Full Code Here

            throw (IOException)new IOException("Cannot instantiate " + Document.class.getName()).initCause(e);
        }
        Document document = documentBuilder.newDocument();
        DomWriter writer = new DomWriter(document);

        XStream xstream = XStreamUtil.createXStream();
        xstream.marshal(gbeanDatas, writer);

//        FileWriter w = new FileWriter("target/foo.xml");
//        xstream.toXML(gbeanDatas, w);
//        w.close();
View Full Code Here

            // ignore, some operations do not require alias or class exchange properties
        }
    }

    protected InputStream getRequestStream(Exchange exchange) throws SalesforceException {
        final XStream localXStream = xStream.get();
        try {
            // get request stream from In message
            Message in = exchange.getIn();
            InputStream request = in.getBody(InputStream.class);
            if (request == null) {
                AbstractSObjectBase sObject = in.getBody(AbstractSObjectBase.class);
                if (sObject != null) {
                    // marshall the SObject
                    // first process annotations on the class, for things like alias, etc.
                    localXStream.processAnnotations(sObject.getClass());
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    // make sure we write the XML with the right encoding
                    localXStream.toXML(sObject, new OutputStreamWriter(out, StringUtil.__UTF8_CHARSET));
                    request = new ByteArrayInputStream(out.toByteArray());
                } else {
                    // if all else fails, get body as String
                    final String body = in.getBody(String.class);
                    if (null == body) {
View Full Code Here

    }

    @Override
    protected void processResponse(Exchange exchange, InputStream responseEntity,
                                   SalesforceException exception, AsyncCallback callback) {
        final XStream localXStream = xStream.get();
        try {
            // do we need to un-marshal a response
            if (responseEntity != null) {
                final Class<?> responseClass = exchange.getProperty(RESPONSE_CLASS, Class.class);
                Object response;
                if (responseClass != null) {
                    // its ok to call this multiple times, as xstream ignores duplicate calls
                    localXStream.processAnnotations(responseClass);
                    final String responseAlias = exchange.getProperty(RESPONSE_ALIAS, String.class);
                    if (responseAlias != null) {
                        // extremely dirty, need to flush entire cache if its holding on to an old alias!!!
                        final CachingMapper mapper = (CachingMapper) localXStream.getMapper();
                        try {
                            if (mapper.realClass(responseAlias) != responseClass) {
                                mapper.flushCache();
                            }
                        } catch (CannotResolveClassException ignore) {
                        }
                        localXStream.alias(responseAlias, responseClass);
                    }
                    response = responseClass.newInstance();
                    localXStream.fromXML(responseEntity, response);
                } else {
                    // return the response as a stream, for getBlobField
                    response = responseEntity;
                }
                exchange.getOut().setBody(response);
View Full Code Here

    /**
     * A factory method which takes a collection of types to be annotated
     */
    public static XStreamDataFormat processAnnotations(Iterable<Class<?>> types) {
        XStreamDataFormat answer = new XStreamDataFormat();
        XStream xstream = answer.getXStream();
        for (Class<?> type : types) {
            xstream.processAnnotations(type);
        }
        return answer;
    }
View Full Code Here

    /**
     * A factory method which takes a number of types to be annotated
     */
    public static XStreamDataFormat processAnnotations(Class<?>... types) {
        XStreamDataFormat answer = new XStreamDataFormat();
        XStream xstream = answer.getXStream();
        for (Class<?> type : types) {
            xstream.processAnnotations(type);
        }
        return answer;
    }
View Full Code Here

    public void setStaxConverter(StaxConverter staxConverter) {
        this.staxConverter = staxConverter;
    }

    protected XStream createXStream() {
        return new XStream();
    }
View Full Code Here

    private XStream xStream;
    private SolverBenchmarkSuite suite = null;

    public XmlSolverBenchmarker() {
        // TODO From Xstream 1.3.3 that KeySorter will be the default. See http://jira.codehaus.org/browse/XSTR-363
        xStream = new XStream(new PureJavaReflectionProvider(new FieldDictionary(new NativeFieldKeySorter())));
        xStream.setMode(XStream.ID_REFERENCES);
        xStream.processAnnotations(SolverBenchmarkSuite.class);
        // It doesn't pick up the annotations of the @XStreamImplicit in xstream 1.2.2
        xStream.processAnnotations(SolverBenchmark.class);
    }
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.