Skip to content

Commit

Permalink
Revert "Backport XStreamSerializer changes"
Browse files Browse the repository at this point in the history
This reverts commit e539d7d.
  • Loading branch information
tlipkis committed Aug 21, 2023
1 parent b1402a9 commit fa3b512
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 58 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Args:
<property name="jbibtex.jar" value="${lib}/jbibtex-1.0.20.jar" />
<!-- W3C RDF Parser -->
<property name="rdf.jar" value="${lib}/rdf-api-2001-01-19.jar" />
<property name="xstream.jar" value="${lib}/xstream-1.4.20.jar" />
<property name="xstream.jar" value="${lib}/xstream-1.1.3.jar" />
<property name="xmlunit.jar" value="${lib}/xmlunit-1.6.jar" />
<property name="oai-harvester.jar" value="${lib}/harvester2-0.1.12-p1.jar"/>
<!-- Needed by OAI harvester: Xalan, Xerces, XML-APIs, Log4j -->
Expand Down
Binary file removed lib/xstream-1.4.20.jar
Binary file not shown.
112 changes: 55 additions & 57 deletions src/org/lockss/util/XStreamSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,25 @@ of this software and associated documentation files (the "Software"), to deal

package org.lockss.util;

import java.io.*;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.util.*;

import com.thoughtworks.xstream.alias.CannotResolveClassException;
import org.lockss.app.LockssApp;
import org.lockss.hasher.HashResult;
import org.lockss.util.SerializationException;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.alias.*;
import com.thoughtworks.xstream.converters.*;
import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;
import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
import com.thoughtworks.xstream.converters.basic.*;
import com.thoughtworks.xstream.converters.reflection.*;
import com.thoughtworks.xstream.core.*;
import com.thoughtworks.xstream.core.util.ThreadSafeSimpleDateFormat;
import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.StreamException;
import com.thoughtworks.xstream.io.*;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.mapper.CannotResolveClassException;
import com.thoughtworks.xstream.mapper.Mapper;
import com.thoughtworks.xstream.security.AnyTypePermission;
import org.lockss.app.LockssApp;
import org.lockss.hasher.HashResult;

import java.io.InterruptedIOException;
import java.io.Reader;
import java.io.Serializable;
import java.io.Writer;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.TimeZone;
import com.thoughtworks.xstream.mapper.*;

/**
* <p>An implementation of {@link ObjectSerializer} based on
Expand Down Expand Up @@ -110,7 +102,7 @@ public class XStreamSerializer extends ObjectSerializer {
* subject of Java Bug Report #709654.</p>
* @author Thib Guicherd-Callin
* @see com.thoughtworks.xstream.converters.basic.DateConverter
* @see com.thoughtworks.xstream.core.util.ThreadSafeSimpleDateFormat
* @see com.thoughtworks.xstream.converters.basic.ThreadSafeSimpleDateFormat
*/
private static class LockssDateConverter implements Converter {

Expand Down Expand Up @@ -143,14 +135,12 @@ public Object unmarshal(HierarchicalStreamReader reader,
}

protected static final ThreadSafeSimpleDateFormat formatter = new ThreadSafeSimpleDateFormat("yyyy-MM-dd HH:mm:ss.S Z",
TimeZone.getDefault(),
4,
20, true);
20);

protected static final ThreadSafeSimpleDateFormat oldFormatter = new ThreadSafeSimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z",
TimeZone.getDefault(),
4,
20, true);
20);

}
/*
Expand Down Expand Up @@ -302,11 +292,10 @@ private static class LockssReferenceByXPathMarshaller
* @param classMapper
*/
public LockssReferenceByXPathMarshaller(HierarchicalStreamWriter writer,
ConverterLookup converterLookup,
Mapper classMapper,
DefaultConverterLookup converterLookup,
ClassMapper classMapper,
String rootClassName) {
super(writer, converterLookup, classMapper,
ReferenceByXPathMarshallingStrategy.ABSOLUTE);
super(writer, converterLookup, classMapper);
this.rootClassName = rootClassName;
}

Expand All @@ -322,7 +311,6 @@ public LockssReferenceByXPathMarshaller(HierarchicalStreamWriter writer,
* {@link LockssSerializable}.
* @see ReferenceByXPathMarshaller#convertAnother
*/
@Override
public void convertAnother(Object parent) {
if ( !( parent instanceof Serializable ||
parent instanceof LockssSerializable) ) {
Expand Down Expand Up @@ -372,23 +360,40 @@ private static class LockssReferenceByXPathMarshallingStrategy
* unmarshaller).
*/
public LockssReferenceByXPathMarshallingStrategy(LockssApp lockssContext) {
super(ReferenceByXPathMarshallingStrategy.ABSOLUTE);
this.lockssContext = lockssContext;
}

@Override
protected TreeMarshaller createMarshallingContext(HierarchicalStreamWriter writer,
ConverterLookup converterLookup,
Mapper mapper) {
return new LockssReferenceByXPathMarshaller(writer, converterLookup, mapper, "<FIXME>"); // FIXME
/**
* <p>Performs unmarshalling with a
* {@link LockssReferenceByXPathMarshaller} instance.</p>
* @see LockssReferenceByXPathMarshaller
*/
public void marshal(HierarchicalStreamWriter writer,
Object root,
DefaultConverterLookup converterLookup,
ClassMapper classMapper,
DataHolder dataHolder) {
new LockssReferenceByXPathMarshaller(
writer,
converterLookup,
classMapper,
root.getClass().getName()
).start(root, dataHolder);
}

@Override
protected TreeUnmarshaller createUnmarshallingContext(Object root,
/**
* <p>Performs unmarshalling with a
* {@link LockssReferenceByXPathUnmarshaller} instance.</p>
* @see LockssReferenceByXPathUnmarshaller
*/
public Object unmarshal(Object root,
HierarchicalStreamReader reader,
ConverterLookup converterLookup,
Mapper mapper) {
return new LockssReferenceByXPathUnmarshaller(lockssContext, root, reader, converterLookup, mapper);
DataHolder dataHolder,
DefaultConverterLookup converterLookup,
ClassMapper classMapper) {
return new LockssReferenceByXPathUnmarshaller(
lockssContext, root, reader, converterLookup, classMapper).start(
dataHolder);
}

}
Expand Down Expand Up @@ -429,7 +434,7 @@ public LockssReferenceByXPathUnmarshaller(LockssApp lockssContext,
Object root,
HierarchicalStreamReader reader,
ConverterLookup converterLookup,
Mapper classMapper) {
ClassMapper classMapper) {
super(root, reader, converterLookup, classMapper);
this.lockssContext = lockssContext;
}
Expand All @@ -442,8 +447,8 @@ public LockssReferenceByXPathUnmarshaller(LockssApp lockssContext,
* @param parent
* @param type
*/
public Object convertAnother(Object parent, Class type, Converter converter) {
Object ret = super.convertAnother(parent, type, converter);
public Object convertAnother(Object parent, Class type) {
Object ret = super.convertAnother(parent, type);
if (ret instanceof LockssSerializable) {
Object[] parameters = new Object[] { lockssContext };
invokeMethod(
Expand Down Expand Up @@ -790,20 +795,13 @@ private synchronized void init() {
else {
reflectionProvider = new PureJavaReflectionProvider();
}
HierarchicalStreamDriver driver = new DomDriver(Constants.DEFAULT_ENCODING);
HierarchicalStreamDriver driver = new DomDriver();

xs = new XStream(reflectionProvider, driver) {
@Override
protected boolean useXStream11XmlFriendlyMapper() {
return true;
}
};

xs = new XStream(reflectionProvider, driver);
xs.setMarshallingStrategy(new LockssReferenceByXPathMarshallingStrategy(lockssContext));
xs.addPermission(AnyTypePermission.ANY);
xs.registerConverter(new LockssDateConverter());
xs.registerConverter(new LockssHashResultConverter());
xs.registerConverter(new LockssConstructingConverter(xs.getMapper()));
xs.registerConverter(new LockssConstructingConverter(xs.getClassMapper()));
initialized = true;
}
}
Expand Down

0 comments on commit fa3b512

Please sign in to comment.