com.thoughtworks.xstream.converters.DataHolder Java Examples

The following examples show how to use com.thoughtworks.xstream.converters.DataHolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XStream.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserialize an object from a hierarchical data structure (such as XML).
 * 
 * @param root If present, the passed in object will have its fields populated, as opposed
 *            to XStream creating a new instance. Note, that this is a special use case!
 *            With the ReflectionConverter XStream will write directly into the raw memory
 *            area of the existing object. Use with care!
 * @param dataHolder Extra data you can use to pass to your converters. Use this as you
 *            want. If not present, XStream shall create one lazily as needed.
 * @throws XStreamException if the object cannot be deserialized
 */
public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) {
    try {
        if (!securityInitialized && !securityWarningGiven) {
            securityWarningGiven = true;
            System.err.println("Security framework of XStream not initialized, XStream is probably vulnerable.");
        }
        return marshallingStrategy.unmarshal(
            root, reader, dataHolder, converterLookup, mapper);

    } catch (ConversionException e) {
        Package pkg = getClass().getPackage();
        String version = pkg != null ? pkg.getImplementationVersion() : null;
        e.add("version", version != null ? version : "not available");
        throw e;
    }
}
 
Example #2
Source File: XStreamMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public void marshalWriter(Object graph, Writer writer, @Nullable DataHolder dataHolder)
		throws XmlMappingException, IOException {

	if (this.streamDriver != null) {
		doMarshal(graph, this.streamDriver.createWriter(writer), dataHolder);
	}
	else {
		doMarshal(graph, new CompactWriter(writer), dataHolder);
	}
}
 
Example #3
Source File: TreeUnmarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Object start(DataHolder dataHolder) {
    this.dataHolder = dataHolder;
    Class type = HierarchicalStreams.readClassType(reader, mapper);
    Object result = convertAnother(null, type);
    Iterator validations = validationList.iterator();
    while (validations.hasNext()) {
        Runnable runnable = (Runnable)validations.next();
        runnable.run();
    }
    return result;
}
 
Example #4
Source File: TreeMarshaller.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void start(Object item, DataHolder dataHolder) {
    this.dataHolder = dataHolder;
    if (item == null) {
        writer.startNode(mapper.serializedClass(null));
        writer.endNode();
    } else {
        ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper
            .serializedClass(item.getClass()), item.getClass());
        convertAnother(item);
        writer.endNode();
    }
}
 
Example #5
Source File: XStream.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.
 *
 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
 * @since 1.4.10
 */
public ObjectInputStream createObjectInputStream(final HierarchicalStreamReader reader, final DataHolder dataHolder)
        throws IOException {
    return new CustomObjectInputStream(new CustomObjectInputStream.StreamCallback() {
        public Object readFromStream() throws EOFException {
            if (!reader.hasMoreChildren()) {
                throw new EOFException();
            }
            reader.moveDown();
            final Object result = unmarshal(reader, dataHolder);
            reader.moveUp();
            return result;
        }

        public Map readFieldsFromStream() throws IOException {
            throw new NotActiveException("not in call to readObject");
        }

        public void defaultReadObject() throws NotActiveException {
            throw new NotActiveException("not in call to readObject");
        }

        public void registerValidation(ObjectInputValidation validation, int priority)
            throws NotActiveException {
            throw new NotActiveException("stream inactive");
        }

        public void close() {
            reader.close();
        }
    }, classLoaderReference);
}
 
Example #6
Source File: XStream.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream.
 *
 * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
 * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader)
 * @since 1.4.10
 */
public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer, final String rootNodeName,
        final DataHolder dataHolder) throws IOException {
    final StatefulWriter statefulWriter = new StatefulWriter(writer);
    statefulWriter.startNode(rootNodeName, null);
    return new CustomObjectOutputStream(new CustomObjectOutputStream.StreamCallback() {
        public void writeToStream(final Object object) {
            marshal(object, statefulWriter, dataHolder);
        }

        public void writeFieldsToStream(Map fields) throws NotActiveException {
            throw new NotActiveException("not in call to writeObject");
        }

        public void defaultWriteObject() throws NotActiveException {
            throw new NotActiveException("not in call to writeObject");
        }

        public void flush() {
            statefulWriter.flush();
        }

        public void close() {
            if (statefulWriter.state() != StatefulWriter.STATE_CLOSED) {
                statefulWriter.endNode();
                statefulWriter.close();
            }
        }
    });
}
 
Example #7
Source File: XStreamMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public void marshalOutputStream(Object graph, OutputStream outputStream, DataHolder dataHolder)
		throws XmlMappingException, IOException {

	if (this.streamDriver != null) {
		doMarshal(graph, this.streamDriver.createWriter(outputStream), dataHolder);
	}
	else {
		marshalWriter(graph, new OutputStreamWriter(outputStream, this.encoding), dataHolder);
	}
}
 
Example #8
Source File: XStreamMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public void marshalWriter(Object graph, Writer writer, DataHolder dataHolder)
		throws XmlMappingException, IOException {

	if (this.streamDriver != null) {
		doMarshal(graph, this.streamDriver.createWriter(writer), dataHolder);
	}
	else {
		doMarshal(graph, new CompactWriter(writer), dataHolder);
	}
}
 
Example #9
Source File: XStreamMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public Object unmarshalInputStream(InputStream inputStream, DataHolder dataHolder) throws XmlMappingException, IOException {
       if (this.streamDriver != null) {
           return doUnmarshal(this.streamDriver.createReader(inputStream), dataHolder);
       }
       else {
	    return unmarshalReader(new InputStreamReader(inputStream, this.encoding), dataHolder);
       }
}
 
Example #10
Source File: XStreamMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Unmarshals the given graph to the given XStream HierarchicalStreamWriter.
 * Converts exceptions using {@link #convertXStreamException}.
 */
private Object doUnmarshal(HierarchicalStreamReader streamReader, @Nullable DataHolder dataHolder) {
	try {
		return getXStream().unmarshal(streamReader, null, dataHolder);
	}
	catch (Exception ex) {
		throw convertXStreamException(ex, false);
	}
}
 
Example #11
Source File: XStreamMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Unmarshals the given graph to the given XStream HierarchicalStreamWriter.
 * Converts exceptions using {@link #convertXStreamException}.
 */
private Object doUnmarshal(HierarchicalStreamReader streamReader, DataHolder dataHolder) {
    try {
        return getXStream().unmarshal(streamReader, null, dataHolder);
    }
    catch (Exception ex) {
        throw convertXStreamException(ex, false);
    }
}
 
Example #12
Source File: XStreamMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
public Object unmarshalInputStream(InputStream inputStream, @Nullable DataHolder dataHolder) throws XmlMappingException, IOException {
	if (this.streamDriver != null) {
		return doUnmarshal(this.streamDriver.createReader(inputStream), dataHolder);
	}
	else {
		return unmarshalReader(new InputStreamReader(inputStream, this.encoding), dataHolder);
	}
}
 
Example #13
Source File: XStreamMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
public void marshalWriter(Object graph, Writer writer, @Nullable DataHolder dataHolder)
		throws XmlMappingException, IOException {

	if (this.streamDriver != null) {
		doMarshal(graph, this.streamDriver.createWriter(writer), dataHolder);
	}
	else {
		doMarshal(graph, new CompactWriter(writer), dataHolder);
	}
}
 
Example #14
Source File: XStreamMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
public void marshalOutputStream(Object graph, OutputStream outputStream, @Nullable DataHolder dataHolder)
		throws XmlMappingException, IOException {

	if (this.streamDriver != null) {
		doMarshal(graph, this.streamDriver.createWriter(outputStream), dataHolder);
	}
	else {
		marshalWriter(graph, new OutputStreamWriter(outputStream, this.encoding), dataHolder);
	}
}
 
Example #15
Source File: XStreamMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Unmarshals the given graph to the given XStream HierarchicalStreamWriter.
 * Converts exceptions using {@link #convertXStreamException}.
 */
private Object doUnmarshal(HierarchicalStreamReader streamReader, @Nullable DataHolder dataHolder) {
	try {
		return getXStream().unmarshal(streamReader, null, dataHolder);
	}
	catch (Exception ex) {
		throw convertXStreamException(ex, false);
	}
}
 
Example #16
Source File: XStreamMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public void marshalOutputStream(Object graph, OutputStream outputStream, @Nullable DataHolder dataHolder)
		throws XmlMappingException, IOException {

	if (this.streamDriver != null) {
		doMarshal(graph, this.streamDriver.createWriter(outputStream), dataHolder);
	}
	else {
		marshalWriter(graph, new OutputStreamWriter(outputStream, this.encoding), dataHolder);
	}
}
 
Example #17
Source File: XStreamMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public Object unmarshalInputStream(InputStream inputStream, @Nullable DataHolder dataHolder) throws XmlMappingException, IOException {
	if (this.streamDriver != null) {
		return doUnmarshal(this.streamDriver.createReader(inputStream), dataHolder);
	}
	else {
		return unmarshalReader(new InputStreamReader(inputStream, this.encoding), dataHolder);
	}
}
 
Example #18
Source File: XStreamMarshaller.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public Object unmarshalReader(Reader reader, DataHolder dataHolder) throws XmlMappingException, IOException {
	return doUnmarshal(getDefaultDriver().createReader(reader), dataHolder);
}
 
Example #19
Source File: CustomObjectInputStream.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated As of 1.4.5 use {@link #getInstance(DataHolder, StreamCallback, ClassLoaderReference)}
 */
public static synchronized CustomObjectInputStream getInstance(DataHolder whereFrom, CustomObjectInputStream.StreamCallback callback, ClassLoader classLoader) {
    return getInstance(whereFrom, callback, new ClassLoaderReference(classLoader));
}
 
Example #20
Source File: GraphModelConverter.java    From depan with Apache License 2.0 4 votes vote down vote up
public static GraphBuilder contextGraphBuilder(DataHolder context) {
  return (GraphBuilder) context.get(GraphBuilder.class);
}
 
Example #21
Source File: CustomObjectInputStream.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @deprecated As of 1.4 use {@link #getInstance(DataHolder, StreamCallback, ClassLoader)}
 */
public static CustomObjectInputStream getInstance(DataHolder whereFrom, CustomObjectInputStream.StreamCallback callback) {
    return getInstance(whereFrom, callback, (ClassLoader)null);
}
 
Example #22
Source File: AbstractTreeMarshallingStrategy.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void marshal(HierarchicalStreamWriter writer, Object obj, ConverterLookup converterLookup, Mapper mapper, DataHolder dataHolder) {
    TreeMarshaller context = createMarshallingContext(writer, converterLookup, mapper);
    context.start(obj, dataHolder);
}
 
Example #23
Source File: AbstractTreeMarshallingStrategy.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public Object unmarshal(Object root, HierarchicalStreamReader reader, DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper) {
    TreeUnmarshaller context = createUnmarshallingContext(root, reader, converterLookup, mapper);
    return context.start(dataHolder);
}
 
Example #24
Source File: XStreamMarshaller.java    From java-technology-stack with MIT License 4 votes vote down vote up
public Object unmarshalReader(Reader reader, @Nullable DataHolder dataHolder) throws XmlMappingException, IOException {
	return doUnmarshal(getDefaultDriver().createReader(reader), dataHolder);
}
 
Example #25
Source File: XStreamMarshaller.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public Object unmarshalReader(Reader reader, @Nullable DataHolder dataHolder) throws XmlMappingException, IOException {
	return doUnmarshal(getDefaultDriver().createReader(reader), dataHolder);
}
 
Example #26
Source File: XStream.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a DataHolder that can be used to pass data to the converters. The DataHolder is provided with a call to
 * {@link #marshal(Object, HierarchicalStreamWriter, DataHolder)},
 * {@link #unmarshal(HierarchicalStreamReader, Object, DataHolder)},
 * {@link #createObjectInputStream(HierarchicalStreamReader, DataHolder)} or
 * {@link #createObjectOutputStream(HierarchicalStreamWriter, String, DataHolder)}.
 *
 * @return a new {@link DataHolder}
 */
public DataHolder newDataHolder() {
    return new MapBackedDataHolder();
}
 
Example #27
Source File: XStream.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Serialize and object to a hierarchical data structure (such as XML).
 * 
 * @param dataHolder Extra data you can use to pass to your converters. Use this as you
 *            want. If not present, XStream shall create one lazily as needed.
 * @throws XStreamException if the object cannot be serialized
 */
public void marshal(Object obj, HierarchicalStreamWriter writer, DataHolder dataHolder) {
    marshallingStrategy.marshal(writer, obj, converterLookup, mapper, dataHolder);
}
 
Example #28
Source File: MarshallingStrategy.java    From lams with GNU General Public License v2.0 votes vote down vote up
void marshal(HierarchicalStreamWriter writer, Object obj, ConverterLookup converterLookup, Mapper mapper, DataHolder dataHolder); 
Example #29
Source File: MarshallingStrategy.java    From lams with GNU General Public License v2.0 votes vote down vote up
Object unmarshal(Object root, HierarchicalStreamReader reader, DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper);