Index: 3rdParty_sources/versions.txt =================================================================== diff -u -rb69db8c0c19115290e73865c3c51b408b78f41c9 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/versions.txt (.../versions.txt) (revision b69db8c0c19115290e73865c3c51b408b78f41c9) +++ 3rdParty_sources/versions.txt (.../versions.txt) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -59,6 +59,6 @@ xmltooling 1.4.0 -XStream 1.5.0 +XStream 1.4.10 websocket api_1.1_spec-1.1.1.Final \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/InitializationException.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/InitializationException.java (.../InitializationException.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/InitializationException.java (.../InitializationException.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2013 XStream Committers. + * Copyright (C) 2007, 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -17,7 +17,7 @@ * @author Jörg Schaible * @since 1.3 */ -public class InitializationException extends XStreamException { +public class InitializationException extends XStream.InitializationException { public InitializationException(String message, Throwable cause) { super(message, cause); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/MarshallingStrategy.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/MarshallingStrategy.java (.../MarshallingStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/MarshallingStrategy.java (.../MarshallingStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2006 Joe Walnes. - * Copyright (C) 2007, 2009, 2014 XStream Committers. + * Copyright (C) 2007, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -17,38 +17,8 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; - -/** - * Core interface for a marshalling strategy. - *

- * An implementation dictates how an object graph is marshalled and unmarshalled. It is the implementation's - * responsibility to deal with references between the objects. - *

- */ public interface MarshallingStrategy { - /** - * Marshal an object graph. - * - * @param writer the target for the marshalled data - * @param obj the object to marshal - * @param converterLookup the converter store - * @param mapper the mapper chain - * @param dataHolder the holder for additional data and state while marshalling - */ - void marshal(HierarchicalStreamWriter writer, Object obj, ConverterLookup converterLookup, Mapper mapper, - DataHolder dataHolder); - - /** - * Unmarshal an object graph. - * - * @param root a possible root object (should be {@code null} in normal cases) - * @param reader the source for the unmarshalled object data - * @param dataHolder the holder for additional data and state while marshalling - * @param converterLookup the converter store - * @param mapper the mapper chain - * @return the unmarshalled object - */ - Object unmarshal(Object root, HierarchicalStreamReader reader, DataHolder dataHolder, ConverterLookup converterLookup, - Mapper mapper); + Object unmarshal(Object root, HierarchicalStreamReader reader, DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper); + void marshal(HierarchicalStreamWriter writer, Object obj, ConverterLookup converterLookup, Mapper mapper, DataHolder dataHolder); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/XStream.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/XStream.java (.../XStream.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/XStream.java (.../XStream.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,12 +1,12 @@ /* * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 26. September 2003 by Joe Walnes */ package com.thoughtworks.xstream; @@ -26,6 +26,7 @@ import java.io.Writer; import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Member; import java.lang.reflect.Method; import java.math.BigDecimal; @@ -35,21 +36,17 @@ import java.nio.charset.Charset; import java.text.DecimalFormatSymbols; import java.util.ArrayList; -import java.util.Arrays; import java.util.BitSet; import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.Currency; import java.util.Date; -import java.util.EnumMap; -import java.util.EnumSet; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -60,18 +57,18 @@ import java.util.TimeZone; import java.util.TreeMap; import java.util.TreeSet; -import java.util.UUID; import java.util.Vector; -import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.ConverterLookup; import com.thoughtworks.xstream.converters.ConverterRegistry; import com.thoughtworks.xstream.converters.DataHolder; +import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.converters.SingleValueConverterWrapper; +import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.converters.basic.BigDecimalConverter; import com.thoughtworks.xstream.converters.basic.BigIntegerConverter; import com.thoughtworks.xstream.converters.basic.BooleanConverter; @@ -85,11 +82,9 @@ import com.thoughtworks.xstream.converters.basic.NullConverter; import com.thoughtworks.xstream.converters.basic.ShortConverter; import com.thoughtworks.xstream.converters.basic.StringBufferConverter; -import com.thoughtworks.xstream.converters.basic.StringBuilderConverter; import com.thoughtworks.xstream.converters.basic.StringConverter; import com.thoughtworks.xstream.converters.basic.URIConverter; import com.thoughtworks.xstream.converters.basic.URLConverter; -import com.thoughtworks.xstream.converters.basic.UUIDConverter; import com.thoughtworks.xstream.converters.collections.ArrayConverter; import com.thoughtworks.xstream.converters.collections.BitSetConverter; import com.thoughtworks.xstream.converters.collections.CharArrayConverter; @@ -100,12 +95,7 @@ import com.thoughtworks.xstream.converters.collections.SingletonMapConverter; import com.thoughtworks.xstream.converters.collections.TreeMapConverter; import com.thoughtworks.xstream.converters.collections.TreeSetConverter; -import com.thoughtworks.xstream.converters.enums.EnumConverter; -import com.thoughtworks.xstream.converters.enums.EnumMapConverter; -import com.thoughtworks.xstream.converters.enums.EnumSetConverter; -import com.thoughtworks.xstream.converters.extended.CharsetConverter; import com.thoughtworks.xstream.converters.extended.ColorConverter; -import com.thoughtworks.xstream.converters.extended.CurrencyConverter; import com.thoughtworks.xstream.converters.extended.DynamicProxyConverter; import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter; import com.thoughtworks.xstream.converters.extended.FileConverter; @@ -116,13 +106,10 @@ import com.thoughtworks.xstream.converters.extended.JavaMethodConverter; import com.thoughtworks.xstream.converters.extended.LocaleConverter; import com.thoughtworks.xstream.converters.extended.LookAndFeelConverter; -import com.thoughtworks.xstream.converters.extended.RegexPatternConverter; import com.thoughtworks.xstream.converters.extended.SqlDateConverter; import com.thoughtworks.xstream.converters.extended.SqlTimeConverter; import com.thoughtworks.xstream.converters.extended.SqlTimestampConverter; -import com.thoughtworks.xstream.converters.extended.StackTraceElementConverter; import com.thoughtworks.xstream.converters.extended.TextAttributeConverter; -import com.thoughtworks.xstream.converters.extended.ThrowableConverter; import com.thoughtworks.xstream.converters.reflection.ExternalizableConverter; import com.thoughtworks.xstream.converters.reflection.ReflectionConverter; import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; @@ -143,7 +130,7 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.StatefulWriter; import com.thoughtworks.xstream.io.xml.XppDriver; -import com.thoughtworks.xstream.mapper.AnnotationMapper; +import com.thoughtworks.xstream.mapper.AnnotationConfiguration; import com.thoughtworks.xstream.mapper.ArrayMapper; import com.thoughtworks.xstream.mapper.AttributeAliasingMapper; import com.thoughtworks.xstream.mapper.AttributeMapper; @@ -152,7 +139,7 @@ import com.thoughtworks.xstream.mapper.DefaultImplementationsMapper; import com.thoughtworks.xstream.mapper.DefaultMapper; import com.thoughtworks.xstream.mapper.DynamicProxyMapper; -import com.thoughtworks.xstream.mapper.EnumMapper; +import com.thoughtworks.xstream.mapper.ElementIgnoringMapper; import com.thoughtworks.xstream.mapper.FieldAliasingMapper; import com.thoughtworks.xstream.mapper.ImmutableTypesMapper; import com.thoughtworks.xstream.mapper.ImplicitCollectionMapper; @@ -183,125 +170,143 @@ *

*


* Example
- * + * *
  * XStream xstream = new XStream();
  * String xml = xstream.toXML(myObject); // serialize to XML
  * Object myObject2 = xstream.fromXML(xml); // deserialize from XML
  * 
- * + * *
*
+ * *

Aliasing classes

+ * *

- * To create shorter XML, you can specify aliases for classes using the alias() method. For example, you - * can shorten all occurrences of element <com.blah.MyThing> to <my-thing> by - * registering an alias for the class. + * To create shorter XML, you can specify aliases for classes using the alias() + * method. For example, you can shorten all occurrences of element + * <com.blah.MyThing> to <my-thing> by registering an + * alias for the class. *

*


*
- * + * *
  * xstream.alias("my-thing", MyThing.class);
  * 
- * + * *
*
+ * *

Converters

+ * *

- * XStream contains a map of {@link com.thoughtworks.xstream.converters.Converter} instances, each of which acts as a - * strategy for converting a particular type of class to XML and back again. Out of the box, XStream contains converters - * for most basic types (String, Date, int, boolean, etc) and collections (Map, List, Set, Properties, etc). For other - * objects reflection is used to serialize each field recursively. + * XStream contains a map of {@link com.thoughtworks.xstream.converters.Converter} instances, each + * of which acts as a strategy for converting a particular type of class to XML and back again. Out + * of the box, XStream contains converters for most basic types (String, Date, int, boolean, etc) + * and collections (Map, List, Set, Properties, etc). For other objects reflection is used to + * serialize each field recursively. *

+ * *

- * Extra converters can be registered using the registerConverter() method. Some non-standard converters - * are supplied in the {@link com.thoughtworks.xstream.converters.extended} package and you can create your own by - * implementing the {@link com.thoughtworks.xstream.converters.Converter} interface. + * Extra converters can be registered using the registerConverter() method. Some + * non-standard converters are supplied in the {@link com.thoughtworks.xstream.converters.extended} + * package and you can create your own by implementing the + * {@link com.thoughtworks.xstream.converters.Converter} interface. *

+ * *

*


* Example
- * + * *
  * xstream.registerConverter(new SqlTimestampConverter());
  * xstream.registerConverter(new DynamicProxyConverter());
  * 
- * + * *
*
*

- * The converters can be registered with an explicit priority. By default they are registered with - * XStream.PRIORITY_NORMAL. Converters of same priority will be used in the reverse sequence they have been registered. - * The default converter, i.e. the converter which will be used if no other registered converter is suitable, can be - * registered with priority XStream.PRIORITY_VERY_LOW. XStream uses by default the - * {@link com.thoughtworks.xstream.converters.reflection.ReflectionConverter} as the fallback converter. + * The converters can be registered with an explicit priority. By default they are registered with + * XStream.PRIORITY_NORMAL. Converters of same priority will be used in the reverse sequence + * they have been registered. The default converter, i.e. the converter which will be used if + * no other registered converter is suitable, can be registered with priority + * XStream.PRIORITY_VERY_LOW. XStream uses by default the + * {@link com.thoughtworks.xstream.converters.reflection.ReflectionConverter} as the fallback + * converter. *

+ * *

*


* Example
- * + * *
  * xstream.registerConverter(new CustomDefaultConverter(), XStream.PRIORITY_VERY_LOW);
  * 
- * + * *
*
+ * *

Object graphs

+ * *

- * XStream has support for object graphs; a deserialized object graph will keep references intact, including circular - * references. + * XStream has support for object graphs; a deserialized object graph will keep references intact, + * including circular references. *

+ * *

* XStream can signify references in XML using either relative/absolute XPath or IDs. The mode can be changed using * setMode(): *

+ * * * * * - * + * * * * - * + * * * * - * + * * * * - * + * * * * - * + * * * * - * + * * *
xstream.setMode(XStream.XPATH_RELATIVE_REFERENCES);(Default) Uses XPath relative references to signify duplicate references. This produces XML with the least - * clutter.(Default) Uses XPath relative references to signify duplicate references. This produces XML + * with the least clutter.
xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);Uses XPath absolute references to signify duplicate references. This produces XML with the least clutter.Uses XPath absolute references to signify duplicate + * references. This produces XML with the least clutter.
xstream.setMode(XStream.SINGLE_NODE_XPATH_RELATIVE_REFERENCES);Uses XPath relative references to signify duplicate references. The XPath expression ensures that a single node - * only is selected always.Uses XPath relative references to signify duplicate references. The XPath expression ensures that + * a single node only is selected always.
xstream.setMode(XStream.SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES);Uses XPath absolute references to signify duplicate references. The XPath expression ensures that a single node - * only is selected always.Uses XPath absolute references to signify duplicate references. The XPath expression ensures that + * a single node only is selected always.
xstream.setMode(XStream.ID_REFERENCES);Uses ID references to signify duplicate references. In some scenarios, such as when using hand-written XML, this - * is easier to work with.Uses ID references to signify duplicate references. In some scenarios, such as when using + * hand-written XML, this is easier to work with.
xstream.setMode(XStream.NO_REFERENCES);This disables object graph support and treats the object structure like a tree. Duplicate references are treated - * as two separate objects and circular references cause an exception. This is slightly faster and uses less memory than - * the other two modes.This disables object graph support and treats the object structure like a tree. Duplicate + * references are treated as two separate objects and circular references cause an exception. This + * is slightly faster and uses less memory than the other two modes.
*

Thread safety

*

- * The XStream instance is thread-safe. That is, once the XStream instance has been created and configured, it may be - * shared across multiple threads allowing objects to be serialized/deserialized concurrently. - * Note, that this only applies if annotations are not + * The XStream instance is thread-safe. That is, once the XStream instance has been created and + * configured, it may be shared across multiple threads allowing objects to be + * serialized/deserialized concurrently. Note, that this only applies if annotations are not * auto-detected on-the-fly. *

*

Implicit collections

+ * *

- * To avoid the need for special tags for collections, you can define implicit collections using one of the - * addImplicitCollection methods. + * To avoid the need for special tags for collections, you can define implicit collections using one + * of the addImplicitCollection methods. *

- * + * * @author Joe Walnes * @author Jörg Schaible * @author Mauro Talevi @@ -311,17 +316,18 @@ // CAUTION: The sequence of the fields is intentional for an optimal XML output of a // self-serialization! - private final ReflectionProvider reflectionProvider; - private final HierarchicalStreamDriver hierarchicalStreamDriver; - private final ClassLoaderReference classLoaderReference; + private ReflectionProvider reflectionProvider; + private HierarchicalStreamDriver hierarchicalStreamDriver; + private ClassLoaderReference classLoaderReference; private MarshallingStrategy marshallingStrategy; - private final ConverterLookup converterLookup; - private final ConverterRegistry converterRegistry; - private final Mapper mapper; + private ConverterLookup converterLookup; + private ConverterRegistry converterRegistry; + private Mapper mapper; private PackageAliasingMapper packageAliasingMapper; private ClassAliasingMapper classAliasingMapper; private FieldAliasingMapper fieldAliasingMapper; + private ElementIgnoringMapper elementIgnoringMapper; private AttributeAliasingMapper attributeAliasingMapper; private SystemAttributeAliasingMapper systemAttributeAliasingMapper; private AttributeMapper attributeMapper; @@ -330,8 +336,10 @@ private ImplicitCollectionMapper implicitCollectionMapper; private LocalConversionMapper localConversionMapper; private SecurityMapper securityMapper; - private AnnotationMapper annotationMapper; + private AnnotationConfiguration annotationConfiguration; + private transient boolean insecureWarning; + public static final int NO_REFERENCES = 1001; public static final int ID_REFERENCES = 1002; public static final int XPATH_RELATIVE_REFERENCES = 1003; @@ -344,19 +352,20 @@ public static final int PRIORITY_LOW = -10; public static final int PRIORITY_VERY_LOW = -20; + private static final String ANNOTATION_MAPPER_TYPE = "com.thoughtworks.xstream.mapper.AnnotationMapper"; private static final Pattern IGNORE_ALL = Pattern.compile(".*"); /** * Constructs a default XStream. *

- * The instance will use the {@link XppDriver} as default and tries to determine the best match for the - * {@link ReflectionProvider} on its own. + * The instance will use the {@link XppDriver} as default and tries to determine the best + * match for the {@link ReflectionProvider} on its own. *

- * + * * @throws InitializationException in case of an initialization problem */ public XStream() { - this(new XppDriver()); + this(null, (Mapper)null, new XppDriver()); } /** @@ -365,179 +374,212 @@ * The instance will use the {@link XppDriver} as default. *

* - * @param reflectionProvider the reflection provider to use or null for best matching reflection provider + * @param reflectionProvider the reflection provider to use or null for best + * matching reflection provider * @throws InitializationException in case of an initialization problem */ - public XStream(final ReflectionProvider reflectionProvider) { - this(reflectionProvider, new XppDriver()); + public XStream(ReflectionProvider reflectionProvider) { + this(reflectionProvider, (Mapper)null, new XppDriver()); } /** * Constructs an XStream with a special {@link HierarchicalStreamDriver}. *

- * The instance will tries to determine the best match for the {@link ReflectionProvider} on its own. + * The instance will tries to determine the best match for the {@link ReflectionProvider} on + * its own. *

- * + * * @param hierarchicalStreamDriver the driver instance * @throws InitializationException in case of an initialization problem */ - public XStream(final HierarchicalStreamDriver hierarchicalStreamDriver) { - this(null, hierarchicalStreamDriver); + public XStream(HierarchicalStreamDriver hierarchicalStreamDriver) { + this(null, (Mapper)null, hierarchicalStreamDriver); } /** - * Constructs an XStream with a special {@link HierarchicalStreamDriver} and {@link ReflectionProvider}. + * Constructs an XStream with a special {@link HierarchicalStreamDriver} and + * {@link ReflectionProvider}. * - * @param reflectionProvider the reflection provider to use or null for best matching Provider + * @param reflectionProvider the reflection provider to use or null for best + * matching Provider * @param hierarchicalStreamDriver the driver instance * @throws InitializationException in case of an initialization problem */ - public XStream(final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver hierarchicalStreamDriver) { - this(reflectionProvider, hierarchicalStreamDriver, new ClassLoaderReference(new CompositeClassLoader())); + public XStream( + ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver) { + this(reflectionProvider, (Mapper)null, hierarchicalStreamDriver); } /** - * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider} and a - * {@link ClassLoaderReference}. + * Constructs an XStream with a special {@link HierarchicalStreamDriver}, + * {@link ReflectionProvider} and a prepared {@link Mapper} chain. * - * @param reflectionProvider the reflection provider to use or null for best matching Provider + * @param reflectionProvider the reflection provider to use or null for best + * matching Provider + * @param mapper the instance with the {@link Mapper} chain or null for the default + * chain * @param driver the driver instance + * @throws InitializationException in case of an initialization problem + * @deprecated As of 1.3, use + * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoader, Mapper)} + * instead + */ + public XStream( + ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver driver) { + this(reflectionProvider, driver, new CompositeClassLoader(), mapper); + } + + /** + * Constructs an XStream with a special {@link HierarchicalStreamDriver}, + * {@link ReflectionProvider} and a {@link ClassLoaderReference}. + * + * @param reflectionProvider the reflection provider to use or null for best + * matching Provider + * @param driver the driver instance * @param classLoaderReference the reference to the {@link ClassLoader} to use * @throws InitializationException in case of an initialization problem * @since 1.4.5 */ public XStream( - final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver, - final ClassLoaderReference classLoaderReference) { + ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, + ClassLoaderReference classLoaderReference) { this(reflectionProvider, driver, classLoaderReference, null); } /** - * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider} and the - * {@link ClassLoader} to use. + * Constructs an XStream with a special {@link HierarchicalStreamDriver}, + * {@link ReflectionProvider} and the {@link ClassLoader} to use. * * @throws InitializationException in case of an initialization problem * @since 1.3 - * @deprecated As of 1.4.5 use {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference)} + * @deprecated As of 1.4.5 use + * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference)} */ - @Deprecated public XStream( - final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver, - final ClassLoader classLoader) { + ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, + ClassLoader classLoader) { this(reflectionProvider, driver, classLoader, null); } /** - * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared - * {@link Mapper} chain and the {@link ClassLoader} to use. + * Constructs an XStream with a special {@link HierarchicalStreamDriver}, + * {@link ReflectionProvider}, a prepared {@link Mapper} chain and the {@link ClassLoader} + * to use. * - * @param reflectionProvider the reflection provider to use or null for best matching Provider + * @param reflectionProvider the reflection provider to use or null for best + * matching Provider * @param driver the driver instance * @param classLoader the {@link ClassLoader} to use - * @param mapper the instance with the {@link Mapper} chain or null for the default chain + * @param mapper the instance with the {@link Mapper} chain or null for the default + * chain * @throws InitializationException in case of an initialization problem * @since 1.3 * @deprecated As of 1.4.5 use * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference, Mapper)} */ - @Deprecated public XStream( - final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver, - final ClassLoader classLoader, final Mapper mapper) { - this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, new DefaultConverterLookup()); + ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, + ClassLoader classLoader, Mapper mapper) { + this( + reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, new DefaultConverterLookup()); } /** - * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared - * {@link Mapper} chain and the {@link ClassLoaderReference}. + * Constructs an XStream with a special {@link HierarchicalStreamDriver}, + * {@link ReflectionProvider}, a prepared {@link Mapper} chain and the + * {@link ClassLoaderReference}. *

* The {@link ClassLoaderReference} should also be used for the {@link Mapper} chain. *

* - * @param reflectionProvider the reflection provider to use or null for best matching Provider + * @param reflectionProvider the reflection provider to use or null for best + * matching Provider * @param driver the driver instance * @param classLoaderReference the reference to the {@link ClassLoader} to use - * @param mapper the instance with the {@link Mapper} chain or null for the default chain + * @param mapper the instance with the {@link Mapper} chain or null for the default + * chain * @throws InitializationException in case of an initialization problem * @since 1.4.5 */ public XStream( - final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver, - final ClassLoaderReference classLoaderReference, final Mapper mapper) { - this(reflectionProvider, driver, classLoaderReference, mapper, new DefaultConverterLookup()); + ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, + ClassLoaderReference classLoaderReference, Mapper mapper) { + this( + reflectionProvider, driver, classLoaderReference, mapper, new DefaultConverterLookup()); } - + private XStream( - final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver, - final ClassLoaderReference classLoader, final Mapper mapper, - final DefaultConverterLookup defaultConverterLookup) { + ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, ClassLoaderReference classLoader, + Mapper mapper, final DefaultConverterLookup defaultConverterLookup) { this(reflectionProvider, driver, classLoader, mapper, new ConverterLookup() { - @Override - public Converter lookupConverterForType(final Class type) { + public Converter lookupConverterForType(Class type) { return defaultConverterLookup.lookupConverterForType(type); } }, new ConverterRegistry() { - @Override - public void registerConverter(final Converter converter, final int priority) { + public void registerConverter(Converter converter, int priority) { defaultConverterLookup.registerConverter(converter, priority); } }); } /** - * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared - * {@link Mapper} chain, the {@link ClassLoaderReference} and an own {@link ConverterLookup} and + * Constructs an XStream with a special {@link HierarchicalStreamDriver}, + * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the + * {@link ClassLoaderReference} and an own {@link ConverterLookup} and * {@link ConverterRegistry}. * - * @param reflectionProvider the reflection provider to use or null for best matching Provider + * @param reflectionProvider the reflection provider to use or null for best + * matching Provider * @param driver the driver instance * @param classLoader the {@link ClassLoader} to use - * @param mapper the instance with the {@link Mapper} chain or null for the default chain + * @param mapper the instance with the {@link Mapper} chain or null for the default + * chain * @param converterLookup the instance that is used to lookup the converters * @param converterRegistry an instance to manage the converter instances * @throws InitializationException in case of an initialization problem * @since 1.3 * @deprecated As of 1.4.5 use * {@link #XStream(ReflectionProvider, HierarchicalStreamDriver, ClassLoaderReference, Mapper, ConverterLookup, ConverterRegistry)} */ - @Deprecated public XStream( - final ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver, - final ClassLoader classLoader, final Mapper mapper, final ConverterLookup converterLookup, - final ConverterRegistry converterRegistry) { - this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, converterLookup, - converterRegistry); + ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, + ClassLoader classLoader, Mapper mapper, ConverterLookup converterLookup, + ConverterRegistry converterRegistry) { + this(reflectionProvider, driver, new ClassLoaderReference(classLoader), mapper, converterLookup, converterRegistry); } /** - * Constructs an XStream with a special {@link HierarchicalStreamDriver}, {@link ReflectionProvider}, a prepared - * {@link Mapper} chain, the {@link ClassLoaderReference} and an own {@link ConverterLookup} and + * Constructs an XStream with a special {@link HierarchicalStreamDriver}, + * {@link ReflectionProvider}, a prepared {@link Mapper} chain, the + * {@link ClassLoaderReference} and an own {@link ConverterLookup} and * {@link ConverterRegistry}. *

- * The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup should access the - * ConverterRegistry if you intent to register {@link Converter} instances with XStream facade or you are using - * annotations. + * The ClassLoaderReference should also be used for the Mapper chain. The ConverterLookup + * should access the ConverterRegistry if you intent to register {@link Converter} instances + * with XStream facade or you are using annotations. *

* - * @param reflectionProvider the reflection provider to use or null for best matching Provider + * @param reflectionProvider the reflection provider to use or null for best + * matching Provider * @param driver the driver instance * @param classLoaderReference the reference to the {@link ClassLoader} to use - * @param mapper the instance with the {@link Mapper} chain or null for the default chain + * @param mapper the instance with the {@link Mapper} chain or null for the default + * chain * @param converterLookup the instance that is used to lookup the converters - * @param converterRegistry an instance to manage the converter instances or null to prevent any further - * registry (including annotations) + * @param converterRegistry an instance to manage the converter instances or null + * to prevent any further registry (including annotations) * @throws InitializationException in case of an initialization problem * @since 1.4.5 */ public XStream( - ReflectionProvider reflectionProvider, final HierarchicalStreamDriver driver, - final ClassLoaderReference classLoaderReference, final Mapper mapper, - final ConverterLookup converterLookup, final ConverterRegistry converterRegistry) { + ReflectionProvider reflectionProvider, HierarchicalStreamDriver driver, + ClassLoaderReference classLoaderReference, Mapper mapper, ConverterLookup converterLookup, + ConverterRegistry converterRegistry) { if (reflectionProvider == null) { reflectionProvider = JVM.newReflectionProvider(); } this.reflectionProvider = reflectionProvider; - hierarchicalStreamDriver = driver; + this.hierarchicalStreamDriver = driver; this.classLoaderReference = classLoaderReference; this.converterLookup = converterLookup; this.converterRegistry = converterRegistry; @@ -560,96 +602,199 @@ mapper = new DynamicProxyMapper(mapper); mapper = new PackageAliasingMapper(mapper); mapper = new ClassAliasingMapper(mapper); + mapper = new ElementIgnoringMapper(mapper); mapper = new FieldAliasingMapper(mapper); mapper = new AttributeAliasingMapper(mapper); mapper = new SystemAttributeAliasingMapper(mapper); - mapper = new ImplicitCollectionMapper(mapper); + mapper = new ImplicitCollectionMapper(mapper, reflectionProvider); mapper = new OuterClassMapper(mapper); mapper = new ArrayMapper(mapper); mapper = new DefaultImplementationsMapper(mapper); mapper = new AttributeMapper(mapper, converterLookup, reflectionProvider); - mapper = new EnumMapper(mapper); + if (JVM.is15()) { + mapper = buildMapperDynamically( + "com.thoughtworks.xstream.mapper.EnumMapper", new Class[]{Mapper.class}, + new Object[]{mapper}); + } mapper = new LocalConversionMapper(mapper); mapper = new ImmutableTypesMapper(mapper); + if (JVM.is18()) { + mapper = buildMapperDynamically("com.thoughtworks.xstream.mapper.LambdaMapper", new Class[]{Mapper.class}, + new Object[]{mapper}); + } mapper = new SecurityMapper(mapper); - mapper = new AnnotationMapper(mapper, converterRegistry, converterLookup, classLoaderReference, - reflectionProvider); + if (JVM.is15()) { + mapper = buildMapperDynamically(ANNOTATION_MAPPER_TYPE, new Class[]{ + Mapper.class, ConverterRegistry.class, ConverterLookup.class, + ClassLoaderReference.class, ReflectionProvider.class}, new Object[]{ + mapper, converterRegistry, converterLookup, classLoaderReference, + reflectionProvider}); + } mapper = wrapMapper((MapperWrapper)mapper); mapper = new CachingMapper(mapper); return mapper; } - @SuppressWarnings("unused") - private Mapper buildMapperDynamically(final String className, final Class[] constructorParamTypes, - final Object[] constructorParamValues) { + private Mapper buildMapperDynamically(String className, Class[] constructorParamTypes, + Object[] constructorParamValues) { try { - final Class type = Class.forName(className, false, classLoaderReference.getReference()); - final Constructor constructor = type.getConstructor(constructorParamTypes); + Class type = Class.forName(className, false, classLoaderReference.getReference()); + Constructor constructor = type.getConstructor(constructorParamTypes); return (Mapper)constructor.newInstance(constructorParamValues); - } catch (final Exception e) { - throw new InitializationException("Could not instantiate mapper : " + className, e); - } catch (final LinkageError e) { - throw new InitializationException("Could not instantiate mapper : " + className, e); + } catch (Exception e) { + throw new com.thoughtworks.xstream.InitializationException( + "Could not instantiate mapper : " + className, e); + } catch (LinkageError e) { + throw new com.thoughtworks.xstream.InitializationException( + "Could not instantiate mapper : " + className, e); } } - protected MapperWrapper wrapMapper(final MapperWrapper next) { + protected MapperWrapper wrapMapper(MapperWrapper next) { return next; } /** - * @deprecated As of upcoming + * @deprecated As of 1.4.8 */ - @Deprecated protected boolean useXStream11XmlFriendlyMapper() { return false; } private void setupMappers() { - packageAliasingMapper = mapper.lookupMapperOfType(PackageAliasingMapper.class); - classAliasingMapper = mapper.lookupMapperOfType(ClassAliasingMapper.class); - fieldAliasingMapper = mapper.lookupMapperOfType(FieldAliasingMapper.class); - attributeMapper = mapper.lookupMapperOfType(AttributeMapper.class); - attributeAliasingMapper = mapper.lookupMapperOfType(AttributeAliasingMapper.class); - systemAttributeAliasingMapper = mapper.lookupMapperOfType(SystemAttributeAliasingMapper.class); - implicitCollectionMapper = mapper.lookupMapperOfType(ImplicitCollectionMapper.class); - defaultImplementationsMapper = mapper.lookupMapperOfType(DefaultImplementationsMapper.class); - immutableTypesMapper = mapper.lookupMapperOfType(ImmutableTypesMapper.class); - localConversionMapper = mapper.lookupMapperOfType(LocalConversionMapper.class); - securityMapper = mapper.lookupMapperOfType(SecurityMapper.class); - annotationMapper = mapper.lookupMapperOfType(AnnotationMapper.class); + packageAliasingMapper = (PackageAliasingMapper)this.mapper + .lookupMapperOfType(PackageAliasingMapper.class); + classAliasingMapper = (ClassAliasingMapper)this.mapper + .lookupMapperOfType(ClassAliasingMapper.class); + elementIgnoringMapper = (ElementIgnoringMapper)this.mapper + .lookupMapperOfType(ElementIgnoringMapper.class); + fieldAliasingMapper = (FieldAliasingMapper)this.mapper + .lookupMapperOfType(FieldAliasingMapper.class); + attributeMapper = (AttributeMapper)this.mapper + .lookupMapperOfType(AttributeMapper.class); + attributeAliasingMapper = (AttributeAliasingMapper)this.mapper + .lookupMapperOfType(AttributeAliasingMapper.class); + systemAttributeAliasingMapper = (SystemAttributeAliasingMapper)this.mapper + .lookupMapperOfType(SystemAttributeAliasingMapper.class); + implicitCollectionMapper = (ImplicitCollectionMapper)this.mapper + .lookupMapperOfType(ImplicitCollectionMapper.class); + defaultImplementationsMapper = (DefaultImplementationsMapper)this.mapper + .lookupMapperOfType(DefaultImplementationsMapper.class); + immutableTypesMapper = (ImmutableTypesMapper)this.mapper + .lookupMapperOfType(ImmutableTypesMapper.class); + localConversionMapper = (LocalConversionMapper)this.mapper + .lookupMapperOfType(LocalConversionMapper.class); + securityMapper = (SecurityMapper)this.mapper + .lookupMapperOfType(SecurityMapper.class); + annotationConfiguration = (AnnotationConfiguration)this.mapper + .lookupMapperOfType(AnnotationConfiguration.class); } - + protected void setupSecurity() { if (securityMapper == null) { return; } + + addPermission(AnyTypePermission.ANY); + insecureWarning = true; + } - addPermission(NullPermission.NULL); - addPermission(PrimitiveTypePermission.PRIMITIVES); - addPermission(ArrayTypePermission.ARRAYS); - addPermission(InterfaceTypePermission.INTERFACES); - allowTypeHierarchy(Calendar.class); - allowTypeHierarchy(Collection.class); - allowTypeHierarchy(Enum.class); - allowTypeHierarchy(Map.class); - allowTypeHierarchy(Map.Entry.class); - allowTypeHierarchy(Member.class); - allowTypeHierarchy(Number.class); - allowTypeHierarchy(Throwable.class); - allowTypeHierarchy(TimeZone.class); + /** + * Setup the security framework of a XStream instance. + *

+ * This method is a pure helper method for XStream 1.4.x. It initializes an XStream instance with a white list of + * well-known and simply types of the Java runtime as it is done in XStream 1.5.x by default. This method will do + * therefore nothing in XStream 1.5. + *

+ * + * @param xstream + * @since 1.4.10 + */ + public static void setupDefaultSecurity(final XStream xstream) { + if (xstream.insecureWarning) { + xstream.addPermission(NoTypePermission.NONE); + xstream.addPermission(NullPermission.NULL); + xstream.addPermission(PrimitiveTypePermission.PRIMITIVES); + xstream.addPermission(ArrayTypePermission.ARRAYS); + xstream.addPermission(InterfaceTypePermission.INTERFACES); + xstream.allowTypeHierarchy(Calendar.class); + xstream.allowTypeHierarchy(Collection.class); + xstream.allowTypeHierarchy(Map.class); + xstream.allowTypeHierarchy(Map.Entry.class); + xstream.allowTypeHierarchy(Member.class); + xstream.allowTypeHierarchy(Number.class); + xstream.allowTypeHierarchy(Throwable.class); + xstream.allowTypeHierarchy(TimeZone.class); - final Set> types = new HashSet>(); - types.addAll(Arrays.>asList(BitSet.class, Charset.class, Class.class, Currency.class, Date.class, - DecimalFormatSymbols.class, File.class, Locale.class, Object.class, Pattern.class, StackTraceElement.class, - String.class, StringBuffer.class, StringBuilder.class, URL.class, URI.class, UUID.class)); - if (JVM.isSQLAvailable()) { - types.add(JVM.loadClassForName("java.sql.Timestamp")); - types.add(JVM.loadClassForName("java.sql.Time")); - types.add(JVM.loadClassForName("java.sql.Date")); + Class type = JVM.loadClassForName("java.lang.Enum"); + if (type != null) { + xstream.allowTypeHierarchy(type); + } + type = JVM.loadClassForName("java.nio.file.Path"); + if (type != null) { + xstream.allowTypeHierarchy(type); + } + + final Set types = new HashSet(); + types.add(BitSet.class); + types.add(Charset.class); + types.add(Class.class); + types.add(Currency.class); + types.add(Date.class); + types.add(DecimalFormatSymbols.class); + types.add(File.class); + types.add(Locale.class); + types.add(Object.class); + types.add(Pattern.class); + types.add(StackTraceElement.class); + types.add(String.class); + types.add(StringBuffer.class); + types.add(JVM.loadClassForName("java.lang.StringBuilder")); + types.add(URL.class); + types.add(URI.class); + types.add(JVM.loadClassForName("java.util.UUID")); + if (JVM.isSQLAvailable()) { + types.add(JVM.loadClassForName("java.sql.Timestamp")); + types.add(JVM.loadClassForName("java.sql.Time")); + types.add(JVM.loadClassForName("java.sql.Date")); + } + if (JVM.is18()) { + xstream.allowTypeHierarchy(JVM.loadClassForName("java.time.Clock")); + types.add(JVM.loadClassForName("java.time.Duration")); + types.add(JVM.loadClassForName("java.time.Instant")); + types.add(JVM.loadClassForName("java.time.LocalDate")); + types.add(JVM.loadClassForName("java.time.LocalDateTime")); + types.add(JVM.loadClassForName("java.time.LocalTime")); + types.add(JVM.loadClassForName("java.time.MonthDay")); + types.add(JVM.loadClassForName("java.time.OffsetDateTime")); + types.add(JVM.loadClassForName("java.time.OffsetTime")); + types.add(JVM.loadClassForName("java.time.Period")); + types.add(JVM.loadClassForName("java.time.Ser")); + types.add(JVM.loadClassForName("java.time.Year")); + types.add(JVM.loadClassForName("java.time.YearMonth")); + types.add(JVM.loadClassForName("java.time.ZonedDateTime")); + xstream.allowTypeHierarchy(JVM.loadClassForName("java.time.ZoneId")); + types.add(JVM.loadClassForName("java.time.chrono.HijrahDate")); + types.add(JVM.loadClassForName("java.time.chrono.JapaneseDate")); + types.add(JVM.loadClassForName("java.time.chrono.JapaneseEra")); + types.add(JVM.loadClassForName("java.time.chrono.MinguoDate")); + types.add(JVM.loadClassForName("java.time.chrono.ThaiBuddhistDate")); + types.add(JVM.loadClassForName("java.time.chrono.Ser")); + xstream.allowTypeHierarchy(JVM.loadClassForName("java.time.chrono.Chronology")); + types.add(JVM.loadClassForName("java.time.temporal.ValueRange")); + types.add(JVM.loadClassForName("java.time.temporal.WeekFields")); + } + types.remove(null); + + final Iterator iter = types.iterator(); + final Class[] classes = new Class[types.size()]; + for (int i = 0; i < classes.length; ++i) { + classes[i] = (Class)iter.next(); + } + xstream.allowTypes(classes); + } else { + throw new IllegalArgumentException("Security framework of XStream instance already initialized"); } - types.remove(null); - allowTypes(types.toArray(new Class[types.size()])); } protected void setupAliases() { @@ -671,23 +816,16 @@ alias("big-int", BigInteger.class); alias("big-decimal", BigDecimal.class); - alias("string", String.class); alias("string-buffer", StringBuffer.class); - alias("string-builder", StringBuilder.class); - alias("uuid", UUID.class); + alias("string", String.class); alias("java-class", Class.class); alias("method", Method.class); alias("constructor", Constructor.class); alias("field", Field.class); alias("date", Date.class); - alias("gregorian-calendar", Calendar.class); alias("uri", URI.class); alias("url", URL.class); - alias("file", File.class); - alias("locale", Locale.class); alias("bit-set", BitSet.class); - alias("trace", StackTraceElement.class); - alias("currency", Currency.class); alias("map", Map.class); alias("entry", Map.Entry.class); @@ -701,12 +839,7 @@ alias("tree-map", TreeMap.class); alias("tree-set", TreeSet.class); alias("hashtable", Hashtable.class); - alias("linked-hash-map", LinkedHashMap.class); - alias("linked-hash-set", LinkedHashSet.class); - alias("concurrent-hash-map", ConcurrentHashMap.class); - - alias("enum-set", EnumSet.class); - alias("enum-map", EnumMap.class); + alias("empty-list", Collections.EMPTY_LIST.getClass()); alias("empty-map", Collections.EMPTY_MAP.getClass()); alias("empty-set", Collections.EMPTY_SET.getClass()); @@ -723,24 +856,88 @@ alias("awt-text-attribute", JVM.loadClassForName("java.awt.font.TextAttribute")); } + Class type = JVM.loadClassForName("javax.activation.ActivationDataFlavor"); + if (type != null) { + alias("activation-data-flavor", type); + } + if (JVM.isSQLAvailable()) { alias("sql-timestamp", JVM.loadClassForName("java.sql.Timestamp")); alias("sql-time", JVM.loadClassForName("java.sql.Time")); alias("sql-date", JVM.loadClassForName("java.sql.Date")); } - aliasType("charset", Charset.class); + alias("file", File.class); + alias("locale", Locale.class); + alias("gregorian-calendar", Calendar.class); - if (JVM.loadClassForName("javax.security.auth.Subject") != null) { + if (JVM.is14()) { aliasDynamically("auth-subject", "javax.security.auth.Subject"); + alias("linked-hash-map", JVM.loadClassForName("java.util.LinkedHashMap")); + alias("linked-hash-set", JVM.loadClassForName("java.util.LinkedHashSet")); + alias("trace", JVM.loadClassForName("java.lang.StackTraceElement")); + alias("currency", JVM.loadClassForName("java.util.Currency")); + aliasType("charset", JVM.loadClassForName("java.nio.charset.Charset")); } - if (JVM.loadClassForName("javax.xml.datatype.Duration") != null) { - aliasDynamically("duration", "javax.xml.datatype.Duration"); + + if (JVM.is15()) { + aliasDynamically("xml-duration", "javax.xml.datatype.Duration"); + alias("concurrent-hash-map", JVM.loadClassForName("java.util.concurrent.ConcurrentHashMap")); + alias("enum-set", JVM.loadClassForName("java.util.EnumSet")); + alias("enum-map", JVM.loadClassForName("java.util.EnumMap")); + alias("string-builder", JVM.loadClassForName("java.lang.StringBuilder")); + alias("uuid", JVM.loadClassForName("java.util.UUID")); } + + if (JVM.is17()) { + aliasType("path", JVM.loadClassForName("java.nio.file.Path")); + } + + if (JVM.is18()) { + alias("fixed-clock", JVM.loadClassForName("java.time.Clock$FixedClock")); + alias("offset-clock", JVM.loadClassForName("java.time.Clock$OffsetClock")); + alias("system-clock", JVM.loadClassForName("java.time.Clock$SystemClock")); + alias("tick-clock", JVM.loadClassForName("java.time.Clock$TickClock")); + alias("day-of-week", JVM.loadClassForName("java.time.DayOfWeek")); + alias("duration", JVM.loadClassForName("java.time.Duration")); + alias("instant", JVM.loadClassForName("java.time.Instant")); + alias("local-date", JVM.loadClassForName("java.time.LocalDate")); + alias("local-date-time", JVM.loadClassForName("java.time.LocalDateTime")); + alias("local-time", JVM.loadClassForName("java.time.LocalTime")); + alias("month", JVM.loadClassForName("java.time.Month")); + alias("month-day", JVM.loadClassForName("java.time.MonthDay")); + alias("offset-date-time", JVM.loadClassForName("java.time.OffsetDateTime")); + alias("offset-time", JVM.loadClassForName("java.time.OffsetTime")); + alias("period", JVM.loadClassForName("java.time.Period")); + alias("year", JVM.loadClassForName("java.time.Year")); + alias("year-month", JVM.loadClassForName("java.time.YearMonth")); + alias("zoned-date-time", JVM.loadClassForName("java.time.ZonedDateTime")); + aliasType("zone-id", JVM.loadClassForName("java.time.ZoneId")); + aliasType("chronology", JVM.loadClassForName("java.time.chrono.Chronology")); + alias("hijrah-date", JVM.loadClassForName("java.time.chrono.HijrahDate")); + alias("hijrah-era", JVM.loadClassForName("java.time.chrono.HijrahEra")); + alias("japanese-date", JVM.loadClassForName("java.time.chrono.JapaneseDate")); + alias("japanese-era", JVM.loadClassForName("java.time.chrono.JapaneseEra")); + alias("minguo-date", JVM.loadClassForName("java.time.chrono.MinguoDate")); + alias("minguo-era", JVM.loadClassForName("java.time.chrono.MinguoEra")); + alias("thai-buddhist-date", JVM.loadClassForName("java.time.chrono.ThaiBuddhistDate")); + alias("thai-buddhist-era", JVM.loadClassForName("java.time.chrono.ThaiBuddhistEra")); + alias("chrono-field", JVM.loadClassForName("java.time.temporal.ChronoField")); + alias("chrono-unit", JVM.loadClassForName("java.time.temporal.ChronoUnit")); + alias("iso-field", JVM.loadClassForName("java.time.temporal.IsoFields$Field")); + alias("iso-unit", JVM.loadClassForName("java.time.temporal.IsoFields$Unit")); + alias("julian-field", JVM.loadClassForName("java.time.temporal.JulianFields$Field")); + alias("temporal-value-range", JVM.loadClassForName("java.time.temporal.ValueRange")); + alias("week-fields", JVM.loadClassForName("java.time.temporal.WeekFields")); + } + + if (JVM.loadClassForName("java.lang.invoke.SerializedLambda") != null) { + aliasDynamically("serialized-lambda", "java.lang.invoke.SerializedLambda"); + } } - private void aliasDynamically(final String alias, final String className) { - final Class type = JVM.loadClassForName(className); + private void aliasDynamically(String alias, String className) { + Class type = JVM.loadClassForName(className); if (type != null) { alias(alias, type); } @@ -758,10 +955,13 @@ } protected void setupConverters() { - registerConverter(new ReflectionConverter(mapper, reflectionProvider), PRIORITY_VERY_LOW); + registerConverter( + new ReflectionConverter(mapper, reflectionProvider), PRIORITY_VERY_LOW); - registerConverter(new SerializableConverter(mapper, reflectionProvider, classLoaderReference), PRIORITY_LOW); + registerConverter( + new SerializableConverter(mapper, reflectionProvider, classLoaderReference), PRIORITY_LOW); registerConverter(new ExternalizableConverter(mapper, classLoaderReference), PRIORITY_LOW); + registerConverter(new InternalBlackList(), PRIORITY_LOW); registerConverter(new NullConverter(), PRIORITY_VERY_HIGH); registerConverter(new IntConverter(), PRIORITY_NORMAL); @@ -775,17 +975,8 @@ registerConverter(new StringConverter(), PRIORITY_NORMAL); registerConverter(new StringBufferConverter(), PRIORITY_NORMAL); - registerConverter(new StringBuilderConverter(), PRIORITY_NORMAL); - registerConverter(new ThrowableConverter(converterLookup), PRIORITY_NORMAL); - registerConverter(new StackTraceElementConverter(), PRIORITY_NORMAL); registerConverter(new DateConverter(), PRIORITY_NORMAL); - registerConverter(new GregorianCalendarConverter(), PRIORITY_NORMAL); - registerConverter(new RegexPatternConverter(), PRIORITY_NORMAL); - registerConverter(new CurrencyConverter(), PRIORITY_NORMAL); - registerConverter(new CharsetConverter(), PRIORITY_NORMAL); - registerConverter(new LocaleConverter(), PRIORITY_NORMAL); registerConverter(new BitSetConverter(), PRIORITY_NORMAL); - registerConverter(new UUIDConverter(), PRIORITY_NORMAL); registerConverter(new URIConverter(), PRIORITY_NORMAL); registerConverter(new URLConverter(), PRIORITY_NORMAL); registerConverter(new BigIntegerConverter(), PRIORITY_NORMAL); @@ -801,9 +992,6 @@ registerConverter(new SingletonMapConverter(mapper), PRIORITY_NORMAL); registerConverter(new PropertiesConverter(), PRIORITY_NORMAL); registerConverter((Converter)new EncodedByteArrayConverter(), PRIORITY_NORMAL); - registerConverter(new EnumConverter(), PRIORITY_NORMAL); - registerConverter(new EnumSetConverter(mapper), PRIORITY_NORMAL); - registerConverter(new EnumMapConverter(mapper), PRIORITY_NORMAL); registerConverter(new FileConverter(), PRIORITY_NORMAL); if (JVM.isSQLAvailable()) { @@ -815,42 +1003,144 @@ registerConverter(new JavaClassConverter(classLoaderReference), PRIORITY_NORMAL); registerConverter(new JavaMethodConverter(classLoaderReference), PRIORITY_NORMAL); registerConverter(new JavaFieldConverter(classLoaderReference), PRIORITY_NORMAL); + if (JVM.isAWTAvailable()) { registerConverter(new FontConverter(mapper), PRIORITY_NORMAL); registerConverter(new ColorConverter(), PRIORITY_NORMAL); registerConverter(new TextAttributeConverter(), PRIORITY_NORMAL); } if (JVM.isSwingAvailable()) { - registerConverter(new LookAndFeelConverter(mapper, reflectionProvider), PRIORITY_NORMAL); + registerConverter( + new LookAndFeelConverter(mapper, reflectionProvider), PRIORITY_NORMAL); } + registerConverter(new LocaleConverter(), PRIORITY_NORMAL); + registerConverter(new GregorianCalendarConverter(), PRIORITY_NORMAL); - if (JVM.loadClassForName("javax.security.auth.Subject") != null) { - registerConverterDynamically("com.thoughtworks.xstream.converters.extended.SubjectConverter", + if (JVM.is14()) { + // late bound converters - allows XStream to be compiled on earlier JDKs + registerConverterDynamically( + "com.thoughtworks.xstream.converters.extended.SubjectConverter", PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper}); + registerConverterDynamically( + "com.thoughtworks.xstream.converters.extended.ThrowableConverter", + PRIORITY_NORMAL, new Class[]{ConverterLookup.class}, + new Object[]{converterLookup}); + registerConverterDynamically( + "com.thoughtworks.xstream.converters.extended.StackTraceElementConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically( + "com.thoughtworks.xstream.converters.extended.CurrencyConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically( + "com.thoughtworks.xstream.converters.extended.RegexPatternConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically( + "com.thoughtworks.xstream.converters.extended.CharsetConverter", + PRIORITY_NORMAL, null, null); } - if (JVM.loadClassForName("javax.xml.datatype.Duration") != null) { - registerConverterDynamically("com.thoughtworks.xstream.converters.extended.DurationConverter", + + if (JVM.is15()) { + // late bound converters - allows XStream to be compiled on earlier JDKs + if (JVM.loadClassForName("javax.xml.datatype.Duration") != null) { + registerConverterDynamically( + "com.thoughtworks.xstream.converters.extended.DurationConverter", + PRIORITY_NORMAL, null, null); + } + registerConverterDynamically( + "com.thoughtworks.xstream.converters.enums.EnumConverter", PRIORITY_NORMAL, + null, null); + registerConverterDynamically( + "com.thoughtworks.xstream.converters.enums.EnumSetConverter", PRIORITY_NORMAL, + new Class[]{Mapper.class}, new Object[]{mapper}); + registerConverterDynamically( + "com.thoughtworks.xstream.converters.enums.EnumMapConverter", PRIORITY_NORMAL, + new Class[]{Mapper.class}, new Object[]{mapper}); + registerConverterDynamically( + "com.thoughtworks.xstream.converters.basic.StringBuilderConverter", PRIORITY_NORMAL, null, null); + registerConverterDynamically( + "com.thoughtworks.xstream.converters.basic.UUIDConverter", PRIORITY_NORMAL, + null, null); } + if (JVM.loadClassForName("javax.activation.ActivationDataFlavor") != null) { + registerConverterDynamically("com.thoughtworks.xstream.converters.extended.ActivationDataFlavorConverter", + PRIORITY_NORMAL, null, null); + } + if (JVM.is17()) { + registerConverterDynamically("com.thoughtworks.xstream.converters.extended.PathConverter", + PRIORITY_NORMAL, null, null); + } + if (JVM.is18()) { + registerConverterDynamically("com.thoughtworks.xstream.converters.time.ChronologyConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.DurationConverter", PRIORITY_NORMAL, + null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.HijrahDateConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.JapaneseDateConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.JapaneseEraConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.InstantConverter", PRIORITY_NORMAL, + null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.LocalDateConverter", PRIORITY_NORMAL, + null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.LocalDateTimeConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.LocalTimeConverter", PRIORITY_NORMAL, + null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.MinguoDateConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.MonthDayConverter", PRIORITY_NORMAL, + null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.OffsetDateTimeConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.OffsetTimeConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.PeriodConverter", PRIORITY_NORMAL, + null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.SystemClockConverter", + PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper}); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.ThaiBuddhistDateConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.ValueRangeConverter", + PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper}); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.WeekFieldsConverter", + PRIORITY_NORMAL, new Class[]{Mapper.class}, new Object[]{mapper}); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.YearConverter", PRIORITY_NORMAL, + null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.YearMonthConverter", PRIORITY_NORMAL, + null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.ZonedDateTimeConverter", + PRIORITY_NORMAL, null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.time.ZoneIdConverter", PRIORITY_NORMAL, + null, null); + registerConverterDynamically("com.thoughtworks.xstream.converters.reflection.LambdaConverter", + PRIORITY_NORMAL, new Class[]{Mapper.class, ReflectionProvider.class, ClassLoaderReference.class}, + new Object[]{mapper, reflectionProvider, classLoaderReference}); + } - registerConverter(new SelfStreamingInstanceChecker(converterLookup, this), PRIORITY_NORMAL); + registerConverter( + new SelfStreamingInstanceChecker(converterLookup, this), PRIORITY_NORMAL); } - private void registerConverterDynamically(final String className, final int priority, - final Class[] constructorParamTypes, final Object[] constructorParamValues) { + private void registerConverterDynamically(String className, int priority, + Class[] constructorParamTypes, Object[] constructorParamValues) { try { - final Class type = Class.forName(className, false, classLoaderReference.getReference()); - final Constructor constructor = type.getConstructor(constructorParamTypes); - final Object instance = constructor.newInstance(constructorParamValues); + Class type = Class.forName(className, false, classLoaderReference.getReference()); + Constructor constructor = type.getConstructor(constructorParamTypes); + Object instance = constructor.newInstance(constructorParamValues); if (instance instanceof Converter) { registerConverter((Converter)instance, priority); } else if (instance instanceof SingleValueConverter) { registerConverter((SingleValueConverter)instance, priority); } - } catch (final Exception e) { - throw new InitializationException("Could not instantiate converter : " + className, e); - } catch (final LinkageError e) { - throw new InitializationException("Could not instantiate converter : " + className, e); + } catch (Exception e) { + throw new com.thoughtworks.xstream.InitializationException( + "Could not instantiate converter : " + className, e); + } catch (LinkageError e) { + throw new com.thoughtworks.xstream.InitializationException( + "Could not instantiate converter : " + className, e); } } @@ -860,81 +1150,133 @@ } // primitives are always immutable - addImmutableType(boolean.class); - addImmutableType(Boolean.class); - addImmutableType(byte.class); - addImmutableType(Byte.class); - addImmutableType(char.class); - addImmutableType(Character.class); - addImmutableType(double.class); - addImmutableType(Double.class); - addImmutableType(float.class); - addImmutableType(Float.class); - addImmutableType(int.class); - addImmutableType(Integer.class); - addImmutableType(long.class); - addImmutableType(Long.class); - addImmutableType(short.class); - addImmutableType(Short.class); + addImmutableType(boolean.class, false); + addImmutableType(Boolean.class, false); + addImmutableType(byte.class, false); + addImmutableType(Byte.class, false); + addImmutableType(char.class, false); + addImmutableType(Character.class, false); + addImmutableType(double.class, false); + addImmutableType(Double.class, false); + addImmutableType(float.class, false); + addImmutableType(Float.class, false); + addImmutableType(int.class, false); + addImmutableType(Integer.class, false); + addImmutableType(long.class, false); + addImmutableType(Long.class, false); + addImmutableType(short.class, false); + addImmutableType(Short.class, false); // additional types - addImmutableType(Mapper.Null.class); - addImmutableType(BigDecimal.class); - addImmutableType(BigInteger.class); - addImmutableType(String.class); - addImmutableType(Charset.class); - addImmutableType(Currency.class); - addImmutableType(URI.class); - addImmutableType(URL.class); - addImmutableType(File.class); - addImmutableType(Class.class); + addImmutableType(Mapper.Null.class, false); + addImmutableType(BigDecimal.class, false); + addImmutableType(BigInteger.class, false); + addImmutableType(String.class, false); + addImmutableType(URL.class, false); + addImmutableType(File.class, false); + addImmutableType(Class.class, false); - addImmutableType(Collections.EMPTY_LIST.getClass()); - addImmutableType(Collections.EMPTY_SET.getClass()); - addImmutableType(Collections.EMPTY_MAP.getClass()); + if (JVM.is17()) { + Class type = JVM.loadClassForName("java.nio.file.Paths"); + if (type != null) { + Method methodGet; + try { + methodGet = type.getDeclaredMethod("get", new Class[] {String.class, String[].class}); + if (methodGet != null) { + Object path = methodGet.invoke(null, new Object[]{".", new String[0]}); + if (path != null) { + addImmutableType(path.getClass(), false); + } + } + } catch (NoSuchMethodException e) { + } catch (SecurityException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } + } + } if (JVM.isAWTAvailable()) { - addImmutableTypeDynamically("java.awt.font.TextAttribute"); + addImmutableTypeDynamically("java.awt.font.TextAttribute", false); } + + if (JVM.is14()) { + // late bound types - allows XStream to be compiled on earlier JDKs + addImmutableTypeDynamically("java.nio.charset.Charset", true); + addImmutableTypeDynamically("java.util.Currency", true); + } + + if (JVM.is15()) { + addImmutableTypeDynamically("java.util.UUID", true); + } + + addImmutableType(URI.class, true); + addImmutableType(Collections.EMPTY_LIST.getClass(), true); + addImmutableType(Collections.EMPTY_SET.getClass(), true); + addImmutableType(Collections.EMPTY_MAP.getClass(), true); + + if (JVM.is18()) { + addImmutableTypeDynamically("java.time.Duration", false); + addImmutableTypeDynamically("java.time.Instant", false); + addImmutableTypeDynamically("java.time.LocalDate", false); + addImmutableTypeDynamically("java.time.LocalDateTime", false); + addImmutableTypeDynamically("java.time.LocalTime", false); + addImmutableTypeDynamically("java.time.MonthDay", false); + addImmutableTypeDynamically("java.time.OffsetDateTime", false); + addImmutableTypeDynamically("java.time.OffsetTime", false); + addImmutableTypeDynamically("java.time.Period", false); + addImmutableTypeDynamically("java.time.Year", false); + addImmutableTypeDynamically("java.time.YearMonth", false); + addImmutableTypeDynamically("java.time.ZonedDateTime", false); + addImmutableTypeDynamically("java.time.ZoneId", false); + addImmutableTypeDynamically("java.time.ZoneOffset", false); + addImmutableTypeDynamically("java.time.ZoneRegion", false); + addImmutableTypeDynamically("java.time.chrono.HijrahChronology", false); + addImmutableTypeDynamically("java.time.chrono.HijrahDate", false); + addImmutableTypeDynamically("java.time.chrono.IsoChronology", false); + addImmutableTypeDynamically("java.time.chrono.JapaneseChronology", false); + addImmutableTypeDynamically("java.time.chrono.JapaneseDate", false); + addImmutableTypeDynamically("java.time.chrono.JapaneseEra", false); + addImmutableTypeDynamically("java.time.chrono.MinguoChronology", false); + addImmutableTypeDynamically("java.time.chrono.MinguoDate", false); + addImmutableTypeDynamically("java.time.chrono.ThaiBuddhistChronology", false); + addImmutableTypeDynamically("java.time.chrono.ThaiBuddhistDate", false); + addImmutableTypeDynamically("java.time.temporal.IsoFields$Field", false); + addImmutableTypeDynamically("java.time.temporal.IsoFields$Unit", false); + addImmutableTypeDynamically("java.time.temporal.JulianFields$Field", false); + } } - private void addImmutableTypeDynamically(final String className) { - final Class type = JVM.loadClassForName(className); + private void addImmutableTypeDynamically(String className, boolean isReferenceable) { + Class type = JVM.loadClassForName(className); if (type != null) { - addImmutableType(type); + addImmutableType(type, isReferenceable); } } - /** - * Setter for an arbitrary marshalling strategy. - * - * @param marshallingStrategy the implementation to use - * @see #setMode(int) - */ - public void setMarshallingStrategy(final MarshallingStrategy marshallingStrategy) { + public void setMarshallingStrategy(MarshallingStrategy marshallingStrategy) { this.marshallingStrategy = marshallingStrategy; } /** * Serialize an object to a pretty-printed XML String. - * + * * @throws XStreamException if the object cannot be serialized */ - public String toXML(final Object obj) { - final Writer writer = new StringWriter(); + public String toXML(Object obj) { + Writer writer = new StringWriter(); toXML(obj, writer); return writer.toString(); } /** - * Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed afterwards and in case - * of an exception. + * Serialize an object to the given Writer as pretty-printed XML. The Writer will be flushed + * afterwards and in case of an exception. * * @throws XStreamException if the object cannot be serialized */ - public void toXML(final Object obj, final Writer out) { - @SuppressWarnings("resource") - final HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out); + public void toXML(Object obj, Writer out) { + HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out); try { marshal(obj, writer); } finally { @@ -943,14 +1285,13 @@ } /** - * Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream will be flushed afterwards - * and in case of an exception. + * Serialize an object to the given OutputStream as pretty-printed XML. The OutputStream + * will be flushed afterwards and in case of an exception. * * @throws XStreamException if the object cannot be serialized */ - public void toXML(final Object obj, final OutputStream out) { - @SuppressWarnings("resource") - final HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out); + public void toXML(Object obj, OutputStream out) { + HierarchicalStreamWriter writer = hierarchicalStreamDriver.createWriter(out); try { marshal(obj, writer); } finally { @@ -960,119 +1301,131 @@ /** * Serialize and object to a hierarchical data structure (such as XML). - * + * * @throws XStreamException if the object cannot be serialized */ - public void marshal(final Object obj, final HierarchicalStreamWriter writer) { + public void marshal(Object obj, HierarchicalStreamWriter writer) { marshal(obj, writer, null); } /** * 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. + * @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(final Object obj, final HierarchicalStreamWriter writer, final DataHolder dataHolder) { + public void marshal(Object obj, HierarchicalStreamWriter writer, DataHolder dataHolder) { marshallingStrategy.marshal(writer, obj, converterLookup, mapper, dataHolder); } /** * Deserialize an object from an XML String. - * + * * @throws XStreamException if the object cannot be deserialized */ - public T fromXML(final String xml) { + public Object fromXML(String xml) { return fromXML(new StringReader(xml)); } /** * Deserialize an object from an XML Reader. - * + * * @throws XStreamException if the object cannot be deserialized */ - public T fromXML(final Reader reader) { + public Object fromXML(Reader reader) { return unmarshal(hierarchicalStreamDriver.createReader(reader), null); } /** * Deserialize an object from an XML InputStream. - * + * * @throws XStreamException if the object cannot be deserialized */ - public T fromXML(final InputStream input) { + public Object fromXML(InputStream input) { return unmarshal(hierarchicalStreamDriver.createReader(input), null); } /** - * Deserialize an object from a URL. Depending on the parser implementation, some might take the file path as - * SystemId to resolve additional references. + * Deserialize an object from a URL. * + * Depending on the parser implementation, some might take the file path as SystemId to + * resolve additional references. + * * @throws XStreamException if the object cannot be deserialized * @since 1.4 */ - public T fromXML(final URL url) { + public Object fromXML(URL url) { return fromXML(url, null); } /** - * Deserialize an object from a file. Depending on the parser implementation, some might take the file path as - * SystemId to resolve additional references. + * Deserialize an object from a file. * + * Depending on the parser implementation, some might take the file path as SystemId to + * resolve additional references. + * * @throws XStreamException if the object cannot be deserialized * @since 1.4 */ - public T fromXML(final File file) { + public Object fromXML(File file) { return fromXML(file, null); } /** - * Deserialize an object from an XML String, populating the fields of the given root object instead of instantiating - * a new one. 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! + * Deserialize an object from an XML String, populating the fields of the given root object + * instead of instantiating a new one. 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! * * @throws XStreamException if the object cannot be deserialized */ - public T fromXML(final String xml, final T root) { + public Object fromXML(String xml, Object root) { return fromXML(new StringReader(xml), root); } /** - * Deserialize an object from an XML Reader, populating the fields of the given root object instead of instantiating - * a new one. 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! + * Deserialize an object from an XML Reader, populating the fields of the given root object + * instead of instantiating a new one. 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! * * @throws XStreamException if the object cannot be deserialized */ - public T fromXML(final Reader xml, final T root) { + public Object fromXML(Reader xml, Object root) { return unmarshal(hierarchicalStreamDriver.createReader(xml), root); } /** - * Deserialize an object from a URL, populating the fields of the given root object instead of instantiating a new - * one. 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! Depending on the parser implementation, some might take the - * file path as SystemId to resolve additional references. + * Deserialize an object from a URL, populating the fields of the given root + * object instead of instantiating a new one. 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! * + * Depending on the parser implementation, some might take the file path as SystemId to + * resolve additional references. + * * @throws XStreamException if the object cannot be deserialized * @since 1.4 */ - public T fromXML(final URL url, final T root) { + public Object fromXML(URL url, Object root) { return unmarshal(hierarchicalStreamDriver.createReader(url), root); } /** - * Deserialize an object from a file, populating the fields of the given root object instead of instantiating a new - * one. 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! Depending on the parser implementation, some might take the - * file path as SystemId to resolve additional references. + * Deserialize an object from a file, populating the fields of the given root + * object instead of instantiating a new one. 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! * + * Depending on the parser implementation, some might take the file path as SystemId to + * resolve additional references. + * * @throws XStreamException if the object cannot be deserialized * @since 1.4 */ - public T fromXML(final File file, final T root) { - final HierarchicalStreamReader reader = hierarchicalStreamDriver.createReader(file); + public Object fromXML(File file, Object root) { + HierarchicalStreamReader reader = hierarchicalStreamDriver.createReader(file); try { return unmarshal(reader, root); } finally { @@ -1081,326 +1434,357 @@ } /** - * Deserialize an object from an XML InputStream, populating the fields of the given root object instead of - * instantiating a new one. 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! + * Deserialize an object from an XML InputStream, populating the fields of the given root + * object instead of instantiating a new one. 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! * * @throws XStreamException if the object cannot be deserialized */ - public T fromXML(final InputStream input, final T root) { + public Object fromXML(InputStream input, Object root) { return unmarshal(hierarchicalStreamDriver.createReader(input), root); } /** * Deserialize an object from a hierarchical data structure (such as XML). - * + * * @throws XStreamException if the object cannot be deserialized */ - public T unmarshal(final HierarchicalStreamReader reader) { + public Object unmarshal(HierarchicalStreamReader reader) { return unmarshal(reader, null, null); } /** - * Deserialize an object from a hierarchical data structure (such as XML), populating the fields of the given root - * object instead of instantiating a new one. 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! + * Deserialize an object from a hierarchical data structure (such as XML), populating the + * fields of the given root object instead of instantiating a new one. 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! * * @throws XStreamException if the object cannot be deserialized */ - public T unmarshal(final HierarchicalStreamReader reader, final T root) { + public Object unmarshal(HierarchicalStreamReader reader, Object root) { return unmarshal(reader, root, null); } /** * 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. + * @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 T unmarshal(final HierarchicalStreamReader reader, final T root, final DataHolder dataHolder) { + public Object unmarshal(HierarchicalStreamReader reader, Object root, DataHolder dataHolder) { try { - @SuppressWarnings("unchecked") - final T t = (T)marshallingStrategy.unmarshal(root, reader, dataHolder, converterLookup, mapper); - return t; + if (insecureWarning) { + insecureWarning = false; + System.err.println("Security framework of XStream not initialized, XStream is probably vulnerable."); + } + return marshallingStrategy.unmarshal( + root, reader, dataHolder, converterLookup, mapper); - } catch (final ConversionException e) { - final Package pkg = getClass().getPackage(); - final String version = pkg != null ? pkg.getImplementationVersion() : null; + } catch (ConversionException e) { + Package pkg = getClass().getPackage(); + String version = pkg != null ? pkg.getImplementationVersion() : null; e.add("version", version != null ? version : "not available"); throw e; } } /** * Alias a Class to a shorter name to be used in XML elements. - * + * * @param name Short name * @param type Type to be aliased * @throws InitializationException if no {@link ClassAliasingMapper} is available */ - public void alias(final String name, final Class type) { + public void alias(String name, Class type) { if (classAliasingMapper == null) { - throw new InitializationException("No " + ClassAliasingMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + ClassAliasingMapper.class.getName() + + " available"); } classAliasingMapper.addClassAlias(name, type); } /** - * Alias a type to a shorter name to be used in XML elements. Any class that is assignable to this type will be - * aliased to the same name. + * Alias a type to a shorter name to be used in XML elements. Any class that is assignable + * to this type will be aliased to the same name. * * @param name Short name * @param type Type to be aliased * @since 1.2 * @throws InitializationException if no {@link ClassAliasingMapper} is available */ - public void aliasType(final String name, final Class type) { + public void aliasType(String name, Class type) { if (classAliasingMapper == null) { - throw new InitializationException("No " + ClassAliasingMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + ClassAliasingMapper.class.getName() + + " available"); } classAliasingMapper.addTypeAlias(name, type); } /** * Alias a Class to a shorter name to be used in XML elements. - * + * * @param name Short name * @param type Type to be aliased * @param defaultImplementation Default implementation of type to use if no other specified. - * @throws InitializationException if no {@link DefaultImplementationsMapper} or no {@link ClassAliasingMapper} is - * available + * @throws InitializationException if no {@link DefaultImplementationsMapper} or no + * {@link ClassAliasingMapper} is available */ - public void alias(final String name, final Class type, final Class defaultImplementation) { + public void alias(String name, Class type, Class defaultImplementation) { alias(name, type); addDefaultImplementation(defaultImplementation, type); } /** * Alias a package to a shorter name to be used in XML elements. - * + * * @param name Short name * @param pkgName package to be aliased - * @throws InitializationException if no {@link DefaultImplementationsMapper} or no {@link PackageAliasingMapper} is - * available + * @throws InitializationException if no {@link DefaultImplementationsMapper} or no + * {@link PackageAliasingMapper} is available * @since 1.3.1 */ - public void aliasPackage(final String name, final String pkgName) { + public void aliasPackage(String name, String pkgName) { if (packageAliasingMapper == null) { - throw new InitializationException("No " + PackageAliasingMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + PackageAliasingMapper.class.getName() + + " available"); } packageAliasingMapper.addPackageAlias(name, pkgName); } /** * Create an alias for a field name. - * + * * @param alias the alias itself * @param definedIn the type that declares the field * @param fieldName the name of the field * @throws InitializationException if no {@link FieldAliasingMapper} is available */ - public void aliasField(final String alias, final Class definedIn, final String fieldName) { + public void aliasField(String alias, Class definedIn, String fieldName) { if (fieldAliasingMapper == null) { - throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + FieldAliasingMapper.class.getName() + + " available"); } fieldAliasingMapper.addFieldAlias(alias, definedIn, fieldName); } /** * Create an alias for an attribute - * + * * @param alias the alias itself * @param attributeName the name of the attribute * @throws InitializationException if no {@link AttributeAliasingMapper} is available */ - public void aliasAttribute(final String alias, final String attributeName) { + public void aliasAttribute(String alias, String attributeName) { if (attributeAliasingMapper == null) { - throw new InitializationException("No " + AttributeAliasingMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + AttributeAliasingMapper.class.getName() + + " available"); } attributeAliasingMapper.addAliasFor(attributeName, alias); } /** - * Create an alias for a system attribute. XStream will not write a system attribute if its alias is set to - * null. However, this is not reversible, i.e. deserialization of the result is likely to fail - * afterwards and will not produce an object equal to the originally written one. + * Create an alias for a system attribute. XStream will not write a system attribute if its + * alias is set to null. However, this is not reversible, i.e. deserialization + * of the result is likely to fail afterwards and will not produce an object equal to the + * originally written one. * * @param alias the alias itself (may be null) * @param systemAttributeName the name of the system attribute * @throws InitializationException if no {@link SystemAttributeAliasingMapper} is available * @since 1.3.1 */ - public void aliasSystemAttribute(final String alias, final String systemAttributeName) { + public void aliasSystemAttribute(String alias, String systemAttributeName) { if (systemAttributeAliasingMapper == null) { - throw new InitializationException("No " + SystemAttributeAliasingMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + SystemAttributeAliasingMapper.class.getName() + + " available"); } systemAttributeAliasingMapper.addAliasFor(systemAttributeName, alias); } /** * Create an alias for an attribute. - * + * * @param definedIn the type where the attribute is defined * @param attributeName the name of the attribute * @param alias the alias itself * @throws InitializationException if no {@link AttributeAliasingMapper} is available * @since 1.2.2 */ - public void aliasAttribute(final Class definedIn, final String attributeName, final String alias) { + public void aliasAttribute(Class definedIn, String attributeName, String alias) { aliasField(alias, definedIn, attributeName); useAttributeFor(definedIn, attributeName); } /** * Use an attribute for a field or a specific type. - * + * * @param fieldName the name of the field * @param type the Class of the type to be rendered as XML attribute * @throws InitializationException if no {@link AttributeMapper} is available * @since 1.2 */ - public void useAttributeFor(final String fieldName, final Class type) { + public void useAttributeFor(String fieldName, Class type) { if (attributeMapper == null) { - throw new InitializationException("No " + AttributeMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + AttributeMapper.class.getName() + + " available"); } attributeMapper.addAttributeFor(fieldName, type); } /** * Use an attribute for a field declared in a specific type. - * + * * @param fieldName the name of the field * @param definedIn the Class containing such field * @throws InitializationException if no {@link AttributeMapper} is available * @since 1.2.2 */ - public void useAttributeFor(final Class definedIn, final String fieldName) { + public void useAttributeFor(Class definedIn, String fieldName) { if (attributeMapper == null) { - throw new InitializationException("No " + AttributeMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + AttributeMapper.class.getName() + + " available"); } attributeMapper.addAttributeFor(definedIn, fieldName); } /** * Use an attribute for an arbitrary type. - * + * * @param type the Class of the type to be rendered as XML attribute * @throws InitializationException if no {@link AttributeMapper} is available * @since 1.2 */ - public void useAttributeFor(final Class type) { + public void useAttributeFor(Class type) { if (attributeMapper == null) { - throw new InitializationException("No " + AttributeMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + AttributeMapper.class.getName() + + " available"); } attributeMapper.addAttributeFor(type); } /** - * Associate a default implementation of a class with an object. Whenever XStream encounters an instance of this - * type, it will use the default implementation instead. For example, java.util.ArrayList is the default - * implementation of java.util.List. + * Associate a default implementation of a class with an object. Whenever XStream encounters + * an instance of this type, it will use the default implementation instead. For example, + * java.util.ArrayList is the default implementation of java.util.List. * * @param defaultImplementation * @param ofType * @throws InitializationException if no {@link DefaultImplementationsMapper} is available */ - public void addDefaultImplementation(final Class defaultImplementation, final Class ofType) { + public void addDefaultImplementation(Class defaultImplementation, Class ofType) { if (defaultImplementationsMapper == null) { - throw new InitializationException("No " + DefaultImplementationsMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + DefaultImplementationsMapper.class.getName() + + " available"); } defaultImplementationsMapper.addDefaultImplementation(defaultImplementation, ofType); } /** * Add immutable types. The value of the instances of these types will always be written into the stream even if + * they appear multiple times. However, references are still supported at deserialization time. + * + * @throws InitializationException if no {@link ImmutableTypesMapper} is available + * @deprecated As of 1.4.9 use {@link #addImmutableType(Class, boolean)} + */ + public void addImmutableType(Class type) { + addImmutableType(type, true); + } + + /** + * Add immutable types. The value of the instances of these types will always be written into the stream even if * they appear multiple times. - * + *

+ * Note, while a reference-keeping marshaller will not write references for immutable types into the stream, a + * reference-keeping unmarshaller can still support such references in the stream for compatibility reasons at the + * expense of memory consumption. Therefore declare these types only as referenceable if your already persisted + * streams do contain such references. Otherwise you may waste a lot of memory during deserialization. + *

+ * + * @param isReferenceable true if support at deserialization time is required for compatibility at the + * cost of a higher memory footprint, false otherwise * @throws InitializationException if no {@link ImmutableTypesMapper} is available + * @since 1.4.9 */ - public void addImmutableType(final Class type) { + public void addImmutableType(final Class type, final boolean isReferenceable) { if (immutableTypesMapper == null) { - throw new InitializationException("No " + ImmutableTypesMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + ImmutableTypesMapper.class.getName() + + " available"); } - immutableTypesMapper.addImmutableType(type); + immutableTypesMapper.addImmutableType(type, isReferenceable); } - /** - * Register a converter with normal priority. - * - * @param converter the converter instance - */ - public void registerConverter(final Converter converter) { + public void registerConverter(Converter converter) { registerConverter(converter, PRIORITY_NORMAL); } - /** - * Register a converter with chosen priority. - * - * @param converter the converter instance - * @param priority the converter priority - */ - public void registerConverter(final Converter converter, final int priority) { + public void registerConverter(Converter converter, int priority) { if (converterRegistry != null) { converterRegistry.registerConverter(converter, priority); } } - /** - * Register a single value converter with normal priority. - * - * @param converter the single value converter instance - */ - public void registerConverter(final SingleValueConverter converter) { + public void registerConverter(SingleValueConverter converter) { registerConverter(converter, PRIORITY_NORMAL); } - /** - * Register a single converter with chosen priority. - * - * @param converter the single converter instance - * @param priority the converter priority - */ - public void registerConverter(final SingleValueConverter converter, final int priority) { + public void registerConverter(SingleValueConverter converter, int priority) { if (converterRegistry != null) { - converterRegistry.registerConverter(new SingleValueConverterWrapper(converter), priority); + converterRegistry.registerConverter( + new SingleValueConverterWrapper(converter), priority); } } /** * Register a local {@link Converter} for a field. - * + * * @param definedIn the class type the field is defined in * @param fieldName the field name * @param converter the converter to use * @since 1.3 */ - public void registerLocalConverter(final Class definedIn, final String fieldName, final Converter converter) { + public void registerLocalConverter(Class definedIn, String fieldName, Converter converter) { if (localConversionMapper == null) { - throw new InitializationException("No " + LocalConversionMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + LocalConversionMapper.class.getName() + + " available"); } localConversionMapper.registerLocalConverter(definedIn, fieldName, converter); } /** * Register a local {@link SingleValueConverter} for a field. - * + * * @param definedIn the class type the field is defined in * @param fieldName the field name * @param converter the converter to use * @since 1.3 */ - public void registerLocalConverter(final Class definedIn, final String fieldName, - final SingleValueConverter converter) { - final Converter wrapper = new SingleValueConverterWrapper(converter); - registerLocalConverter(definedIn, fieldName, wrapper); + public void registerLocalConverter(Class definedIn, String fieldName, + SingleValueConverter converter) { + registerLocalConverter( + definedIn, fieldName, (Converter)new SingleValueConverterWrapper(converter)); } /** - * Retrieve the {@link Mapper}. This is by default a chain of {@link MapperWrapper MapperWrappers}. + * Retrieve the {@link Mapper}. This is by default a chain of {@link MapperWrapper + * MapperWrappers}. * * @return the mapper * @since 1.2 @@ -1411,7 +1795,7 @@ /** * Retrieve the {@link ReflectionProvider} in use. - * + * * @return the mapper * @since 1.2.1 */ @@ -1424,18 +1808,17 @@ } /** - * Change mode for dealing with duplicate references. Valid values are XPATH_ABSOLUTE_REFERENCES, - * XPATH_RELATIVE_REFERENCES, XStream.ID_REFERENCES and XStream.NO_REFERENCES - * . + * Change mode for dealing with duplicate references. Valid values are + * XPATH_ABSOLUTE_REFERENCES, XPATH_RELATIVE_REFERENCES, + * XStream.ID_REFERENCES and XStream.NO_REFERENCES. * * @throws IllegalArgumentException if the mode is not one of the declared types - * @see #setMarshallingStrategy(MarshallingStrategy) * @see #XPATH_ABSOLUTE_REFERENCES * @see #XPATH_RELATIVE_REFERENCES * @see #ID_REFERENCES * @see #NO_REFERENCES */ - public void setMode(final int mode) { + public void setMode(int mode) { switch (mode) { case NO_REFERENCES: setMarshallingStrategy(new TreeMarshallingStrategy()); @@ -1444,17 +1827,21 @@ setMarshallingStrategy(new ReferenceByIdMarshallingStrategy()); break; case XPATH_RELATIVE_REFERENCES: - setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.RELATIVE)); + setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy( + ReferenceByXPathMarshallingStrategy.RELATIVE)); break; case XPATH_ABSOLUTE_REFERENCES: - setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.ABSOLUTE)); + setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy( + ReferenceByXPathMarshallingStrategy.ABSOLUTE)); break; case SINGLE_NODE_XPATH_RELATIVE_REFERENCES: - setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.RELATIVE + setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy( + ReferenceByXPathMarshallingStrategy.RELATIVE | ReferenceByXPathMarshallingStrategy.SINGLE_NODE)); break; case SINGLE_NODE_XPATH_ABSOLUTE_REFERENCES: - setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy(ReferenceByXPathMarshallingStrategy.ABSOLUTE + setMarshallingStrategy(new ReferenceByXPathMarshallingStrategy( + ReferenceByXPathMarshallingStrategy.ABSOLUTE | ReferenceByXPathMarshallingStrategy.SINGLE_NODE)); break; default: @@ -1464,246 +1851,280 @@ /** * Adds a default implicit collection which is used for any unmapped XML tag. - * + * * @param ownerType class owning the implicit collection - * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching - * the default implementation type of the collection type. + * @param fieldName name of the field in the ownerType. This field must be a concrete + * collection type or matching the default implementation type of the collection + * type. */ - public void addImplicitCollection(final Class ownerType, final String fieldName) { + public void addImplicitCollection(Class ownerType, String fieldName) { addImplicitCollection(ownerType, fieldName, null, null); } /** * Adds implicit collection which is used for all items of the given itemType. - * + * * @param ownerType class owning the implicit collection - * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching - * the default implementation type of the collection type. + * @param fieldName name of the field in the ownerType. This field must be a concrete + * collection type or matching the default implementation type of the collection + * type. * @param itemType type of the items to be part of this collection * @throws InitializationException if no {@link ImplicitCollectionMapper} is available */ - public void addImplicitCollection(final Class ownerType, final String fieldName, final Class itemType) { + public void addImplicitCollection(Class ownerType, String fieldName, Class itemType) { addImplicitCollection(ownerType, fieldName, null, itemType); } /** - * Adds implicit collection which is used for all items of the given element name defined by itemFieldName. + * Adds implicit collection which is used for all items of the given element name defined by + * itemFieldName. * * @param ownerType class owning the implicit collection - * @param fieldName name of the field in the ownerType. This field must be a concrete collection type or matching - * the default implementation type of the collection type. + * @param fieldName name of the field in the ownerType. This field must be a concrete + * collection type or matching the default implementation type of the collection + * type. * @param itemFieldName element name of the implicit collection * @param itemType item type to be aliases be the itemFieldName * @throws InitializationException if no {@link ImplicitCollectionMapper} is available */ - public void addImplicitCollection(final Class ownerType, final String fieldName, final String itemFieldName, - final Class itemType) { + public void addImplicitCollection(Class ownerType, String fieldName, String itemFieldName, + Class itemType) { addImplicitMap(ownerType, fieldName, itemFieldName, itemType, null); } /** * Adds an implicit array. - * + * * @param ownerType class owning the implicit array * @param fieldName name of the array field - * @since 1.4 + * @since 1.4 */ - public void addImplicitArray(final Class ownerType, final String fieldName) { + public void addImplicitArray(Class ownerType, String fieldName) { addImplicitCollection(ownerType, fieldName); } /** - * Adds an implicit array which is used for all items of the given itemType when the array type matches. + * Adds an implicit array which is used for all items of the given itemType when the array + * type matches. * * @param ownerType class owning the implicit array * @param fieldName name of the array field in the ownerType * @param itemType type of the items to be part of this array - * @throws InitializationException if no {@link ImplicitCollectionMapper} is available or the array type does not - * match the itemType - * @since 1.4 + * @throws InitializationException if no {@link ImplicitCollectionMapper} is available or the + * array type does not match the itemType + * @since 1.4 */ - public void addImplicitArray(final Class ownerType, final String fieldName, final Class itemType) { + public void addImplicitArray(Class ownerType, String fieldName, Class itemType) { addImplicitCollection(ownerType, fieldName, itemType); } /** - * Adds an implicit array which is used for all items of the given element name defined by itemName. + * Adds an implicit array which is used for all items of the given element name defined by + * itemName. * * @param ownerType class owning the implicit array * @param fieldName name of the array field in the ownerType * @param itemName alias name of the items * @throws InitializationException if no {@link ImplicitCollectionMapper} is available - * @since 1.4 + * @since 1.4 */ - public void addImplicitArray(final Class ownerType, final String fieldName, final String itemName) { + public void addImplicitArray(Class ownerType, String fieldName, String itemName) { addImplicitCollection(ownerType, fieldName, itemName, null); } /** * Adds an implicit map. - * + * * @param ownerType class owning the implicit map - * @param fieldName name of the field in the ownerType. This field must be a concrete map type or matching the - * default implementation type of the map type. + * @param fieldName name of the field in the ownerType. This field must be a concrete + * map type or matching the default implementation type of the map + * type. * @param itemType type of the items to be part of this map as value * @param keyFieldName the name of the field of the itemType that is used for the key in the map - * @since 1.4 + * @since 1.4 */ - public void addImplicitMap(final Class ownerType, final String fieldName, final Class itemType, - final String keyFieldName) { + public void addImplicitMap(Class ownerType, String fieldName, Class itemType, String keyFieldName) { addImplicitMap(ownerType, fieldName, null, itemType, keyFieldName); } /** * Adds an implicit map. - * + * * @param ownerType class owning the implicit map - * @param fieldName name of the field in the ownerType. This field must be a concrete map type or matching the - * default implementation type of the map type. + * @param fieldName name of the field in the ownerType. This field must be a concrete + * map type or matching the default implementation type of the map + * type. * @param itemName alias name of the items * @param itemType type of the items to be part of this map as value * @param keyFieldName the name of the field of the itemType that is used for the key in the map - * @since 1.4 + * @since 1.4 */ - public void addImplicitMap(final Class ownerType, final String fieldName, final String itemName, - final Class itemType, final String keyFieldName) { + public void addImplicitMap(Class ownerType, String fieldName, String itemName, + Class itemType, String keyFieldName) { if (implicitCollectionMapper == null) { - throw new InitializationException("No " + ImplicitCollectionMapper.class.getName() + " available"); + throw new com.thoughtworks.xstream.InitializationException("No " + + ImplicitCollectionMapper.class.getName() + + " available"); } implicitCollectionMapper.add(ownerType, fieldName, itemName, itemType, keyFieldName); } /** * 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)} or - * {@link #unmarshal(HierarchicalStreamReader, Object, DataHolder)}. - * + * {@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(); } /** - * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream. + * Creates an ObjectOutputStream that serializes a stream of objects to the writer using + * XStream. *

* To change the name of the root element (from <object-stream>), use * {@link #createObjectOutputStream(java.io.Writer, String)}. *

* - * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) + * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, + * String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.0.3 */ - public ObjectOutputStream createObjectOutputStream(final Writer writer) throws IOException { - return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), "object-stream"); + public ObjectOutputStream createObjectOutputStream(Writer writer) throws IOException { + return createObjectOutputStream( + hierarchicalStreamDriver.createWriter(writer), "object-stream"); } /** - * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream. + * Creates an ObjectOutputStream that serializes a stream of objects to the writer using + * XStream. *

* To change the name of the root element (from <object-stream>), use * {@link #createObjectOutputStream(java.io.Writer, String)}. *

* - * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) + * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, + * String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.0.3 */ - public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer) throws IOException { + public ObjectOutputStream createObjectOutputStream(HierarchicalStreamWriter writer) + throws IOException { return createObjectOutputStream(writer, "object-stream"); } /** - * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream. + * Creates an ObjectOutputStream that serializes a stream of objects to the writer using + * XStream. * - * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) + * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, + * String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.0.3 */ - public ObjectOutputStream createObjectOutputStream(final Writer writer, final String rootNodeName) - throws IOException { - return createObjectOutputStream(hierarchicalStreamDriver.createWriter(writer), rootNodeName); + public ObjectOutputStream createObjectOutputStream(Writer writer, String rootNodeName) + throws IOException { + return createObjectOutputStream( + hierarchicalStreamDriver.createWriter(writer), rootNodeName); } /** - * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream. + * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream + * using XStream. *

* To change the name of the root element (from <object-stream>), use * {@link #createObjectOutputStream(java.io.Writer, String)}. *

* - * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) + * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, + * String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.3 */ - public ObjectOutputStream createObjectOutputStream(final OutputStream out) throws IOException { - return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), "object-stream"); + public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException { + return createObjectOutputStream( + hierarchicalStreamDriver.createWriter(out), "object-stream"); } /** - * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream using XStream. + * Creates an ObjectOutputStream that serializes a stream of objects to the OutputStream + * using XStream. * - * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) + * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, + * String) * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.3 */ - public ObjectOutputStream createObjectOutputStream(final OutputStream out, final String rootNodeName) - throws IOException { - return createObjectOutputStream(hierarchicalStreamDriver.createWriter(out), rootNodeName); + public ObjectOutputStream createObjectOutputStream(OutputStream out, String rootNodeName) + throws IOException { + return createObjectOutputStream( + hierarchicalStreamDriver.createWriter(out), rootNodeName); } /** - * Creates an ObjectOutputStream that serializes a stream of objects to the writer using XStream. + * Creates an ObjectOutputStream that serializes a stream of objects to the writer using + * XStream. *

- * Because an ObjectOutputStream can contain multiple items and XML only allows a single root node, the stream must - * be written inside an enclosing node. + * Because an ObjectOutputStream can contain multiple items and XML only allows a single + * root node, the stream must be written inside an enclosing node. *

*

- * It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will be incomplete. + * It is necessary to call ObjectOutputStream.close() when done, otherwise the stream will + * be incomplete. *

*

Example

- * + * *
      *  ObjectOutputStream out = xstream.createObjectOutputStream(aWriter, "things");
      *   out.writeInt(123);
      *   out.writeObject("Hello");
      *   out.writeObject(someObject)
      *   out.close();
      * 
- * + * * @param writer The writer to serialize the objects to. * @param rootNodeName The name of the root node enclosing the stream of objects. * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) * @since 1.0.3 */ - @SuppressWarnings("resource") public ObjectOutputStream createObjectOutputStream(final HierarchicalStreamWriter writer, final String rootNodeName) throws IOException { + return createObjectOutputStream(writer, rootNodeName, null); + } + + /** + * 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() { - @Override public void writeToStream(final Object object) { - marshal(object, statefulWriter); + marshal(object, statefulWriter, dataHolder); } - @Override - public void writeFieldsToStream(final Map fields) throws NotActiveException { + public void writeFieldsToStream(Map fields) throws NotActiveException { throw new NotActiveException("not in call to writeObject"); } - @Override public void defaultWriteObject() throws NotActiveException { throw new NotActiveException("not in call to writeObject"); } - @Override public void flush() { statefulWriter.flush(); } - @Override public void close() { if (statefulWriter.state() != StatefulWriter.STATE_CLOSED) { statefulWriter.endNode(); @@ -1714,100 +2135,118 @@ } /** - * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream. + * Creates an ObjectInputStream that deserializes a stream of objects from a reader using + * XStream. * * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) - * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) + * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, + * String) * @since 1.0.3 */ - public ObjectInputStream createObjectInputStream(final Reader xmlReader) throws IOException { + public ObjectInputStream createObjectInputStream(Reader xmlReader) throws IOException { return createObjectInputStream(hierarchicalStreamDriver.createReader(xmlReader)); } /** - * Creates an ObjectInputStream that deserializes a stream of objects from an InputStream using XStream. + * Creates an ObjectInputStream that deserializes a stream of objects from an InputStream + * using XStream. * * @see #createObjectInputStream(com.thoughtworks.xstream.io.HierarchicalStreamReader) - * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) + * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, + * String) * @since 1.3 */ - public ObjectInputStream createObjectInputStream(final InputStream in) throws IOException { + public ObjectInputStream createObjectInputStream(InputStream in) throws IOException { return createObjectInputStream(hierarchicalStreamDriver.createReader(in)); } /** - * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream.

Example

- * + * Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream. + *

+ * It is necessary to call ObjectInputStream.close() when done, otherwise the stream might keep system resources. + *

+ *

Example

+ * *
      * ObjectInputStream in = xstream.createObjectOutputStream(aReader);
      * int a = out.readInt();
      * Object b = out.readObject();
      * Object c = out.readObject();
      * 
* - * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String) + * @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, + * String) * @since 1.0.3 */ public ObjectInputStream createObjectInputStream(final HierarchicalStreamReader reader) throws IOException { + return createObjectInputStream(reader, null); + } + + /** + * 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() { - @Override public Object readFromStream() throws EOFException { if (!reader.hasMoreChildren()) { throw new EOFException(); } reader.moveDown(); - final Object result = unmarshal(reader); + final Object result = unmarshal(reader, dataHolder); reader.moveUp(); return result; } - @Override - public Map readFieldsFromStream() throws IOException { + public Map readFieldsFromStream() throws IOException { throw new NotActiveException("not in call to readObject"); } - @Override public void defaultReadObject() throws NotActiveException { throw new NotActiveException("not in call to readObject"); } - @Override - public void registerValidation(final ObjectInputValidation validation, final int priority) - throws NotActiveException { + public void registerValidation(ObjectInputValidation validation, int priority) + throws NotActiveException { throw new NotActiveException("stream inactive"); } - @Override public void close() { reader.close(); } }, classLoaderReference); } /** - * Change the ClassLoader XStream uses to load classes. Creating an XStream instance it will register for all kind - * of classes and types of the current JDK, but not for any 3rd party type. To ensure that all other types are - * loaded with your class loader, you should call this method as early as possible - or consider to provide the - * class loader directly in the constructor. + * Change the ClassLoader XStream uses to load classes. Creating an XStream instance it will + * register for all kind of classes and types of the current JDK, but not for any 3rd party + * type. To ensure that all other types are loaded with your class loader, you should call + * this method as early as possible - or consider to provide the class loader directly in + * the constructor. * * @since 1.1.1 */ - public void setClassLoader(final ClassLoader classLoader) { + public void setClassLoader(ClassLoader classLoader) { classLoaderReference.setReference(classLoader); } /** * Retrieve the ClassLoader XStream uses to load classes. - * + * * @since 1.1.1 */ public ClassLoader getClassLoader() { return classLoaderReference.getReference(); } - + /** - * Retrieve the reference to this instance' ClassLoader. Use this reference for other XStream components (like - * converters) to ensure that they will use a changed ClassLoader instance automatically. + * Retrieve the reference to this instance' ClassLoader. Use this reference for other + * XStream components (like converters) to ensure that they will use a changed ClassLoader + * instance automatically. * * @return the reference * @since 1.4.5 @@ -1817,22 +2256,24 @@ } /** - * Prevents a field from being serialized. To omit a field you must always provide the declaring type and not - * necessarily the type that is converted. + * Prevents a field from being serialized. To omit a field you must always provide the + * declaring type and not necessarily the type that is converted. * * @since 1.1.3 - * @throws InitializationException if no {@link FieldAliasingMapper} is available + * @throws InitializationException if no {@link ElementIgnoringMapper} is available */ - public void omitField(final Class definedIn, final String fieldName) { - if (fieldAliasingMapper == null) { - throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available"); + public void omitField(Class definedIn, String fieldName) { + if (elementIgnoringMapper == null) { + throw new com.thoughtworks.xstream.InitializationException("No " + + ElementIgnoringMapper.class.getName() + + " available"); } - fieldAliasingMapper.omitField(definedIn, fieldName); + elementIgnoringMapper.omitField(definedIn, fieldName); } - + /** * Ignore all unknown elements. - * + * * @since 1.4.5 */ public void ignoreUnknownElements() { @@ -1841,217 +2282,276 @@ /** * Add pattern for unknown element names to ignore. - * + * * @param pattern the name pattern as regular expression * @since 1.4.5 */ - public void ignoreUnknownElements(final String pattern) { + public void ignoreUnknownElements(String pattern) { ignoreUnknownElements(Pattern.compile(pattern)); } /** * Add pattern for unknown element names to ignore. - * + * * @param pattern the name pattern as regular expression * @since 1.4.5 */ - private void ignoreUnknownElements(final Pattern pattern) { - if (fieldAliasingMapper == null) { - throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available"); + public void ignoreUnknownElements(final Pattern pattern) { + if (elementIgnoringMapper == null) { + throw new com.thoughtworks.xstream.InitializationException("No " + + ElementIgnoringMapper.class.getName() + + " available"); } - fieldAliasingMapper.addFieldsToIgnore(pattern); + elementIgnoringMapper.addElementsToIgnore(pattern); } /** * Process the annotations of the given types and configure the XStream. - * + * * @param types the types with XStream annotations * @since 1.3 */ - public void processAnnotations(final Class... types) { - if (annotationMapper == null) { - throw new InitializationException("No " + AnnotationMapper.class.getName() + " available"); + public void processAnnotations(final Class[] types) { + if (annotationConfiguration == null) { + throw new com.thoughtworks.xstream.InitializationException("No " + + ANNOTATION_MAPPER_TYPE + + " available"); } - annotationMapper.processAnnotations(types); + annotationConfiguration.processAnnotations(types); } /** - * Set the auto-detection mode of the AnnotationMapper. Note that auto-detection implies that the XStream is - * configured while it is processing the XML steams. This is a potential concurrency problem. Also is it technically - * not possible to detect all class aliases at deserialization. You have been warned! + * Process the annotations of the given type and configure the XStream. A call of this + * method will automatically turn the auto-detection mode for annotations off. * + * @param type the type with XStream annotations + * @since 1.3 + */ + public void processAnnotations(final Class type) { + processAnnotations(new Class[]{type}); + } + + /** + * Set the auto-detection mode of the AnnotationMapper. Note that auto-detection implies + * that the XStream is configured while it is processing the XML steams. This is a potential + * concurrency problem. Also is it technically not possible to detect all class aliases at + * deserialization. You have been warned! + * * @param mode true if annotations are auto-detected * @since 1.3 */ - public void autodetectAnnotations(final boolean mode) { - if (annotationMapper != null) { - annotationMapper.autodetectAnnotations(mode); + public void autodetectAnnotations(boolean mode) { + if (annotationConfiguration != null) { + annotationConfiguration.autodetectAnnotations(mode); } } - + /** * Add a new security permission. + * *

* Permissions are evaluated in the added sequence. An instance of {@link NoTypePermission} or * {@link AnyTypePermission} will implicitly wipe any existing permission. *

- * + * * @param permission the permission to add * @since 1.4.7 */ - public void addPermission(final TypePermission permission) { + public void addPermission(TypePermission permission) { if (securityMapper != null) { + insecureWarning &= permission != NoTypePermission.NONE; securityMapper.addPermission(permission); } } - + /** * Add security permission for explicit types by name. - * + * * @param names the type names to allow * @since 1.4.7 */ - public void allowTypes(final String... names) { + public void allowTypes(String[] names) { addPermission(new ExplicitTypePermission(names)); } - + /** * Add security permission for explicit types. - * + * * @param types the types to allow * @since 1.4.7 */ - public void allowTypes(final Class... types) { + public void allowTypes(Class[] types) { addPermission(new ExplicitTypePermission(types)); } - + /** * Add security permission for a type hierarchy. - * + * * @param type the base type to allow * @since 1.4.7 */ - public void allowTypeHierarchy(final Class type) { + public void allowTypeHierarchy(Class type) { addPermission(new TypeHierarchyPermission(type)); } - + /** * Add security permission for types matching one of the specified regular expressions. - * + * * @param regexps the regular expressions to allow type names * @since 1.4.7 */ - public void allowTypesByRegExp(final String... regexps) { + public void allowTypesByRegExp(String[] regexps) { addPermission(new RegExpTypePermission(regexps)); } - + /** * Add security permission for types matching one of the specified regular expressions. - * + * * @param regexps the regular expressions to allow type names * @since 1.4.7 */ - public void allowTypesByRegExp(final Pattern... regexps) { + public void allowTypesByRegExp(Pattern[] regexps) { addPermission(new RegExpTypePermission(regexps)); } - + /** * Add security permission for types matching one of the specified wildcard patterns. *

* Supported are patterns with path expressions using dot as separator: *

*
    *
  • ?: one non-control character except separator, e.g. for 'java.net.Inet?Address'
  • - *
  • *: arbitrary number of non-control characters except separator, e.g. for types in a package like - * 'java.lang.*'
  • - *
  • **: arbitrary number of non-control characters including separator, e.g. for types in a package and - * subpackages like 'java.lang.**'
  • + *
  • *: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'
  • + *
  • **: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'
  • *
- * + * * @param patterns the patterns to allow type names * @since 1.4.7 */ - public void allowTypesByWildcard(final String... patterns) { + public void allowTypesByWildcard(String[] patterns) { addPermission(new WildcardTypePermission(patterns)); } - + /** * Add security permission denying another one. - * + * * @param permission the permission to deny * @since 1.4.7 */ - public void denyPermission(final TypePermission permission) { + public void denyPermission(TypePermission permission) { addPermission(new NoPermission(permission)); } - + /** * Add security permission forbidding explicit types by name. - * + * * @param names the type names to forbid * @since 1.4.7 */ - public void denyTypes(final String... names) { + public void denyTypes(String[] names) { denyPermission(new ExplicitTypePermission(names)); } - + /** * Add security permission forbidding explicit types. - * + * * @param types the types to forbid * @since 1.4.7 */ - public void denyTypes(final Class... types) { + public void denyTypes(Class[] types) { denyPermission(new ExplicitTypePermission(types)); } - + /** * Add security permission forbidding a type hierarchy. - * + * * @param type the base type to forbid * @since 1.4.7 */ - public void denyTypeHierarchy(final Class type) { + public void denyTypeHierarchy(Class type) { denyPermission(new TypeHierarchyPermission(type)); } - + /** * Add security permission forbidding types matching one of the specified regular expressions. - * + * * @param regexps the regular expressions to forbid type names * @since 1.4.7 */ - public void denyTypesByRegExp(final String... regexps) { + public void denyTypesByRegExp(String[] regexps) { denyPermission(new RegExpTypePermission(regexps)); } - + /** * Add security permission forbidding types matching one of the specified regular expressions. - * + * * @param regexps the regular expressions to forbid type names * @since 1.4.7 */ - public void denyTypesByRegExp(final Pattern... regexps) { + public void denyTypesByRegExp(Pattern[] regexps) { denyPermission(new RegExpTypePermission(regexps)); } - + /** * Add security permission forbidding types matching one of the specified wildcard patterns. *

* Supported are patterns with path expressions using dot as separator: *

*
    *
  • ?: one non-control character except separator, e.g. for 'java.net.Inet?Address'
  • - *
  • *: arbitrary number of non-control characters except separator, e.g. for types in a package like - * 'java.lang.*'
  • - *
  • **: arbitrary number of non-control characters including separator, e.g. for types in a package and - * subpackages like 'java.lang.**'
  • + *
  • *: arbitrary number of non-control characters except separator, e.g. for types in a package like 'java.lang.*'
  • + *
  • **: arbitrary number of non-control characters including separator, e.g. for types in a package and subpackages like 'java.lang.**'
  • *
- * + * * @param patterns the patterns to forbid names * @since 1.4.7 */ - public void denyTypesByWildcard(final String... patterns) { + public void denyTypesByWildcard(String[] patterns) { denyPermission(new WildcardTypePermission(patterns)); } + + /** + * @deprecated As of 1.3, use {@link com.thoughtworks.xstream.InitializationException} + * instead + */ + public static class InitializationException extends XStreamException { + /** + * @deprecated As of 1.3, use + * {@link com.thoughtworks.xstream.InitializationException#InitializationException(String, Throwable)} + * instead + */ + public InitializationException(String message, Throwable cause) { + super(message, cause); + } + + /** + * @deprecated As of 1.3, use + * {@link com.thoughtworks.xstream.InitializationException#InitializationException(String)} + * instead + */ + public InitializationException(String message) { + super(message); + } + } + + private class InternalBlackList implements Converter { + + public boolean canConvert(final Class type) { + return (type == void.class || type == Void.class) + || (insecureWarning + && type != null + && (type.getName().equals("java.beans.EventHandler") + || type.getName().endsWith("$LazyIterator") + || type.getName().startsWith("javax.crypto."))); + } + + public void marshal(final Object source, final HierarchicalStreamWriter writer, + final MarshallingContext context) { + throw new ConversionException("Security alert. Marshalling rejected."); + } + + public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + throw new ConversionException("Security alert. Unmarshalling rejected."); + } + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamException.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamException.java (.../XStreamException.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamException.java (.../XStreamException.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2013 XStream Committers. + * Copyright (C) 2007, 2008, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,15 +10,17 @@ */ package com.thoughtworks.xstream; +import com.thoughtworks.xstream.core.BaseException; + /** * Base exception for all thrown exceptions with XStream. * * @author Joe Walnes * @author Jörg Schaible * @since 1.3 */ -public class XStreamException extends RuntimeException { +public class XStreamException extends BaseException { /** * Default constructor. @@ -58,6 +60,6 @@ * @since 1.3 */ public XStreamException(String message, Throwable cause) { - super(message + (cause == null ? "" : " : " + cause.getMessage()), cause); + super(message, cause); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamer.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamer.java (.../XStreamer.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/XStreamer.java (.../XStreamer.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2014, 2016, 2017 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -21,7 +21,6 @@ import javax.xml.datatype.DatatypeFactory; -import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.ConverterLookup; import com.thoughtworks.xstream.converters.ConverterMatcher; import com.thoughtworks.xstream.converters.ConverterRegistry; @@ -33,34 +32,41 @@ import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.io.HierarchicalStreamDriver; import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.naming.NameCoder; import com.thoughtworks.xstream.io.xml.XppDriver; import com.thoughtworks.xstream.mapper.Mapper; +import com.thoughtworks.xstream.security.AnyTypePermission; import com.thoughtworks.xstream.security.TypeHierarchyPermission; import com.thoughtworks.xstream.security.TypePermission; import com.thoughtworks.xstream.security.WildcardTypePermission; - /** - * Self-contained XStream generator. The class is a utility to write XML streams that contain additionally the XStream - * that was used to serialize the object graph. Such a stream can be unmarshalled using this embedded XStream instance, - * that kept any settings. + * Self-contained XStream generator. The class is a utility to write XML streams that contain + * additionally the XStream that was used to serialize the object graph. Such a stream can + * be unmarshalled using this embedded XStream instance, that kept any settings. * * @author Jörg Schaible * @since 1.2 */ public class XStreamer { private final static TypePermission[] PERMISSIONS = { - new TypeHierarchyPermission(ConverterMatcher.class), new TypeHierarchyPermission(Mapper.class), - new TypeHierarchyPermission(XStream.class), new TypeHierarchyPermission(ReflectionProvider.class), - new TypeHierarchyPermission(JavaBeanProvider.class), new TypeHierarchyPermission(FieldKeySorter.class), - new TypeHierarchyPermission(ConverterLookup.class), new TypeHierarchyPermission(ConverterRegistry.class), + new TypeHierarchyPermission(ConverterMatcher.class), + new TypeHierarchyPermission(Mapper.class), + new TypeHierarchyPermission(XStream.class), + new TypeHierarchyPermission(ReflectionProvider.class), + new TypeHierarchyPermission(JavaBeanProvider.class), + new TypeHierarchyPermission(FieldKeySorter.class), + new TypeHierarchyPermission(ConverterLookup.class), + new TypeHierarchyPermission(ConverterRegistry.class), new TypeHierarchyPermission(HierarchicalStreamDriver.class), - new TypeHierarchyPermission(MarshallingStrategy.class), new TypeHierarchyPermission(MarshallingContext.class), - new TypeHierarchyPermission(UnmarshallingContext.class), new TypeHierarchyPermission(NameCoder.class), + new TypeHierarchyPermission(MarshallingStrategy.class), + new TypeHierarchyPermission(MarshallingContext.class), + new TypeHierarchyPermission(UnmarshallingContext.class), + new TypeHierarchyPermission(NameCoder.class), new TypeHierarchyPermission(TypePermission.class), - new WildcardTypePermission(JVM.class.getPackage().getName() + ".**"), + new WildcardTypePermission(new String[]{JVM.class.getPackage().getName()+".**"}), new TypeHierarchyPermission(DatatypeFactory.class) // required by DurationConverter }; @@ -79,27 +85,30 @@ } catch (final ObjectStreamException e) { throw e; } catch (final IOException e) { - throw new ConversionException("Unexpected IO error from a StringWriter", e); + throw new StreamException("Unexpected IO error from a StringWriter", e); } return writer.toString(); } /** * Serialize an object including the XStream to the given Writer as pretty-printed XML. *

- * Warning: XStream will serialize itself into this XML stream. To read such an XML code, you should use - * {@link XStreamer#fromXML(Reader)} or one of the other overloaded methods. Since a lot of internals are written - * into the stream, you cannot expect to use such an XML to work with another XStream version or with XStream - * running on different JDKs and/or versions. We have currently no JDK 1.3 support, nor will the - * PureReflectionConverter work with a JDK less than 1.5. + * Warning: XStream will serialize itself into this XML stream. To read such an XML code, you + * should use {@link XStreamer#fromXML(Reader)} or one of the other overloaded + * methods. Since a lot of internals are written into the stream, you cannot expect to use such + * an XML to work with another XStream version or with XStream running on different JDKs and/or + * versions. We have currently no JDK 1.3 support, nor will the PureReflectionConverter work + * with a JDK less than 1.5. *

* * @throws IOException if an error occurs reading from the Writer. * @throws com.thoughtworks.xstream.XStreamException if the object cannot be serialized * @since 1.2 */ - public void toXML(final XStream xstream, final Object obj, final Writer out) throws IOException { + public void toXML(final XStream xstream, final Object obj, final Writer out) + throws IOException { final XStream outer = new XStream(); + XStream.setupDefaultSecurity(outer); final ObjectOutputStream oos = outer.createObjectOutputStream(out); try { oos.writeObject(xstream); @@ -111,8 +120,8 @@ } /** - * Deserialize a self-contained XStream with object from a String. The method will use internally an XppDriver to - * load the contained XStream instance with default permissions. + * Deserialize a self-contained XStream with object from a String. The method will use + * internally an XppDriver to load the contained XStream instance with default permissions. * * @param xml the XML data * @throws ClassNotFoundException if a class in the XML stream cannot be found @@ -121,19 +130,19 @@ * @since 1.2 * @see #toXML(XStream, Object, Writer) */ - public T fromXML(final String xml) throws ClassNotFoundException, ObjectStreamException { + public Object fromXML(final String xml) throws ClassNotFoundException, ObjectStreamException { try { return fromXML(new StringReader(xml)); } catch (final ObjectStreamException e) { throw e; } catch (final IOException e) { - throw new ConversionException("Unexpected IO error from a StringReader", e); + throw new StreamException("Unexpected IO error from a StringReader", e); } } /** - * Deserialize a self-contained XStream with object from a String. The method will use internally an XppDriver to - * load the contained XStream instance. + * Deserialize a self-contained XStream with object from a String. The method will use + * internally an XppDriver to load the contained XStream instance. * * @param xml the XML data * @param permissions the permissions to use (ensure that they include the defaults) @@ -143,14 +152,13 @@ * @since 1.4.7 * @see #toXML(XStream, Object, Writer) */ - public T fromXML(final String xml, final TypePermission... permissions) - throws ClassNotFoundException, ObjectStreamException { + public Object fromXML(final String xml, final TypePermission[] permissions) throws ClassNotFoundException, ObjectStreamException { try { return fromXML(new StringReader(xml), permissions); } catch (final ObjectStreamException e) { throw e; } catch (final IOException e) { - throw new ConversionException("Unexpected IO error from a StringReader", e); + throw new StreamException("Unexpected IO error from a StringReader", e); } } @@ -165,14 +173,14 @@ * @since 1.2 * @see #toXML(XStream, Object, Writer) */ - public T fromXML(final HierarchicalStreamDriver driver, final String xml) + public Object fromXML(final HierarchicalStreamDriver driver, final String xml) throws ClassNotFoundException, ObjectStreamException { try { return fromXML(driver, new StringReader(xml)); } catch (final ObjectStreamException e) { throw e; } catch (final IOException e) { - throw new ConversionException("Unexpected IO error from a StringReader", e); + throw new StreamException("Unexpected IO error from a StringReader", e); } } @@ -188,20 +196,20 @@ * @since 1.4.7 * @see #toXML(XStream, Object, Writer) */ - public T fromXML(final HierarchicalStreamDriver driver, final String xml, final TypePermission... permissions) + public Object fromXML(final HierarchicalStreamDriver driver, final String xml, final TypePermission[] permissions) throws ClassNotFoundException, ObjectStreamException { try { return fromXML(driver, new StringReader(xml), permissions); } catch (final ObjectStreamException e) { throw e; } catch (final IOException e) { - throw new ConversionException("Unexpected IO error from a StringReader", e); + throw new StreamException("Unexpected IO error from a StringReader", e); } } /** - * Deserialize a self-contained XStream with object from an XML Reader. The method will use internally an XppDriver - * to load the contained XStream instance with default permissions. + * Deserialize a self-contained XStream with object from an XML Reader. The method will use + * internally an XppDriver to load the contained XStream instance with default permissions. * * @param xml the {@link Reader} providing the XML data * @throws IOException if an error occurs reading from the Reader. @@ -210,13 +218,14 @@ * @since 1.2 * @see #toXML(XStream, Object, Writer) */ - public T fromXML(final Reader xml) throws IOException, ClassNotFoundException { + public Object fromXML(final Reader xml) + throws IOException, ClassNotFoundException { return fromXML(new XppDriver(), xml); } /** - * Deserialize a self-contained XStream with object from an XML Reader. The method will use internally an XppDriver - * to load the contained XStream instance. + * Deserialize a self-contained XStream with object from an XML Reader. The method will use + * internally an XppDriver to load the contained XStream instance. * * @param xml the {@link Reader} providing the XML data * @param permissions the permissions to use (ensure that they include the defaults) @@ -226,24 +235,24 @@ * @since 1.4.7 * @see #toXML(XStream, Object, Writer) */ - public T fromXML(final Reader xml, final TypePermission... permissions) + public Object fromXML(final Reader xml, final TypePermission[] permissions) throws IOException, ClassNotFoundException { return fromXML(new XppDriver(), xml, permissions); } /** * Deserialize a self-contained XStream with object from an XML Reader. - * + * * @param driver the implementation to use * @param xml the {@link Reader} providing the XML data * @throws IOException if an error occurs reading from the Reader. * @throws ClassNotFoundException if a class in the XML stream cannot be found * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized * @since 1.2 */ - public T fromXML(final HierarchicalStreamDriver driver, final Reader xml) + public Object fromXML(final HierarchicalStreamDriver driver, final Reader xml) throws IOException, ClassNotFoundException { - return fromXML(driver, xml, PERMISSIONS); + return fromXML(driver, xml, new TypePermission[]{AnyTypePermission.ANY}); } /** @@ -257,21 +266,20 @@ * @throws com.thoughtworks.xstream.XStreamException if the object cannot be deserialized * @since 1.4.7 */ - public T fromXML(final HierarchicalStreamDriver driver, final Reader xml, final TypePermission... permissions) + public Object fromXML(final HierarchicalStreamDriver driver, final Reader xml, final TypePermission[] permissions) throws IOException, ClassNotFoundException { final XStream outer = new XStream(driver); - for (final TypePermission permission : permissions) { - outer.addPermission(permission); + XStream.setupDefaultSecurity(outer); + for(int i = 0; i < permissions.length; ++i) { + outer.addPermission(permissions[i]); } final HierarchicalStreamReader reader = driver.createReader(xml); final ObjectInputStream configIn = outer.createObjectInputStream(reader); try { final XStream configured = (XStream)configIn.readObject(); final ObjectInputStream in = configured.createObjectInputStream(reader); try { - @SuppressWarnings("unchecked") - final T t = (T)in.readObject(); - return t; + return in.readObject(); } finally { in.close(); } @@ -290,6 +298,6 @@ * @since 1.4.7 */ public static TypePermission[] getDefaultPermissions() { - return PERMISSIONS.clone(); + return (TypePermission[])PERMISSIONS.clone(); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationProvider.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationProvider.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationProvider.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 02. March 2006 by Mauro Talevi + */ +package com.thoughtworks.xstream.annotations; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + + +/** + * An utility class to provide annotations from different sources + * + * @author Guilherme Silveira + * @deprecated As of 1.3 + */ +@Deprecated +public class AnnotationProvider { + + /** + * Returns a field annotation based on an annotation type + * + * @param field the annotation Field + * @param annotationClass the annotation Class + * @return The Annotation type + * @deprecated As of 1.3 + */ + @Deprecated + public T getAnnotation(Field field, Class annotationClass) { + return field.getAnnotation(annotationClass); + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationReflectionConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationReflectionConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/AnnotationReflectionConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 02. March 2006 by Mauro Talevi + */ +package com.thoughtworks.xstream.annotations; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +import com.thoughtworks.xstream.converters.Converter; +import com.thoughtworks.xstream.converters.ConverterMatcher; +import com.thoughtworks.xstream.converters.MarshallingContext; +import com.thoughtworks.xstream.converters.SingleValueConverter; +import com.thoughtworks.xstream.converters.SingleValueConverterWrapper; +import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; +import com.thoughtworks.xstream.converters.reflection.ReflectionConverter; +import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; +import com.thoughtworks.xstream.mapper.Mapper; + + +/** + * ReflectionConverter which uses an AnnotationProvider to marshall and unmarshall fields based + * on the annotated converters. + * + * @author Guilherme Silveira + * @author Mauro Talevi + * @deprecated As of 1.3, build into {@link ReflectionConverter} + */ +@Deprecated +public class AnnotationReflectionConverter extends ReflectionConverter { + + private final AnnotationProvider annotationProvider; + + private final Map, Converter> cachedConverters; + + @Deprecated + public AnnotationReflectionConverter( + Mapper mapper, ReflectionProvider reflectionProvider, + AnnotationProvider annotationProvider) { + super(mapper, reflectionProvider); + this.annotationProvider = annotationProvider; + this.cachedConverters = new HashMap, Converter>(); + } + + protected void marshallField(final MarshallingContext context, Object newObj, Field field) { + XStreamConverter annotation = annotationProvider.getAnnotation( + field, XStreamConverter.class); + if (annotation != null) { + Class type = annotation.value(); + ensureCache(type); + context.convertAnother(newObj, cachedConverters.get(type)); + } else { + context.convertAnother(newObj); + } + } + + private void ensureCache(Class type) { + if (!this.cachedConverters.containsKey(type)) { + cachedConverters.put(type, newInstance(type)); + } + } + + protected Object unmarshallField( + final UnmarshallingContext context, final Object result, + Class type, Field field) { + XStreamConverter annotation = annotationProvider.getAnnotation( + field, XStreamConverter.class); + if (annotation != null) { + Class converterType = (Class)annotation.value(); + ensureCache(converterType); + return context.convertAnother(result, type, cachedConverters.get(converterType)); + } else { + return context.convertAnother(result, type); + } + } + + /** + * Instantiates a converter using its default constructor. + * + * @param type the converter type to instantiate + * @return the new instance + */ + private Converter newInstance(Class type) { + Converter converter; + // TODO: We need a separate exception for runtime initialization. + try { + if (SingleValueConverter.class.isAssignableFrom(type)) { + final SingleValueConverter svc = (SingleValueConverter)type.getConstructor().newInstance(); + converter = new SingleValueConverterWrapper(svc); + } else { + converter = (Converter)type.getConstructor().newInstance(); + } + } catch (InvocationTargetException e) { + throw new ObjectAccessException("Cannot construct " + type.getName(), e + .getCause()); + } catch (InstantiationException e) { + throw new ObjectAccessException("Cannot construct " + type.getName(), e); + } catch (IllegalAccessException e) { + throw new ObjectAccessException("Cannot construct " + type.getName(), e); + } catch (NoSuchMethodException e) { + throw new ObjectAccessException("Cannot construct " + type.getName(), e); + } + return converter; + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/Annotations.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/Annotations.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/Annotations.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2005 Joe Walnes. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 11. August 2005 by Mauro Talevi + */ +package com.thoughtworks.xstream.annotations; + +import com.thoughtworks.xstream.XStream; + + +/** + * Contains utility methods that enable to configure an XStream instance with class and field + * aliases, based on a class decorated with annotations defined in this package. + * + * @author Emil Kirschner + * @author Chung-Onn Cheong + * @author Guilherme Silveira + * @author Jörg Schaible + * @deprecated As of 1.3, use {@link XStream#processAnnotations(Class[])} + */ +@Deprecated +public class Annotations { + /** + * This class is not instantiable + */ + private Annotations() { + } + + /** + * Configures aliases on the specified XStream object based on annotations that decorate the + * specified class. It will recursively invoke itself. If a field is parameterized, a + * recursive call for each of its parameters type will be made. + * + * @param topLevelClasses the class for which the XStream object is configured. This class + * is expected to be decorated with annotations defined in this package. + * @param xstream the XStream object that will be configured + * @deprecated As of 1.3, use {@link XStream#processAnnotations(Class[])} + */ + @Deprecated + public static synchronized void configureAliases(XStream xstream, + Class ... topLevelClasses) { + xstream.processAnnotations(topLevelClasses); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamContainedType.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamContainedType.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamContainedType.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2005 Joe Walnes. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 11. August 2005 by Mauro Talevi + */ +package com.thoughtworks.xstream.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation used to notify Annotations.configureAliases that it should recursively invoke itself for + * all parameterized types of this field. + * + * @author Emil Kirschner + * @author Chung-Onn Cheong + * @deprecated As of 1.3, recursive behaviour is now always used and the annotation is therefore superfluous + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@Deprecated +public @interface XStreamContainedType { + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamConverter.java (.../XStreamConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamConverter.java (.../XStreamConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -106,4 +106,12 @@ double[] doubles() default {}; boolean[] booleans() default {}; + + /** + * Provide null types as arguments for the converter's constructor arguments. + * + * @return the types provided as null values + * @since 1.4.9 + */ + Class[] nulls() default {}; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamImplicitCollection.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamImplicitCollection.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/annotations/XStreamImplicitCollection.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005 Joe Walnes. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 16. September 2005 by Mauro Talevi + */ +package com.thoughtworks.xstream.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author Chung-Onn Cheong + * @deprecated As of 1.3, use @XStreamImplicit at field level + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface XStreamImplicitCollection { + String value(); //fieldName + String item() default ""; //itemfieldName +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConversionException.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConversionException.java (.../ConversionException.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConversionException.java (.../ConversionException.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,106 +11,29 @@ */ package com.thoughtworks.xstream.converters; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -import com.thoughtworks.xstream.XStreamException; - - /** - * Thrown by {@link Converter} implementations when they cannot convert an object to/from textual data. When this - * exception is thrown it can be passed around to things that accept an {@link ErrorWriter}, allowing them to add - * diagnostics to the stack trace. - * + * Thrown by {@link Converter} implementations when they cannot convert an object + * to/from textual data. + * + * When this exception is thrown it can be passed around to things that accept an + * {@link ErrorWriter}, allowing them to add diagnostics to the stack trace. + * * @author Joe Walnes * @author Jörg Schaible + * * @see ErrorWriter */ -public class ConversionException extends XStreamException implements ErrorWriter { +public class ConversionException extends ErrorWritingException { - private static final String SEPARATOR = "\n-------------------------------"; - private final Map stuff = new LinkedHashMap(); - - public ConversionException(final String msg, final Throwable cause) { + public ConversionException(String msg, Throwable cause) { super(msg, cause); - if (msg != null) { - add("message", msg); - } - if (cause != null) { - add("cause-exception", cause.getClass().getName()); - add("cause-message", cause instanceof ConversionException - ? ((ConversionException)cause).getShortMessage() - : cause.getMessage()); - } } - public ConversionException(final String msg) { + public ConversionException(String msg) { super(msg); } - public ConversionException(final Throwable cause) { - this(cause.getMessage(), cause); + public ConversionException(Throwable cause) { + super(cause); } - - @Override - public String get(final String errorKey) { - return stuff.get(errorKey); - } - - @Override - public void add(final String name, final String information) { - String key = name; - int i = 0; - while (stuff.containsKey(key)) { - final String value = stuff.get(key); - if (information.equals(value)) { - return; - } - key = name + "[" + ++i + "]"; - } - stuff.put(key, information); - } - - @Override - public void set(final String name, final String information) { - String key = name; - int i = 0; - stuff.put(key, information); // keep order - while (stuff.containsKey(key)) { - if (i != 0) { - stuff.remove(key); - } - key = name + "[" + ++i + "]"; - } - } - - @Override - public Iterator keys() { - return stuff.keySet().iterator(); - } - - @Override - public String getMessage() { - final StringBuilder result = new StringBuilder(); - if (super.getMessage() != null) { - result.append(super.getMessage()); - } - if (!result.toString().endsWith(SEPARATOR)) { - result.append("\n---- Debugging information ----"); - } - for (final Iterator iterator = keys(); iterator.hasNext();) { - final String k = iterator.next(); - final String v = get(k); - result.append('\n').append(k); - result.append(" ".substring(Math.min(20, k.length()))); - result.append(": ").append(v); - } - result.append(SEPARATOR); - return result.toString(); - } - - public String getShortMessage() { - return super.getMessage(); - } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/Converter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/Converter.java (.../Converter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/Converter.java (.../Converter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,30 +14,29 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; - /** - * Converter implementations are responsible marshalling Java objects to/from textual data. - *

- * If an exception occurs during processing, a {@link ConversionException} should be thrown. - *

- *

- * If working with the high level {@link com.thoughtworks.xstream.XStream} facade, you can register new converters using - * the XStream.registerConverter() method. - *

- *

- * If working with the lower level API, the {@link com.thoughtworks.xstream.converters.ConverterLookup} implementation - * is responsible for looking up the appropriate converter. - *

- *

- * Converters for object that can store all information in a single value should implement - * {@link com.thoughtworks.xstream.converters.SingleValueConverter}. - * {@link com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter} provides a starting point. - *

- *

- * {@link com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter} provides a starting point for - * objects that hold a collection of other objects (such as Lists and Maps). - *

+ * Converter implementations are responsible marshalling Java objects + * to/from textual data. * + *

If an exception occurs during processing, a {@link ConversionException} + * should be thrown.

+ * + *

If working with the high level {@link com.thoughtworks.xstream.XStream} facade, + * you can register new converters using the XStream.registerConverter() method.

+ * + *

If working with the lower level API, the + * {@link com.thoughtworks.xstream.converters.ConverterLookup} implementation is + * responsible for looking up the appropriate converter.

+ * + *

Converters for object that can store all information in a single value + * should implement {@link com.thoughtworks.xstream.converters.SingleValueConverter}. + * {@link com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter} + * provides a starting point.

+ * + *

{@link com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter} + * provides a starting point for objects that hold a collection of other objects + * (such as Lists and Maps).

+ * * @author Joe Walnes * @see com.thoughtworks.xstream.XStream * @see com.thoughtworks.xstream.converters.ConverterLookup @@ -48,19 +47,19 @@ /** * Convert an object to textual data. - * - * @param source the object to be marshalled. - * @param writer a stream to write to. - * @param context a context that allows nested objects to be processed by XStream. + * + * @param source The object to be marshalled. + * @param writer A stream to write to. + * @param context A context that allows nested objects to be processed by XStream. */ void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context); /** * Convert textual data back into an object. - * - * @param reader the stream to read the text from. - * @param context a context that allows nested objects to be processed by XStream. - * @return the resulting object. + * + * @param reader The stream to read the text from. + * @param context + * @return The resulting object. */ Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterLookup.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterLookup.java (.../ConverterLookup.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterLookup.java (.../ConverterLookup.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,7 +13,7 @@ /** * Responsible for looking up the correct Converter implementation for a specific type. - * + * * @author Joe Walnes * @see Converter */ @@ -22,9 +22,9 @@ /** * Lookup a converter for a specific type. *

- * This type may be any Class, including primitive and array types. It may also be null, signifying the value to be - * converted is a null type. + * This type may be any Class, including primitive and array types. It may also be null, signifying + * the value to be converted is a null type. *

*/ - Converter lookupConverterForType(Class type); + Converter lookupConverterForType(Class type); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterMatcher.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterMatcher.java (.../ConverterMatcher.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ConverterMatcher.java (.../ConverterMatcher.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,8 +11,9 @@ package com.thoughtworks.xstream.converters; /** - * ConverterMatcher allows to match converters to classes by determining if a given type can be converted by the - * converter instance. ConverterMatcher is the base interface of any converter. + * ConverterMatcher allows to match converters to classes by + * determining if a given type can be converted by the converter instance. + * ConverterMatcher is the base interface of any converter. * * @author Joe Walnes * @author Jörg Schaible @@ -24,10 +25,9 @@ public interface ConverterMatcher { /** - * Determines whether the converter can marshal a particular type. - * + * Determines whether the converter can marshall a particular type. * @param type the Class representing the object type to be converted */ - boolean canConvert(Class type); + boolean canConvert(Class type); -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/DataHolder.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/DataHolder.java (.../DataHolder.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/DataHolder.java (.../DataHolder.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,17 +13,15 @@ import java.util.Iterator; - /** * Holds generic data, to be used as seen fit by the user. - * + * * @author Joe Walnes */ public interface DataHolder { Object get(Object key); - void put(Object key, Object value); + Iterator keys(); - Iterator keys(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ErrorWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ErrorWriter.java (.../ErrorWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ErrorWriter.java (.../ErrorWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,30 +13,30 @@ import java.util.Iterator; - /** - * To aid debugging, some components are passed an ErrorWriter when things go wrong, allowing them to add information to - * the error message that may be helpful to diagnose problems. - * + * To aid debugging, some components are passed an ErrorWriter + * when things go wrong, allowing them to add information + * to the error message that may be helpful to diagnose problems. + * * @author Joe Walnes * @author Jörg Schaible */ public interface ErrorWriter { /** - * Add some information to the error message. The information will be added even if the identifier is already in - * use. - * - * @param name something to identify the type of information (e.g. 'XPath'). + * Add some information to the error message. The information will be added even + * if the identifier is already in use. + * + * @param name something to identify the type of information (e.g. 'XPath'). * @param information detail of the message (e.g. '/blah/moo[3]' */ void add(String name, String information); /** - * Set some information to the error message. If the identifier is already in use, the new information will replace - * the old one. - * - * @param name something to identify the type of information (e.g. 'XPath'). + * Set some information to the error message. If the identifier is already in use, the + * new information will replace the old one. + * + * @param name something to identify the type of information (e.g. 'XPath'). * @param information detail of the message (e.g. '/blah/moo[3]' * @since 1.4 */ @@ -57,5 +57,5 @@ * @return an Iterator * @since 1.3 */ - Iterator keys(); + Iterator keys(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ErrorWritingException.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ErrorWritingException.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/ErrorWritingException.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2003, 2004, 2005 Joe Walnes. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2016 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 24. February 2016 by Joerg Schaible, factored out of ConversionException. + */ +package com.thoughtworks.xstream.converters; + +import java.util.Iterator; +import java.util.Map; + +import com.thoughtworks.xstream.XStreamException; +import com.thoughtworks.xstream.core.util.OrderRetainingMap; + + +/** + * Abstract base class for exceptions supporting an ErrorWriter. It can be passed around to things accepting an + * ErrorWriter to add diagnostics. + * + * @author Jörg Schaible + * @see ErrorWriter + * @since 1.4.9 + */ +public abstract class ErrorWritingException extends XStreamException implements ErrorWriter { + + private static final String SEPARATOR = "\n-------------------------------"; + private final Map stuff = new OrderRetainingMap(); + + /** + * Constructs a ErrorWritingException. + * + * @param message the error message + * @since 1.4.9 + */ + public ErrorWritingException(String message) { + super(message); + addData(message, null); + } + + /** + * Constructs a ErrorWritingException. + * + * @param cause the causing exception + * @since 1.4.9 + */ + public ErrorWritingException(Throwable cause) { + super(cause); + addData(null, cause); + } + + /** + * Constructs a ErrorWritingException. + * + * @param message the error message + * @param cause the causing exception + * @since 1.4.9 + */ + public ErrorWritingException(String message, Throwable cause) { + super(message, cause); + addData(message, cause); + } + + private void addData(String msg, Throwable cause) { + if (msg != null) { + add("message", msg); + } + if (cause != null) { + add("cause-exception", cause.getClass().getName()); + add("cause-message", cause instanceof ErrorWritingException ? ((ErrorWritingException)cause).getShortMessage() : cause.getMessage()); + } + } + + public String get(String errorKey) { + return (String) stuff.get(errorKey); + } + + public void add(String name, String information) { + String key = name; + int i = 0; + while (stuff.containsKey(key)) { + String value = (String)stuff.get(key); + if (information.equals(value)) + return; + key = name + "[" + ++i +"]"; + } + stuff.put(key, information); + } + + public void set(String name, String information) { + String key = name; + int i = 0; + stuff.put(key, information); // keep order + while (stuff.containsKey(key)) { + if (i != 0) { + stuff.remove(key); + } + key = name + "[" + ++i +"]"; + } + } + + public Iterator keys() { + return stuff.keySet().iterator(); + } + + public String getMessage() { + StringBuffer result = new StringBuffer(); + if (super.getMessage() != null) { + result.append(super.getMessage()); + } + if (!result.toString().endsWith(SEPARATOR)) { + result.append("\n---- Debugging information ----"); + } + for (Iterator iterator = keys(); iterator.hasNext();) { + String k = (String) iterator.next(); + String v = get(k); + result.append('\n').append(k); + result.append(" ".substring(Math.min(20, k.length()))); + result.append(": ").append(v); + } + result.append(SEPARATOR); + return result.toString(); + } + + public String getShortMessage() { + return super.getMessage(); + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/SingleValueConverterWrapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/SingleValueConverterWrapper.java (.../SingleValueConverterWrapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/SingleValueConverterWrapper.java (.../SingleValueConverterWrapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -13,11 +13,10 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; - /** - * Wrapper to convert a {@link com.thoughtworks.xstream.converters.SingleValueConverter} into a + * Wrapper to convert a {@link com.thoughtworks.xstream.converters.SingleValueConverter} into a * {@link com.thoughtworks.xstream.converters.Converter}. - * + * * @author Jörg Schaible * @see com.thoughtworks.xstream.converters.Converter * @see com.thoughtworks.xstream.converters.SingleValueConverter @@ -26,37 +25,31 @@ private final SingleValueConverter wrapped; - public SingleValueConverterWrapper(final SingleValueConverter wrapped) { + public SingleValueConverterWrapper(SingleValueConverter wrapped) { this.wrapped = wrapped; } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return wrapped.canConvert(type); } - @Override - public String toString(final Object obj) { + public String toString(Object obj) { return wrapped.toString(obj); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return wrapped.fromString(str); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { writer.setValue(toString(source)); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { return fromString(reader.getValue()); } - @Override - public void appendErrors(final ErrorWriter errorWriter) { + public void appendErrors(ErrorWriter errorWriter) { errorWriter.add("wrapped-converter", wrapped == null ? "(null)" : wrapped.getClass().getName()); if (wrapped instanceof ErrorReporter) { ((ErrorReporter)wrapped).appendErrors(errorWriter); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/UnmarshallingContext.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/UnmarshallingContext.java (.../UnmarshallingContext.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/UnmarshallingContext.java (.../UnmarshallingContext.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,43 +13,17 @@ public interface UnmarshallingContext extends DataHolder { - /** - * Convert a nested object of given type. - * - * @param current the current instance (can be {@code null}) - * @param type the expected type of the nested object - * @return the unmarshalled object - */ - Object convertAnother(Object current, Class type); + Object convertAnother(Object current, Class type); /** - * Convert a nested object of given type with a specified converter. - * - * @param current the current instance (can be {@code null}) - * @param type the expected type of the nested object - * @param converter the converter to use (special cases only) - * @return the unmarshalled object * @since 1.2 */ - Object convertAnother(Object current, Class type, Converter converter); + Object convertAnother(Object current, Class type, Converter converter); - /** - * Retrieve the given root object. - * - *

This method will return only an object, if the parent object is root and the root was provided.

- * - * @return the root object or {@code null} - * @see com.thoughtworks.xstream.XStream#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader, Object, DataHolder) - */ Object currentObject(); - /** - * Retrieve the required type for the current conversion. - * - * @return the class type - */ - Class getRequiredType(); + Class getRequiredType(); void addCompletionCallback(Runnable work, int priority); - + } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/AbstractSingleValueConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/AbstractSingleValueConverter.java (.../AbstractSingleValueConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/AbstractSingleValueConverter.java (.../AbstractSingleValueConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,29 +12,24 @@ import com.thoughtworks.xstream.converters.SingleValueConverter; - /** - * Base abstract implementation of {@link SingleValueConverter}. - *

- * Subclasses should implement methods canConvert(Class) and fromString(String) for the conversion. - *

- * + * Base abstract implementation of {@link com.thoughtworks.xstream.converters.SingleValueConverter}. + * + *

Subclasses should implement methods canConvert(Class) and fromString(String) for the conversion.

+ * * @author Joe Walnes * @author Jörg Schaible * @author Mauro Talevi * @see com.thoughtworks.xstream.converters.SingleValueConverter */ public abstract class AbstractSingleValueConverter implements SingleValueConverter { - @Override - public abstract boolean canConvert(Class type); + public abstract boolean canConvert(Class type); - @Override - public String toString(final Object obj) { + public String toString(Object obj) { return obj == null ? null : obj.toString(); } - @Override public abstract Object fromString(String str); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/BigDecimalConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/BigDecimalConverter.java (.../BigDecimalConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/BigDecimalConverter.java (.../BigDecimalConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,21 +13,19 @@ import java.math.BigDecimal; - /** - * Converts a {@link BigDecimal} to a string, retaining its precision. - * + * Converts a java.math.BigDecimal to a String, retaining + * its precision. + * * @author Joe Walnes */ public class BigDecimalConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(BigDecimal.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return new BigDecimal(str); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/BigIntegerConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/BigIntegerConverter.java (.../BigIntegerConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/BigIntegerConverter.java (.../BigIntegerConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,21 +13,18 @@ import java.math.BigInteger; - /** - * Converts a {@link BigInteger} to a string. - * + * Converts a java.math.BigInteger to a String. + * * @author Joe Walnes */ public class BigIntegerConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(BigInteger.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return new BigInteger(str); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/BooleanConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/BooleanConverter.java (.../BooleanConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/BooleanConverter.java (.../BooleanConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -11,9 +11,11 @@ */ package com.thoughtworks.xstream.converters.basic; + /** - * Converts a boolean primitive or {@link Boolean} wrapper to a string. - * + * Converts a boolean primitive or java.lang.Boolean wrapper to + * a String. + * * @author Joe Walnes * @author David Blevins */ @@ -40,19 +42,16 @@ } /** - * @deprecated As of upcoming use {@link #canConvert(Class)} + * @deprecated As of 1.4.8 use {@link #canConvert(Class)} */ - @Deprecated - public boolean shouldConvert(final Class type, final Object value) { + public boolean shouldConvert(final Class type, final Object value) { return true; } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(final Class type) { return type.equals(boolean.class) || type.equals(Boolean.class); } - @Override public Object fromString(final String str) { if (caseSensitive) { return positive.equals(str) ? Boolean.TRUE : Boolean.FALSE; @@ -61,9 +60,8 @@ } } - @Override public String toString(final Object obj) { - final Boolean value = (Boolean)obj; + final Boolean value = (Boolean) obj; return obj == null ? null : value.booleanValue() ? positive : negative; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/ByteConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/ByteConverter.java (.../ByteConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/ByteConverter.java (.../ByteConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,24 +12,22 @@ package com.thoughtworks.xstream.converters.basic; /** - * Converts a byte primitive or {@link Byte} wrapper to - * a string. + * Converts a byte primitive or java.lang.Byte wrapper to + * a String. * * @author Joe Walnes */ public class ByteConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(byte.class) || type.equals(Byte.class); } - @Override - public Object fromString(final String str) { - final int value = Integer.decode(str).intValue(); - if(value < Byte.MIN_VALUE || value > 0xFF) { - throw new NumberFormatException("For input string: \"" + str + '"'); - } + public Object fromString(String str) { + int value = Integer.decode(str).intValue(); + if(value < Byte.MIN_VALUE || value > 0xFF) { + throw new NumberFormatException("For input string: \"" + str + '"'); + } return new Byte((byte)value); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/CharConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/CharConverter.java (.../CharConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/CharConverter.java (.../CharConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -19,47 +19,41 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; /** - * Converts a char primitive or {@link Character} wrapper to - * a string. If char is '\0' the representing string is empty. + * Converts a char primitive or java.lang.Character wrapper to + * a String. If char is \0 the representing String is empty. * * @author Joe Walnes * @author Jörg Schaible */ public class CharConverter implements Converter, SingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(char.class) || type.equals(Character.class); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Character ch = (Character)source; - writer.setValue(toString(ch)); + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + writer.setValue(toString(source)); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final String nullAttribute = reader.getAttribute("null"); + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + String nullAttribute = reader.getAttribute("null"); if (nullAttribute != null && nullAttribute.equals("true")) { return new Character('\0'); } else { return fromString(reader.getValue()); } } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { if (str.length() == 0) { return new Character('\0'); } else { return new Character(str.charAt(0)); } } - @Override - public String toString(final Object obj) { - final char ch = ((Character)obj).charValue(); + public String toString(Object obj) { + char ch = ((Character)obj).charValue(); return ch == '\0' ? "" : obj.toString(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/DateConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/DateConverter.java (.../DateConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/DateConverter.java (.../DateConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -36,6 +36,11 @@ * is localized since Java 6. *

*

+ * Using a Java 7 runtime or higher, the converter supports the datetime + * format defined by W3C (a subset of ISO 8601) at deserialization. Only the formats that also contain the time + * information. + *

+ *

* Dates in a different era are using a special default pattern that contains the era itself. *

* @@ -51,10 +56,10 @@ private static final long ERA_START; static { UTC = TimeZone.getTimeZone("UTC"); - + final String defaultPattern = "yyyy-MM-dd HH:mm:ss.S z"; final String defaultEraPattern = "yyyy-MM-dd G HH:mm:ss.S z"; - final List acceptablePatterns = new ArrayList(); + final List acceptablePatterns = new ArrayList(); final boolean utcSupported = JVM.canParseUTCDateFormat(); DEFAULT_PATTERN = utcSupported ? defaultPattern : "yyyy-MM-dd HH:mm:ss.S 'UTC'"; DEFAULT_ERA_PATTERN = utcSupported ? defaultEraPattern : "yyyy-MM-dd G HH:mm:ss.S 'UTC'"; @@ -63,21 +68,26 @@ acceptablePatterns.add(defaultPattern); } acceptablePatterns.add("yyyy-MM-dd HH:mm:ss.S a"); - // TODO: JDK 1.3 needs both versions + // JDK 1.3 needs both versions acceptablePatterns.add("yyyy-MM-dd HH:mm:ssz"); acceptablePatterns.add("yyyy-MM-dd HH:mm:ss z"); if (!utcSupported) { acceptablePatterns.add("yyyy-MM-dd HH:mm:ss 'UTC'"); } + if (JVM.canParseISO8601TimeZoneInDateFormat()) { + acceptablePatterns.add("yyyy-MM-dd'T'HH:mm:ss.SX"); + acceptablePatterns.add("yyyy-MM-dd'T'HH:mm:ssX"); + acceptablePatterns.add("yyyy-MM-dd'T'HH:mmX"); + } // backwards compatibility acceptablePatterns.add("yyyy-MM-dd HH:mm:ssa"); - DEFAULT_ACCEPTABLE_FORMATS = acceptablePatterns.toArray(new String[acceptablePatterns.size()]); - + DEFAULT_ACCEPTABLE_FORMATS = (String[]) acceptablePatterns.toArray(new String[acceptablePatterns.size()]); + final Calendar cal = Calendar.getInstance(); cal.setTimeZone(UTC); cal.clear(); cal.set(1, Calendar.JANUARY, 1); - ERA_START = cal.getTimeInMillis(); + ERA_START = cal.getTime().getTime(); // calendar.getTimeInMillis() not available under JDK 1.3 } private final ThreadSafeSimpleDateFormat defaultFormat; private final ThreadSafeSimpleDateFormat defaultEraFormat; @@ -91,7 +101,8 @@ } /** - * Construct a DateConverter with standard formats, lenient set off and uses a given TimeZone for serialization. + * Construct a DateConverter with standard formats, lenient set off and uses a given + * TimeZone for serialization. * * @param timeZone the TimeZone used to serialize the Date * @since 1.4 @@ -160,8 +171,8 @@ /** * Construct a DateConverter. * - * @param defaultEraFormat the default format for dates in a different era (may be null to drop era - * support) + * @param defaultEraFormat the default format for dates in a different era (may be + * null to drop era support) * @param defaultFormat the default format * @param acceptableFormats fallback formats * @param locale locale to use for the format @@ -173,54 +184,55 @@ final String defaultEraFormat, final String defaultFormat, final String[] acceptableFormats, final Locale locale, final TimeZone timeZone, final boolean lenient) { if (defaultEraFormat != null) { - this.defaultEraFormat = new ThreadSafeSimpleDateFormat(defaultEraFormat, timeZone, locale, 4, 20, lenient); + this.defaultEraFormat = new ThreadSafeSimpleDateFormat( + defaultEraFormat, timeZone, locale, 4, 20, lenient); } else { this.defaultEraFormat = null; } - this.defaultFormat = new ThreadSafeSimpleDateFormat(defaultFormat, timeZone, locale, 4, 20, lenient); + this.defaultFormat = new ThreadSafeSimpleDateFormat( + defaultFormat, timeZone, locale, 4, 20, lenient); this.acceptableFormats = acceptableFormats != null ? new ThreadSafeSimpleDateFormat[acceptableFormats.length] : new ThreadSafeSimpleDateFormat[0]; - for (int i = 0; i < this.acceptableFormats.length; i++) { - this.acceptableFormats[i] = new ThreadSafeSimpleDateFormat(acceptableFormats[i], timeZone, locale, 1, 20, - lenient); + for (int i = 0; i < this.acceptableFormats.length; i++ ) { + this.acceptableFormats[i] = new ThreadSafeSimpleDateFormat( + acceptableFormats[i], timeZone, locale, 1, 20, lenient); } } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(Date.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { if (defaultEraFormat != null) { try { return defaultEraFormat.parse(str); - } catch (final ParseException e) { + } catch (ParseException e) { // try next ... } } if (defaultEraFormat != defaultFormat) { try { return defaultFormat.parse(str); - } catch (final ParseException e) { + } catch (ParseException e) { // try next ... } } - for (final ThreadSafeSimpleDateFormat acceptableFormat : acceptableFormats) { + for (int i = 0; i < acceptableFormats.length; i++ ) { try { - return acceptableFormat.parse(str); - } catch (final ParseException e3) { + return acceptableFormats[i].parse(str); + } catch (ParseException e3) { // no worries, let's try the next format. } } // no dateFormats left to try - throw new ConversionException("Cannot parse date " + str); + ConversionException exception = new ConversionException("Cannot parse date"); + exception.add("date", str); + throw exception; } - @Override - public String toString(final Object obj) { + public String toString(Object obj) { final Date date = (Date)obj; if (date.getTime() < ERA_START && defaultEraFormat != null) { return defaultEraFormat.format(date); @@ -229,14 +241,13 @@ } } - @Override - public void appendErrors(final ErrorWriter errorWriter) { + public void appendErrors(ErrorWriter errorWriter) { errorWriter.add("Default date pattern", defaultFormat.toString()); if (defaultEraFormat != null) { errorWriter.add("Default era date pattern", defaultEraFormat.toString()); } - for (final ThreadSafeSimpleDateFormat acceptableFormat : acceptableFormats) { - errorWriter.add("Alternative date pattern", acceptableFormat.toString()); + for (int i = 0; i < acceptableFormats.length; i++ ) { + errorWriter.add("Alternative date pattern", acceptableFormats[i].toString()); } } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/DoubleConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/DoubleConverter.java (.../DoubleConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/DoubleConverter.java (.../DoubleConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,19 +12,18 @@ package com.thoughtworks.xstream.converters.basic; /** - * Converts a double primitive or {@link Double} wrapper to a string. - * + * Converts a double primitive or java.lang.Double wrapper to + * a String. + * * @author Joe Walnes */ public class DoubleConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(double.class) || type.equals(Double.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return Double.valueOf(str); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/FloatConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/FloatConverter.java (.../FloatConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/FloatConverter.java (.../FloatConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,19 +12,18 @@ package com.thoughtworks.xstream.converters.basic; /** - * Converts a float primitive or {@link Float} wrapper to a string. - * + * Converts a float primitive or java.lang.Float wrapper to + * a String. + * * @author Joe Walnes */ public class FloatConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(float.class) || type.equals(Float.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return Float.valueOf(str); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/IntConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/IntConverter.java (.../IntConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/IntConverter.java (.../IntConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -12,23 +12,22 @@ package com.thoughtworks.xstream.converters.basic; /** - * Converts an int primitive or {@link Integer} wrapper to a string. - * + * Converts an int primitive or java.lang.Integer wrapper to + * a String. + * * @author Joe Walnes */ public class IntConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(int.class) || type.equals(Integer.class); } - @Override - public Object fromString(final String str) { - final long value = Long.decode(str).longValue(); - if (value < Integer.MIN_VALUE || value > 0xFFFFFFFFl) { - throw new NumberFormatException("For input string: \"" + str + '"'); - } + public Object fromString(String str) { + long value = Long.decode(str).longValue(); + if(value < Integer.MIN_VALUE || value > 0xFFFFFFFFl) { + throw new NumberFormatException("For input string: \"" + str + '"'); + } return new Integer((int)value); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/LongConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/LongConverter.java (.../LongConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/LongConverter.java (.../LongConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,31 +12,29 @@ package com.thoughtworks.xstream.converters.basic; /** - * Converts a long primitive or {@link Long} wrapper to a string. + * Converts a long primitive or java.lang.Long wrapper to a String. * * @author Joe Walnes */ public class LongConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(long.class) || type.equals(Long.class); } - @Override - public Object fromString(final String str) { - final int len = str.length(); + public Object fromString(String str) { + int len = str.length(); if (len == 0) { throw new NumberFormatException("For input string: \"\""); } if (len < 17) { return Long.decode(str); } - final char c0 = str.charAt(0); + char c0 = str.charAt(0); if (c0 != '0' && c0 != '#') { return Long.decode(str); } - final char c1 = str.charAt(1); + char c1 = str.charAt(1); final long high; final long low; if (c0 == '#' && len == 17) { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/NullConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/NullConverter.java (.../NullConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/NullConverter.java (.../NullConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2012, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2012 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,32 +14,28 @@ import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; -import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.mapper.Mapper; - /** - * Special converter to signify nulls at the root level or in collection types. - * + * Special converter to signify nulls at the root level. + * * @author Joe Walnes */ public class NullConverter implements Converter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type == null || Mapper.Null.class.isAssignableFrom(type); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { ExtendedHierarchicalStreamWriterHelper.startNode(writer, "null", Mapper.Null.class); writer.endNode(); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { return null; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/ShortConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/ShortConverter.java (.../ShortConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/ShortConverter.java (.../ShortConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,23 +12,22 @@ package com.thoughtworks.xstream.converters.basic; /** - * Converts a short primitive or {@link Short} wrapper to a string. - * + * Converts a short primitive or java.lang.Short wrapper to + * a String. + * * @author Joe Walnes */ public class ShortConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(short.class) || type.equals(Short.class); } - @Override - public Object fromString(final String str) { - final int value = Integer.decode(str).intValue(); - if (value < Short.MIN_VALUE || value > 0xFFFF) { - throw new NumberFormatException("For input string: \"" + str + '"'); - } + public Object fromString(String str) { + int value = Integer.decode(str).intValue(); + if(value < Short.MIN_VALUE || value > 0xFFFF) { + throw new NumberFormatException("For input string: \"" + str + '"'); + } return new Short((short)value); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/StringBufferConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/StringBufferConverter.java (.../StringBufferConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/StringBufferConverter.java (.../StringBufferConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,19 +12,17 @@ package com.thoughtworks.xstream.converters.basic; /** - * Converts the contents of a {@link StringBuffer} to a string. - * + * Converts the contents of a StringBuffer to XML. + * * @author Joe Walnes */ public class StringBufferConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { - return type.equals(StringBuffer.class); + public Object fromString(String str) { + return new StringBuffer(str); } - @Override - public Object fromString(final String str) { - return new StringBuffer(str); + public boolean canConvert(Class type) { + return type.equals(StringBuffer.class); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/StringBuilderConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/StringBuilderConverter.java (.../StringBuilderConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/StringBuilderConverter.java (.../StringBuilderConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2014 XStream Committers. + * Copyright (C) 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,19 +11,17 @@ package com.thoughtworks.xstream.converters.basic; /** - * Converts the contents of a {@link StringBuilder} to a string. - * + * Converts the contents of a StringBuilder to XML. + * * @author Jörg Schaible */ public class StringBuilderConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { - return type.equals(StringBuilder.class); + public Object fromString(String str) { + return new StringBuilder(str); } - @Override - public Object fromString(final String str) { - return new StringBuilder(str); + public boolean canConvert(Class type) { + return type.equals(StringBuilder.class); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/StringConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/StringConverter.java (.../StringConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/StringConverter.java (.../StringConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -18,11 +18,12 @@ /** - * Converts a {@link String} to a string ;). + * Converts a String to a String ;). *

- * Well ok, it doesn't actually do any conversion. The converter uses by default a map with weak references to - * reuse instances of strings that do not exceed a length limit. This limit is by default 38 characters to cache typical - * strings containing UUIDs. Only shorter strings are typically repeated more often in XML values. + * Well ok, it doesn't actually do any conversion. The converter uses by default a map + * with weak references to reuse instances of strings that do not exceed a length limit. This + * limit is by default 38 characters to cache typical strings containing UUIDs. Only shorter + * strings are typically repeated more often in XML values. *

* * @author Joe Walnes @@ -32,12 +33,13 @@ public class StringConverter extends AbstractSingleValueConverter { private static final int LENGTH_LIMIT = 38; - + /** - * A Map to store strings as long as needed to map similar strings onto the same instance and conserve memory. The - * map can be set from the outside during construction, so it can be a LRU map or a weak map, synchronized or not. + * A Map to store strings as long as needed to map similar strings onto the same instance + * and conserve memory. The map can be set from the outside during construction, so it can + * be a LRU map or a weak map, synchronised or not. */ - private final Map cache; + private final Map cache; private final int lengthLimit; /** @@ -47,7 +49,7 @@ * @param lengthLimit maximum string length of a cached string, -1 to cache all, 0 to turn off the cache * @since 1.4.2 */ - public StringConverter(final Map map, final int lengthLimit) { + public StringConverter(final Map map, int lengthLimit) { cache = map; this.lengthLimit = lengthLimit; } @@ -57,7 +59,7 @@ * * @param map the map to use for the instances to reuse (may be null to not cache at all) */ - public StringConverter(final Map map) { + public StringConverter(final Map map) { this(map, LENGTH_LIMIT); } @@ -67,8 +69,8 @@ * @param lengthLimit maximum string length of a cached string, -1 to cache all, 0 to turn off the cache * @since 1.4.2 */ - public StringConverter(final int lengthLimit) { - this(Collections.synchronizedMap(new WeakCache()), lengthLimit); + public StringConverter(int lengthLimit) { + this(Collections.synchronizedMap(new WeakCache()), lengthLimit); } /** @@ -78,15 +80,13 @@ this(LENGTH_LIMIT); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(final Class type) { return type.equals(String.class); } - @Override public Object fromString(final String str) { if (cache != null && str != null && (lengthLimit < 0 || str.length() <= lengthLimit)) { - String s = cache.get(str); + String s = (String)cache.get(str); if (s == null) { // fill cache Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/URIConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/URIConverter.java (.../URIConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/URIConverter.java (.../URIConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2014 XStream Committers. + * Copyright (C) 2010 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -17,22 +17,20 @@ /** - * Converts a {@link URI} to a string. + * Converts a java.net.URI to a string. * * @author Carlos Roman */ public class URIConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(URI.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { try { return new URI(str); - } catch (final URISyntaxException e) { + } catch (URISyntaxException e) { throw new ConversionException(e); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/URLConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/URLConverter.java (.../URLConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/URLConverter.java (.../URLConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,29 +11,26 @@ */ package com.thoughtworks.xstream.converters.basic; +import com.thoughtworks.xstream.converters.ConversionException; + import java.net.MalformedURLException; import java.net.URL; -import com.thoughtworks.xstream.converters.ConversionException; - - /** - * Converts a {@link URL} to a string. - * + * Converts a java.net.URL to a string. + * * @author J. Matthew Pryor */ public class URLConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(URL.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { try { return new URL(str); - } catch (final MalformedURLException e) { + } catch (MalformedURLException e) { throw new ConversionException(e); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/UUIDConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/UUIDConverter.java (.../UUIDConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/basic/UUIDConverter.java (.../UUIDConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2014 XStream Committers. + * Copyright (C) 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,28 +10,26 @@ */ package com.thoughtworks.xstream.converters.basic; -import java.util.UUID; - import com.thoughtworks.xstream.converters.ConversionException; +import java.util.UUID; + /** - * Converts a {@link UUID} to a string. + * Converts a java.util.UUID to a string. * * @author Jörg Schaible */ public class UUIDConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(UUID.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { try { return UUID.fromString(str); - } catch (final IllegalArgumentException e) { + } catch(IllegalArgumentException e) { throw new ConversionException("Cannot create UUID instance", e); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/AbstractCollectionConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/AbstractCollectionConverter.java (.../AbstractCollectionConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/AbstractCollectionConverter.java (.../AbstractCollectionConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,74 +13,78 @@ import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; +import com.thoughtworks.xstream.converters.ErrorWritingException; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; import com.thoughtworks.xstream.core.util.HierarchicalStreams; -import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.mapper.Mapper; - /** - * Base helper class for converters that need to handle collections of items (arrays, Lists, Maps, etc). - *

- * Typically, subclasses of this will converter the outer structure of the collection, loop through the contents and - * call readItem() or writeItem() for each item. - *

- * + * Base helper class for converters that need to handle + * collections of items (arrays, Lists, Maps, etc). + * + *

Typically, subclasses of this will converter the outer + * structure of the collection, loop through the contents and + * call readItem() or writeItem() for each item.

+ * * @author Joe Walnes */ public abstract class AbstractCollectionConverter implements Converter { private final Mapper mapper; - @Override - public abstract boolean canConvert(Class type); + public abstract boolean canConvert(Class type); - public AbstractCollectionConverter(final Mapper mapper) { + public AbstractCollectionConverter(Mapper mapper) { this.mapper = mapper; } protected Mapper mapper() { return mapper; } - @Override public abstract void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context); - @Override public abstract Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context); - protected void writeItem(final Object item, final MarshallingContext context, final HierarchicalStreamWriter writer) { + + + protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) { // PUBLISHED API METHOD! If changing signature, ensure backwards compatibility. if (item == null) { // todo: this is duplicated in TreeMarshaller.start() - final String name = mapper().serializedClass(null); + String name = mapper().serializedClass(null); ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, Mapper.Null.class); writer.endNode(); } else { - final String name = mapper().serializedClass(item.getClass()); + String name = mapper().serializedClass(item.getClass()); ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, item.getClass()); context.convertAnother(item); writer.endNode(); } } - protected Object readItem(final HierarchicalStreamReader reader, final UnmarshallingContext context, - final Object current) { - final Class type = HierarchicalStreams.readClassType(reader, mapper()); + protected Object readItem(HierarchicalStreamReader reader, UnmarshallingContext context, Object current) { + Class type = HierarchicalStreams.readClassType(reader, mapper()); return context.convertAnother(current, type); } - protected Object createCollection(final Class type) { - final Class defaultType = mapper().defaultImplementationOf(type); + protected Object createCollection(Class type) { + ErrorWritingException ex = null; + Class defaultType = mapper().defaultImplementationOf(type); try { return defaultType.newInstance(); - } catch (final InstantiationException e) { - throw new ConversionException("Cannot instantiate " + defaultType.getName(), e); - } catch (final IllegalAccessException e) { - throw new ConversionException("Cannot instantiate " + defaultType.getName(), e); + } catch (InstantiationException e) { + ex = new ConversionException("Cannot instantiate default collection", e); + } catch (IllegalAccessException e) { + ex = new ObjectAccessException("Cannot instantiate default collection", e); } + ex.add("collection-type", type.getName()); + ex.add("default-type", defaultType.getName()); + throw ex; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/ArrayConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/ArrayConverter.java (.../ArrayConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/ArrayConverter.java (.../ArrayConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,59 +11,58 @@ */ package com.thoughtworks.xstream.converters.collections; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.List; - import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; /** - * Converts an array of objects or primitives, using a nested child element for each item. - * + * Converts an array of objects or primitives to XML, using + * a nested child element for each item. + * * @author Joe Walnes - * @see com.thoughtworks.xstream.converters.extended.NamedArrayConverter */ public class ArrayConverter extends AbstractCollectionConverter { - public ArrayConverter(final Mapper mapper) { + public ArrayConverter(Mapper mapper) { super(mapper); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.isArray(); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final int length = Array.getLength(source); + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + int length = Array.getLength(source); for (int i = 0; i < length; i++) { - final Object item = Array.get(source, i); + Object item = Array.get(source, i); writeItem(item, context, writer); } } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - // read the items from xml into a list (the array size is not known until all items have been read) - final List items = new ArrayList(); + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + // read the items from xml into a list + List items = new ArrayList(); while (reader.hasMoreChildren()) { reader.moveDown(); - final Object item = readItem(reader, context, null); // TODO: arg, what should replace null? + Object item = readItem(reader, context, null); // TODO: arg, what should replace null? items.add(item); reader.moveUp(); } // now convertAnother the list into an array - final Object array = Array.newInstance(context.getRequiredType().getComponentType(), items.size()); + // (this has to be done as a separate list as the array size is not + // known until all items have been read) + Object array = Array.newInstance(context.getRequiredType().getComponentType(), items.size()); int i = 0; - for (final Object item : items) { - Array.set(array, i++, item); + for (Iterator iterator = items.iterator(); iterator.hasNext();) { + Array.set(array, i++, iterator.next()); } return array; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/BitSetConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/BitSetConverter.java (.../BitSetConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/BitSetConverter.java (.../BitSetConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,32 +11,30 @@ */ package com.thoughtworks.xstream.converters.collections; -import java.util.BitSet; -import java.util.StringTokenizer; - import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import java.util.BitSet; +import java.util.StringTokenizer; /** - * Converts a {@link BitSet}, as a compact comma delimited list of ones and zeros. - * + * Converts a java.util.BitSet to XML, as a compact + * comma delimited list of ones and zeros. + * * @author Joe Walnes */ public class BitSetConverter implements Converter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(BitSet.class); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final BitSet bitSet = (BitSet)source; - final StringBuilder buffer = new StringBuilder(); + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + BitSet bitSet = (BitSet) source; + StringBuffer buffer = new StringBuffer(); boolean seenFirst = false; for (int i = 0; i < bitSet.length(); i++) { if (bitSet.get(i)) { @@ -51,12 +49,11 @@ writer.setValue(buffer.toString()); } - @Override - public BitSet unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final BitSet result = new BitSet(); - final StringTokenizer tokenizer = new StringTokenizer(reader.getValue(), ",", false); + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + BitSet result = new BitSet(); + StringTokenizer tokenizer = new StringTokenizer(reader.getValue(), ",", false); while (tokenizer.hasMoreTokens()) { - final int index = Integer.parseInt(tokenizer.nextToken()); + int index = Integer.parseInt(tokenizer.nextToken()); result.set(index); } return result; Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/CharArrayConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/CharArrayConverter.java (.../CharArrayConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/CharArrayConverter.java (.../CharArrayConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -17,27 +17,24 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; - /** - * Converts a char[] as a single string. - * + * Converts a char[] to XML, storing the contents as a single + * String. + * * @author Joe Walnes */ public class CharArrayConverter implements Converter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.isArray() && type.getComponentType().equals(char.class); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - char[] chars = (char[])source; + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + char[] chars = (char[]) source; writer.setValue(new String(chars)); } - @Override - public char[] unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { return reader.getValue().toCharArray(); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/CollectionConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/CollectionConverter.java (.../CollectionConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/CollectionConverter.java (.../CollectionConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2010, 2011, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,106 +11,95 @@ */ package com.thoughtworks.xstream.converters.collections; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.Vector; - import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Vector; /** - * Converts most common Collections (Lists and Sets), specifying a nested element for each item. - *

- * Supports {@link ArrayList}, {@link HashSet}, {@link LinkedList}, {@link Vector} and {@link LinkedHashSet}. - *

- * + * Converts most common Collections (Lists and Sets) to XML, specifying a nested + * element for each item. + * + *

Supports java.util.ArrayList, java.util.HashSet, + * java.util.LinkedList, java.util.Vector and java.util.LinkedHashSet.

+ * * @author Joe Walnes - * @see com.thoughtworks.xstream.converters.extended.NamedCollectionConverter */ public class CollectionConverter extends AbstractCollectionConverter { - private final Class> type; + private final Class type; - public CollectionConverter(final Mapper mapper) { + public CollectionConverter(Mapper mapper) { this(mapper, null); } /** * Construct a CollectionConverter for a special Collection type. - * * @param mapper the mapper * @param type the Collection type to handle * @since 1.4.5 */ - public CollectionConverter(final Mapper mapper, @SuppressWarnings("rawtypes") final Class type) { + public CollectionConverter(Mapper mapper, Class type) { super(mapper); - @SuppressWarnings("unchecked") - final Class> checkedType = (Class>)type; - this.type = checkedType; + this.type = type; if (type != null && !Collection.class.isAssignableFrom(type)) { throw new IllegalArgumentException(type + " not of type " + Collection.class); } } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { if (this.type != null) { return type.equals(this.type); } return type.equals(ArrayList.class) || type.equals(HashSet.class) || type.equals(LinkedList.class) - || type.equals(Vector.class) - || type.equals(LinkedHashSet.class); + || type.equals(Vector.class) + || (JVM.is14() && type.getName().equals("java.util.LinkedHashSet")); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Collection collection = (Collection)source; - for (final Object item : collection) { + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + Collection collection = (Collection) source; + for (Iterator iterator = collection.iterator(); iterator.hasNext();) { + Object item = iterator.next(); writeItem(item, context, writer); } } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final Class collectionType = context.getRequiredType(); - final Collection collection = createCollection(collectionType); + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + Collection collection = (Collection) createCollection(context.getRequiredType()); populateCollection(reader, context, collection); return collection; } - protected void populateCollection(final HierarchicalStreamReader reader, final UnmarshallingContext context, - final Collection collection) { + protected void populateCollection(HierarchicalStreamReader reader, UnmarshallingContext context, Collection collection) { populateCollection(reader, context, collection, collection); } - protected void populateCollection(final HierarchicalStreamReader reader, final UnmarshallingContext context, - final Collection collection, final Collection target) { + protected void populateCollection(HierarchicalStreamReader reader, UnmarshallingContext context, Collection collection, Collection target) { while (reader.hasMoreChildren()) { reader.moveDown(); addCurrentElementToCollection(reader, context, collection, target); reader.moveUp(); } } - protected void addCurrentElementToCollection(final HierarchicalStreamReader reader, - final UnmarshallingContext context, final Collection collection, final Collection target) { - final Object item = readItem(reader, context, collection); - @SuppressWarnings("unchecked") - final Collection targetCollection = (Collection)target; - targetCollection.add(item); + protected void addCurrentElementToCollection(HierarchicalStreamReader reader, UnmarshallingContext context, + Collection collection, Collection target) { + Object item = readItem(reader, context, collection); + target.add(item); } - @Override - protected Collection createCollection(final Class type) { - return (Collection)super.createCollection(this.type != null ? this.type : type); + protected Object createCollection(Class type) { + return super.createCollection(this.type != null ? this.type : type); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/MapConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/MapConverter.java (.../MapConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/MapConverter.java (.../MapConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,77 +11,68 @@ */ package com.thoughtworks.xstream.converters.collections; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; /** - * Converts a {@link Map}, specifying an 'entry' element with 'key' and 'value' children. - *

- * Note: 'key' and 'value' is not the name of the generated tag. The children are serialized as normal elements and the - * implementation expects them in the order 'key'/'value'. - *

- *

- * Supports {@link HashMap}, {@link Hashtable}, {@link LinkedHashMap}, {@link ConcurrentHashMap} and - * sun.font.AttributeMap. - *

- * - * @see com.thoughtworks.xstream.converters.extended.NamedMapConverter + * Converts a java.util.Map to XML, specifying an 'entry' + * element with 'key' and 'value' children. + *

Note: 'key' and 'value' is not the name of the generated tag. The + * children are serialized as normal elements and the implementation expects + * them in the order 'key'/'value'.

+ *

Supports java.util.HashMap, java.util.Hashtable, + * java.util.LinkedHashMap and java.util.concurrent.ConcurrentHashMap.

+ * * @author Joe Walnes */ public class MapConverter extends AbstractCollectionConverter { - private final Class> type; + private final Class type; - public MapConverter(final Mapper mapper) { + public MapConverter(Mapper mapper) { this(mapper, null); } /** * Construct a MapConverter for a special Map type. - * * @param mapper the mapper * @param type the type to handle * @since 1.4.5 */ - public MapConverter(final Mapper mapper, @SuppressWarnings("rawtypes") final Class type) { + public MapConverter(Mapper mapper, Class type) { super(mapper); - @SuppressWarnings("unchecked") - final Class> checkedType = (Class>)type; - this.type = checkedType; + this.type = type; if (type != null && !Map.class.isAssignableFrom(type)) { throw new IllegalArgumentException(type + " not of type " + Map.class); } } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { if (this.type != null) { return type.equals(this.type); } return type.equals(HashMap.class) || type.equals(Hashtable.class) - || type.equals(LinkedHashMap.class) - || type.equals(ConcurrentHashMap.class) - || type.getName().equals("sun.font.AttributeMap") // Used by java.awt.Font since JDK 6 - ; + || type.getName().equals("java.util.LinkedHashMap") + || type.getName().equals("java.util.concurrent.ConcurrentHashMap") + || type.getName().equals("sun.font.AttributeMap") // Used by java.awt.Font in JDK 6 + ; } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Map map = (Map)source; - final String entryName = mapper().serializedClass(Map.Entry.class); - for (final Map.Entry entry : map.entrySet()) { + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + Map map = (Map) source; + String entryName = mapper().serializedClass(Map.Entry.class); + for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { + Map.Entry entry = (Map.Entry) iterator.next(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryName, entry.getClass()); writeItem(entry.getKey(), context, writer); @@ -91,45 +82,38 @@ } } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final Class requiredType = context.getRequiredType(); - final Map map = createCollection(requiredType); + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + Map map = (Map) createCollection(context.getRequiredType()); populateMap(reader, context, map); return map; } - protected void populateMap(final HierarchicalStreamReader reader, final UnmarshallingContext context, - final Map map) { + protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, Map map) { populateMap(reader, context, map, map); } - protected void populateMap(final HierarchicalStreamReader reader, final UnmarshallingContext context, - final Map map, final Map target) { + protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context, Map map, Map target) { while (reader.hasMoreChildren()) { reader.moveDown(); putCurrentEntryIntoMap(reader, context, map, target); reader.moveUp(); } } - protected void putCurrentEntryIntoMap(final HierarchicalStreamReader reader, final UnmarshallingContext context, - final Map map, final Map target) { + protected void putCurrentEntryIntoMap(HierarchicalStreamReader reader, UnmarshallingContext context, + Map map, Map target) { reader.moveDown(); - final Object key = readItem(reader, context, map); + Object key = readItem(reader, context, map); reader.moveUp(); reader.moveDown(); - final Object value = readItem(reader, context, map); + Object value = readItem(reader, context, map); reader.moveUp(); - @SuppressWarnings("unchecked") - final Map targetMap = (Map)target; - targetMap.put(key, value); + target.put(key, value); } - @Override - protected Map createCollection(final Class type) { - return (Map)super.createCollection(this.type != null ? this.type : type); + protected Object createCollection(Class type) { + return super.createCollection(this.type != null ? this.type : type); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/PropertiesConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/PropertiesConverter.java (.../PropertiesConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/PropertiesConverter.java (.../PropertiesConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,28 +11,31 @@ */ package com.thoughtworks.xstream.converters.collections; -import java.lang.reflect.Field; -import java.util.Map; -import java.util.Properties; -import java.util.TreeMap; - import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.core.util.Fields; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import java.lang.reflect.Field; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; + /** - * Special converter for {@link Properties} that stores properties in a more compact form than java.util.Map. + * Special converter for java.util.Properties that stores properties in a more compact form than + * java.util.Map. *

- * Because all entries of a Properties instance are Strings, a single element is used for each property with two - * attributes; one for key and one for value. + * Because all entries of a Properties instance are Strings, a single element is used for each + * property with two attributes; one for key and one for value. *

*

- * Additionally, default properties are also serialized, if they are present or if a SecurityManager is set, and it has - * permissions for SecurityManager.checkPackageAccess, SecurityManager.checkMemberAccess(this, EnumSet.MEMBER) and + * Additionally, default properties are also serialized, if they are present or if a + * SecurityManager is set, and it has permissions for SecurityManager.checkPackageAccess, + * SecurityManager.checkMemberAccess(this, EnumSet.MEMBER) and * ReflectPermission("suppressAccessChecks"). *

* @@ -48,27 +51,26 @@ this(false); } - public PropertiesConverter(final boolean sort) { + public PropertiesConverter(boolean sort) { this.sort = sort; } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return Properties.class == type; } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Properties properties = (Properties)source; - final Map map = sort ? new TreeMap(properties) : properties; - for (final Map.Entry entry : map.entrySet()) { + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + final Properties properties = (Properties) source; + Map map = sort ? (Map)new TreeMap(properties) : (Map)properties; + for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { + Map.Entry entry = (Map.Entry) iterator.next(); writer.startNode("property"); writer.addAttribute("name", entry.getKey().toString()); writer.addAttribute("value", entry.getValue().toString()); writer.endNode(); } if (defaultsField != null) { - final Properties defaults = (Properties)Fields.read(defaultsField, properties); + Properties defaults = (Properties)Fields.read(defaultsField, properties); if (defaults != null) { writer.startNode("defaults"); marshal(defaults, writer, context); @@ -77,25 +79,24 @@ } } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final Properties properties = new Properties(); + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + Properties properties = new Properties(); Properties defaults = null; while (reader.hasMoreChildren()) { reader.moveDown(); if (reader.getNodeName().equals("defaults")) { - defaults = (Properties)unmarshal(reader, context); + defaults = (Properties) unmarshal(reader, context); } else { - final String name = reader.getAttribute("name"); - final String value = reader.getAttribute("value"); + String name = reader.getAttribute("name"); + String value = reader.getAttribute("value"); properties.setProperty(name, value); } reader.moveUp(); } if (defaults == null) { return properties; } else { - final Properties propertiesWithDefaults = new Properties(defaults); + Properties propertiesWithDefaults = new Properties(defaults); propertiesWithDefaults.putAll(properties); return propertiesWithDefaults; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/SingletonCollectionConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/SingletonCollectionConverter.java (.../SingletonCollectionConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/SingletonCollectionConverter.java (.../SingletonCollectionConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2014 XStream Committers. + * Copyright (C) 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,7 +10,6 @@ */ package com.thoughtworks.xstream.converters.collections; -import java.util.Collection; import java.util.Collections; import com.thoughtworks.xstream.converters.UnmarshallingContext; @@ -19,7 +18,8 @@ /** - * Converts singleton collections (list and set) to XML, specifying a nested element for the item. + * Converts singleton collections (list and set) to XML, specifying a nested element for the + * item. *

* Supports Collections.singleton(Object) and Collections.singletonList(Object). *

@@ -29,29 +29,29 @@ */ public class SingletonCollectionConverter extends CollectionConverter { - private static final Class LIST = Collections.singletonList(Boolean.TRUE).getClass(); - private static final Class SET = Collections.singleton(Boolean.TRUE).getClass(); + private static final Class LIST = Collections.singletonList(Boolean.TRUE).getClass(); + private static final Class SET = Collections.singleton(Boolean.TRUE).getClass(); /** * Construct a SingletonCollectionConverter. * * @param mapper the mapper * @since 1.4.2 */ - public SingletonCollectionConverter(final Mapper mapper) { + public SingletonCollectionConverter(Mapper mapper) { super(mapper); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return LIST == type || SET == type; } - @Override - public Collection unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { reader.moveDown(); - final Object item = readItem(reader, context, null); + Object item = readItem(reader, context, null); reader.moveUp(); - return context.getRequiredType() == LIST ? Collections.singletonList(item) : Collections.singleton(item); + return context.getRequiredType() == LIST + ? (Object)Collections.singletonList(item) + : (Object)Collections.singleton(item); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/SingletonMapConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/SingletonMapConverter.java (.../SingletonMapConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/SingletonMapConverter.java (.../SingletonMapConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2014 XStream Committers. + * Copyright (C) 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,58 +11,51 @@ package com.thoughtworks.xstream.converters.collections; import java.util.Collections; -import java.util.Map; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.mapper.Mapper; - /** - * Converts a singleton map to XML, specifying an 'entry' element with 'key' and 'value' children. - *

- * Note: 'key' and 'value' is not the name of the generated tag. The children are serialized as normal elements and the - * implementation expects them in the order 'key'/'value'. - *

- *

- * Supports Collections.singletonMap. - *

+ * Converts a singleton map to XML, specifying an 'entry' + * element with 'key' and 'value' children. + *

Note: 'key' and 'value' is not the name of the generated tag. The + * children are serialized as normal elements and the implementation expects + * them in the order 'key'/'value'.

+ *

Supports Collections.singletonMap.

* * @author Jörg Schaible * @since 1.4.2 */ public class SingletonMapConverter extends MapConverter { - private static final Class MAP = Collections.singletonMap(Boolean.TRUE, null).getClass(); + private static final Class MAP = Collections.singletonMap(Boolean.TRUE, null).getClass(); /** * Construct a SingletonMapConverter. - * * @param mapper * @since 1.4.2 */ - public SingletonMapConverter(final Mapper mapper) { + public SingletonMapConverter(Mapper mapper) { super(mapper); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return MAP == type; } - @Override - public Map unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { reader.moveDown(); reader.moveDown(); - final Object key = readItem(reader, context, null); + Object key = readItem(reader, context, null); reader.moveUp(); reader.moveDown(); - final Object value = readItem(reader, context, null); + Object value = readItem(reader, context, null); reader.moveUp(); reader.moveUp(); - - return Collections.singletonMap(key, value); + + return Collections.singletonMap(key, value); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/TreeMapConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/TreeMapConverter.java (.../TreeMapConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/TreeMapConverter.java (.../TreeMapConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,14 +11,9 @@ */ package com.thoughtworks.xstream.converters.collections; -import java.lang.reflect.Field; -import java.util.Comparator; -import java.util.SortedMap; -import java.util.TreeMap; - -import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.core.util.Fields; import com.thoughtworks.xstream.core.util.HierarchicalStreams; @@ -27,72 +22,72 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; +import java.lang.reflect.Field; +import java.util.Comparator; +import java.util.SortedMap; +import java.util.TreeMap; /** - * Converts a {@link TreeMap} to XML, and serializes the associated {@link Comparator}. - *

- * The converter assumes that the entries in the XML are already sorted according the comparator. - *

- * + * Converts a java.util.TreeMap to XML, and serializes + * the associated java.util.Comparator. The converter + * assumes that the entries in the XML are already sorted + * according the comparator. + * * @author Joe Walnes * @author Jörg Schaible */ public class TreeMapConverter extends MapConverter { - - private static final class NullComparator extends Mapper.Null implements Comparator> { - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public int compare(final Comparable o1, final Comparable o2) { - return o1.compareTo(o2); + + private static final class NullComparator extends Mapper.Null implements Comparator { + public int compare(Object o1, Object o2) { + Comparable c1 = (Comparable)o1; + Comparable c2 = (Comparable)o2; + return c1.compareTo(o2); } } - @SuppressWarnings("rawtypes") private final static Comparator NULL_MARKER = new NullComparator(); private final static Field comparatorField = Fields.locate(TreeMap.class, Comparator.class, false); - public TreeMapConverter(final Mapper mapper) { + public TreeMapConverter(Mapper mapper) { super(mapper, TreeMap.class); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final SortedMap sortedMap = (SortedMap)source; + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + SortedMap sortedMap = (SortedMap) source; marshalComparator(sortedMap.comparator(), writer, context); super.marshal(source, writer, context); } - protected void marshalComparator(final Comparator comparator, final HierarchicalStreamWriter writer, - final MarshallingContext context) { + protected void marshalComparator(Comparator comparator, HierarchicalStreamWriter writer, + MarshallingContext context) { if (comparator != null) { writer.startNode("comparator"); - writer.addAttribute(mapper().aliasForSystemAttribute("class"), mapper().serializedClass( - comparator.getClass())); + writer.addAttribute(mapper().aliasForSystemAttribute("class"), + mapper().serializedClass(comparator.getClass())); context.convertAnother(comparator); writer.endNode(); } } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - TreeMap result = comparatorField != null ? new TreeMap() : null; - @SuppressWarnings("unchecked") - final Comparator comparator = (Comparator)unmarshalComparator(reader, context, result); + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + TreeMap result = comparatorField != null ? new TreeMap() : null; + final Comparator comparator = unmarshalComparator(reader, context, result); if (result == null) { - result = comparator == null ? new TreeMap() : new TreeMap(comparator); + result = comparator == null ? new TreeMap() : new TreeMap(comparator); } populateTreeMap(reader, context, result, comparator); return result; } - protected Comparator unmarshalComparator(final HierarchicalStreamReader reader, - final UnmarshallingContext context, final TreeMap result) { - final Comparator comparator; + protected Comparator unmarshalComparator(HierarchicalStreamReader reader, + UnmarshallingContext context, TreeMap result) { + final Comparator comparator; if (reader.hasMoreChildren()) { reader.moveDown(); if (reader.getNodeName().equals("comparator")) { - final Class comparatorClass = HierarchicalStreams.readClassType(reader, mapper()); - comparator = (Comparator)context.convertAnother(result, comparatorClass); + Class comparatorClass = HierarchicalStreams.readClassType(reader, mapper()); + comparator = (Comparator) context.convertAnother(result, comparatorClass); } else if (reader.getNodeName().equals("no-comparator")) { // pre 1.4 format comparator = null; } else { @@ -106,38 +101,34 @@ return comparator; } - protected void populateTreeMap(final HierarchicalStreamReader reader, final UnmarshallingContext context, - final TreeMap result, Comparator comparator) { - final boolean inFirstElement = comparator == NULL_MARKER; + protected void populateTreeMap(HierarchicalStreamReader reader, UnmarshallingContext context, + TreeMap result, Comparator comparator) { + boolean inFirstElement = comparator == NULL_MARKER; if (inFirstElement) { comparator = null; } - @SuppressWarnings("unchecked") - final SortedMap sortedMap = new PresortedMap( - (Comparator)(comparator != null && JVM.hasOptimizedTreeMapPutAll() ? comparator : null)); + SortedMap sortedMap = new PresortedMap(comparator != null && JVM.hasOptimizedTreeMapPutAll() ? comparator : null); if (inFirstElement) { // we are already within the first entry putCurrentEntryIntoMap(reader, context, result, sortedMap); reader.moveUp(); } populateMap(reader, context, result, sortedMap); - @SuppressWarnings("unchecked") - final TreeMap typedResult = (TreeMap)result; try { if (JVM.hasOptimizedTreeMapPutAll()) { if (comparator != null && comparatorField != null) { - comparatorField.set(result, comparator); + comparatorField.set(result, comparator); } - typedResult.putAll(sortedMap); // internal optimization will not call comparator + result.putAll(sortedMap); // internal optimization will not call comparator } else if (comparatorField != null) { comparatorField.set(result, sortedMap.comparator()); - typedResult.putAll(sortedMap); // "sort" by index - comparatorField.set(result, comparator); + result.putAll(sortedMap); // "sort" by index + comparatorField.set(result, comparator); } else { - typedResult.putAll(sortedMap); // will use comparator for already sorted map + result.putAll(sortedMap); // will use comparator for already sorted map } } catch (final IllegalAccessException e) { - throw new ConversionException("Cannot set comparator of TreeMap", e); + throw new ObjectAccessException("Cannot set comparator of TreeMap", e); } } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/TreeSetConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/TreeSetConverter.java (.../TreeSetConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/collections/TreeSetConverter.java (.../TreeSetConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,71 +11,98 @@ */ package com.thoughtworks.xstream.converters.collections; -import java.lang.reflect.Field; -import java.util.AbstractList; -import java.util.Comparator; -import java.util.Map; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; - -import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.core.util.Fields; import com.thoughtworks.xstream.core.util.PresortedSet; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; +import java.lang.reflect.Field; +import java.util.AbstractList; +import java.util.Comparator; +import java.util.Map; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; /** - * Converts a {@link TreeSet} to XML, and serializes the associated {@link Comparator}. - *

- * The converter assumes that the elements in the XML are already sorted according the comparator. - *

- * + * Converts a java.util.TreeSet to XML, and serializes + * the associated java.util.Comparator. The converter + * assumes that the elements in the XML are already sorted + * according the comparator. + * * @author Joe Walnes * @author Jörg Schaible */ public class TreeSetConverter extends CollectionConverter { - private transient TreeMapConverter treeMapConverter; - private final static Field sortedMapField = JVM.hasOptimizedTreeSetAddAll() ? Fields.locate(TreeSet.class, - SortedMap.class, false) : null; + private transient TreeMapConverter treeMapConverter; + private final static Field sortedMapField; + private final static Object constantValue; + static { + Object value = null; + sortedMapField = JVM.hasOptimizedTreeSetAddAll() ? Fields.locate(TreeSet.class, SortedMap.class, false) : null; + if (sortedMapField != null) { + TreeSet set = new TreeSet(); + set.add("1"); + set.add("2"); - public TreeSetConverter(final Mapper mapper) { + Map backingMap = null; + try { + backingMap = (Map)sortedMapField.get(set); + } catch (final IllegalAccessException e) { + // give up; + } + if (backingMap != null) { + Object[] values = backingMap.values().toArray(); + if (values[0] == values[1]) { + value = values[0]; + } + } + } else { + Field valueField = Fields.locate(TreeSet.class, Object.class, true); + if (valueField != null) { + try { + value = valueField.get(null); + } catch (final IllegalAccessException e) { + // give up; + } + } + } + constantValue = value; + } + + public TreeSetConverter(Mapper mapper) { super(mapper, TreeSet.class); readResolve(); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final SortedSet sortedSet = (SortedSet)source; + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + SortedSet sortedSet = (SortedSet) source; treeMapConverter.marshalComparator(sortedSet.comparator(), writer, context); super.marshal(source, writer, context); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - TreeSet result = null; - final TreeMap treeMap; - final Comparator unmarshalledComparator = treeMapConverter.unmarshalComparator(reader, context, null); - final boolean inFirstElement = unmarshalledComparator instanceof Mapper.Null; - @SuppressWarnings("unchecked") - final Comparator comparator = inFirstElement ? null : (Comparator)unmarshalledComparator; + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + TreeSet result = null; + final TreeMap treeMap; + Comparator unmarshalledComparator = treeMapConverter.unmarshalComparator(reader, context, null); + boolean inFirstElement = unmarshalledComparator instanceof Mapper.Null; + Comparator comparator = inFirstElement ? null : unmarshalledComparator; if (sortedMapField != null) { - final TreeSet possibleResult = comparator == null ? new TreeSet() : new TreeSet( - comparator); + TreeSet possibleResult = comparator == null ? new TreeSet() : new TreeSet(comparator); Object backingMap = null; try { backingMap = sortedMapField.get(possibleResult); - } catch (final IllegalAccessException e) { - throw new ConversionException("Cannot get backing map of TreeSet", e); + } catch (IllegalAccessException e) { + throw new ObjectAccessException("Cannot get backing map of TreeSet", e); } if (backingMap instanceof TreeMap) { - treeMap = (TreeMap)backingMap; + treeMap = (TreeMap)backingMap; result = possibleResult; } else { treeMap = null; @@ -84,8 +111,8 @@ treeMap = null; } if (treeMap == null) { - final PresortedSet set = new PresortedSet(comparator); - result = comparator == null ? new TreeSet() : new TreeSet(comparator); + final PresortedSet set = new PresortedSet(comparator); + result = comparator == null ? new TreeSet() : new TreeSet(comparator); if (inFirstElement) { // we are already within the first element addCurrentElementToCollection(reader, context, result, set); @@ -104,36 +131,27 @@ private Object readResolve() { treeMapConverter = new TreeMapConverter(mapper()) { - @Override - protected void populateMap(final HierarchicalStreamReader reader, final UnmarshallingContext context, - final Map map, final Map target) { - populateCollection(reader, context, new AbstractList() { - @Override - public boolean add(final Object object) { - @SuppressWarnings("unchecked") - final Map collectionTarget = (Map)target; - return collectionTarget.put(object, object) != null; + protected void populateMap(HierarchicalStreamReader reader, + UnmarshallingContext context, Map map, final Map target) { + populateCollection(reader, context, new AbstractList() { + public boolean add(Object object) { + return target.put(object, constantValue != null ? constantValue : object) != null; } - @Override - public Object get(final int location) { + public Object get(int location) { return null; } - @Override public int size() { return target.size(); } }); } - @Override - protected void putCurrentEntryIntoMap(final HierarchicalStreamReader reader, - final UnmarshallingContext context, final Map map, final Map target) { - final Object key = readItem(reader, context, map); - @SuppressWarnings("unchecked") - final Map checkedTarget = (Map)target; - checkedTarget.put(key, key); + protected void putCurrentEntryIntoMap(HierarchicalStreamReader reader, UnmarshallingContext context, + Map map, Map target) { + Object key = readItem(reader, context, map); + target.put(key, key); } }; return this; Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumConverter.java (.../EnumConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumConverter.java (.../EnumConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -19,52 +19,39 @@ import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; -import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; -import com.thoughtworks.xstream.mapper.EnumMapper; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; - /** - * Converter for {@link Enum} types. - *

- * Combined with {@link EnumMapper} this also deals with polymorphic enums. - *

- * - * @author Eric Snell + * Converter for JDK 1.5 enums. Combined with EnumMapper this also deals with polymorphic enums. + * + * @author Eric Snell * @author Bryan Coleman */ public class EnumConverter implements Converter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.isEnum() || Enum.class.isAssignableFrom(type); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - writer.setValue(((Enum)source).name()); + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + writer.setValue(((Enum) source).name()); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - Class type = context.getRequiredType(); + @SuppressWarnings("unchecked") + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + Class type = context.getRequiredType(); if (type.getSuperclass() != Enum.class) { type = type.getSuperclass(); // polymorphic enums } - final String name = reader.getValue(); + String name = reader.getValue(); try { - @SuppressWarnings("rawtypes") - final Class rawType = type; - @SuppressWarnings("unchecked") - final Enum enumValue = Enum.valueOf(rawType, name); - return enumValue; - } catch (final IllegalArgumentException e) { + return Enum.valueOf(type, name); + } catch (IllegalArgumentException e) { // failed to find it, do a case insensitive match - for (final Enum c : (Enum[])type.getEnumConstants()) { - if (c.name().equalsIgnoreCase(name)) { + for (Enum c : (Enum[])type.getEnumConstants()) + if (c.name().equalsIgnoreCase(name)) return c; - } - } // all else failed throw e; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumMapConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumMapConverter.java (.../EnumMapConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumMapConverter.java (.../EnumMapConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,62 +10,60 @@ * Created on 06. April 2005 by Joe Walnes */ +// ***** READ THIS ***** +// This class will only compile with JDK 1.5.0 or above as it test Java enums. +// If you are using an earlier version of Java, just don't try to build this class. XStream should work fine without it. + package com.thoughtworks.xstream.converters.enums; -import java.lang.reflect.Field; -import java.util.EnumMap; - +import com.thoughtworks.xstream.converters.collections.MapConverter; import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; -import com.thoughtworks.xstream.converters.collections.MapConverter; -import com.thoughtworks.xstream.core.util.Fields; -import com.thoughtworks.xstream.io.HierarchicalStreamReader; -import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.core.util.Fields; +import java.util.EnumMap; +import java.lang.reflect.Field; /** - * Converts an {@link EnumMap}, including the type of Enum it's for. - *

- * If a {@link SecurityManager} is set, the converter will only work with permissions for SecurityManager.checkPackageAccess, - * SecurityManager.checkMemberAccess(this, EnumSet.MEMBER) and ReflectPermission("suppressAccessChecks"). - *

- * + * Serializes an Java 5 EnumMap, including the type of Enum it's for. If a SecurityManager is set, the converter will only work with permissions + * for SecurityManager.checkPackageAccess, SecurityManager.checkMemberAccess(this, EnumSet.MEMBER) + * and ReflectPermission("suppressAccessChecks"). + * * @author Joe Walnes */ public class EnumMapConverter extends MapConverter { private final static Field typeField = Fields.locate(EnumMap.class, Class.class, false); - public EnumMapConverter(final Mapper mapper) { + public EnumMapConverter(Mapper mapper) { super(mapper); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return typeField != null && type == EnumMap.class; } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Class type = (Class)Fields.read(typeField, source); - final String attributeName = mapper().aliasForSystemAttribute("enum-type"); + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + Class type = (Class) Fields.read(typeField, source); + String attributeName = mapper().aliasForSystemAttribute("enum-type"); if (attributeName != null) { writer.addAttribute(attributeName, mapper().serializedClass(type)); } super.marshal(source, writer, context); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final String attributeName = mapper().aliasForSystemAttribute("enum-type"); + @SuppressWarnings("unchecked") + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + String attributeName = mapper().aliasForSystemAttribute("enum-type"); if (attributeName == null) { throw new ConversionException("No EnumType specified for EnumMap"); } - final Class type = mapper().realClass(reader.getAttribute(attributeName)); - @SuppressWarnings({"rawtypes", "unchecked"}) - final EnumMap map = new EnumMap(type); + Class type = mapper().realClass(reader.getAttribute(attributeName)); + EnumMap map = new EnumMap(type); populateMap(reader, context, map); return map; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumSetConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumSetConverter.java (.../EnumSetConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumSetConverter.java (.../EnumSetConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,28 +10,30 @@ * Created on 06. April 2005 by Joe Walnes */ +// ***** READ THIS ***** +// This class will only compile with JDK 1.5.0 or above as it test Java enums. +// If you are using an earlier version of Java, just don't try to build this class. XStream should work fine without it. + package com.thoughtworks.xstream.converters.enums; -import java.lang.reflect.Field; -import java.util.EnumSet; - import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; -import com.thoughtworks.xstream.core.util.Fields; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; +import com.thoughtworks.xstream.core.util.Fields; +import java.lang.reflect.Field; +import java.util.EnumSet; +import java.util.Iterator; /** - * Converts an {@link EnumSet}. - *

- * If a SecurityManager is set, the converter will only work with permissions for SecurityManager.checkPackageAccess, - * SecurityManager.checkMemberAccess(this, EnumSet.MEMBER) and ReflectPermission("suppressAccessChecks"). - *

- * + * Serializes a Java 5 EnumSet. If a SecurityManager is set, the converter will only work with permissions + * for SecurityManager.checkPackageAccess, SecurityManager.checkMemberAccess(this, EnumSet.MEMBER) + * and ReflectPermission("suppressAccessChecks"). + * * @author Joe Walnes * @author Jörg Schaible */ @@ -40,30 +42,29 @@ private final static Field typeField = Fields.locate(EnumSet.class, Class.class, false); private final Mapper mapper; - public EnumSetConverter(final Mapper mapper) { + public EnumSetConverter(Mapper mapper) { this.mapper = mapper; } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return typeField != null && EnumSet.class.isAssignableFrom(type); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final EnumSet set = (EnumSet)source; - final Class enumTypeForSet = (Class)Fields.read(typeField, set); - final String attributeName = mapper.aliasForSystemAttribute("enum-type"); + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + EnumSet set = (EnumSet) source; + Class enumTypeForSet = (Class) Fields.read(typeField, set); + String attributeName = mapper.aliasForSystemAttribute("enum-type"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(enumTypeForSet)); } writer.setValue(joinEnumValues(set)); } - private String joinEnumValues(final EnumSet set) { + private String joinEnumValues(EnumSet set) { boolean seenFirst = false; - final StringBuilder result = new StringBuilder(); - for (final Enum value : set) { + StringBuffer result = new StringBuffer(); + for (Iterator iterator = set.iterator(); iterator.hasNext();) { + Enum value = (Enum) iterator.next(); if (seenFirst) { result.append(','); } else { @@ -74,26 +75,19 @@ return result.toString(); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final String attributeName = mapper.aliasForSystemAttribute("enum-type"); + @SuppressWarnings("unchecked") + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + String attributeName = mapper.aliasForSystemAttribute("enum-type"); if (attributeName == null) { throw new ConversionException("No EnumType specified for EnumSet"); } - @SuppressWarnings("rawtypes") - final Class enumTypeForSet = mapper.realClass(reader.getAttribute(attributeName)); - @SuppressWarnings("unchecked") - final EnumSet set = create(enumTypeForSet, reader.getValue()); - return set; - } - - private > EnumSet create(final Class type, final String s) { - final String[] enumValues = s.split(","); - final EnumSet set = EnumSet.noneOf(type); - for (final String enumValue : enumValues) { - if (enumValue.length() > 0) { - final T value = Enum.valueOf(type, enumValue); - set.add(value); + Class enumTypeForSet = mapper.realClass(reader.getAttribute(attributeName)); + EnumSet set = EnumSet.noneOf(enumTypeForSet); + String[] enumValues = reader.getValue().split(","); + for (int i = 0; i < enumValues.length; i++) { + String enumValue = enumValues[i]; + if(enumValue.length() > 0) { + set.add(Enum.valueOf(enumTypeForSet, enumValue)); } } return set; Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumSingleValueConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumSingleValueConverter.java (.../EnumSingleValueConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumSingleValueConverter.java (.../EnumSingleValueConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2009, 2010, 2013, 2014 XStream Committers. + * Copyright (C) 2008, 2009, 2010, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,34 +14,37 @@ /** - * A single value converter for a special enum type. Converter is internally automatically instantiated for enum types. + * A single value converter for a special enum type. Converter is internally automatically + * instantiated for enum types. * * @author Jörg Schaible * @since 1.3 */ -public class EnumSingleValueConverter> extends AbstractSingleValueConverter { +public class EnumSingleValueConverter extends AbstractSingleValueConverter { - private final Class enumType; + private final Class enumType; - public EnumSingleValueConverter(final Class type) { - if (!Enum.class.isAssignableFrom(type) && !Enum.class.equals(type)) { + public EnumSingleValueConverter(Class type) { + if (!Enum.class.isAssignableFrom(type) && type != Enum.class) { throw new IllegalArgumentException("Converter can only handle defined enums"); } enumType = type; } @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return enumType.isAssignableFrom(type); } @Override - public String toString(final Object obj) { + public String toString(Object obj) { return Enum.class.cast(obj).name(); } @Override - public Object fromString(final String str) { - return Enum.valueOf(enumType, str); + public Object fromString(String str) { + @SuppressWarnings("unchecked") + Enum result = Enum.valueOf(enumType, str); + return result; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumToStringConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumToStringConverter.java (.../EnumToStringConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/enums/EnumToStringConverter.java (.../EnumToStringConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2014 XStream Committers. + * Copyright (C) 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.Map; +import com.thoughtworks.xstream.InitializationException; import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; @@ -31,71 +32,72 @@ private final Map strings; private final EnumMap values; - public EnumToStringConverter(final Class type) { + public EnumToStringConverter(Class type) { this(type, extractStringMap(type), null); } - public EnumToStringConverter(final Class type, final Map strings) { + public EnumToStringConverter(Class type, Map strings) { this(type, strings, buildValueMap(type, strings)); } - private EnumToStringConverter(final Class type, final Map strings, final EnumMap values) { + private EnumToStringConverter( + Class type, Map strings, EnumMap values) { enumType = type; this.strings = strings; this.values = values; } - private static > Map extractStringMap(final Class type) { + private static > Map extractStringMap(Class type) { checkType(type); - final EnumSet values = EnumSet.allOf(type); - final Map strings = new HashMap(values.size()); - for (final T value : values) { + EnumSet values = EnumSet.allOf(type); + Map strings = new HashMap(values.size()); + for (T value : values) { if (strings.put(value.toString(), value) != null) { - throw new IllegalArgumentException("Enum type " + throw new InitializationException("Enum type " + type.getName() + " does not have unique string representations for its values"); } } return strings; } - private static void checkType(final Class type) { + private static void checkType(Class type) { if (!Enum.class.isAssignableFrom(type) && type != Enum.class) { - throw new IllegalArgumentException("Converter can only handle enum types"); + throw new InitializationException("Converter can only handle enum types"); } } - private static > EnumMap buildValueMap(final Class type, - final Map strings) { - final EnumMap values = new EnumMap(type); - for (final Map.Entry entry : strings.entrySet()) { + private static > EnumMap buildValueMap(Class type, + Map strings) { + EnumMap values = new EnumMap(type); + for (Map.Entry entry : strings.entrySet()) { values.put(entry.getValue(), entry.getKey()); } return values; } @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return enumType.isAssignableFrom(type); } @Override - public String toString(final Object obj) { - return values == null ? obj.toString() : values.get(obj); + public String toString(Object obj) { + Enum value = Enum.class.cast(obj); + return values == null ? value.toString() : values.get(value); } @Override - public Object fromString(final String str) { + public Object fromString(String str) { if (str == null) { return null; } - final T result = strings.get(str); + T result = strings.get(str); if (result == null) { - throw new ConversionException("Invalid string representation for enum type " - + enumType.getName() - + ": <" - + str - + ">"); + ConversionException exception = new ConversionException("Invalid string representation for enum type"); + exception.add("enum-type", enumType.getName()); + exception.add("enum-string", str); + throw exception; } return result; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ActivationDataFlavorConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ActivationDataFlavorConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ActivationDataFlavorConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2015 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 21.06.2015 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.extended; + +import javax.activation.ActivationDataFlavor; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.Converter; +import com.thoughtworks.xstream.converters.MarshallingContext; +import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; + + +/** + * Converts an {@link ActivationDataFlavor}. + * + * @author Jörg Schaible + * @since 1.4.9 + */ +public class ActivationDataFlavorConverter implements Converter { + + public boolean canConvert(final Class type) { + return type == ActivationDataFlavor.class; + } + + public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { + final ActivationDataFlavor dataFlavor = (ActivationDataFlavor)source; + final String mimeType = dataFlavor.getMimeType(); + if (mimeType != null) { + writer.startNode("mimeType"); + writer.setValue(mimeType); + writer.endNode(); + } + final String name = dataFlavor.getHumanPresentableName(); + if (name != null) { + writer.startNode("humanRepresentableName"); + writer.setValue(name); + writer.endNode(); + } + final Class representationClass = dataFlavor.getRepresentationClass(); + if (representationClass != null) { + writer.startNode("representationClass"); + context.convertAnother(representationClass); + writer.endNode(); + } + } + + public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + String mimeType = null; + String name = null; + Class type = null; + while (reader.hasMoreChildren()) { + reader.moveDown(); + + final String elementName = reader.getNodeName(); + if (elementName.equals("mimeType")) { + mimeType = reader.getValue(); + } else if (elementName.equals("humanRepresentableName")) { + name = reader.getValue(); + } else if (elementName.equals("representationClass")) { + type = (Class)context.convertAnother(null, Class.class); + } else { + final ConversionException exception = new ConversionException("Unknown child element"); + exception.add("element", reader.getNodeName()); + throw exception; + } + reader.moveUp(); + } + ActivationDataFlavor dataFlavor = null; + try { + if (type == null) { + dataFlavor = new ActivationDataFlavor(mimeType, name); + } else if (mimeType == null) { + dataFlavor = new ActivationDataFlavor(type, name); + } else { + dataFlavor = new ActivationDataFlavor(type, mimeType, name); + } + } catch (final IllegalArgumentException ex) { + throw new ConversionException(ex); + } catch (final NullPointerException ex) { + throw new ConversionException(ex); + } + return dataFlavor; + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/CharsetConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/CharsetConverter.java (.../CharsetConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/CharsetConverter.java (.../CharsetConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,31 +10,28 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.nio.charset.Charset; - import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; +import java.nio.charset.Charset; /** - * Converts a {@link Charset} to a string. + * Converts a java.nio.charset.Carset to a string. * * @author Jörg Schaible * @since 1.2 */ public class CharsetConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return Charset.class.isAssignableFrom(type); } - @Override - public String toString(final Object obj) { - return ((Charset)obj).name(); + public String toString(Object obj) { + return obj == null ? null : ((Charset)obj).name(); } - @Override - public Object fromString(final String str) { + + public Object fromString(String str) { return Charset.forName(str); } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ColorConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ColorConverter.java (.../ColorConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ColorConverter.java (.../ColorConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,57 +11,56 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.awt.Color; -import java.util.HashMap; -import java.util.Map; - import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import java.awt.Color; +import java.util.HashMap; +import java.util.Map; /** - * Converts an AWT {@link Color}, using four nested elements: red, green, blue, alpha. - * + * Converts a java.awt.Color to XML, using four nested elements: + * red, green, blue, alpha. + * * @author Joe Walnes */ public class ColorConverter implements Converter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { // String comparison is used here because Color.class loads the class which in turns instantiates AWT, // which is nasty if you don't want it. return type.getName().equals("java.awt.Color"); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Color color = (Color)source; + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + Color color = (Color) source; write("red", color.getRed(), writer); write("green", color.getGreen(), writer); write("blue", color.getBlue(), writer); write("alpha", color.getAlpha(), writer); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final Map elements = new HashMap(); + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + Map elements = new HashMap(); while (reader.hasMoreChildren()) { reader.moveDown(); elements.put(reader.getNodeName(), Integer.valueOf(reader.getValue())); reader.moveUp(); } - return new Color(elements.get("red").intValue(), elements.get("green").intValue(), elements - .get("blue") - .intValue(), elements.get("alpha").intValue()); + return new Color(((Integer) elements.get("red")).intValue(), + ((Integer) elements.get("green")).intValue(), + ((Integer) elements.get("blue")).intValue(), + ((Integer) elements.get("alpha")).intValue()); } - private void write(final String fieldName, final int value, final HierarchicalStreamWriter writer) { + private void write(String fieldName, int value, HierarchicalStreamWriter writer) { ExtendedHierarchicalStreamWriterHelper.startNode(writer, fieldName, int.class); writer.setValue(String.valueOf(value)); writer.endNode(); } + } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/CurrencyConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/CurrencyConverter.java (.../CurrencyConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/CurrencyConverter.java (.../CurrencyConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -15,26 +15,21 @@ import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; - /** - * Converts a {@link Currency} to a string. - *

- * Despite the name of this class, it has nothing to do with converting currencies between exchange rates! It makes - * sense in the context of XStream. - *

- * - * @author Jose A. Illescas + * Converts a java.util.Currency to String. Despite the name of this class, it has nothing to do with converting + * currencies between exchange rates! It makes sense in the context of XStream. + * + * @author Jose A. Illescas * @author Joe Walnes */ public class CurrencyConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(Currency.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return Currency.getInstance(str); } + } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/DurationConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/DurationConverter.java (.../DurationConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/DurationConverter.java (.../DurationConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2011, 2014 XStream Committers. + * Copyright (C) 2007, 2008, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,21 +10,20 @@ */ package com.thoughtworks.xstream.converters.extended; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.Duration; -import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; - /** - * A Converter for the XML Schema datatype duration and the - * Java type {@link Duration}. - *

- * The implementation uses a {@link DatatypeFactory} to create Duration objects. If no factory is provided and the - * instantiation of the internal factory fails with a {@link DatatypeConfigurationException} , the converter will not - * claim the responsibility for Duration objects. - *

+ * A Converter for the XML Schema datatype duration and the Java type + * {@link Duration}. The implementation uses a {@link DatatypeFactory} to create Duration + * objects. If no factory is provided and the instantiation of the internal factory fails with a + * {@link DatatypeConfigurationException}, the converter will not claim the responsibility for + * Duration objects. * * @author John Kristian * @author Jörg Schaible @@ -45,17 +44,15 @@ }.getFactory()); } - public DurationConverter(final DatatypeFactory factory) { + public DurationConverter(DatatypeFactory factory) { this.factory = factory; } - @Override - public boolean canConvert(final Class c) { + public boolean canConvert(Class c) { return factory != null && Duration.class.isAssignableFrom(c); } - @Override - public Object fromString(final String s) { + public Object fromString(String s) { return factory.newDuration(s); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/DynamicProxyConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/DynamicProxyConverter.java (.../DynamicProxyConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/DynamicProxyConverter.java (.../DynamicProxyConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2010, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2010, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,13 +11,6 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.ArrayList; -import java.util.List; - import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; @@ -29,91 +22,92 @@ import com.thoughtworks.xstream.mapper.DynamicProxyMapper; import com.thoughtworks.xstream.mapper.Mapper; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.List; /** - * Converts a dynamic proxy to XML, storing the implemented interfaces and handler. - * + * Converts a dynamic proxy to XML, storing the implemented + * interfaces and handler. + * * @author Joe Walnes */ public class DynamicProxyConverter implements Converter { - private final ClassLoaderReference classLoaderReference; - private final Mapper mapper; + private ClassLoaderReference classLoaderReference; + private Mapper mapper; private static final Field HANDLER = Fields.locate(Proxy.class, InvocationHandler.class, false); private static final InvocationHandler DUMMY = new InvocationHandler() { - @Override - public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return null; } }; /** * @deprecated As of 1.4.5 use {@link #DynamicProxyConverter(Mapper, ClassLoaderReference)} */ - @Deprecated - public DynamicProxyConverter(final Mapper mapper) { + public DynamicProxyConverter(Mapper mapper) { this(mapper, DynamicProxyConverter.class.getClassLoader()); } /** * Construct a DynamicProxyConverter. - * * @param mapper the Mapper chain * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance * @since 1.4.5 */ - public DynamicProxyConverter(final Mapper mapper, final ClassLoaderReference classLoaderReference) { + public DynamicProxyConverter(Mapper mapper, ClassLoaderReference classLoaderReference) { this.classLoaderReference = classLoaderReference; this.mapper = mapper; } /** * @deprecated As of 1.4.5 use {@link #DynamicProxyConverter(Mapper, ClassLoaderReference)} */ - @Deprecated - public DynamicProxyConverter(final Mapper mapper, final ClassLoader classLoader) { - this(mapper, new ClassLoaderReference(classLoader)); + public DynamicProxyConverter(Mapper mapper, ClassLoader classLoader) { + this(mapper,new ClassLoaderReference(classLoader)); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(DynamicProxyMapper.DynamicProxy.class) || Proxy.isProxyClass(type); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final InvocationHandler invocationHandler = Proxy.getInvocationHandler(source); + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + InvocationHandler invocationHandler = Proxy.getInvocationHandler(source); addInterfacesToXml(source, writer); writer.startNode("handler"); - final String attributeName = mapper.aliasForSystemAttribute("class"); + String attributeName = mapper.aliasForSystemAttribute("class"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(invocationHandler.getClass())); } context.convertAnother(invocationHandler); writer.endNode(); } - private void addInterfacesToXml(final Object source, final HierarchicalStreamWriter writer) { - final Class[] interfaces = source.getClass().getInterfaces(); - for (final Class currentInterface : interfaces) { + private void addInterfacesToXml(Object source, HierarchicalStreamWriter writer) { + Class[] interfaces = source.getClass().getInterfaces(); + for (int i = 0; i < interfaces.length; i++) { + Class currentInterface = interfaces[i]; writer.startNode("interface"); writer.setValue(mapper.serializedClass(currentInterface)); writer.endNode(); } } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final List> interfaces = new ArrayList>(); + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + List interfaces = new ArrayList(); InvocationHandler handler = null; - Class handlerType = null; + Class handlerType = null; while (reader.hasMoreChildren()) { reader.moveDown(); - final String elementName = reader.getNodeName(); + String elementName = reader.getNodeName(); if (elementName.equals("interface")) { interfaces.add(mapper.realClass(reader.getValue())); } else if (elementName.equals("handler")) { - final String attributeName = mapper.aliasForSystemAttribute("class"); + String attributeName = mapper.aliasForSystemAttribute("class"); if (attributeName != null) { handlerType = mapper.realClass(reader.getAttribute(attributeName)); break; @@ -124,13 +118,13 @@ if (handlerType == null) { throw new ConversionException("No InvocationHandler specified for dynamic proxy"); } - final Class[] interfacesAsArray = new Class[interfaces.size()]; + Class[] interfacesAsArray = new Class[interfaces.size()]; interfaces.toArray(interfacesAsArray); Object proxy = null; if (HANDLER != null) { // we will not be able to resolve references to the proxy proxy = Proxy.newProxyInstance(classLoaderReference.getReference(), interfacesAsArray, DUMMY); } - handler = (InvocationHandler)context.convertAnother(proxy, handlerType); + handler = (InvocationHandler) context.convertAnother(proxy, handlerType); reader.moveUp(); if (HANDLER != null) { Fields.write(HANDLER, proxy, handler); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/EncodedByteArrayConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/EncodedByteArrayConverter.java (.../EncodedByteArrayConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/EncodedByteArrayConverter.java (.../EncodedByteArrayConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2010, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2010 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,9 +11,6 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.util.ArrayList; -import java.util.List; - import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.SingleValueConverter; @@ -23,10 +20,13 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; /** * Converts a byte array to a single Base64 encoding string. - * + * * @author Joe Walnes * @author Jörg Schaible */ @@ -35,19 +35,16 @@ private static final Base64Encoder base64 = new Base64Encoder(); private static final ByteConverter byteConverter = new ByteConverter(); - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.isArray() && type.getComponentType().equals(byte.class); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { writer.setValue(toString(source)); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final String data = reader.getValue(); // needs to be called before hasMoreChildren. + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + String data = reader.getValue(); // needs to be called before hasMoreChildren. if (!reader.hasMoreChildren()) { return fromString(data); } else { @@ -56,32 +53,31 @@ } } - private Object unmarshalIndividualByteElements(final HierarchicalStreamReader reader, - final UnmarshallingContext context) { - // have to create a temporary list because we don't know the size of the array - final List bytes = new ArrayList(); + private Object unmarshalIndividualByteElements(HierarchicalStreamReader reader, UnmarshallingContext context) { + List bytes = new ArrayList(); // have to create a temporary list because don't know the size of the array boolean firstIteration = true; while (firstIteration || reader.hasMoreChildren()) { // hangover from previous hasMoreChildren reader.moveDown(); - bytes.add((Byte)byteConverter.fromString(reader.getValue())); + bytes.add(byteConverter.fromString(reader.getValue())); reader.moveUp(); firstIteration = false; } // copy into real array - final byte[] result = new byte[bytes.size()]; - for (int i = 0; i < result.length; ++i) { - result[i] = bytes.get(i).byteValue(); + byte[] result = new byte[bytes.size()]; + int i = 0; + for (Iterator iterator = bytes.iterator(); iterator.hasNext();) { + Byte b = (Byte) iterator.next(); + result[i] = b.byteValue(); + i++; } return result; } - @Override - public String toString(final Object obj) { - return base64.encode((byte[])obj); + public String toString(Object obj) { + return base64.encode((byte[]) obj); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return base64.decode(str); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/FileConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/FileConverter.java (.../FileConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/FileConverter.java (.../FileConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,34 +11,28 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.io.File; - import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; +import java.io.File; /** - * Converts a {@link File}. - * - *

This converter will take care of storing and retrieving {@link File} with either an absolute path OR a relative path - * depending on how they were created.

- * + * This converter will take care of storing and retrieving File with either + * an absolute path OR a relative path depending on how they were created. + * * @author Joe Walnes */ public class FileConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(File.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return new File(str); } - @Override - public String toString(final Object obj) { - return ((File)obj).getPath(); + public String toString(Object obj) { + return ((File) obj).getPath(); } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/FontConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/FontConverter.java (.../FontConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/FontConverter.java (.../FontConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,75 +11,69 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.awt.Font; -import java.awt.font.TextAttribute; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import javax.swing.plaf.FontUIResource; - import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; +import javax.swing.plaf.FontUIResource; -/** - * Converts an AWT {@link Font}. - */ +import java.awt.Font; +import java.awt.font.TextAttribute; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + public class FontConverter implements Converter { private final SingleValueConverter textAttributeConverter; private final Mapper mapper; /** * Constructs a FontConverter. - * * @deprecated As of 1.4.5 */ - @Deprecated public FontConverter() { this(null); } /** * Constructs a FontConverter. - * * @param mapper * @since 1.4.5 */ - public FontConverter(final Mapper mapper) { + public FontConverter(Mapper mapper) { this.mapper = mapper; if (mapper == null) { textAttributeConverter = null; } else { textAttributeConverter = new TextAttributeConverter(); } } - - @Override - public boolean canConvert(final Class type) { + + public boolean canConvert(Class type) { // String comparison is used here because Font.class loads the class which in turns instantiates AWT, // which is nasty if you don't want it. return type.getName().equals("java.awt.Font") || type.getName().equals("javax.swing.plaf.FontUIResource"); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Font font = (Font)source; - final Map attributes = font.getAttributes(); + public void marshal(Object source, HierarchicalStreamWriter writer, + MarshallingContext context) { + Font font = (Font)source; + Map attributes = font.getAttributes(); if (mapper != null) { - final String classAlias = mapper.aliasForSystemAttribute("class"); - for (final Map.Entry entry : attributes.entrySet()) { - final String name = textAttributeConverter.toString(entry.getKey()); - final Object value = entry.getValue(); - final Class type = value != null ? value.getClass() : Mapper.Null.class; + String classAlias = mapper.aliasForSystemAttribute("class"); + for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { + Map.Entry entry = (Map.Entry)iter.next(); + String name = textAttributeConverter.toString(entry.getKey()); + Object value = entry.getValue(); + Class type = value != null ? value.getClass() : Mapper.Null.class; ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, type); writer.addAttribute(classAlias, mapper.serializedClass(type)); if (value != null) { @@ -94,41 +88,39 @@ } } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final Map attributes; + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + final Map attributes; if (reader.hasMoreChildren()) { reader.moveDown(); if (!reader.getNodeName().equals("attributes")) { - final String classAlias = mapper.aliasForSystemAttribute("class"); - attributes = new HashMap(); + String classAlias = mapper.aliasForSystemAttribute("class"); + attributes = new HashMap(); do { if (!attributes.isEmpty()) { reader.moveDown(); } - final Class type = mapper.realClass(reader.getAttribute(classAlias)); - final TextAttribute attribute = (TextAttribute)textAttributeConverter.fromString(reader.getNodeName()); - final Object value = type == Mapper.Null.class ? null : context.convertAnother(null, type); + Class type = mapper.realClass(reader.getAttribute(classAlias)); + TextAttribute attribute = (TextAttribute)textAttributeConverter.fromString(reader.getNodeName()); + Object value = type == Mapper.Null.class ? null : context.convertAnother(null, type); attributes.put(attribute, value); reader.moveUp(); - } while (reader.hasMoreChildren()); + } while(reader.hasMoreChildren()); } else { // in - @SuppressWarnings("unchecked") - final Map typedAttributes = (Map)context.convertAnother( - null, Map.class); - attributes = typedAttributes; + attributes = (Map)context.convertAnother(null, Map.class); reader.moveUp(); // out of } } else { - attributes = Collections.emptyMap(); + attributes = Collections.EMPTY_MAP; } - for (final Iterator iter = attributes.values().iterator(); iter.hasNext();) { - if (iter.next() == null) { - iter.remove(); + if (!JVM.is16()) { + for (Iterator iter = attributes.values().iterator(); iter.hasNext(); ) { + if (iter.next() == null) { + iter.remove(); + } } } - final Font font = Font.getFont(attributes); + Font font = Font.getFont(attributes); if (context.getRequiredType() == FontUIResource.class) { return new FontUIResource(font); } else { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/GregorianCalendarConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/GregorianCalendarConverter.java (.../GregorianCalendarConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/GregorianCalendarConverter.java (.../GregorianCalendarConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,50 +11,44 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.util.GregorianCalendar; -import java.util.TimeZone; - import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; /** - * Converts a {@link GregorianCalendar}. - *

- * Note that although it currently only contains one field, it nests it inside a child element, to allow for other - * fields to be stored in the future. - *

- * + * Converts a java.util.GregorianCalendar to XML. Note that although it currently only contains one field, it nests + * it inside a child element, to allow for other fields to be stored in the future. + * * @author Joe Walnes * @author Jörg Schaible */ public class GregorianCalendarConverter implements Converter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(GregorianCalendar.class); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final GregorianCalendar calendar = (GregorianCalendar)source; + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + GregorianCalendar calendar = (GregorianCalendar) source; ExtendedHierarchicalStreamWriterHelper.startNode(writer, "time", long.class); - final long timeInMillis = calendar.getTimeInMillis(); + long timeInMillis = calendar.getTime().getTime(); // calendar.getTimeInMillis() not available under JDK 1.3 writer.setValue(String.valueOf(timeInMillis)); writer.endNode(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, "timezone", String.class); writer.setValue(calendar.getTimeZone().getID()); writer.endNode(); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { reader.moveDown(); - final long timeInMillis = Long.parseLong(reader.getValue()); + long timeInMillis = Long.parseLong(reader.getValue()); reader.moveUp(); final String timeZone; if (reader.hasMoreChildren()) { @@ -65,9 +59,9 @@ timeZone = TimeZone.getDefault().getID(); } - final GregorianCalendar result = new GregorianCalendar(); + GregorianCalendar result = new GregorianCalendar(); result.setTimeZone(TimeZone.getTimeZone(timeZone)); - result.setTimeInMillis(timeInMillis); + result.setTime(new Date(timeInMillis)); // calendar.setTimeInMillis() not available under JDK 1.3 return result; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ISO8601DateConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ISO8601DateConverter.java (.../ISO8601DateConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ISO8601DateConverter.java (.../ISO8601DateConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2017 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,33 +13,30 @@ import java.util.Calendar; import java.util.Date; +import java.util.GregorianCalendar; import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; /** - * A converter for {@link Date} conforming to the ISO8601 standard. + * A DateConverter conforming to the ISO8601 standard. + * http://www.iso.ch/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=26780 * - * @see ISO 8601 * @author Mauro Talevi * @author Jörg Schaible */ public class ISO8601DateConverter extends AbstractSingleValueConverter { - private final ISO8601GregorianCalendarConverter converter = new ISO8601GregorianCalendarConverter(); - @Override - public boolean canConvert(final Class type) { - return type.equals(Date.class); + public boolean canConvert(Class type) { + return type.equals(Date.class) && converter.canConvert(GregorianCalendar.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return ((Calendar)converter.fromString(str)).getTime(); } - @Override - public String toString(final Object obj) { + public String toString(Object obj) { final Calendar calendar = Calendar.getInstance(); calendar.setTime((Date)obj); return converter.toString(calendar); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter.java (.../ISO8601GregorianCalendarConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ISO8601GregorianCalendarConverter.java (.../ISO8601GregorianCalendarConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2011, 2013, 2014, 2015, 2016, 2017 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,113 +11,57 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.util.Calendar; +import java.lang.reflect.InvocationTargetException; import java.util.GregorianCalendar; -import java.util.TimeZone; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.ISODateTimeFormat; - -import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; +import com.thoughtworks.xstream.core.JVM; /** - * A converter for {@link GregorianCalendar} conforming to the ISO8601 standard. - *

- * The converter will always serialize the calendar value in UTC and deserialize it to a value in the current default - * time zone. - *

+ * A GregorianCalendarConverter conforming to the ISO8601 standard. The converter will always serialize the calendar + * value in UTC and deserialize it to a value in the current default time zone. * * @author Mauro Talevi * @author Jörg Schaible * @see ISO 8601 * @since 1.1.3 */ public class ISO8601GregorianCalendarConverter extends AbstractSingleValueConverter { - private static final DateTimeFormatter[] formattersUTC = new DateTimeFormatter[]{ // - ISODateTimeFormat.dateTime(), // - ISODateTimeFormat.dateTimeNoMillis(), // - ISODateTimeFormat.basicDateTime(), // - ISODateTimeFormat.basicOrdinalDateTime(), // - ISODateTimeFormat.basicOrdinalDateTimeNoMillis(), // - ISODateTimeFormat.basicTime(), // - ISODateTimeFormat.basicTimeNoMillis(), // - ISODateTimeFormat.basicTTime(), // - ISODateTimeFormat.basicTTimeNoMillis(), // - ISODateTimeFormat.basicWeekDateTime(), // - ISODateTimeFormat.basicWeekDateTimeNoMillis(), // - ISODateTimeFormat.ordinalDateTime(), // - ISODateTimeFormat.ordinalDateTimeNoMillis(), // - ISODateTimeFormat.time(), // - ISODateTimeFormat.timeNoMillis(), // - ISODateTimeFormat.tTime(), // - ISODateTimeFormat.tTimeNoMillis(), // - ISODateTimeFormat.weekDateTime(), // - ISODateTimeFormat.weekDateTimeNoMillis() // - }; - private static final DateTimeFormatter[] formattersNoUTC = new DateTimeFormatter[]{ // - ISODateTimeFormat.basicDate(), // - ISODateTimeFormat.basicOrdinalDate(), // - ISODateTimeFormat.basicWeekDate(), // - ISODateTimeFormat.date(), // - ISODateTimeFormat.dateHour(), // - ISODateTimeFormat.dateHourMinute(), // - ISODateTimeFormat.dateHourMinuteSecond(), // - ISODateTimeFormat.dateHourMinuteSecondFraction(), // - ISODateTimeFormat.dateHourMinuteSecondMillis(), // - ISODateTimeFormat.hour(), // - ISODateTimeFormat.hourMinute(), // - ISODateTimeFormat.hourMinuteSecond(), // - ISODateTimeFormat.hourMinuteSecondFraction(), // - ISODateTimeFormat.hourMinuteSecondMillis(), // - ISODateTimeFormat.ordinalDate(), // - ISODateTimeFormat.weekDate(), // - ISODateTimeFormat.year(), // - ISODateTimeFormat.yearMonth(), // - ISODateTimeFormat.yearMonthDay(), // - ISODateTimeFormat.weekyear(), // - ISODateTimeFormat.weekyearWeek(), // - ISODateTimeFormat.weekyearWeekDay() // - }; + private final static Class[] EMPTY_CLASS_ARRAY = new Class[0]; + private final static Object[] EMPTY_OBJECT_ARRAY = new Object[0]; + private final SingleValueConverter converter; - @Override - public boolean canConvert(final Class type) { - return type.equals(GregorianCalendar.class); + public ISO8601GregorianCalendarConverter() { + SingleValueConverter svConverter = null; + final Class type = JVM.loadClassForName(JVM.is18() + ? "com.thoughtworks.xstream.core.util.ISO8601JavaTimeConverter" + : "com.thoughtworks.xstream.core.util.ISO8601JodaTimeConverter"); + try { + svConverter = (SingleValueConverter)type.getDeclaredConstructor(EMPTY_CLASS_ARRAY).newInstance( + EMPTY_OBJECT_ARRAY); + } catch (final InstantiationException e) { + // ignore + } catch (final IllegalAccessException e) { + // ignore + } catch (final InvocationTargetException e) { + // ignore + } catch (final NoSuchMethodException e) { + // ignore + } + converter = svConverter; } - @Override + public boolean canConvert(final Class type) { + return converter != null && type.equals(GregorianCalendar.class); + } + public Object fromString(final String str) { - for (final DateTimeFormatter formatter : formattersUTC) { - try { - final DateTime dt = formatter.parseDateTime(str); - final Calendar calendar = dt.toGregorianCalendar(); - calendar.setTimeZone(TimeZone.getDefault()); - return calendar; - } catch (final IllegalArgumentException e) { - // try with next formatter - } - } - final String timeZoneID = TimeZone.getDefault().getID(); - for (final DateTimeFormatter element : formattersNoUTC) { - try { - final DateTimeFormatter formatter = element.withZone(DateTimeZone.forID(timeZoneID)); - final DateTime dt = formatter.parseDateTime(str); - final Calendar calendar = dt.toGregorianCalendar(); - calendar.setTimeZone(TimeZone.getDefault()); - return calendar; - } catch (final IllegalArgumentException e) { - // try with next formatter - } - } - throw new ConversionException("Cannot parse date " + str); + return converter.fromString(str); } - @Override public String toString(final Object obj) { - final DateTime dt = new DateTime(obj); - return dt.toString(formattersUTC[0]); + return converter.toString(obj); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ISO8601SqlTimestampConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ISO8601SqlTimestampConverter.java (.../ISO8601SqlTimestampConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ISO8601SqlTimestampConverter.java (.../ISO8601SqlTimestampConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2017 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,30 +16,27 @@ /** - * A converter for {@link Timestamp} conforming to the ISO8601 standard. + * A SqlTimestampConverter conforming to the ISO8601 standard. + * http://www.iso.ch/iso/en/CatalogueDetailPage.CatalogueDetail?CSNUMBER=26780 * - * @see ISO 8601 * @author Jörg Schaible * @since 1.1.3 */ public class ISO8601SqlTimestampConverter extends ISO8601DateConverter { private final static String PADDING = "000000000"; - @Override - public boolean canConvert(final Class type) { - return type.equals(Timestamp.class); + public boolean canConvert(Class type) { + return type.equals(Timestamp.class) && super.canConvert(Date.class); } - @Override public Object fromString(String str) { final int idxFraction = str.lastIndexOf('.'); int nanos = 0; if (idxFraction > 0) { int idx; - for (idx = idxFraction + 1; Character.isDigit(str.charAt(idx)); ++idx) { + for (idx = idxFraction + 1; Character.isDigit(str.charAt(idx)); ++idx) ; - } nanos = Integer.parseInt(str.substring(idxFraction + 1, idx)); str = str.substring(0, idxFraction) + str.substring(idx); } @@ -49,16 +46,15 @@ return timestamp; } - @Override - public String toString(final Object obj) { + public String toString(Object obj) { final Timestamp timestamp = (Timestamp)obj; - String str = super.toString(new Date(timestamp.getTime() / 1000 * 1000)); + String str = super.toString(new Date((timestamp.getTime() / 1000) * 1000)); final String nanos = String.valueOf(timestamp.getNanos()); final int idxFraction = str.lastIndexOf('.'); str = str.substring(0, idxFraction + 1) - + PADDING.substring(nanos.length()) - + nanos - + str.substring(idxFraction + 4); + + PADDING.substring(nanos.length()) + + nanos + + str.substring(idxFraction + 4); return str; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/JavaClassConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/JavaClassConverter.java (.../JavaClassConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/JavaClassConverter.java (.../JavaClassConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -18,9 +18,8 @@ import com.thoughtworks.xstream.mapper.DefaultMapper; import com.thoughtworks.xstream.mapper.Mapper; - /** - * Converts a {@link Class} to a string. + * Converts a java.lang.Class to XML. * * @author Aslak Hellesøy * @author Joe Walnes @@ -29,52 +28,46 @@ */ public class JavaClassConverter extends AbstractSingleValueConverter { - private final Mapper mapper; + private Mapper mapper; /** * Construct a JavaClassConverter. - * * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance * @since 1.4.5 */ - public JavaClassConverter(final ClassLoaderReference classLoaderReference) { + public JavaClassConverter(ClassLoaderReference classLoaderReference) { this(new DefaultMapper(classLoaderReference)); } /** * @deprecated As of 1.4.5 use {@link #JavaClassConverter(ClassLoaderReference)} */ - @Deprecated - public JavaClassConverter(final ClassLoader classLoader) { + public JavaClassConverter(ClassLoader classLoader) { this(new ClassLoaderReference(classLoader)); } /** - * Construct a JavaClassConverter that uses a provided mapper. Depending on the mapper chain it will not only be - * used to load classes, but also to support type aliases. - * + * Construct a JavaClassConverter that uses a provided mapper. Depending on the mapper + * chain it will not only be used to load classes, but also to support type aliases. * @param mapper to use * @since 1.4.5 */ - protected JavaClassConverter(final Mapper mapper) { + protected JavaClassConverter(Mapper mapper) { this.mapper = mapper; } - @Override - public boolean canConvert(final Class clazz) { + public boolean canConvert(Class clazz) { return Class.class.equals(clazz); // :) } - @Override - public String toString(final Object obj) { - return mapper.serializedClass((Class)obj); + public String toString(Object obj) { + return mapper.serializedClass(((Class) obj)); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { try { return mapper.realClass(str); - } catch (final CannotResolveClassException e) { + } catch (CannotResolveClassException e) { throw new ConversionException("Cannot load java class " + str, e.getCause()); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/JavaFieldConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/JavaFieldConverter.java (.../JavaFieldConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/JavaFieldConverter.java (.../JavaFieldConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2013, 2014 XStream Committers. + * Copyright (C) 2009, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,9 +10,6 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.lang.reflect.Field; - -import com.thoughtworks.xstream.InitializationException; import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; @@ -24,9 +21,10 @@ import com.thoughtworks.xstream.mapper.DefaultMapper; import com.thoughtworks.xstream.mapper.Mapper; +import java.lang.reflect.Field; /** - * Converts a {@link Field}. + * Converts a java.lang.reflect.Field to XML. * * @author Jörg Schaible */ @@ -37,46 +35,38 @@ /** * Construct a JavaFieldConverter. - * * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance * @since 1.4.5 */ - public JavaFieldConverter(final ClassLoaderReference classLoaderReference) { + public JavaFieldConverter(ClassLoaderReference classLoaderReference) { this(new JavaClassConverter(classLoaderReference), new DefaultMapper(classLoaderReference)); } /** * @deprecated As of 1.4.5 use {@link #JavaFieldConverter(ClassLoaderReference)} */ - @Deprecated - public JavaFieldConverter(final ClassLoader classLoader) { + public JavaFieldConverter(ClassLoader classLoader) { this(new ClassLoaderReference(classLoader)); } /** * Construct a JavaFieldConverter. Depending on the mapper chain the converter will also respect aliases. - * - * @param javaClassConverter the converter to use + * @param javaClassConverter the converter to use * @param mapper to use * @since 1.4.5 */ - protected JavaFieldConverter(final SingleValueConverter javaClassConverter, final Mapper mapper) { - if (!javaClassConverter.canConvert(Class.class)) { - throw new InitializationException("Java Class Converter cannot handle Class types"); - } + protected JavaFieldConverter(SingleValueConverter javaClassConverter, Mapper mapper) { this.javaClassConverter = javaClassConverter; this.mapper = mapper; } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(Field.class); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Field field = (Field)source; - final Class type = field.getDeclaringClass(); + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + Field field = (Field) source; + Class type = field.getDeclaringClass(); writer.startNode("name"); writer.setValue(mapper.serializedMember(type, field.getName())); @@ -87,26 +77,25 @@ writer.endNode(); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { String methodName = null; String declaringClassName = null; - - while ((methodName == null || declaringClassName == null) && reader.hasMoreChildren()) { + + while((methodName == null || declaringClassName == null) && reader.hasMoreChildren()) { reader.moveDown(); - + if (reader.getNodeName().equals("name")) { methodName = reader.getValue(); } else if (reader.getNodeName().equals("clazz")) { declaringClassName = reader.getValue(); } reader.moveUp(); } - - final Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName); + + Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName); try { return declaringClass.getDeclaredField(mapper.realMember(declaringClass, methodName)); - } catch (final NoSuchFieldException e) { + } catch (NoSuchFieldException e) { throw new ConversionException(e); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/JavaMethodConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/JavaMethodConverter.java (.../JavaMethodConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/JavaMethodConverter.java (.../JavaMethodConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,12 +11,6 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import com.thoughtworks.xstream.InitializationException; import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; @@ -26,9 +20,13 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; /** - * Converts a {@link Method}. + * Converts a java.lang.reflect.Method to XML. * * @author Aslak Hellesøy * @author Jörg Schaible @@ -39,55 +37,46 @@ /** * Construct a JavaMethodConverter. - * * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance * @since 1.4.5 */ - public JavaMethodConverter(final ClassLoaderReference classLoaderReference) { + public JavaMethodConverter(ClassLoaderReference classLoaderReference) { this(new JavaClassConverter(classLoaderReference)); } /** * @deprecated As of 1.4.5 use {@link #JavaMethodConverter(ClassLoaderReference)} */ - @Deprecated - public JavaMethodConverter(final ClassLoader classLoader) { + public JavaMethodConverter(ClassLoader classLoader) { this(new ClassLoaderReference(classLoader)); } /** * Construct a JavaMethodConverter. - * - * @param javaClassConverter the converter to use + * @param javaClassConverter the converter to use * @since 1.4.5 */ - protected JavaMethodConverter(final SingleValueConverter javaClassConverter) { - if (!javaClassConverter.canConvert(Class.class)) { - throw new InitializationException("Java Class Converter cannot handle Class types"); - } + protected JavaMethodConverter(SingleValueConverter javaClassConverter) { this.javaClassConverter = javaClassConverter; } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(Method.class) || type.equals(Constructor.class); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { if (source instanceof Method) { - final Method method = (Method)source; - final String declaringClassName = javaClassConverter.toString(method.getDeclaringClass()); + Method method = (Method) source; + String declaringClassName = javaClassConverter.toString(method.getDeclaringClass()); marshalMethod(writer, declaringClassName, method.getName(), method.getParameterTypes()); } else { - final Constructor method = (Constructor)source; - final String declaringClassName = javaClassConverter.toString(method.getDeclaringClass()); + Constructor method = (Constructor) source; + String declaringClassName = javaClassConverter.toString(method.getDeclaringClass()); marshalMethod(writer, declaringClassName, null, method.getParameterTypes()); } } - private void marshalMethod(final HierarchicalStreamWriter writer, final String declaringClassName, - final String methodName, final Class[] parameterTypes) { + private void marshalMethod(HierarchicalStreamWriter writer, String declaringClassName, String methodName, Class[] parameterTypes) { writer.startNode("class"); writer.setValue(declaringClassName); @@ -101,22 +90,21 @@ } writer.startNode("parameter-types"); - for (final Class parameterType : parameterTypes) { + for (int i = 0; i < parameterTypes.length; i++) { writer.startNode("class"); - writer.setValue(javaClassConverter.toString(parameterType)); + writer.setValue(javaClassConverter.toString(parameterTypes[i])); writer.endNode(); } writer.endNode(); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { try { - final boolean isMethodNotConstructor = context.getRequiredType().equals(Method.class); + boolean isMethodNotConstructor = context.getRequiredType().equals(Method.class); reader.moveDown(); - final String declaringClassName = reader.getValue(); - final Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName); + String declaringClassName = reader.getValue(); + Class declaringClass = (Class)javaClassConverter.fromString(declaringClassName); reader.moveUp(); String methodName = null; @@ -127,22 +115,22 @@ } reader.moveDown(); - final List> parameterTypeList = new ArrayList>(); + List parameterTypeList = new ArrayList(); while (reader.hasMoreChildren()) { reader.moveDown(); - final String parameterTypeName = reader.getValue(); - parameterTypeList.add((Class)javaClassConverter.fromString(parameterTypeName)); + String parameterTypeName = reader.getValue(); + parameterTypeList.add(javaClassConverter.fromString(parameterTypeName)); reader.moveUp(); } - final Class[] parameterTypes = parameterTypeList.toArray(new Class[parameterTypeList.size()]); + Class[] parameterTypes = (Class[]) parameterTypeList.toArray(new Class[parameterTypeList.size()]); reader.moveUp(); if (isMethodNotConstructor) { return declaringClass.getDeclaredMethod(methodName, parameterTypes); } else { return declaringClass.getDeclaredConstructor(parameterTypes); } - } catch (final NoSuchMethodException e) { + } catch (NoSuchMethodException e) { throw new ConversionException(e); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/LocaleConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/LocaleConverter.java (.../LocaleConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/LocaleConverter.java (.../LocaleConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,37 +1,34 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. * - * Created on 24. July 2004 by Joe Walnes + * Created on 24. Julyl 2004 by Joe Walnes */ package com.thoughtworks.xstream.converters.extended; -import java.util.Locale; - import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; +import java.util.Locale; /** - * Converts a {@link Locale} to a string. - * + * Converts a java.util.Locale to a string. + * * @author Jose A. Illescas * @author Joe Walnes */ public class LocaleConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(Locale.class); } - @Override - public Object fromString(final String str) { - final int[] underscorePositions = underscorePositions(str); + public Object fromString(String str) { + int[] underscorePositions = underscorePositions(str); String language, country, variant; if (underscorePositions[0] == -1) { // "language" language = str; @@ -49,13 +46,13 @@ return new Locale(language, country, variant); } - private int[] underscorePositions(final String in) { - final int[] result = new int[2]; + private int[] underscorePositions(String in) { + int[] result = new int[2]; for (int i = 0; i < result.length; i++) { - final int last = i == 0 ? 0 : result[i - 1]; + int last = i == 0 ? 0 : result[i - 1]; result[i] = in.indexOf('_', last + 1); } return result; } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/LookAndFeelConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/LookAndFeelConverter.java (.../LookAndFeelConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/LookAndFeelConverter.java (.../LookAndFeelConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2013, 2014 XStream Committers. + * Copyright (C) 2007, 2008, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,21 +10,19 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.io.NotSerializableException; - -import javax.swing.LookAndFeel; - import com.thoughtworks.xstream.converters.reflection.ReflectionConverter; import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; import com.thoughtworks.xstream.mapper.Mapper; +import javax.swing.LookAndFeel; +import java.io.NotSerializableException; + + /** - * A converter for Swing {@link LookAndFeel} implementations. - *

- * The JDK's implementations are serializable for historical reasons but will throw a {@link NotSerializableException} - * in their writeObject method. Therefore XStream will use an implementation based on the ReflectionConverter. - *

+ * A converter for Swing LookAndFeel implementations. The JDK's implementations are serializable + * for historical reasons but will throw a {@link NotSerializableException} in their writeObject + * method. Therefore XStream will use an implementation based on the ReflectionConverter. * * @author Jörg Schaible * @since 1.3 @@ -38,12 +36,11 @@ * @param reflectionProvider the reflection provider * @since 1.3 */ - public LookAndFeelConverter(final Mapper mapper, final ReflectionProvider reflectionProvider) { + public LookAndFeelConverter(Mapper mapper, ReflectionProvider reflectionProvider) { super(mapper, reflectionProvider); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return LookAndFeel.class.isAssignableFrom(type) && canAccess(type); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/NamedArrayConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/NamedArrayConverter.java (.../NamedArrayConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/NamedArrayConverter.java (.../NamedArrayConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2014 XStream Committers. + * Copyright (C) 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -24,7 +24,6 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; - /** * An array converter that uses predefined names for its items. *

@@ -36,19 +35,18 @@ */ public class NamedArrayConverter implements Converter { - private final Class arrayType; + private final Class arrayType; private final String itemName; private final Mapper mapper; /** * Construct a NamedArrayConverter. - * * @param arrayType * @param mapper * @param itemName * @since 1.4.6 */ - public NamedArrayConverter(final Class arrayType, final Mapper mapper, final String itemName) { + public NamedArrayConverter(final Class arrayType, final Mapper mapper, final String itemName) { if (!arrayType.isArray()) { throw new IllegalArgumentException(arrayType.getName() + " is not an array"); } @@ -57,19 +55,19 @@ this.itemName = itemName; } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(final Class type) { return type == arrayType; } - @Override public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final int length = Array.getLength(source); for (int i = 0; i < length; ++i) { final Object item = Array.get(source, i); - final Class itemType = item == null ? Mapper.Null.class : arrayType.getComponentType().isPrimitive() - ? Primitives.unbox(item.getClass()) - : item.getClass(); + final Class itemType = item == null + ? Mapper.Null.class + : arrayType.getComponentType().isPrimitive() + ? Primitives.unbox(item.getClass()) + : item.getClass(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, itemName, itemType); if (!itemType.equals(arrayType.getComponentType())) { final String attributeName = mapper.aliasForSystemAttribute("class"); @@ -84,14 +82,13 @@ } } - @Override public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final List list = new ArrayList(); + final List list = new ArrayList(); while (reader.hasMoreChildren()) { reader.moveDown(); final Object item; final String className = HierarchicalStreams.readClassAttribute(reader, mapper); - final Class itemType = className == null ? arrayType.getComponentType() : mapper.realClass(className); + final Class itemType = className == null ? arrayType.getComponentType() : mapper.realClass(className); if (Mapper.Null.class.equals(itemType)) { item = null; } else { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/NamedCollectionConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/NamedCollectionConverter.java (.../NamedCollectionConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/NamedCollectionConverter.java (.../NamedCollectionConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2014 XStream Committers. + * Copyright (C) 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,8 +10,6 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.util.Collection; - import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.converters.collections.CollectionConverter; @@ -25,7 +23,8 @@ /** * A collection converter that uses predefined names for its items. *

- * To be used as local converter. Note, suppress the usage of the implicit type argument, if registered with annotation. + * To be used as local converter. Note, suppress the usage of the implicit type argument, if + * registered with annotation. *

* * @author Jörg Schaible @@ -34,7 +33,7 @@ public class NamedCollectionConverter extends CollectionConverter { private final String name; - private final Class type; + private final Class type; /** * Constructs a NamedCollectionConverter. @@ -44,7 +43,7 @@ * @param itemType the base type of the items * @since 1.4.5 */ - public NamedCollectionConverter(final Mapper mapper, final String itemName, final Class itemType) { + public NamedCollectionConverter(Mapper mapper, String itemName, Class itemType) { this(null, mapper, itemName, itemType); } @@ -57,20 +56,17 @@ * @param itemType the base type of the items * @since 1.4.5 */ - public NamedCollectionConverter( - @SuppressWarnings("rawtypes") final Class type, final Mapper mapper, - final String itemName, final Class itemType) { + public NamedCollectionConverter(Class type, Mapper mapper, String itemName, Class itemType) { super(mapper, type); - name = itemName; + this.name = itemName; this.type = itemType; } - @Override - protected void writeItem(final Object item, final MarshallingContext context, final HierarchicalStreamWriter writer) { - final Class itemType = item == null ? Mapper.Null.class : item.getClass(); + protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) { + Class itemType = item == null ? Mapper.Null.class : item.getClass(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType); if (!itemType.equals(type)) { - final String attributeName = mapper().aliasForSystemAttribute("class"); + String attributeName = mapper().aliasForSystemAttribute("class"); if (attributeName != null) { writer.addAttribute(attributeName, mapper().serializedClass(itemType)); } @@ -81,11 +77,9 @@ writer.endNode(); } - @Override - protected Object readItem(final HierarchicalStreamReader reader, final UnmarshallingContext context, - final Object current) { - final String className = HierarchicalStreams.readClassAttribute(reader, mapper()); - final Class itemType = className == null ? type : mapper().realClass(className); + protected Object readItem(HierarchicalStreamReader reader, UnmarshallingContext context, Object current) { + String className = HierarchicalStreams.readClassAttribute(reader, mapper()); + Class itemType = className == null ? type : mapper().realClass(className); if (Mapper.Null.class.equals(itemType)) { return null; } else { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/NamedMapConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/NamedMapConverter.java (.../NamedMapConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/NamedMapConverter.java (.../NamedMapConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2014 XStream Committers. + * Copyright (C) 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,6 +10,7 @@ */ package com.thoughtworks.xstream.converters.extended; +import java.util.Iterator; import java.util.Map; import com.thoughtworks.xstream.converters.ConversionException; @@ -19,6 +20,7 @@ import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.converters.collections.MapConverter; +import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.core.util.HierarchicalStreams; import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; @@ -29,11 +31,13 @@ /** * A map converter that uses predefined names for its elements. *

- * To be used as local converter. Note, suppress the usage of the implicit type argument, if registered with annotation. - * Depending on the constructor arguments it is possible to support various formats: + * To be used as local converter. Note, suppress the usage of the implicit type argument, if + * registered with annotation. Depending on the constructor arguments it is possible to support + * various formats: *

*
    - *
  • new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value", Integer.class); + *
  • new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value", + * Integer.class); * *
      * <map>
    @@ -45,7 +49,8 @@
      * 
    * *
  • - *
  • new NamedMapConverter(xstream.getMapper(), null, "key", String.class, "value", Integer.class); + *
  • new NamedMapConverter(xstream.getMapper(), null, "key", String.class, "value", + * Integer.class); * *
      * <map>
    @@ -55,8 +60,8 @@
      * 
    * *
  • - *
  • new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value", Integer.class, true, true, - * xstream.getConverterLookup()); + *
  • new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value", + * Integer.class, true, true, xstream.getConverterLookup()); * *
      * <map>
    @@ -65,8 +70,8 @@
      * 
    * *
  • - *
  • new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value", Integer.class, true, false, - * xstream.getConverterLookup()); + *
  • new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value", + * Integer.class, true, false, xstream.getConverterLookup()); * *
      * <map>
    @@ -77,8 +82,8 @@
      * 
    * *
  • - *
  • new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value", Integer.class, false, true, - * xstream.getConverterLookup()); + *
  • new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, "value", + * Integer.class, false, true, xstream.getConverterLookup()); * *
      * <map>
    @@ -89,8 +94,8 @@
      * 
    * *
  • - *
  • new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, null, Integer.class, true, false, - * xstream.getConverterLookup()); + *
  • new NamedMapConverter(xstream.getMapper(), "entry", "key", String.class, null, + * Integer.class, true, false, xstream.getConverterLookup()); * *
      * <map>
    @@ -108,9 +113,9 @@
     
         private final String entryName;
         private final String keyName;
    -    private final Class keyType;
    +    private final Class keyType;
         private final String valueName;
    -    private final Class valueType;
    +    private final Class valueType;
         private final boolean keyAsAttribute;
         private final boolean valueAsAttribute;
         private final ConverterLookup lookup;
    @@ -128,8 +133,8 @@
          * @since 1.4.5
          */
         public NamedMapConverter(
    -            final Mapper mapper, final String entryName, final String keyName, final Class keyType,
    -            final String valueName, final Class valueType) {
    +        Mapper mapper, String entryName, String keyName, Class keyType, String valueName,
    +        Class valueType) {
             this(mapper, entryName, keyName, keyType, valueName, valueType, false, false, null);
         }
     
    @@ -146,9 +151,10 @@
          * @since 1.4.5
          */
         public NamedMapConverter(
    -            @SuppressWarnings("rawtypes") final Class type, final Mapper mapper, final String entryName,
    -            final String keyName, final Class keyType, final String valueName, final Class valueType) {
    -        this(type, mapper, entryName, keyName, keyType, valueName, valueType, false, false, null);
    +        Class type, Mapper mapper, String entryName, String keyName, Class keyType,
    +        String valueName, Class valueType) {
    +        this(
    +            type, mapper, entryName, keyName, keyType, valueName, valueType, false, false, null);
         }
     
         /**
    @@ -166,10 +172,12 @@
          * @since 1.4.5
          */
         public NamedMapConverter(
    -            final Mapper mapper, final String entryName, final String keyName, final Class keyType,
    -            final String valueName, final Class valueType, final boolean keyAsAttribute,
    -            final boolean valueAsAttribute, final ConverterLookup lookup) {
    -        this(null, mapper, entryName, keyName, keyType, valueName, valueType, keyAsAttribute, valueAsAttribute, lookup);
    +        Mapper mapper, String entryName, String keyName, Class keyType, String valueName,
    +        Class valueType, boolean keyAsAttribute, boolean valueAsAttribute,
    +        ConverterLookup lookup) {
    +        this(
    +            null, mapper, entryName, keyName, keyType, valueName, valueType, keyAsAttribute,
    +            valueAsAttribute, lookup);
         }
     
         /**
    @@ -188,9 +196,9 @@
          * @since 1.4.5
          */
         public NamedMapConverter(
    -            @SuppressWarnings("rawtypes") final Class type, final Mapper mapper, final String entryName,
    -            final String keyName, final Class keyType, final String valueName, final Class valueType,
    -            final boolean keyAsAttribute, final boolean valueAsAttribute, final ConverterLookup lookup) {
    +        Class type, Mapper mapper, String entryName, String keyName, Class keyType,
    +        String valueName, Class valueType, boolean keyAsAttribute, boolean valueAsAttribute,
    +        ConverterLookup lookup) {
             super(mapper, type);
             this.entryName = entryName != null && entryName.length() == 0 ? null : entryName;
             this.keyName = keyName != null && keyName.length() == 0 ? null : keyName;
    @@ -200,52 +208,57 @@
             this.keyAsAttribute = keyAsAttribute;
             this.valueAsAttribute = valueAsAttribute;
             this.lookup = lookup;
    -        enumMapper = UseAttributeForEnumMapper.createEnumMapper(mapper);
    +        enumMapper = JVM.is15() ? UseAttributeForEnumMapper.createEnumMapper(mapper) : null;
     
             if (keyType == null || valueType == null) {
                 throw new IllegalArgumentException("Class types of key and value are mandatory");
             }
             if (entryName == null) {
                 if (keyAsAttribute || valueAsAttribute) {
    -                throw new IllegalArgumentException("Cannot write attributes to map entry, if map entry must be omitted");
    +                throw new IllegalArgumentException(
    +                    "Cannot write attributes to map entry, if map entry must be omitted");
                 }
                 if (valueName == null) {
    -                throw new IllegalArgumentException("Cannot write value as text of entry, if entry must be omitted");
    +                throw new IllegalArgumentException(
    +                    "Cannot write value as text of entry, if entry must be omitted");
                 }
             }
             if (keyName == null) {
                 throw new IllegalArgumentException("Cannot write key without name");
             }
             if (valueName == null) {
                 if (valueAsAttribute) {
    -                throw new IllegalArgumentException("Cannot write value as attribute without name");
    +                throw new IllegalArgumentException(
    +                    "Cannot write value as attribute without name");
                 } else if (!keyAsAttribute) {
    -                throw new IllegalArgumentException("Cannot write value as text of entry, if key is also child element");
    +                throw new IllegalArgumentException(
    +                    "Cannot write value as text of entry, if key is also child element");
                 }
             }
             if (keyAsAttribute && valueAsAttribute && keyName.equals(valueName)) {
    -            throw new IllegalArgumentException("Cannot write key and value with same attribute name");
    +            throw new IllegalArgumentException(
    +                "Cannot write key and value with same attribute name");
             }
         }
     
    -    @Override
    -    public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
    -        final Map map = (Map)source;
    +    public void marshal(Object source, HierarchicalStreamWriter writer,
    +        MarshallingContext context) {
    +        Map map = (Map)source;
             SingleValueConverter keyConverter = null;
             SingleValueConverter valueConverter = null;
             if (keyAsAttribute) {
    -            final SingleValueConverter singleValueConverter = getSingleValueConverter(keyType);
    -            keyConverter = singleValueConverter;
    +            keyConverter = getSingleValueConverter(keyType, "key");
             }
             if (valueAsAttribute || valueName == null) {
    -            final SingleValueConverter singleValueConverter = getSingleValueConverter(valueType);
    -            valueConverter = singleValueConverter;
    +            valueConverter = getSingleValueConverter(valueType, "value");
             }
    -        for (final Map.Entry entry : map.entrySet()) {
    -            final Object key = entry.getKey();
    -            final Object value = entry.getValue();
    +        for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
    +            Map.Entry entry = (Map.Entry)iterator.next();
    +            Object key = entry.getKey();
    +            Object value = entry.getValue();
                 if (entryName != null) {
    -                ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryName, entry.getClass());
    +                ExtendedHierarchicalStreamWriterHelper.startNode(
    +                    writer, entryName, entry.getClass());
                     if (keyConverter != null && key != null) {
                         writer.addAttribute(keyName, keyConverter.toString(key));
                     }
    @@ -269,16 +282,15 @@
             }
         }
     
    -    @Override
    -    protected void populateMap(final HierarchicalStreamReader reader, final UnmarshallingContext context,
    -            final Map map, final Map target) {
    +    protected void populateMap(HierarchicalStreamReader reader, UnmarshallingContext context,
    +        Map map, Map target) {
             SingleValueConverter keyConverter = null;
             SingleValueConverter valueConverter = null;
             if (keyAsAttribute) {
    -            keyConverter = getSingleValueConverter(keyType);
    +            keyConverter = getSingleValueConverter(keyType, "key");
             }
             if (valueAsAttribute || valueName == null) {
    -            valueConverter = getSingleValueConverter(valueType);
    +            valueConverter = getSingleValueConverter(valueType, "value");
             }
     
             while (reader.hasMoreChildren()) {
    @@ -289,14 +301,14 @@
                     reader.moveDown();
     
                     if (keyConverter != null) {
    -                    final String attribute = reader.getAttribute(keyName);
    +                    String attribute = reader.getAttribute(keyName);
                         if (attribute != null) {
                             key = keyConverter.fromString(attribute);
                         }
                     }
     
                     if (valueAsAttribute && valueConverter != null) {
    -                    final String attribute = reader.getAttribute(valueName);
    +                    String attribute = reader.getAttribute(valueName);
                         if (attribute != null) {
                             value = valueConverter.fromString(attribute);
                         }
    @@ -305,7 +317,9 @@
     
                 if (keyConverter == null) {
                     reader.moveDown();
    -                if (valueConverter == null && !keyName.equals(valueName) && reader.getNodeName().equals(valueName)) {
    +                if (valueConverter == null
    +                    && !keyName.equals(valueName)
    +                    && reader.getNodeName().equals(valueName)) {
                         value = readItem(valueType, reader, context, map);
                     } else {
                         key = readItem(keyType, reader, context, map);
    @@ -322,39 +336,38 @@
                     }
                     reader.moveUp();
                 } else if (!valueAsAttribute) {
    -                value = reader.getValue();
    +                value = valueConverter.fromString(reader.getValue());
                 }
     
    -            @SuppressWarnings("unchecked")
    -            final Map targetMap = (Map)target;
    -            targetMap.put(key, value);
    +            target.put(key, value);
     
                 if (entryName != null) {
                     reader.moveUp();
                 }
             }
         }
     
    -    private SingleValueConverter getSingleValueConverter(final Class type) {
    -        SingleValueConverter conv = Enum.class.isAssignableFrom(type) ? enumMapper.getConverterFromItemType(null, type,
    -            null) : mapper().getConverterFromItemType(null, type, null);
    +    private SingleValueConverter getSingleValueConverter(Class type, String part) {
    +        SingleValueConverter conv = UseAttributeForEnumMapper.isEnum(type) ? enumMapper
    +            .getConverterFromItemType(null, type, null) : mapper().getConverterFromItemType(
    +            null, type, null);
             if (conv == null) {
    -            final Converter converter = lookup.lookupConverterForType(type);
    +            Converter converter = lookup.lookupConverterForType(type);
                 if (converter instanceof SingleValueConverter) {
                     conv = (SingleValueConverter)converter;
                 } else {
    -                throw new ConversionException("No SingleValueConverter for key available");
    +                throw new ConversionException("No SingleValueConverter for " + part +  " available");
                 }
             }
             return conv;
         }
     
    -    protected void writeItem(final String name, final Class type, final Object item,
    -            final MarshallingContext context, final HierarchicalStreamWriter writer) {
    -        final Class itemType = item == null ? Mapper.Null.class : item.getClass();
    +    protected void writeItem(String name, Class type, Object item, MarshallingContext context,
    +        HierarchicalStreamWriter writer) {
    +        Class itemType = item == null ? Mapper.Null.class : item.getClass();
             ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
             if (!itemType.equals(type)) {
    -            final String attributeName = mapper().aliasForSystemAttribute("class");
    +            String attributeName = mapper().aliasForSystemAttribute("class");
                 if (attributeName != null) {
                     writer.addAttribute(attributeName, mapper().serializedClass(itemType));
                 }
    @@ -365,10 +378,10 @@
             writer.endNode();
         }
     
    -    protected Object readItem(final Class type, final HierarchicalStreamReader reader,
    -            final UnmarshallingContext context, final Object current) {
    -        final String className = HierarchicalStreams.readClassAttribute(reader, mapper());
    -        final Class itemType = className == null ? type : mapper().realClass(className);
    +    protected Object readItem(Class type, HierarchicalStreamReader reader,
    +        UnmarshallingContext context, Object current) {
    +        String className = HierarchicalStreams.readClassAttribute(reader, mapper());
    +        Class itemType = className == null ? type : mapper().realClass(className);
             if (Mapper.Null.class.equals(itemType)) {
                 return null;
             } else {
    Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/PathConverter.java
    ===================================================================
    diff -u
    --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/PathConverter.java	(revision 0)
    +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/PathConverter.java	(revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
    @@ -0,0 +1,64 @@
    +/*
    + * Copyright (C) 2016 XStream Committers.
    + * All rights reserved.
    + *
    + * The software in this package is published under the terms of the BSD
    + * style license a copy of which has been included with this distribution in
    + * the LICENSE.txt file.
    + *
    + * Created on 7. February 2016 by Aaron Johnson
    + */
    +package com.thoughtworks.xstream.converters.extended;
    +
    +import java.io.File;
    +import java.net.URI;
    +import java.net.URISyntaxException;
    +import java.nio.file.FileSystems;
    +import java.nio.file.Path;
    +import java.nio.file.Paths;
    +
    +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
    +
    +
    +/**
    + * Converts a {@link Path} to string.
    + *
    + * @author Aaron Johnson
    + * @author Jörg Schaible
    + */
    +public class PathConverter extends AbstractSingleValueConverter {
    +
    +    @Override
    +    public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) {
    +        return Path.class.isAssignableFrom(type);
    +    }
    +
    +    @Override
    +    public Path fromString(final String str) {
    +        try {
    +            final URI uri = new URI(str);
    +            if (uri.getScheme() == null) {
    +                return Paths.get(str);
    +            } else {
    +                return Paths.get(uri);
    +            }
    +        } catch (final URISyntaxException e) {
    +            return Paths.get(str);
    +        }
    +    }
    +
    +    @Override
    +    public String toString(final Object obj) {
    +        final Path path = (Path)obj;
    +        if (path.getFileSystem() == FileSystems.getDefault()) {
    +            final String localPath = path.toString();
    +            if (File.separatorChar != '/') {
    +                return localPath.replace(File.separatorChar, '/');
    +            } else {
    +                return localPath;
    +            }
    +        } else {
    +            return path.toUri().toString();
    +        }
    +    }
    +}
    Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/PropertyEditorCapableConverter.java
    ===================================================================
    diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
    --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/PropertyEditorCapableConverter.java	(.../PropertyEditorCapableConverter.java)	(revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
    +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/PropertyEditorCapableConverter.java	(.../PropertyEditorCapableConverter.java)	(revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
    @@ -1,5 +1,5 @@
     /*
    - * Copyright (C) 2007, 2008, 2014 XStream Committers.
    + * Copyright (C) 2007, 2008 XStream Committers.
      * All rights reserved.
      *
      * The software in this package is published under the terms of the BSD
    @@ -10,15 +10,15 @@
      */
     package com.thoughtworks.xstream.converters.extended;
     
    -import java.beans.PropertyEditor;
    -
     import com.thoughtworks.xstream.converters.SingleValueConverter;
     import com.thoughtworks.xstream.core.util.ThreadSafePropertyEditor;
     
    +import java.beans.PropertyEditor;
     
    +
     /**
    - * A SingleValueConverter that can utilize a {@link PropertyEditor} implementation used for a specific type. The
    - * converter ensures that the editors can be used concurrently.
    + * A SingleValueConverter that can utilize a {@link PropertyEditor} implementation used for a
    + * specific type. The converter ensures that the editors can be used concurrently.
      * 
      * @author Jukka Lindström
      * @author Jörg Schaible
    @@ -27,24 +27,21 @@
     public class PropertyEditorCapableConverter implements SingleValueConverter {
     
         private final ThreadSafePropertyEditor editor;
    -    private final Class type;
    +    private final Class type;
     
    -    public PropertyEditorCapableConverter(final Class propertyEditorType, final Class type) {
    +    public PropertyEditorCapableConverter(final Class propertyEditorType, final Class type) {
             this.type = type;
             editor = new ThreadSafePropertyEditor(propertyEditorType, 2, 5);
         }
     
    -    @Override
    -    public boolean canConvert(final Class type) {
    +    public boolean canConvert(final Class type) {
             return this.type == type;
         }
     
    -    @Override
         public Object fromString(final String str) {
             return editor.setAsText(str);
         }
     
    -    @Override
         public String toString(final Object obj) {
             return editor.getAsText(obj);
         }
    Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/RegexPatternConverter.java
    ===================================================================
    diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81
    --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/RegexPatternConverter.java	(.../RegexPatternConverter.java)	(revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80)
    +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/RegexPatternConverter.java	(.../RegexPatternConverter.java)	(revision e22799e3f19d9b43efda2fcad687abb2e111fa81)
    @@ -1,6 +1,6 @@
     /*
      * Copyright (C) 2004, 2005 Joe Walnes.
    - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers.
    + * Copyright (C) 2006, 2007, 2013 XStream Committers.
      * All rights reserved.
      *
      * The software in this package is published under the terms of the BSD
    @@ -11,20 +11,16 @@
      */
     package com.thoughtworks.xstream.converters.extended;
     
    -import java.util.regex.Pattern;
    -
     import com.thoughtworks.xstream.converters.Converter;
     import com.thoughtworks.xstream.converters.MarshallingContext;
     import com.thoughtworks.xstream.converters.UnmarshallingContext;
     import com.thoughtworks.xstream.io.HierarchicalStreamReader;
     import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
     
    +import java.util.regex.Pattern;
     
     /**
    - * Converts a {@link Pattern} using two nested elements for the pattern itself and its flags.
    - * 

    - * Ensures that the pattern is compiled upon deserialization. - *

    + * Ensures java.util.regex.Pattern is compiled upon deserialization. * * @author Joe Walnes * @author Jörg Schaible @@ -40,18 +36,15 @@ /** * @deprecated As of 1.4.5, use {@link #RegexPatternConverter()} instead */ - @Deprecated - public RegexPatternConverter(final Converter defaultConverter) { + public RegexPatternConverter(Converter defaultConverter) { } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(final Class type) { return type.equals(Pattern.class); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Pattern pattern = (Pattern)source; + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + Pattern pattern = (Pattern)source; writer.startNode("pattern"); writer.setValue(pattern.pattern()); writer.endNode(); @@ -60,13 +53,12 @@ writer.endNode(); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { reader.moveDown(); - final String pattern = reader.getValue(); + String pattern = reader.getValue(); reader.moveUp(); reader.moveDown(); - final int flags = Integer.parseInt(reader.getValue()); + int flags = Integer.parseInt(reader.getValue()); reader.moveUp(); return Pattern.compile(pattern, flags); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SqlDateConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SqlDateConverter.java (.../SqlDateConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SqlDateConverter.java (.../SqlDateConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -15,21 +15,18 @@ import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; - /** - * Converts a {@link Date} to a string. - * - * @author Jose A. Illescas + * Converts a java.sql.Date to text. + * + * @author Jose A. Illescas */ public class SqlDateConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(Date.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return Date.valueOf(str); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SqlTimeConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SqlTimeConverter.java (.../SqlTimeConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SqlTimeConverter.java (.../SqlTimeConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,28 +11,22 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.sql.Time; - import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; +import java.sql.Time; /** - * Converts a {@link Time} to a string. - *

    - * Warning: Any granularity smaller than seconds is lost. - *

    - * + * Converts a java.sql.Time to text. Warning: Any granularity smaller than seconds is lost. + * * @author Jose A. Illescas */ public class SqlTimeConverter extends AbstractSingleValueConverter { - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(Time.class); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { return Time.valueOf(str); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SqlTimestampConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SqlTimestampConverter.java (.../SqlTimestampConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SqlTimestampConverter.java (.../SqlTimestampConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,76 +1,96 @@ /* * Copyright (C) 2003, 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2012, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2012, 2014, 2016, 2017 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 01. October 2004 by Joe Walnes */ package com.thoughtworks.xstream.converters.extended; -import java.sql.Timestamp; -import java.text.ParseException; -import java.util.TimeZone; - import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; import com.thoughtworks.xstream.core.util.ThreadSafeSimpleDateFormat; +import java.sql.Timestamp; +import java.text.ParseException; +import java.util.TimeZone; + /** * Converts a {@link Timestamp} to a string. - * + * * @author Joe Walnes * @author Jörg Schaible */ public class SqlTimestampConverter extends AbstractSingleValueConverter { - private final ThreadSafeSimpleDateFormat format = new ThreadSafeSimpleDateFormat("yyyy-MM-dd HH:mm:ss", TimeZone - .getTimeZone("UTC"), 0, 5, false); + private final ThreadSafeSimpleDateFormat format; - @Override - public boolean canConvert(final Class type) { + /** + * Constructs a SqlTimestampConverter using UTC format. + */ + public SqlTimestampConverter() { + this(TimeZone.getTimeZone("UTC")); + } + + /** + * Constructs a SqlTimestampConverter. + *

    + * XStream uses by default UTC as time zone. However, if the resulting XML is used as feed for a data base (like MS + * SQL) the server might expect the timestamp to be in local time and does the conversion to UTC on its own. In such + * a case you can register an own instance of the SqlTimestamp converter using e.g. {@link TimeZone#getDefault()}. + *

    + * + * @param timeZone the time zone used for the format + * @since 1.4.10 + */ + public SqlTimestampConverter(final TimeZone timeZone) { + format = new ThreadSafeSimpleDateFormat("yyyy-MM-dd HH:mm:ss", timeZone, 0, 5, false); + } + + public boolean canConvert(Class type) { return type.equals(Timestamp.class); } - @Override public String toString(final Object obj) { final Timestamp timestamp = (Timestamp)obj; - final StringBuilder buffer = new StringBuilder(format.format(timestamp)).append('.'); - if (timestamp.getNanos() == 0) { - buffer.append('0'); - } else { + final StringBuffer buffer = new StringBuffer(format.format(timestamp)); + if (timestamp.getNanos() != 0) { + buffer.append('.'); final String nanos = String.valueOf(timestamp.getNanos() + 1000000000); int last = 10; - while (last > 2 && nanos.charAt(last - 1) == '0') { + while (last > 2 && nanos.charAt(last-1) == '0') --last; - } buffer.append(nanos.subSequence(1, last)); } return buffer.toString(); } - @Override public Object fromString(final String str) { final int idx = str.lastIndexOf('.'); - if (idx < 0 || str.length() - idx < 2 || str.length() - idx > 10) { + if (idx > 0 && (str.length() - idx < 2 || str.length() - idx > 10)) { throw new ConversionException("Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]"); } try { - final Timestamp timestamp = new Timestamp(format.parse(str.substring(0, idx)).getTime()); - final StringBuilder buffer = new StringBuilder(str.substring(idx + 1)); - while (buffer.length() != 9) { - buffer.append('0'); + final Timestamp timestamp = new Timestamp(format.parse(idx < 0 ? str : str.substring(0, idx)).getTime()); + if (idx > 0) { + final StringBuffer buffer = new StringBuffer(str.substring(idx + 1)); + while (buffer.length() != 9) { + buffer.append('0'); + } + timestamp.setNanos(Integer.parseInt(buffer.toString())); } - timestamp.setNanos(Integer.parseInt(buffer.toString())); return timestamp; - } catch (final NumberFormatException e) { - throw new ConversionException("Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]", e); - } catch (final ParseException e) { - throw new ConversionException("Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]"); + } catch (NumberFormatException e) { + throw new ConversionException( + "Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]", e); + } catch (ParseException e) { + throw new ConversionException( + "Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]", e); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/StackTraceElementConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/StackTraceElementConverter.java (.../StackTraceElementConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/StackTraceElementConverter.java (.../StackTraceElementConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,52 +16,74 @@ import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; +import com.thoughtworks.xstream.core.JVM; - /** - * Converter for {@link StackTraceElement} (the lines of a stack trace) to a string. - * + * Converter for StackTraceElement (the lines of a stack trace) - JDK 1.4+ only. + * * @author B. K. Oxley (binkley) * @author Joe Walnes */ public class StackTraceElementConverter extends AbstractSingleValueConverter { // Regular expression to parse a line of a stack trace. Returns 4 groups. // - // Example: - // com.blah.MyClass.doStuff(MyClass.java:123) - // |-------1------| |--2--| |----3-----| |4| + // Example: com.blah.MyClass.doStuff(MyClass.java:123) + // |-------1------| |--2--| |----3-----| |4| // (Note group 4 is optional is optional and only present if a colon char exists.) private static final Pattern PATTERN = Pattern.compile("^(.+)\\.([^\\(]+)\\(([^:]*)(:(\\d+))?\\)$"); - private static final StackTraceElementFactory FACTORY = new StackTraceElementFactory(); - - @Override - public boolean canConvert(final Class type) { - return StackTraceElement.class.equals(type); + private static final StackTraceElementFactory FACTORY; + static { + StackTraceElementFactory factory = null; + if (JVM.is15()) { + Class factoryType = JVM.loadClassForName( + "com.thoughtworks.xstream.converters.extended.StackTraceElementFactory15", + false); + try { + factory = (StackTraceElementFactory)factoryType.newInstance(); + } catch (Exception e) { + // N/A + } catch (LinkageError e) { + // N/A + } + } + if (factory == null) { + factory = new StackTraceElementFactory(); + } + try { + factory.unknownSourceElement("a", "b"); + } catch (Exception e) { + factory = null; + } catch (NoClassDefFoundError e) { // GAE + factory = null; + } + FACTORY = factory; } - @Override - public String toString(final Object obj) { - final String s = super.toString(obj); + public boolean canConvert(Class type) { + return StackTraceElement.class.equals(type) && FACTORY != null; + } + + public String toString(Object obj) { + String s = super.toString(obj); // JRockit adds ":???" for invalid line number return s.replaceFirst(":\\?\\?\\?", ""); } - @Override - public Object fromString(final String str) { - final Matcher matcher = PATTERN.matcher(str); + public Object fromString(String str) { + Matcher matcher = PATTERN.matcher(str); if (matcher.matches()) { - final String declaringClass = matcher.group(1); - final String methodName = matcher.group(2); - final String fileName = matcher.group(3); + String declaringClass = matcher.group(1); + String methodName = matcher.group(2); + String fileName = matcher.group(3); if (fileName.equals("Unknown Source")) { return FACTORY.unknownSourceElement(declaringClass, methodName); } else if (fileName.equals("Native Method")) { return FACTORY.nativeMethodElement(declaringClass, methodName); } else { if (matcher.group(4) != null) { - final int lineNumber = Integer.parseInt(matcher.group(5)); + int lineNumber = Integer.parseInt(matcher.group(5)); return FACTORY.element(declaringClass, methodName, fileName, lineNumber); } else { return FACTORY.element(declaringClass, methodName, fileName); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/StackTraceElementFactory.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/StackTraceElementFactory.java (.../StackTraceElementFactory.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/StackTraceElementFactory.java (.../StackTraceElementFactory.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,43 +1,60 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2014, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 30. May 2004 by Joe Walnes */ package com.thoughtworks.xstream.converters.extended; +import java.lang.reflect.Field; + +import com.thoughtworks.xstream.core.util.Fields; + + /** * Factory for creating StackTraceElements. * * @author B. K. Oxley (binkley) * @author Joe Walnes - * @deprecated As of upcoming, it is an internal helper class + * @deprecated As of 1.4.8, it is an internal helper class */ -@Deprecated public class StackTraceElementFactory { - public StackTraceElement nativeMethodElement(String declaringClass, String methodName) { + public StackTraceElement nativeMethodElement(final String declaringClass, final String methodName) { return create(declaringClass, methodName, "Native Method", -2); } - public StackTraceElement unknownSourceElement(String declaringClass, String methodName) { + public StackTraceElement unknownSourceElement(final String declaringClass, final String methodName) { return create(declaringClass, methodName, "Unknown Source", -1); } - public StackTraceElement element(String declaringClass, String methodName, String fileName) { + public StackTraceElement element(final String declaringClass, final String methodName, final String fileName) { return create(declaringClass, methodName, fileName, -1); } - public StackTraceElement element(String declaringClass, String methodName, String fileName, int lineNumber) { + public StackTraceElement element(final String declaringClass, final String methodName, final String fileName, + final int lineNumber) { return create(declaringClass, methodName, fileName, lineNumber); } - private StackTraceElement create(String declaringClass, String methodName, String fileName, int lineNumber) { - return new StackTraceElement(declaringClass, methodName, fileName, lineNumber); + protected StackTraceElement create(final String declaringClass, final String methodName, final String fileName, + final int lineNumber) { + final StackTraceElement result = new Throwable().getStackTrace()[0]; + setField(result, "declaringClass", declaringClass); + setField(result, "methodName", methodName); + setField(result, "fileName", fileName); + setField(result, "lineNumber", new Integer(lineNumber)); + return result; } + + private void setField(final StackTraceElement element, final String fieldName, final Object value) { + final Field field = Fields.find(StackTraceElement.class, fieldName); + Fields.write(field, element, value); + } + } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/StackTraceElementFactory15.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/StackTraceElementFactory15.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/StackTraceElementFactory15.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2013 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 03. December 2013 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.extended; + +/** + * @author Jörg Schaible + * + * @since 1.4.6 + */ +class StackTraceElementFactory15 extends StackTraceElementFactory { + + @Override + protected StackTraceElement create(final String declaringClass, final String methodName, + final String fileName, final int lineNumber) { + return new StackTraceElement(declaringClass, methodName, fileName, lineNumber); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SubjectConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SubjectConverter.java (.../SubjectConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/SubjectConverter.java (.../SubjectConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,114 +10,102 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.security.Principal; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import javax.security.auth.Subject; - import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; +import javax.security.auth.Subject; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + /** - * Converts a {@link Subject} instance. - *

    - * Note, that this Converter does only convert the contained Principals as it is done by JDK serialization, but not any - * credentials. For other behavior you can derive your own converter, overload the appropriate methods and register it - * in the {@link com.thoughtworks.xstream.XStream}. - *

    - * + * Converts a {@link Subject} instance. Note, that this Converter does only convert the contained Principals as + * it is done by JDK serialization, but not any credentials. For other behaviour you can derive your own converter, + * overload the appropriate methods and register it in the {@link com.thoughtworks.xstream.XStream}. + * * @author Jörg Schaible * @since 1.1.3 */ public class SubjectConverter extends AbstractCollectionConverter { - public SubjectConverter(final Mapper mapper) { + public SubjectConverter(Mapper mapper) { super(mapper); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(Subject.class); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Subject subject = (Subject)source; + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + Subject subject = (Subject) source; marshalPrincipals(subject.getPrincipals(), writer, context); marshalPublicCredentials(subject.getPublicCredentials(), writer, context); marshalPrivateCredentials(subject.getPrivateCredentials(), writer, context); marshalReadOnly(subject.isReadOnly(), writer); } - - protected void marshalPrincipals(final Set principals, final HierarchicalStreamWriter writer, - final MarshallingContext context) { + + protected void marshalPrincipals(Set principals, HierarchicalStreamWriter writer, MarshallingContext context) { writer.startNode("principals"); - for (final Principal principal : principals) { + for (final Iterator iter = principals.iterator(); iter.hasNext();) { + final Object principal = iter.next(); // pre jdk 1.4 a Principal was also in javax.security writeItem(principal, context, writer); } writer.endNode(); }; - - protected void marshalPublicCredentials(final Set pubCredentials, final HierarchicalStreamWriter writer, - final MarshallingContext context) { + + protected void marshalPublicCredentials(Set pubCredentials, HierarchicalStreamWriter writer, MarshallingContext context) { }; - protected void marshalPrivateCredentials(final Set privCredentials, final HierarchicalStreamWriter writer, - final MarshallingContext context) { + protected void marshalPrivateCredentials(Set privCredentials, HierarchicalStreamWriter writer, MarshallingContext context) { }; - - protected void marshalReadOnly(final boolean readOnly, final HierarchicalStreamWriter writer) { + + protected void marshalReadOnly(boolean readOnly, HierarchicalStreamWriter writer) { writer.startNode("readOnly"); writer.setValue(String.valueOf(readOnly)); writer.endNode(); }; - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final Set principals = unmarshalPrincipals(reader, context); - final Set publicCredentials = unmarshalPublicCredentials(reader, context); - final Set privateCredentials = unmarshalPrivateCredentials(reader, context); - final boolean readOnly = unmarshalReadOnly(reader); + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { + Set principals = unmarshalPrincipals(reader, context); + Set publicCredentials = unmarshalPublicCredentials(reader, context); + Set privateCredentials = unmarshalPrivateCredentials(reader, context); + boolean readOnly = unmarshalReadOnly(reader); return new Subject(readOnly, principals, publicCredentials, privateCredentials); } - - protected Set unmarshalPrincipals(final HierarchicalStreamReader reader, - final UnmarshallingContext context) { + + protected Set unmarshalPrincipals(HierarchicalStreamReader reader, UnmarshallingContext context) { return populateSet(reader, context); }; - - protected Set unmarshalPublicCredentials(final HierarchicalStreamReader reader, - final UnmarshallingContext context) { - return Collections.emptySet(); + + protected Set unmarshalPublicCredentials(HierarchicalStreamReader reader, UnmarshallingContext context) { + return Collections.EMPTY_SET; }; - protected Set unmarshalPrivateCredentials(final HierarchicalStreamReader reader, - final UnmarshallingContext context) { - return Collections.emptySet(); + protected Set unmarshalPrivateCredentials(HierarchicalStreamReader reader, UnmarshallingContext context) { + return Collections.EMPTY_SET; }; - protected boolean unmarshalReadOnly(final HierarchicalStreamReader reader) { + protected boolean unmarshalReadOnly(HierarchicalStreamReader reader) { reader.moveDown(); - final boolean readOnly = Boolean.getBoolean(reader.getValue()); + boolean readOnly = Boolean.getBoolean(reader.getValue()); reader.moveUp(); return readOnly; }; - protected Set populateSet(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final Set set = new HashSet(); + protected Set populateSet(HierarchicalStreamReader reader, UnmarshallingContext context) { + Set set = new HashSet(); reader.moveDown(); while (reader.hasMoreChildren()) { reader.moveDown(); - final Principal principal = (Principal)readItem(reader, context, set); + Object elementl = readItem(reader, context, set); reader.moveUp(); - set.add(principal); + set.add(elementl); } reader.moveUp(); return set; Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/TextAttributeConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/TextAttributeConverter.java (.../TextAttributeConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/TextAttributeConverter.java (.../TextAttributeConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,18 +10,19 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.awt.font.TextAttribute; - import com.thoughtworks.xstream.converters.reflection.AbstractAttributedCharacterIteratorAttributeConverter; +import java.awt.font.TextAttribute; + /** - * A converter for {@link TextAttribute} constants to a string. + * A converter for {@link TextAttribute} constants. * * @author Jörg Schaible * @since 1.2 */ -public class TextAttributeConverter extends AbstractAttributedCharacterIteratorAttributeConverter { +public class TextAttributeConverter extends + AbstractAttributedCharacterIteratorAttributeConverter { /** * Constructs a TextAttributeConverter. Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ThrowableConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ThrowableConverter.java (.../ThrowableConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ThrowableConverter.java (.../ThrowableConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -18,61 +18,55 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; - /** - * Converter for {@link Throwable} (and {@link Exception}) that retains stack trace. - * + * Converter for Throwable (and Exception) that retains stack trace. + * * @author B. K. Oxley (binkley) * @author Joe Walnes * @author Jörg Schaible */ public class ThrowableConverter implements Converter { - + private Converter defaultConverter; private final ConverterLookup lookup; /** * @deprecated As of 1.4.5 use {@link #ThrowableConverter(ConverterLookup)} */ - @Deprecated - public ThrowableConverter(final Converter defaultConverter) { + public ThrowableConverter(Converter defaultConverter) { this.defaultConverter = defaultConverter; lookup = null; } /** * @since 1.4.5 */ - public ThrowableConverter(final ConverterLookup lookup) { + public ThrowableConverter(ConverterLookup lookup) { this.lookup = lookup; } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(final Class type) { return Throwable.class.isAssignableFrom(type); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Throwable throwable = (Throwable)source; + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { + Throwable throwable = (Throwable) source; if (throwable.getCause() == null) { try { throwable.initCause(null); - } catch (final IllegalStateException e) { + } catch (IllegalStateException e) { // ignore, initCause failed, cause was already set } } - // force stackTrace field to be lazy loaded by special JVM native witchcraft (outside our control). - throwable.getStackTrace(); + throwable.getStackTrace(); // Force stackTrace field to be lazy loaded by special JVM native witchcraft (outside our control). getConverter().marshal(throwable, writer, context); } private Converter getConverter() { return defaultConverter != null ? defaultConverter : lookup.lookupConverterForType(Object.class); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { return getConverter().unmarshal(reader, context); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ToAttributedValueConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ToAttributedValueConverter.java (.../ToAttributedValueConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ToAttributedValueConverter.java (.../ToAttributedValueConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2011, 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -28,6 +28,7 @@ import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.DuplicateFieldException; import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; +import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.core.util.FastField; import com.thoughtworks.xstream.core.util.HierarchicalStreams; import com.thoughtworks.xstream.core.util.Primitives; @@ -37,21 +38,19 @@ /** - * Converter that supports the definition of one field member that will be written as value and all other field members - * are written as attributes. - *

    - * The converter requires that all the field types (expect the one with the value) are handled by a - * {@link SingleValueConverter}. The value field is defined using the name of the type that declares the field and the - * field name itself. Therefore it is possible to define an inherited field as value. It is also possible to provide no - * value field at all, so that all fields are written as attributes. - *

    + * Converter that supports the definition of one field member that will be written as value and + * all other field members are written as attributes. The converter requires that all the field + * types (expect the one with the value) are handled by a {@link SingleValueConverter}. The + * value field is defined using the name of the type that declares the field and the field name + * itself. Therefore it is possible to define an inherited field as value. It is also possible + * to provide no value field at all, so that all fields are written as attributes. * * @author Jörg Schaible * @since 1.4 */ public class ToAttributedValueConverter implements Converter { private static final String STRUCTURE_MARKER = ""; - private final Class type; + private final Class type; private final Mapper mapper; private final Mapper enumMapper; private final ReflectionProvider reflectionProvider; @@ -61,15 +60,32 @@ /** * Creates a new ToAttributedValueConverter instance. * + * All field elements will be attributes, the element itself will have no value. + * * @param type the type that is handled by this converter instance * @param mapper the mapper in use * @param reflectionProvider the reflection provider in use * @param lookup the converter lookup in use + * @since 1.4.9 + */ + public ToAttributedValueConverter( + final Class type, final Mapper mapper, final ReflectionProvider reflectionProvider, + final ConverterLookup lookup) { + this(type, mapper, reflectionProvider, lookup, null, null); + } + + /** + * Creates a new ToAttributedValueConverter instance. + * + * @param type the type that is handled by this converter instance + * @param mapper the mapper in use + * @param reflectionProvider the reflection provider in use + * @param lookup the converter lookup in use * @param valueFieldName the field defining the tag's value (may be null) */ public ToAttributedValueConverter( - final Class type, final Mapper mapper, final ReflectionProvider reflectionProvider, - final ConverterLookup lookup, final String valueFieldName) { + final Class type, final Mapper mapper, final ReflectionProvider reflectionProvider, + final ConverterLookup lookup, final String valueFieldName) { this(type, mapper, reflectionProvider, lookup, valueFieldName, null); } @@ -84,8 +100,8 @@ * @param valueDefinedIn the type defining the field */ public ToAttributedValueConverter( - final Class type, final Mapper mapper, final ReflectionProvider reflectionProvider, - final ConverterLookup lookup, final String valueFieldName, final Class valueDefinedIn) { + final Class type, final Mapper mapper, final ReflectionProvider reflectionProvider, + final ConverterLookup lookup, final String valueFieldName, Class valueDefinedIn) { this.type = type; this.mapper = mapper; this.reflectionProvider = reflectionProvider; @@ -96,43 +112,44 @@ } else { Field field = null; try { - field = (valueDefinedIn != null ? valueDefinedIn : type).getDeclaredField(valueFieldName); + field = (valueDefinedIn != null ? valueDefinedIn : type) + .getDeclaredField(valueFieldName); if (!field.isAccessible()) { field.setAccessible(true); } - } catch (final NoSuchFieldException e) { + } catch (NoSuchFieldException e) { throw new IllegalArgumentException(e.getMessage() + ": " + valueFieldName); } - valueField = field; + this.valueField = field; } - enumMapper = UseAttributeForEnumMapper.createEnumMapper(mapper); + enumMapper = JVM.is15() ? UseAttributeForEnumMapper.createEnumMapper(mapper) : null; } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(final Class type) { return this.type == type; } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Class sourceType = source.getClass(); - final Map defaultFieldDefinition = new HashMap(); + public void marshal(final Object source, final HierarchicalStreamWriter writer, + final MarshallingContext context) { + final Class sourceType = source.getClass(); + final Map defaultFieldDefinition = new HashMap(); final String[] tagValue = new String[1]; final Object[] realValue = new Object[1]; - final Class[] fieldType = new Class[1]; - final Class[] definingType = new Class[1]; + final Class[] fieldType = new Class[1]; + final Class[] definingType = new Class[1]; reflectionProvider.visitSerializableFields(source, new ReflectionProvider.Visitor() { - @Override - public void visit(final String fieldName, final Class type, final Class definedIn, final Object value) { + public void visit(final String fieldName, final Class type, final Class definedIn, + final Object value) { if (!mapper.shouldSerializeMember(definedIn, fieldName)) { return; } final FastField field = new FastField(definedIn, fieldName); final String alias = mapper.serializedMember(definedIn, fieldName); if (!defaultFieldDefinition.containsKey(alias)) { - final Class lookupType = sourceType; - defaultFieldDefinition.put(alias, reflectionProvider.getField(lookupType, fieldName)); + final Class lookupType = sourceType; + defaultFieldDefinition.put( + alias, reflectionProvider.getField(lookupType, fieldName)); } else if (!fieldIsEqual(field)) { final ConversionException exception = new ConversionException( "Cannot write attribute twice for object"); @@ -141,15 +158,15 @@ throw exception; } - ConverterMatcher converter = Enum.class.isAssignableFrom(type) ? (ConverterMatcher)enumMapper - .getConverterFromItemType(null, type, null) : (ConverterMatcher)mapper.getLocalConverter(definedIn, - fieldName); + ConverterMatcher converter = UseAttributeForEnumMapper.isEnum(type) + ? (ConverterMatcher)enumMapper.getConverterFromItemType(null, type, null) + : (ConverterMatcher)mapper.getLocalConverter(definedIn, fieldName); if (converter == null) { converter = lookup.lookupConverterForType(type); } if (value != null) { - final boolean isValueField = valueField != null && fieldIsEqual(field); + boolean isValueField = valueField != null && fieldIsEqual(field); if (isValueField) { definingType[0] = definedIn; fieldType[0] = type; @@ -169,19 +186,19 @@ } else { if (!isValueField) { final ConversionException exception = new ConversionException( - "Cannot write element as attribute"); - exception.add("alias", alias); - exception.add("type", sourceType.getName()); - throw exception; + "Cannot write element as attribute"); + exception.add("alias", alias); + exception.add("type", sourceType.getName()); + throw exception; } } } } }); if (tagValue[0] != null) { - final Class actualType = realValue[0].getClass(); - final Class defaultType = mapper.defaultImplementationOf(fieldType[0]); + final Class actualType = realValue[0].getClass(); + final Class defaultType = mapper.defaultImplementationOf(fieldType[0]); if (!actualType.equals(defaultType)) { final String serializedClassName = mapper.serializedClass(actualType); if (!serializedClassName.equals(mapper.serializedClass(defaultType))) { @@ -194,26 +211,26 @@ if (tagValue[0] == STRUCTURE_MARKER) { context.convertAnother(realValue[0]); - } else { + } else { writer.setValue(tagValue[0]); } } } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(final HierarchicalStreamReader reader, + final UnmarshallingContext context) { final Object result = reflectionProvider.newInstance(context.getRequiredType()); - final Class resultType = result.getClass(); + final Class resultType = result.getClass(); - final Set seenFields = new HashSet(); - final Iterator it = reader.getAttributeNames(); + final Set seenFields = new HashSet(); + final Iterator it = reader.getAttributeNames(); - final Set systemAttributes = new HashSet(); + final Set systemAttributes = new HashSet(); systemAttributes.add(mapper.aliasForSystemAttribute("class")); // Process attributes before recursing into child elements. while (it.hasNext()) { - final String attrName = it.next(); + final String attrName = (String)it.next(); if (systemAttributes.contains(attrName)) { continue; } @@ -225,11 +242,11 @@ continue; } - Class type = field.getType(); - final Class declaringClass = field.getDeclaringClass(); - ConverterMatcher converter = Enum.class.isAssignableFrom(type) ? (ConverterMatcher)enumMapper - .getConverterFromItemType(null, type, null) : (ConverterMatcher)mapper.getLocalConverter( - declaringClass, fieldName); + Class type = field.getType(); + final Class declaringClass = field.getDeclaringClass(); + ConverterMatcher converter = UseAttributeForEnumMapper.isEnum(type) + ? (ConverterMatcher)enumMapper.getConverterFromItemType(null, type, null) + : (ConverterMatcher)mapper.getLocalConverter(declaringClass, fieldName); if (converter == null) { converter = lookup.lookupConverterForType(type); } @@ -243,71 +260,85 @@ } if (converter != null) { - final Object value = ((SingleValueConverter)converter).fromString(reader.getAttribute(attrName)); + final Object value = ((SingleValueConverter)converter).fromString(reader + .getAttribute(attrName)); if (type.isPrimitive()) { type = Primitives.box(type); } if (value != null && !type.isAssignableFrom(value.getClass())) { - final ConversionException exception = new ConversionException("Cannot assign object to type"); + final ConversionException exception = new ConversionException( + "Cannot assign object to type"); exception.add("object type", value.getClass().getName()); exception.add("target type", type.getName()); throw exception; } reflectionProvider.writeField(result, fieldName, value, declaringClass); if (!seenFields.add(new FastField(declaringClass, fieldName))) { - throw new DuplicateFieldException(fieldName + " [" + declaringClass.getName() + "]"); + throw new DuplicateFieldException(fieldName + + " [" + + declaringClass.getName() + + "]"); } } } } if (valueField != null) { - final Class classDefiningField = valueField.getDeclaringClass(); + final Class classDefiningField = valueField.getDeclaringClass(); final String fieldName = valueField.getName(); - final Field field = fieldName == null ? null : reflectionProvider.getField(classDefiningField, fieldName); + final Field field = fieldName == null ? null : reflectionProvider.getField( + classDefiningField, fieldName); if (fieldName == null || field == null) { - final ConversionException exception = new ConversionException("Cannot assign value to field of type"); + final ConversionException exception = new ConversionException( + "Cannot assign value to field of type"); exception.add("element", reader.getNodeName()); exception.add("field", fieldName); exception.add("target type", context.getRequiredType().getName()); throw exception; } - Class type; - final String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); + Class type; + final String classAttribute = HierarchicalStreams + .readClassAttribute(reader, mapper); if (classAttribute != null) { type = mapper.realClass(classAttribute); } else { - type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, - classDefiningField)); + type = mapper.defaultImplementationOf(reflectionProvider.getFieldType( + result, fieldName, classDefiningField)); } - final Object value = context.convertAnother(result, type, mapper.getLocalConverter(field - .getDeclaringClass(), field.getName())); + final Object value = context.convertAnother( + result, type, + mapper.getLocalConverter(field.getDeclaringClass(), field.getName())); - final Class definedType = reflectionProvider.getFieldType(result, fieldName, classDefiningField); + final Class definedType = reflectionProvider.getFieldType( + result, fieldName, classDefiningField); if (!definedType.isPrimitive()) { type = definedType; } if (value != null && !type.isAssignableFrom(value.getClass())) { - final ConversionException exception = new ConversionException("Cannot assign object to type"); + final ConversionException exception = new ConversionException( + "Cannot assign object to type"); exception.add("object type", value.getClass().getName()); exception.add("target type", type.getName()); throw exception; } reflectionProvider.writeField(result, fieldName, value, classDefiningField); if (!seenFields.add(new FastField(classDefiningField, fieldName))) { - throw new DuplicateFieldException(fieldName + " [" + classDefiningField.getName() + "]"); + throw new DuplicateFieldException(fieldName + + " [" + + classDefiningField.getName() + + "]"); } } return result; } - private boolean fieldIsEqual(final FastField field) { + private boolean fieldIsEqual(FastField field) { return valueField.getName().equals(field.getName()) && valueField.getDeclaringClass().getName().equals(field.getDeclaringClass()); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ToStringConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ToStringConverter.java (.../ToStringConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/ToStringConverter.java (.../ToStringConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,50 +10,46 @@ */ package com.thoughtworks.xstream.converters.extended; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; /** * Convenient converter for classes with natural string representation. - *

    - * Converter for classes that adopt the following convention: - a constructor that takes a single string parameter - a - * toString() that is overloaded to issue a string that is meaningful - *

    * + * Converter for classes that adopt the following convention: + * - a constructor that takes a single string parameter + * - a toString() that is overloaded to issue a string that is meaningful + * * @author Paul Hammant */ public class ToStringConverter extends AbstractSingleValueConverter { - private final Class clazz; - private final Constructor ctor; + private static final Class[] STRING_PARAMETER = {String.class}; + private final Class clazz; + private final Constructor ctor; - public ToStringConverter(final Class clazz) throws NoSuchMethodException { + public ToStringConverter(Class clazz) throws NoSuchMethodException { this.clazz = clazz; - ctor = clazz.getConstructor(String.class); + ctor = clazz.getConstructor(STRING_PARAMETER); } - - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type.equals(clazz); } - - @Override - public String toString(final Object obj) { + public String toString(Object obj) { return obj == null ? null : obj.toString(); } - @Override - public Object fromString(final String str) { + public Object fromString(String str) { try { - return ctor.newInstance(str); - } catch (final InstantiationException e) { + return ctor.newInstance(new Object[] {str}); + } catch (InstantiationException e) { throw new ConversionException("Unable to instantiate single String param constructor", e); - } catch (final IllegalAccessException e) { - throw new ConversionException("Unable to access single String param constructor", e); - } catch (final InvocationTargetException e) { + } catch (IllegalAccessException e) { + throw new ObjectAccessException("Unable to access single String param constructor", e); + } catch (InvocationTargetException e) { throw new ConversionException("Unable to target single String param constructor", e.getTargetException()); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/UseAttributeForEnumMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/UseAttributeForEnumMapper.java (.../UseAttributeForEnumMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/extended/UseAttributeForEnumMapper.java (.../UseAttributeForEnumMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2014 XStream Committers. + * Copyright (C) 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,37 +11,56 @@ package com.thoughtworks.xstream.converters.extended; import com.thoughtworks.xstream.converters.SingleValueConverter; +import com.thoughtworks.xstream.core.util.DependencyInjectionFactory; import com.thoughtworks.xstream.mapper.AttributeMapper; import com.thoughtworks.xstream.mapper.DefaultMapper; -import com.thoughtworks.xstream.mapper.EnumMapper; import com.thoughtworks.xstream.mapper.Mapper; - class UseAttributeForEnumMapper extends AttributeMapper { - public UseAttributeForEnumMapper(final Mapper wrapped) { + public UseAttributeForEnumMapper(Mapper wrapped) { super(wrapped, null, null); } - @Override - public boolean shouldLookForSingleValueConverter(final String fieldName, final Class type, - final Class definedIn) { - return Enum.class.isAssignableFrom(type); + /** + * @deprecated only used for Java 1.4 support + */ + public static boolean isEnum(Class type) { + while(type != null && type != Object.class) { + if (type.getName().equals("java.lang.Enum")) { + return true; + } + type = type.getSuperclass(); + } + return false; } - @Override - public SingleValueConverter getConverterFromItemType(final String fieldName, final Class type, - final Class definedIn) { + public boolean shouldLookForSingleValueConverter(String fieldName, Class type, + Class definedIn) { + return isEnum(type); + } + + public SingleValueConverter getConverterFromItemType(String fieldName, Class type, + Class definedIn) { return null; } - @Override - public SingleValueConverter getConverterFromAttribute(final Class definedIn, final String attribute, - final Class type) { + public SingleValueConverter getConverterFromAttribute(Class definedIn, + String attribute, Class type) { return null; } static Mapper createEnumMapper(final Mapper mapper) { - return new EnumMapper(new UseAttributeForEnumMapper(mapper.lookupMapperOfType(DefaultMapper.class))); + try { + Class enumMapperClass = Class.forName( + "com.thoughtworks.xstream.mapper.EnumMapper", true, + Mapper.class.getClassLoader()); + return (Mapper)DependencyInjectionFactory.newInstance( + enumMapperClass, + new Object[]{new UseAttributeForEnumMapper(mapper + .lookupMapperOfType(DefaultMapper.class))}); + } catch (Exception e) { + return null; + } } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/BeanProperty.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/BeanProperty.java (.../BeanProperty.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/BeanProperty.java (.../BeanProperty.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -15,51 +15,52 @@ import java.lang.reflect.Method; import java.lang.reflect.UndeclaredThrowableException; - /** * Provide access to a bean property. * * @author Andrea Aime * @deprecated As of 1.3.1, no longer in use */ -@Deprecated public class BeanProperty { /** the target class */ - private final Class memberClass; + private Class memberClass; /** the property name */ - private final String propertyName; + private String propertyName; /** the property type */ - private final Class type; + private Class type; /** the getter */ protected Method getter; /** the setter */ private Method setter; + + private static final Object[] EMPTY_ARGS = new Object[0]; /** - * Creates a new {@link BeanProperty}that gets the specified property from the specified class. + * Creates a new {@link BeanProperty}that gets the specified property from + * the specified class. */ - public BeanProperty(final Class memberClass, final String propertyName, final Class propertyType) { + public BeanProperty(Class memberClass, String propertyName, Class propertyType) { this.memberClass = memberClass; this.propertyName = propertyName; - type = propertyType; + this.type = propertyType; } /** * Gets the base class that this getter accesses. */ - public Class getBeanClass() { + public Class getBeanClass() { return memberClass; } /** * Returns the property type */ - public Class getType() { + public Class getType() { return type; } @@ -74,65 +75,62 @@ * Gets whether this property can get get. */ public boolean isReadable() { - return getter != null; + return (getter != null); } /** * Gets whether this property can be set. */ public boolean isWritable() { - return setter != null; + return (setter != null); } /** * Gets the value of this property for the specified Object. - * * @throws IllegalAccessException * @throws IllegalArgumentException */ - public Object get(final Object member) throws IllegalArgumentException, IllegalAccessException { - if (!isReadable()) { - throw new IllegalStateException("Property " + propertyName + " of " + memberClass + " not readable"); - } + public Object get(Object member) throws IllegalArgumentException, IllegalAccessException { + if (!isReadable()) + throw new IllegalStateException("Property " + propertyName + " of " + memberClass + + " not readable"); try { - return getter.invoke(member); - } catch (final InvocationTargetException e) { + return getter.invoke(member, EMPTY_ARGS); + } catch (InvocationTargetException e) { throw new UndeclaredThrowableException(e.getTargetException()); } } /** * Sets the value of this property for the specified Object. - * * @throws IllegalAccessException * @throws IllegalArgumentException */ - public Object set(final Object member, final Object newValue) - throws IllegalArgumentException, IllegalAccessException { - if (!isWritable()) { - throw new IllegalStateException("Property " + propertyName + " of " + memberClass + " not writable"); - } + public Object set(Object member, Object newValue) throws IllegalArgumentException, IllegalAccessException { + if (!isWritable()) + throw new IllegalStateException("Property " + propertyName + " of " + memberClass + + " not writable"); try { - return setter.invoke(member, newValue); - } catch (final InvocationTargetException e) { + return setter.invoke(member, new Object[] { newValue }); + } catch (InvocationTargetException e) { throw new UndeclaredThrowableException(e.getTargetException()); } } /** * @param method */ - public void setGetterMethod(final Method method) { - getter = method; + public void setGetterMethod(Method method) { + this.getter = method; } /** * @param method */ - public void setSetterMethod(final Method method) { - setter = method; + public void setSetterMethod(Method method) { + this.setter = method; } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/BeanProvider.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/BeanProvider.java (.../BeanProvider.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/BeanProvider.java (.../BeanProvider.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -21,6 +21,8 @@ import java.util.Iterator; import java.util.List; +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.ErrorWritingException; import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; @@ -29,7 +31,6 @@ /** * @deprecated As of 1.4.6 */ - @Deprecated protected static final Object[] NO_PARAMS = new Object[0]; protected PropertyDictionary propertyDictionary; @@ -41,11 +42,12 @@ } /** - * Construct a BeanProvider with a comparator to sort the bean properties by name in the dictionary. + * Construct a BeanProvider with a comparator to sort the bean properties by name in the + * dictionary. * * @param propertyNameComparator the comparator */ - public BeanProvider(final Comparator propertyNameComparator) { + public BeanProvider(final Comparator propertyNameComparator) { this(new PropertyDictionary(new ComparingPropertySorter(propertyNameComparator))); } @@ -59,84 +61,83 @@ this.propertyDictionary = propertyDictionary; } - @Override - public Object newInstance(final Class type) { + public Object newInstance(Class type) { + ErrorWritingException ex = null; try { return type.newInstance(); - } catch (final InstantiationException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); - } catch (final SecurityException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); - } catch (final ExceptionInInitializerError e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); + } catch (InstantiationException e) { + ex = new ConversionException("Cannot construct type", e); + } catch (IllegalAccessException e) { + ex = new ObjectAccessException("Cannot construct type", e); + } catch (SecurityException e) { + ex = new ObjectAccessException("Cannot construct type", e); + } catch (ExceptionInInitializerError e) { + ex = new ConversionException("Cannot construct type", e); } + ex.add("construction-type", type.getName()); + throw ex; } - @Override - public void visitSerializableProperties(final Object object, final JavaBeanProvider.Visitor visitor) { - final PropertyDescriptor[] propertyDescriptors = getSerializableProperties(object); - for (final PropertyDescriptor property : propertyDescriptors) { + public void visitSerializableProperties(Object object, JavaBeanProvider.Visitor visitor) { + PropertyDescriptor[] propertyDescriptors = getSerializableProperties(object); + for (int i = 0; i < propertyDescriptors.length; i++ ) { + ErrorWritingException ex = null; + PropertyDescriptor property = propertyDescriptors[i]; try { - final Method readMethod = property.getReadMethod(); - final String name = property.getName(); - final Class definedIn = readMethod.getDeclaringClass(); + Method readMethod = property.getReadMethod(); + String name = property.getName(); + Class definedIn = readMethod.getDeclaringClass(); if (visitor.shouldVisit(name, definedIn)) { - final Object value = readMethod.invoke(object); + Object value = readMethod.invoke(object, new Object[0]); visitor.visit(name, property.getPropertyType(), definedIn, value); } - } catch (final IllegalArgumentException e) { - throw new ObjectAccessException("Could not get property " - + object.getClass() - + "." - + property.getName(), e); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Could not get property " - + object.getClass() - + "." - + property.getName(), e); - } catch (final InvocationTargetException e) { - throw new ObjectAccessException("Could not get property " - + object.getClass() - + "." - + property.getName(), e); + } catch (IllegalArgumentException e) { + ex = new ConversionException("Cannot get property", e); + } catch (IllegalAccessException e) { + ex = new ObjectAccessException("Cannot access property", e); + } catch (InvocationTargetException e) { + ex = new ConversionException("Cannot get property", e.getTargetException()); } + if (ex != null) { + ex.add("property", object.getClass() + "." + property.getName()); + throw ex; + } } } - @Override - public void writeProperty(final Object object, final String propertyName, final Object value) { - final PropertyDescriptor property = getProperty(propertyName, object.getClass()); + public void writeProperty(Object object, String propertyName, Object value) { + ErrorWritingException ex = null; + PropertyDescriptor property = getProperty(propertyName, object.getClass()); try { property.getWriteMethod().invoke(object, new Object[]{value}); - } catch (final IllegalArgumentException e) { - throw new ObjectAccessException("Could not set property " + object.getClass() + "." + property.getName(), e); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Could not set property " + object.getClass() + "." + property.getName(), e); - } catch (final InvocationTargetException e) { - throw new ObjectAccessException("Could not set property " + object.getClass() + "." + property.getName(), e); + } catch (IllegalArgumentException e) { + ex = new ConversionException("Cannot set property", e); + } catch (IllegalAccessException e) { + ex = new ObjectAccessException("Cannot access property", e); + } catch (InvocationTargetException e) { + ex = new ConversionException("Cannot set property", e.getTargetException()); } + if (ex != null) { + ex.add("property", object.getClass() + "." + property.getName()); + throw ex; + } } - @Override - public Class getPropertyType(final Object object, final String name) { + public Class getPropertyType(Object object, String name) { return getProperty(name, object.getClass()).getPropertyType(); } - @Override - public boolean propertyDefinedInClass(final String name, final Class type) { - return getProperty(name, type) != null; + public boolean propertyDefinedInClass(String name, Class type) { + return propertyDictionary.propertyDescriptorOrNull(type, name) != null; } /** * Returns true if the Bean provider can instantiate the specified class */ - @Override - public boolean canInstantiate(final Class type) { + public boolean canInstantiate(Class type) { try { - return newInstance(type) != null; - } catch (final ObjectAccessException e) { + return type != null && newInstance(type) != null; + } catch (final ErrorWritingException e) { return false; } } @@ -147,46 +148,44 @@ * @param type * @deprecated As of 1.4.6 use {@link #newInstance(Class)} or {@link #canInstantiate(Class)} directly. */ - @Deprecated - protected Constructor getDefaultConstrutor(final Class type) { - - final Constructor[] constructors = type.getConstructors(); - for (final Constructor c : constructors) { - if (c.getParameterTypes().length == 0 && Modifier.isPublic(c.getModifiers())) { + protected Constructor getDefaultConstrutor(Class type) { + + Constructor[] constructors = type.getConstructors(); + for (int i = 0; i < constructors.length; i++ ) { + Constructor c = constructors[i]; + if (c.getParameterTypes().length == 0 && Modifier.isPublic(c.getModifiers())) return c; - } } return null; } - protected PropertyDescriptor[] getSerializableProperties(final Object object) { - final List result = new ArrayList(); - for (final Iterator iter = propertyDictionary.propertiesFor(object.getClass()); iter - .hasNext();) { - final PropertyDescriptor descriptor = iter.next(); + protected PropertyDescriptor[] getSerializableProperties(Object object) { + List result = new ArrayList(); + for (final Iterator iter = propertyDictionary.propertiesFor(object.getClass()); iter.hasNext();) { + final PropertyDescriptor descriptor = (PropertyDescriptor)iter.next(); if (canStreamProperty(descriptor)) { result.add(descriptor); } } - return result.toArray(new PropertyDescriptor[result.size()]); + return (PropertyDescriptor[])result.toArray(new PropertyDescriptor[result.size()]); } - protected boolean canStreamProperty(final PropertyDescriptor descriptor) { + protected boolean canStreamProperty(PropertyDescriptor descriptor) { return descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null; } - public boolean propertyWriteable(final String name, final Class type) { - final PropertyDescriptor property = getProperty(name, type); + public boolean propertyWriteable(String name, Class type) { + PropertyDescriptor property = getProperty(name, type); return property.getWriteMethod() != null; } - protected PropertyDescriptor getProperty(final String name, final Class type) { - return propertyDictionary.propertyDescriptor(type, name); + protected PropertyDescriptor getProperty(String name, Class type) { + return (PropertyDescriptor)propertyDictionary.propertyDescriptor(type, name); } /** * @deprecated As of 1.4 use {@link JavaBeanProvider.Visitor} */ - @Deprecated - public interface Visitor extends JavaBeanProvider.Visitor {} + public interface Visitor extends JavaBeanProvider.Visitor { + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/ComparingPropertySorter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/ComparingPropertySorter.java (.../ComparingPropertySorter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/ComparingPropertySorter.java (.../ComparingPropertySorter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2014 XStream Committers. + * Copyright (C) 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,12 +10,10 @@ */ package com.thoughtworks.xstream.converters.javabean; -import java.beans.PropertyDescriptor; import java.util.Comparator; import java.util.Map; import java.util.TreeMap; - /** * A sorter that uses a comparator to determine the order of the bean properties. * @@ -24,17 +22,16 @@ */ public class ComparingPropertySorter implements PropertySorter { - private final Comparator comparator; + private final Comparator comparator; - public ComparingPropertySorter(final Comparator propertyNameComparator) { - comparator = propertyNameComparator; + public ComparingPropertySorter(final Comparator propertyNameComparator) { + this.comparator = propertyNameComparator; } - @Override - public Map sort(final Class type, final Map nameMap) { - final TreeMap map = new TreeMap(comparator); + public Map sort(final Class type, final Map nameMap) { + TreeMap map = new TreeMap(comparator); map.putAll(nameMap); return map; } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/JavaBeanConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/JavaBeanConverter.java (.../JavaBeanConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/JavaBeanConverter.java (.../JavaBeanConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,12 +1,12 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 12. April 2005 by Joe Walnes */ package com.thoughtworks.xstream.converters.javabean; @@ -32,60 +32,75 @@ */ public class JavaBeanConverter implements Converter { - /* TODO: - support indexed properties - support attributes (XSTR-620) - support local converters (XSTR-601) Problem: - * Mappers take definitions based on reflection, they don't know about bean info */ + /* + * TODO: + * - support indexed properties + * - support attributes (XSTR-620) + * - support local converters (XSTR-601) + * Problem: Mappers take definitions based on reflection, they don't know about bean info + */ protected final Mapper mapper; protected final JavaBeanProvider beanProvider; - private final Class type; + private final Class type; + + /** + * @deprecated As of 1.3, no necessity for field anymore. + */ + private String classAttributeIdentifier; - public JavaBeanConverter(final Mapper mapper) { - this(mapper, (Class)null); + public JavaBeanConverter(Mapper mapper) { + this(mapper, (Class)null); } - public JavaBeanConverter(final Mapper mapper, final Class type) { + public JavaBeanConverter(Mapper mapper, Class type) { this(mapper, new BeanProvider(), type); } - public JavaBeanConverter(final Mapper mapper, final JavaBeanProvider beanProvider) { - this(mapper, beanProvider, null); + public JavaBeanConverter(Mapper mapper, JavaBeanProvider beanProvider) { + this(mapper,beanProvider, null); } - public JavaBeanConverter(final Mapper mapper, final JavaBeanProvider beanProvider, final Class type) { + public JavaBeanConverter(Mapper mapper, JavaBeanProvider beanProvider, Class type) { this.mapper = mapper; this.beanProvider = beanProvider; this.type = type; } /** - * Checks if the bean provider can instantiate this type. If you need less strict checks, subclass JavaBeanConverter + * @deprecated As of 1.3, use {@link #JavaBeanConverter(Mapper)} and {@link com.thoughtworks.xstream.XStream#aliasAttribute(String, String)} */ - @Override - public boolean canConvert(final Class type) { + public JavaBeanConverter(Mapper mapper, String classAttributeIdentifier) { + this(mapper, new BeanProvider()); + this.classAttributeIdentifier = classAttributeIdentifier; + } + + /** + * Checks if the bean provider can instantiate this type. + * If you need less strict checks, subclass JavaBeanConverter + */ + public boolean canConvert(Class type) { return (this.type == null || this.type == type) && beanProvider.canInstantiate(type); } - @Override public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final String classAttributeName = mapper.aliasForSystemAttribute("class"); beanProvider.visitSerializableProperties(source, new JavaBeanProvider.Visitor() { - @Override - public boolean shouldVisit(final String name, final Class definedIn) { + public boolean shouldVisit(String name, Class definedIn) { return mapper.shouldSerializeMember(definedIn, name); } - - @Override - public void visit(final String propertyName, final Class fieldType, final Class definedIn, - final Object newObj) { + + public void visit(String propertyName, Class fieldType, Class definedIn, Object newObj) { if (newObj != null) { - writeField(propertyName, fieldType, newObj, definedIn); + writeField(propertyName, fieldType, newObj); + } else { + writeNullField(propertyName); } } - private void writeField(final String propertyName, final Class fieldType, final Object newObj, - final Class definedIn) { - final Class actualType = newObj.getClass(); - final Class defaultType = mapper.defaultImplementationOf(fieldType); - final String serializedMember = mapper.serializedMember(source.getClass(), propertyName); + private void writeField(String propertyName, Class fieldType, Object newObj) { + Class actualType = newObj.getClass(); + Class defaultType = mapper.defaultImplementationOf(fieldType); + String serializedMember = mapper.serializedMember(source.getClass(), propertyName); ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedMember, actualType); if (!actualType.equals(defaultType) && classAttributeName != null) { writer.addAttribute(classAttributeName, mapper.serializedClass(actualType)); @@ -94,37 +109,42 @@ writer.endNode(); } + + private void writeNullField(final String propertyName) { + final String serializedMember = mapper.serializedMember(source.getClass(), propertyName); + ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedMember, Mapper.Null.class); + writer.addAttribute(classAttributeName, mapper.serializedClass(Mapper.Null.class)); + writer.endNode(); + } }); } - @Override public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { final Object result = instantiateNewInstance(context); - final Set seenProperties = new HashSet() { - @Override - public boolean add(final FastField e) { + final Set seenProperties = new HashSet() { + public boolean add(Object e) { if (!super.add(e)) { - throw new DuplicatePropertyException(e.getName()); + throw new DuplicatePropertyException(((FastField)e).getName()); } return true; } }; - final Class resultType = result.getClass(); + Class resultType = result.getClass(); while (reader.hasMoreChildren()) { reader.moveDown(); - final String propertyName = mapper.realMember(resultType, reader.getNodeName()); + String propertyName = mapper.realMember(resultType, reader.getNodeName()); if (mapper.shouldSerializeMember(resultType, propertyName)) { - final boolean propertyExistsInClass = beanProvider.propertyDefinedInClass(propertyName, resultType); - + boolean propertyExistsInClass = beanProvider.propertyDefinedInClass(propertyName, resultType); + if (propertyExistsInClass) { - final Class type = determineType(reader, result, propertyName); - final Object value = context.convertAnother(result, type); + Class type = determineType(reader, result, propertyName); + Object value = context.convertAnother(result, type); beanProvider.writeProperty(result, propertyName, value); seenProperties.add(new FastField(resultType, propertyName)); - } else { + } else if (!mapper.isIgnoredElement(propertyName)) { throw new MissingFieldException(resultType.getName(), propertyName); } } @@ -134,17 +154,17 @@ return result; } - private Object instantiateNewInstance(final UnmarshallingContext context) { + private Object instantiateNewInstance(UnmarshallingContext context) { Object result = context.currentObject(); if (result == null) { result = beanProvider.newInstance(context.getRequiredType()); } return result; } - private Class determineType(final HierarchicalStreamReader reader, final Object result, final String fieldName) { - final String classAttributeName = mapper.aliasForSystemAttribute("class"); - final String classAttribute = classAttributeName == null ? null : reader.getAttribute(classAttributeName); + private Class determineType(HierarchicalStreamReader reader, Object result, String fieldName) { + final String classAttributeName = classAttributeIdentifier != null ? classAttributeIdentifier : mapper.aliasForSystemAttribute("class"); + String classAttribute = classAttributeName == null ? null : reader.getAttribute(classAttributeName); if (classAttribute != null) { return mapper.realClass(classAttribute); } else { @@ -153,15 +173,24 @@ } /** + * @deprecated As of 1.3 + */ + public static class DuplicateFieldException extends ConversionException { + public DuplicateFieldException(String msg) { + super(msg); + } + } + + /** * Exception to indicate double processing of a property to avoid silent clobbering. * * @author Jörg Schaible * @since 1.4.2 */ public static class DuplicatePropertyException extends ConversionException { - public DuplicatePropertyException(final String msg) { + public DuplicatePropertyException(String msg) { super("Duplicate property " + msg); add("property", msg); } } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/JavaBeanProvider.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/JavaBeanProvider.java (.../JavaBeanProvider.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/JavaBeanProvider.java (.../JavaBeanProvider.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2014 XStream Committers. + * Copyright (C) 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,31 +10,32 @@ */ package com.thoughtworks.xstream.converters.javabean; + /** * @author Jörg Schaible + * * @since 1.4 */ public interface JavaBeanProvider { - Object newInstance(Class type); + Object newInstance(Class type); void visitSerializableProperties(Object object, Visitor visitor); void writeProperty(Object object, String propertyName, Object value); - Class getPropertyType(Object object, String name); + Class getPropertyType(Object object, String name); - boolean propertyDefinedInClass(String name, Class type); + boolean propertyDefinedInClass(String name, Class type); /** * Returns true if the Bean provider can instantiate the specified class */ - boolean canInstantiate(Class type); + boolean canInstantiate(Class type); public interface Visitor { - boolean shouldVisit(String name, Class definedIn); - - void visit(String name, Class type, Class definedIn, Object value); + boolean shouldVisit(String name, Class definedIn); + void visit(String name, Class type, Class definedIn, Object value); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/NativePropertySorter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/NativePropertySorter.java (.../NativePropertySorter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/NativePropertySorter.java (.../NativePropertySorter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2014 XStream Committers. + * Copyright (C) 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,20 +10,19 @@ */ package com.thoughtworks.xstream.converters.javabean; -import java.beans.PropertyDescriptor; import java.util.Map; /** - * A sorter that keeps the natural order of the bean properties as they are returned by the JavaBean introspection. + * A sorter that keeps the natural order of the bean properties as they are returned by the + * JavaBean introspection. * * @author Jörg Schaible * @since 1.4 */ public class NativePropertySorter implements PropertySorter { - @Override - public Map sort(final Class type, final Map nameMap) { + public Map sort(final Class type, final Map nameMap) { return nameMap; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/PropertyDictionary.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/PropertyDictionary.java (.../PropertyDictionary.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/PropertyDictionary.java (.../PropertyDictionary.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2016, 2017 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -20,12 +20,12 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.Map; import com.thoughtworks.xstream.converters.reflection.MissingFieldException; import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; import com.thoughtworks.xstream.core.Caching; +import com.thoughtworks.xstream.core.util.OrderRetainingMap; /** @@ -35,28 +35,28 @@ * @author Jörg Schaible */ public class PropertyDictionary implements Caching { - private transient Map, Map> propertyNameCache = Collections - .synchronizedMap(new HashMap, Map>()); + private transient Map propertyNameCache = Collections.synchronizedMap(new HashMap()); private final PropertySorter sorter; public PropertyDictionary() { this(new NativePropertySorter()); } - public PropertyDictionary(final PropertySorter sorter) { + public PropertyDictionary(PropertySorter sorter) { this.sorter = sorter; } /** * @deprecated As of 1.3.1, use {@link #propertiesFor(Class)} instead */ - @Deprecated - public Iterator serializablePropertiesFor(final Class type) { - final Collection beanProperties = new ArrayList(); - final Collection descriptors = buildMap(type).values(); - for (final PropertyDescriptor descriptor : descriptors) { + public Iterator serializablePropertiesFor(Class type) { + Collection beanProperties = new ArrayList(); + Collection descriptors = buildMap(type).values(); + for (Iterator iter = descriptors.iterator(); iter.hasNext();) { + PropertyDescriptor descriptor = (PropertyDescriptor)iter.next(); if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { - beanProperties.add(new BeanProperty(type, descriptor.getName(), descriptor.getPropertyType())); + beanProperties.add(new BeanProperty(type, descriptor.getName(), descriptor + .getPropertyType())); } } return beanProperties.iterator(); @@ -69,20 +69,20 @@ * @param name * @deprecated As of 1.3.1, use {@link #propertyDescriptor(Class, String)} instead */ - @Deprecated - public BeanProperty property(final Class cls, final String name) { + public BeanProperty property(Class cls, String name) { BeanProperty beanProperty = null; - final PropertyDescriptor descriptor = buildMap(cls).get(name); + PropertyDescriptor descriptor = propertyDescriptorOrNull(cls, name); if (descriptor == null) { throw new MissingFieldException(cls.getName(), name); } if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { - beanProperty = new BeanProperty(cls, descriptor.getName(), descriptor.getPropertyType()); + beanProperty = new BeanProperty( + cls, descriptor.getName(), descriptor.getPropertyType()); } return beanProperty; } - public Iterator propertiesFor(final Class type) { + public Iterator propertiesFor(Class type) { return buildMap(type).values().iterator(); } @@ -91,27 +91,43 @@ * * @param type * @param name + * @throws MissingFieldException if property does not exist */ - public PropertyDescriptor propertyDescriptor(final Class type, final String name) { - final PropertyDescriptor descriptor = buildMap(type).get(name); + public PropertyDescriptor propertyDescriptor(Class type, String name) { + PropertyDescriptor descriptor = propertyDescriptorOrNull(type, name); if (descriptor == null) { throw new MissingFieldException(type.getName(), name); } return descriptor; } - private Map buildMap(final Class type) { - Map nameMap = propertyNameCache.get(type); + /** + * Locates a property descriptor. + * + * @param type + * @param name + * @return {@code null} if property does not exist + * @since 1.4.10 + */ + public PropertyDescriptor propertyDescriptorOrNull(Class type, String name) { + return (PropertyDescriptor)buildMap(type).get(name); + } + + private Map buildMap(Class type) { + Map nameMap = (Map)propertyNameCache.get(type); if (nameMap == null) { BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(type, Object.class); - } catch (final IntrospectionException e) { - throw new ObjectAccessException("Cannot get BeanInfo of type " + type.getName(), e); + } catch (IntrospectionException e) { + ObjectAccessException oaex = new ObjectAccessException("Cannot get BeanInfo of type", e); + oaex.add("bean-type", type.getName()); + throw oaex; } - nameMap = new LinkedHashMap(); - final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); - for (final PropertyDescriptor descriptor : propertyDescriptors) { + nameMap = new OrderRetainingMap(); + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); + for (int i = 0; i < propertyDescriptors.length; i++ ) { + PropertyDescriptor descriptor = propertyDescriptors[i]; nameMap.put(descriptor.getName(), descriptor); } nameMap = sorter.sort(type, nameMap); @@ -120,7 +136,6 @@ return nameMap; } - @Override public void flushCache() { propertyNameCache.clear(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/PropertySorter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/PropertySorter.java (.../PropertySorter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/javabean/PropertySorter.java (.../PropertySorter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2014 XStream Committers. + * Copyright (C) 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,32 +13,29 @@ import java.beans.PropertyDescriptor; import java.util.Map; - /** - * An interface capable of sorting Java bean properties. - *

    - * Implement this interface if you want to customize the order in which XStream serializes the properties of a bean. - *

    + * An interface capable of sorting Java bean properties. Implement this interface if you + * want to customize the order in which XStream serializes the properties of a bean. * * @author Jörg Schaible * @since 1.4 */ public interface PropertySorter { /** - * Sort the properties of a bean type. - *

    - * The method will be called with the class type that contains all the properties and a Map that retains the order - * in which the elements have been added. The sequence in which elements are returned by an iterator defines the - * processing order of the properties. An implementation may create a different Map with similar semantic, add all - * elements of the original map and return the new one. - *

    + * Sort the properties of a bean type. The method will be called with the class type + * that contains all the properties and a Map that retains the order in which the + * elements have been added. The sequence in which elements are returned by an iterator + * defines the processing order of the properties. An implementation may create a + * different Map with similar semantic, add all elements of the original map and return + * the new one. * * @param type the bean class that contains all the properties - * @param nameMap the map to sort, key is the property name, value the {@link PropertyDescriptor} + * @param nameMap the map to sort, key is the property name, value the + * {@link PropertyDescriptor} * @return the sorted nameMap * @since 1.4 */ - Map sort(Class type, Map nameMap); + Map sort(Class type, Map nameMap); -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/AbstractAttributedCharacterIteratorAttributeConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/AbstractAttributedCharacterIteratorAttributeConverter.java (.../AbstractAttributedCharacterIteratorAttributeConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/AbstractAttributedCharacterIteratorAttributeConverter.java (.../AbstractAttributedCharacterIteratorAttributeConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2007, 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,137 +10,136 @@ */ package com.thoughtworks.xstream.converters.reflection; +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; +import com.thoughtworks.xstream.core.util.Fields; + import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.text.AttributedCharacterIterator; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; -import com.thoughtworks.xstream.converters.ConversionException; -import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; -import com.thoughtworks.xstream.core.util.Fields; - /** - * An abstract converter implementation for constants of {@link java.text.AttributedCharacterIterator.Attribute} and - * derived types. + * An abstract converter implementation for constants of + * {@link java.text.AttributedCharacterIterator.Attribute} and derived types. * * @author Jörg Schaible * @since 1.2.2 */ -public class AbstractAttributedCharacterIteratorAttributeConverter - extends AbstractSingleValueConverter { +public class AbstractAttributedCharacterIteratorAttributeConverter extends + AbstractSingleValueConverter { - private static final Map> instanceMaps = new HashMap>(); + private static final Map instanceMaps = new HashMap(); private static final Method getName; static { Method method = null; try { - method = AttributedCharacterIterator.Attribute.class.getDeclaredMethod("getName", (Class[])null); + method = AttributedCharacterIterator.Attribute.class.getDeclaredMethod( + "getName", (Class[])null); if (!method.isAccessible()) { method.setAccessible(true); } - } catch (final SecurityException e) { + } catch (SecurityException e) { // ignore for now - } catch (final NoSuchMethodException e) { + } catch (NoSuchMethodException e) { // ignore for now } getName = method; } - private final Class type; - private transient Map attributeMap; + private final Class type; + private transient Map attributeMap; - public AbstractAttributedCharacterIteratorAttributeConverter(final Class type) { + public AbstractAttributedCharacterIteratorAttributeConverter(final Class type) { super(); if (!AttributedCharacterIterator.Attribute.class.isAssignableFrom(type)) { throw new IllegalArgumentException(type.getName() - + " is not a " - + AttributedCharacterIterator.Attribute.class.getName()); + + " is not a " + AttributedCharacterIterator.Attribute.class.getName()); } this.type = type; readResolve(); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(final Class type) { return type == this.type && !attributeMap.isEmpty(); } - @Override public String toString(final Object source) { - @SuppressWarnings("unchecked") - final T t = (T)source; - return getName(t); + return getName((AttributedCharacterIterator.Attribute)source); } - private String getName(final AttributedCharacterIterator.Attribute attribute) { + private String getName(AttributedCharacterIterator.Attribute attribute) { Exception ex = null; if (getName != null) { try { - return (String)getName.invoke(attribute); - } catch (final IllegalAccessException e) { + return (String)getName.invoke(attribute, (Object[])null); + } catch (IllegalAccessException e) { ex = e; - } catch (final InvocationTargetException e) { + } catch (InvocationTargetException e) { ex = e; } } - final String s = attribute.toString(); - final String className = attribute.getClass().getName(); + String s = attribute.toString(); + String className = attribute.getClass().getName(); if (s.startsWith(className)) { - return s.substring(className.length() + 1, s.length() - 1); + return s.substring(className.length()+1, s.length()-1); } - throw new ConversionException("Cannot find name of attribute of type " + className, ex); + ConversionException exception = new ConversionException("Cannot find name of attribute", ex); + exception.add("attribute-type", className); + throw exception; } - @Override public Object fromString(final String str) { if (attributeMap.containsKey(str)) { return attributeMap.get(str); } - throw new ConversionException("Cannot find attribute of type " + type.getName() + " with name " + str); + ConversionException exception = new ConversionException("Cannot find attribute"); + exception.add("attribute-type", type.getName()); + exception.add("attribute-name", str); + throw exception; } private Object readResolve() { - @SuppressWarnings("unchecked") - final Map typedMap = (Map)instanceMaps.get(type.getName()); - attributeMap = typedMap; + attributeMap = (Map)instanceMaps.get(type.getName()); if (attributeMap == null) { - attributeMap = new HashMap(); - final Field instanceMap = Fields.locate(type, Map.class, true); + attributeMap = new HashMap(); + Field instanceMap = Fields.locate(type, Map.class, true); if (instanceMap != null) { try { - @SuppressWarnings("unchecked") - final Map map = (Map)Fields.read(instanceMap, null); + Map map = (Map)Fields.read(instanceMap, null); if (map != null) { boolean valid = true; - for (final Map.Entry entry : map.entrySet()) { + for (Iterator iter = map.entrySet().iterator(); valid && iter.hasNext(); ) { + Map.Entry entry = (Map.Entry)iter.next(); valid = entry.getKey().getClass() == String.class && entry.getValue().getClass() == type; } if (valid) { attributeMap.putAll(map); } } - } catch (final ObjectAccessException e) { + } catch (ObjectAccessException e) { } } if (attributeMap.isEmpty()) { try { - final Field[] fields = type.getDeclaredFields(); - for (final Field field : fields) { - if (field.getType() == type == Modifier.isStatic(field.getModifiers())) { - @SuppressWarnings("unchecked") - final T attribute = (T)Fields.read(field, null); + Field[] fields = type.getDeclaredFields(); + for(int i = 0; i < fields.length; ++i) { + if(fields[i].getType() == type == Modifier.isStatic(fields[i].getModifiers())) { + AttributedCharacterIterator.Attribute attribute = + (AttributedCharacterIterator.Attribute)Fields.read(fields[i], null); attributeMap.put(toString(attribute), attribute); } } - } catch (final SecurityException e) { + } catch (SecurityException e) { attributeMap.clear(); - } catch (final ObjectAccessException e) { + } catch (ObjectAccessException e) { attributeMap.clear(); - } catch (final NoClassDefFoundError e) { + } catch (NoClassDefFoundError e) { attributeMap.clear(); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/AbstractReflectionConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/AbstractReflectionConverter.java (.../AbstractReflectionConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/AbstractReflectionConverter.java (.../AbstractReflectionConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,30 +1,16 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 02. March 2006 by Joerg Schaible */ package com.thoughtworks.xstream.converters.reflection; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; @@ -34,47 +20,68 @@ import com.thoughtworks.xstream.core.ReferencingMarshallingContext; import com.thoughtworks.xstream.core.util.ArrayIterator; import com.thoughtworks.xstream.core.util.FastField; +import com.thoughtworks.xstream.core.util.Fields; import com.thoughtworks.xstream.core.util.HierarchicalStreams; import com.thoughtworks.xstream.core.util.Primitives; +import com.thoughtworks.xstream.core.util.SerializationMembers; import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.CannotResolveClassException; import com.thoughtworks.xstream.mapper.Mapper; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + public abstract class AbstractReflectionConverter implements Converter, Caching { protected final ReflectionProvider reflectionProvider; protected final Mapper mapper; + /** + * @deprecated As of 1.4.8, use {@link #serializationMembers}. + */ protected transient SerializationMethodInvoker serializationMethodInvoker; + protected transient SerializationMembers serializationMembers; private transient ReflectionProvider pureJavaReflectionProvider; - public AbstractReflectionConverter(final Mapper mapper, final ReflectionProvider reflectionProvider) { + public AbstractReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider) { this.mapper = mapper; this.reflectionProvider = reflectionProvider; serializationMethodInvoker = new SerializationMethodInvoker(); + serializationMembers = serializationMethodInvoker.serializationMembers; } - - protected boolean canAccess(final Class type) { + + protected boolean canAccess(Class type) { try { reflectionProvider.getFieldOrNull(type, "%"); return true; - } catch (final NoClassDefFoundError e) { + } catch (NoClassDefFoundError e) { // restricted type in GAE } return false; } - @Override - public void marshal(final Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Object source = serializationMethodInvoker.callWriteReplace(original); + public void marshal(Object original, final HierarchicalStreamWriter writer, + final MarshallingContext context) { + final Object source = serializationMembers.callWriteReplace(original); if (source != original && context instanceof ReferencingMarshallingContext) { - ((ReferencingMarshallingContext)context).replace(original, source); + ((ReferencingMarshallingContext)context).replace(original, source); } if (source.getClass() != original.getClass()) { - final String attributeName = mapper.aliasForSystemAttribute("resolves-to"); + String attributeName = mapper.aliasForSystemAttribute("resolves-to"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(source.getClass())); } @@ -85,44 +92,49 @@ } protected void doMarshal(final Object source, final HierarchicalStreamWriter writer, - final MarshallingContext context) { - final List fields = new ArrayList(); - final Map defaultFieldDefinition = new HashMap(); + final MarshallingContext context) { + final List fields = new ArrayList(); + final Map defaultFieldDefinition = new HashMap(); + final Class sourceType = source.getClass(); // Attributes might be preferred to child elements ... reflectionProvider.visitSerializableFields(source, new ReflectionProvider.Visitor() { - final Set writtenAttributes = new HashSet(); + final Set writtenAttributes = new HashSet(); - @Override - public void visit(final String fieldName, final Class type, final Class definedIn, final Object value) { + public void visit(String fieldName, Class type, Class definedIn, Object value) { if (!mapper.shouldSerializeMember(definedIn, fieldName)) { return; } if (!defaultFieldDefinition.containsKey(fieldName)) { - Class lookupType = source.getClass(); + Class lookupType = source.getClass(); // See XSTR-457 and OmitFieldsTest - if (definedIn != source.getClass() && !mapper.shouldSerializeMember(lookupType, fieldName)) { + if (definedIn != sourceType + && !mapper.shouldSerializeMember(lookupType, fieldName)) { lookupType = definedIn; } - defaultFieldDefinition.put(fieldName, reflectionProvider.getField(lookupType, fieldName)); + defaultFieldDefinition.put( + fieldName, reflectionProvider.getField(lookupType, fieldName)); } - final SingleValueConverter converter = mapper.getConverterFromItemType(fieldName, type, definedIn); + SingleValueConverter converter = mapper.getConverterFromItemType( + fieldName, type, definedIn); if (converter != null) { - final String attribute = mapper.aliasForAttribute(mapper.serializedMember(definedIn, fieldName)); + final String attribute = mapper.aliasForAttribute(mapper.serializedMember( + definedIn, fieldName)); if (value != null) { - if (writtenAttributes.contains(fieldName)) { // TODO: use attribute - throw new ConversionException("Cannot write field with name '" - + fieldName - + "' twice as attribute for object of type " - + source.getClass().getName()); + if (writtenAttributes.contains(fieldName)) { + ConversionException exception = + new ConversionException("Cannot write field as attribute for object, attribute name already in use"); + exception.add("field-name", fieldName); + exception.add("object-type", sourceType.getName()); + throw exception; } final String str = converter.toString(value); if (str != null) { writer.addAttribute(attribute, str); } } - writtenAttributes.add(fieldName); // TODO: use attribute + writtenAttributes.add(fieldName); } else { fields.add(new FieldInfo(fieldName, type, definedIn, value)); } @@ -131,41 +143,58 @@ new Object() { { - for (final FieldInfo fieldInfo : fields) { - final FieldInfo info = fieldInfo; + final Map hiddenMappers = new HashMap(); + for (Iterator fieldIter = fields.iterator(); fieldIter.hasNext();) { + FieldInfo info = (FieldInfo)fieldIter.next(); if (info.value != null) { - final Mapper.ImplicitCollectionMapping mapping = mapper.getImplicitCollectionDefForFieldName( - source.getClass(), info.fieldName); + final Field defaultField = (Field)defaultFieldDefinition.get(info.fieldName); + Mapper.ImplicitCollectionMapping mapping = mapper + .getImplicitCollectionDefForFieldName( + defaultField.getDeclaringClass() == info.definedIn ? sourceType : info.definedIn, + info.fieldName); if (mapping != null) { + Set mappings = (Set)hiddenMappers.get(info.fieldName); + if (mappings == null) { + mappings = new HashSet(); + mappings.add(mapping); + hiddenMappers.put(info.fieldName, mappings); + } else { + if (!mappings.add(mapping)) { + mapping = null; + } + } + } + if (mapping != null) { if (context instanceof ReferencingMarshallingContext) { if (info.value != Collections.EMPTY_LIST && info.value != Collections.EMPTY_SET && info.value != Collections.EMPTY_MAP) { - final ReferencingMarshallingContext refContext = (ReferencingMarshallingContext)context; + ReferencingMarshallingContext refContext = (ReferencingMarshallingContext)context; refContext.registerImplicit(info.value); } } final boolean isCollection = info.value instanceof Collection; final boolean isMap = info.value instanceof Map; final boolean isEntry = isMap && mapping.getKeyFieldName() == null; final boolean isArray = info.value.getClass().isArray(); - for (final Iterator iter = isArray ? new ArrayIterator(info.value) : isCollection - ? ((Collection)info.value).iterator() - : isEntry ? ((Map)info.value).entrySet().iterator() : ((Map)info.value) - .values() - .iterator(); iter.hasNext();) { - final Object obj = iter.next(); + for (Iterator iter = isArray + ? new ArrayIterator(info.value) + : isCollection ? ((Collection)info.value).iterator() : isEntry + ? ((Map)info.value).entrySet().iterator() + : ((Map)info.value).values().iterator(); iter.hasNext();) { + Object obj = iter.next(); final String itemName; - final Class itemType; + final Class itemType; if (obj == null) { itemType = Object.class; itemName = mapper.serializedClass(null); } else if (isEntry) { - final String entryName = mapping.getItemFieldName() != null ? mapping - .getItemFieldName() : mapper.serializedClass(Map.Entry.class); - final Map.Entry entry = (Map.Entry)obj; - ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryName, entry - .getClass()); + final String entryName = mapping.getItemFieldName() != null + ? mapping.getItemFieldName() + : mapper.serializedClass(Map.Entry.class); + Map.Entry entry = (Map.Entry)obj; + ExtendedHierarchicalStreamWriterHelper.startNode( + writer, entryName, entry.getClass()); writeItem(entry.getKey(), context, writer); writeItem(entry.getValue(), context, writer); writer.endNode(); @@ -177,143 +206,154 @@ itemType = obj.getClass(); itemName = mapper.serializedClass(itemType); } - writeField(info.fieldName, itemName, itemType, info.definedIn, obj); + writeField( + info.fieldName, itemName, itemType, info.definedIn, obj); } } else { - writeField(info.fieldName, null, info.type, info.definedIn, info.value); + writeField( + info.fieldName, null, info.type, info.definedIn, info.value); } } } } - void writeField(final String fieldName, final String aliasName, final Class fieldType, - final Class definedIn, final Object newObj) { - final Class actualType = newObj != null ? newObj.getClass() : fieldType; - ExtendedHierarchicalStreamWriterHelper.startNode(writer, aliasName != null ? aliasName : mapper - .serializedMember(source.getClass(), fieldName), actualType); + void writeField(String fieldName, String aliasName, Class fieldType, + Class definedIn, Object newObj) { + Class actualType = newObj != null ? newObj.getClass() : fieldType; + ExtendedHierarchicalStreamWriterHelper.startNode(writer, aliasName != null + ? aliasName + : mapper.serializedMember(sourceType, fieldName), actualType); if (newObj != null) { - final Class defaultType = mapper.defaultImplementationOf(fieldType); + Class defaultType = mapper.defaultImplementationOf(fieldType); if (!actualType.equals(defaultType)) { - final String serializedClassName = mapper.serializedClass(actualType); + String serializedClassName = mapper.serializedClass(actualType); if (!serializedClassName.equals(mapper.serializedClass(defaultType))) { - final String attributeName = mapper.aliasForSystemAttribute("class"); + String attributeName = mapper.aliasForSystemAttribute("class"); if (attributeName != null) { writer.addAttribute(attributeName, serializedClassName); } } } - final Field defaultField = defaultFieldDefinition.get(fieldName); + final Field defaultField = (Field)defaultFieldDefinition.get(fieldName); if (defaultField.getDeclaringClass() != definedIn) { - final String attributeName = mapper.aliasForSystemAttribute("defined-in"); + String attributeName = mapper.aliasForSystemAttribute("defined-in"); if (attributeName != null) { - writer.addAttribute(attributeName, mapper.serializedClass(definedIn)); + writer.addAttribute( + attributeName, mapper.serializedClass(definedIn)); } } - final Field field = reflectionProvider.getField(definedIn, fieldName); + Field field = reflectionProvider.getField(definedIn, fieldName); marshallField(context, newObj, field); } writer.endNode(); } - void writeItem(final Object item, final MarshallingContext context, final HierarchicalStreamWriter writer) { + void writeItem(Object item, MarshallingContext context, + HierarchicalStreamWriter writer) { if (item == null) { - final String name = mapper.serializedClass(null); - ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, Mapper.Null.class); + String name = mapper.serializedClass(null); + ExtendedHierarchicalStreamWriterHelper.startNode( + writer, name, Mapper.Null.class); writer.endNode(); } else { - final String name = mapper.serializedClass(item.getClass()); - ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, item.getClass()); + String name = mapper.serializedClass(item.getClass()); + ExtendedHierarchicalStreamWriterHelper.startNode( + writer, name, item.getClass()); context.convertAnother(item); writer.endNode(); } } }; } - protected void marshallField(final MarshallingContext context, final Object newObj, final Field field) { - context.convertAnother(newObj, mapper.getLocalConverter(field.getDeclaringClass(), field.getName())); + protected void marshallField(final MarshallingContext context, Object newObj, Field field) { + context.convertAnother( + newObj, mapper.getLocalConverter(field.getDeclaringClass(), field.getName())); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(final HierarchicalStreamReader reader, + final UnmarshallingContext context) { Object result = instantiateNewInstance(reader, context); result = doUnmarshal(result, reader, context); - return serializationMethodInvoker.callReadResolve(result); + return serializationMembers.callReadResolve(result); } public Object doUnmarshal(final Object result, final HierarchicalStreamReader reader, - final UnmarshallingContext context) { - final Class resultType = result.getClass(); - final Set seenFields = new HashSet() { - @Override - public boolean add(final FastField e) { + final UnmarshallingContext context) { + final Class resultType = result.getClass(); + final Set seenFields = new HashSet() { + public boolean add(Object e) { if (!super.add(e)) { - throw new DuplicateFieldException(e.getName()); + throw new DuplicateFieldException(((FastField)e).getName()); } return true; } }; // process attributes before recursing into child elements. - final Iterator it = reader.getAttributeNames(); + Iterator it = reader.getAttributeNames(); while (it.hasNext()) { - final String attrAlias = it.next(); + String attrAlias = (String)it.next(); // TODO: realMember should return FastField - final String attrName = mapper.realMember(resultType, mapper.attributeForAlias(attrAlias)); - final Field field = reflectionProvider.getFieldOrNull(resultType, attrName); + String attrName = mapper + .realMember(resultType, mapper.attributeForAlias(attrAlias)); + Field field = reflectionProvider.getFieldOrNull(resultType, attrName); if (field != null && shouldUnmarshalField(field)) { - final Class classDefiningField = field.getDeclaringClass(); + Class classDefiningField = field.getDeclaringClass(); if (!mapper.shouldSerializeMember(classDefiningField, attrName)) { continue; } - + // we need a converter that produces a string representation only - final SingleValueConverter converter = mapper.getConverterFromAttribute(classDefiningField, attrName, - field.getType()); - Class type = field.getType(); + SingleValueConverter converter = mapper.getConverterFromAttribute( + classDefiningField, attrName, field.getType()); + Class type = field.getType(); if (converter != null) { - final Object value = converter.fromString(reader.getAttribute(attrAlias)); + Object value = converter.fromString(reader.getAttribute(attrAlias)); if (type.isPrimitive()) { type = Primitives.box(type); } if (value != null && !type.isAssignableFrom(value.getClass())) { - throw new ConversionException("Cannot convert type " - + value.getClass().getName() - + " to type " - + type.getName()); + ConversionException exception = new ConversionException("Cannot convert type"); + exception.add("source-type", value.getClass().getName()); + exception.add("target-type", type.getName()); + throw exception; } seenFields.add(new FastField(classDefiningField, attrName)); reflectionProvider.writeField(result, attrName, value, classDefiningField); } } } - Map> implicitCollectionsForCurrentObject = null; + Map implicitCollectionsForCurrentObject = null; while (reader.hasMoreChildren()) { reader.moveDown(); - final String originalNodeName = reader.getNodeName(); - final Class explicitDeclaringClass = readDeclaringClass(reader); - final Class fieldDeclaringClass = explicitDeclaringClass == null ? resultType : explicitDeclaringClass; - final String fieldName = mapper.realMember(fieldDeclaringClass, originalNodeName); - final Mapper.ImplicitCollectionMapping implicitCollectionMapping = mapper + String originalNodeName = reader.getNodeName(); + Class explicitDeclaringClass = readDeclaringClass(reader); + Class fieldDeclaringClass = explicitDeclaringClass == null + ? resultType + : explicitDeclaringClass; + String fieldName = mapper.realMember(fieldDeclaringClass, originalNodeName); + Mapper.ImplicitCollectionMapping implicitCollectionMapping = mapper .getImplicitCollectionDefForFieldName(fieldDeclaringClass, fieldName); final Object value; String implicitFieldName = null; Field field = null; - Class type = null; + Class type = null; if (implicitCollectionMapping == null) { // no item of an implicit collection for this name ... do we have a field? field = reflectionProvider.getFieldOrNull(fieldDeclaringClass, fieldName); if (field == null) { // it is not a field ... do we have a field alias? - final Class itemType = mapper.getItemTypeForItemFieldName(resultType, fieldName); + Class itemType = mapper.getItemTypeForItemFieldName(fieldDeclaringClass, fieldName); if (itemType != null) { - final String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); + String classAttribute = HierarchicalStreams.readClassAttribute( + reader, mapper); if (classAttribute != null) { type = mapper.realClass(classAttribute); } else { @@ -324,16 +364,17 @@ // collection based on type only? try { type = mapper.realClass(originalNodeName); - implicitFieldName = mapper.getFieldNameForItemTypeAndName(context.getRequiredType(), type, - originalNodeName); - } catch (final CannotResolveClassException e) { + implicitFieldName = mapper.getFieldNameForItemTypeAndName( + fieldDeclaringClass, type, originalNodeName); + } catch (CannotResolveClassException e) { // type stays null ... } - if (type == null || type != null && implicitFieldName == null) { + if (type == null || (type != null && implicitFieldName == null)) { // either not a type or element is a type alias, but does not // belong to an implicit field - handleUnknownField(explicitDeclaringClass, fieldName, resultType, originalNodeName); - + handleUnknownField( + explicitDeclaringClass, fieldName, fieldDeclaringClass, originalNodeName); + // element is unknown in declaring class, ignore it now type = null; } @@ -344,46 +385,49 @@ } else { if (Map.Entry.class.equals(type)) { // it is an element of an implicit map with two elements now for - // key and value + // key and value reader.moveDown(); - final Object key = context.convertAnother(result, HierarchicalStreams.readClassType(reader, - mapper)); + final Object key = context.convertAnother( + result, HierarchicalStreams.readClassType(reader, mapper)); reader.moveUp(); reader.moveDown(); - final Object v = context.convertAnother(result, HierarchicalStreams.readClassType(reader, - mapper)); + final Object v = context.convertAnother( + result, HierarchicalStreams.readClassType(reader, mapper)); reader.moveUp(); - value = Collections.singletonMap(key, v).entrySet().iterator().next(); + value = Collections.singletonMap(key, v) + .entrySet().iterator().next(); } else { // recurse info hierarchy value = context.convertAnother(result, type); } } } else { boolean fieldAlreadyChecked = false; - + // we have a field, but do we have to address a hidden one? if (explicitDeclaringClass == null) { while (field != null && !(fieldAlreadyChecked = shouldUnmarshalField(field) - && mapper.shouldSerializeMember(field.getDeclaringClass(), fieldName))) { - field = reflectionProvider.getFieldOrNull(field.getDeclaringClass().getSuperclass(), - fieldName); + && mapper.shouldSerializeMember( + field.getDeclaringClass(), fieldName))) { + field = reflectionProvider.getFieldOrNull(field + .getDeclaringClass() + .getSuperclass(), fieldName); } } if (field != null - && (fieldAlreadyChecked || shouldUnmarshalField(field) - && mapper.shouldSerializeMember(field.getDeclaringClass(), fieldName))) { - - final String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); + && (fieldAlreadyChecked || (shouldUnmarshalField(field) && mapper + .shouldSerializeMember(field.getDeclaringClass(), fieldName)))) { + String classAttribute = HierarchicalStreams.readClassAttribute( + reader, mapper); if (classAttribute != null) { type = mapper.realClass(classAttribute); } else { type = mapper.defaultImplementationOf(field.getType()); } // TODO the reflection provider should already return the proper field value = unmarshallField(context, result, type, field); - final Class definedType = field.getType(); + Class definedType = field.getType(); if (!definedType.isPrimitive()) { type = definedType; } @@ -396,8 +440,11 @@ implicitFieldName = implicitCollectionMapping.getFieldName(); type = implicitCollectionMapping.getItemType(); if (type == null) { - final String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); - type = mapper.realClass(classAttribute != null ? classAttribute : originalNodeName); + String classAttribute = HierarchicalStreams.readClassAttribute( + reader, mapper); + type = mapper.realClass(classAttribute != null + ? classAttribute + : originalNodeName); } value = context.convertAnother(result, type); } @@ -415,51 +462,60 @@ } else if (type != null) { if (implicitFieldName == null) { // look for implicit field - implicitFieldName = mapper.getFieldNameForItemTypeAndName(context.getRequiredType(), value != null - ? value.getClass() - : Mapper.Null.class, originalNodeName); + implicitFieldName = mapper.getFieldNameForItemTypeAndName( + fieldDeclaringClass, + value != null ? value.getClass() : Mapper.Null.class, + originalNodeName); } if (implicitCollectionsForCurrentObject == null) { - implicitCollectionsForCurrentObject = new HashMap>(); + implicitCollectionsForCurrentObject = new HashMap(); } - writeValueToImplicitCollection(value, implicitCollectionsForCurrentObject, result, implicitFieldName); + writeValueToImplicitCollection( + value, implicitCollectionsForCurrentObject, result, new FieldLocation( + implicitFieldName, fieldDeclaringClass)); } reader.moveUp(); } if (implicitCollectionsForCurrentObject != null) { - for (final Map.Entry> entry : implicitCollectionsForCurrentObject - .entrySet()) { - final Object value = entry.getValue(); + for (Iterator iter = implicitCollectionsForCurrentObject.entrySet().iterator(); iter + .hasNext();) { + Map.Entry entry = (Map.Entry)iter.next(); + Object value = entry.getValue(); if (value instanceof ArraysList) { - final Object array = ((ArraysList)value).toPhysicalArray(); - reflectionProvider.writeField(result, entry.getKey(), array, null); + Object array = ((ArraysList)value).toPhysicalArray(); + final FieldLocation fieldLocation = (FieldLocation)entry.getKey(); + final Field field = reflectionProvider.getFieldOrNull(fieldLocation.definedIn, + fieldLocation.fieldName); + reflectionProvider.writeField(result, fieldLocation.fieldName, array, field != null + ? field.getDeclaringClass() + : null); } } } return result; } - protected Object unmarshallField(final UnmarshallingContext context, final Object result, final Class type, - final Field field) { - return context.convertAnother(result, type, mapper - .getLocalConverter(field.getDeclaringClass(), field.getName())); + protected Object unmarshallField(final UnmarshallingContext context, final Object result, + Class type, Field field) { + return context.convertAnother( + result, type, mapper.getLocalConverter(field.getDeclaringClass(), field.getName())); } protected boolean shouldUnmarshalTransientFields() { return false; } - protected boolean shouldUnmarshalField(final Field field) { + protected boolean shouldUnmarshalField(Field field) { return !(Modifier.isTransient(field.getModifiers()) && !shouldUnmarshalTransientFields()); } - private void handleUnknownField(final Class classDefiningField, final String fieldName, - final Class resultType, final String originalNodeName) { + private void handleUnknownField(Class classDefiningField, String fieldName, + Class resultType, String originalNodeName) { if (classDefiningField == null) { - for (Class cls = resultType; cls != null; cls = cls.getSuperclass()) { + for (Class cls = resultType; cls != null; cls = cls.getSuperclass()) { if (!mapper.shouldSerializeMember(cls, originalNodeName)) { return; } @@ -468,56 +524,58 @@ throw new UnknownFieldException(resultType.getName(), fieldName); } - private void writeValueToImplicitCollection(final Object value, - final Map> implicitCollections, final Object result, - final String implicitFieldName) { - Collection collection = implicitCollections.get(implicitFieldName); + private void writeValueToImplicitCollection(Object value, Map implicitCollections, Object result, final FieldLocation fieldLocation) { + Collection collection = (Collection)implicitCollections.get(fieldLocation); if (collection == null) { - final Class physicalFieldType = reflectionProvider.getFieldType(result, implicitFieldName, null); + final Field field = reflectionProvider.getFieldOrNull(fieldLocation.definedIn, fieldLocation.fieldName); + Class physicalFieldType = field != null + ? field.getType() + : reflectionProvider.getFieldType(result, fieldLocation.fieldName, null); if (physicalFieldType.isArray()) { collection = new ArraysList(physicalFieldType); } else { - final Class fieldType = mapper.defaultImplementationOf(physicalFieldType); - if (!(Collection.class.isAssignableFrom(fieldType) || Map.class.isAssignableFrom(fieldType))) { - throw new ObjectAccessException("Field " - + implicitFieldName - + " of " - + result.getClass().getName() - + " is configured for an implicit Collection or Map, but field is of type " - + fieldType.getName()); + Class fieldType = mapper.defaultImplementationOf(physicalFieldType); + if (!(Collection.class.isAssignableFrom(fieldType) || Map.class + .isAssignableFrom(fieldType))) { + ObjectAccessException oaex = new ObjectAccessException( + "Field is configured for an implicit Collection or Map, but is of an incompatible type"); + oaex.add("field", result.getClass().getName() + "."+fieldLocation.fieldName); + oaex.add("field-type", fieldType.getName()); + throw oaex; } if (pureJavaReflectionProvider == null) { pureJavaReflectionProvider = new PureJavaReflectionProvider(); } - final Object instance = pureJavaReflectionProvider.newInstance(fieldType); + Object instance = pureJavaReflectionProvider.newInstance(fieldType); if (instance instanceof Collection) { - @SuppressWarnings("unchecked") - final Collection uncheckedCollection = (Collection)instance; - collection = uncheckedCollection; + collection = (Collection)instance; } else { - final Mapper.ImplicitCollectionMapping implicitCollectionMapping = mapper - .getImplicitCollectionDefForFieldName(result.getClass(), implicitFieldName); - @SuppressWarnings("unchecked") - final Map map = (Map)instance; - collection = new MappingList(map, implicitCollectionMapping.getKeyFieldName()); + Mapper.ImplicitCollectionMapping implicitCollectionMapping = mapper + .getImplicitCollectionDefForFieldName(fieldLocation.definedIn, fieldLocation.fieldName); + collection = new MappingList( + (Map)instance, implicitCollectionMapping.getKeyFieldName()); } - reflectionProvider.writeField(result, implicitFieldName, instance, null); + reflectionProvider.writeField(result, fieldLocation.fieldName, instance, field != null + ? field.getDeclaringClass() + : null); } - implicitCollections.put(implicitFieldName, collection); + implicitCollections.put(fieldLocation, collection); } collection.add(value); } - private Class readDeclaringClass(final HierarchicalStreamReader reader) { - final String attributeName = mapper.aliasForSystemAttribute("defined-in"); - final String definedIn = attributeName == null ? null : reader.getAttribute(attributeName); + private Class readDeclaringClass(HierarchicalStreamReader reader) { + String attributeName = mapper.aliasForSystemAttribute("defined-in"); + String definedIn = attributeName == null ? null : reader.getAttribute(attributeName); return definedIn == null ? null : mapper.realClass(definedIn); } - protected Object instantiateNewInstance(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final String attributeName = mapper.aliasForSystemAttribute("resolves-to"); - final String readResolveValue = attributeName == null ? null : reader.getAttribute(attributeName); - final Object currentObject = context.currentObject(); + protected Object instantiateNewInstance(HierarchicalStreamReader reader, + UnmarshallingContext context) { + String attributeName = mapper.aliasForSystemAttribute("resolves-to"); + String readResolveValue = attributeName == null ? null : reader + .getAttribute(attributeName); + Object currentObject = context.currentObject(); if (currentObject != null) { return currentObject; } else if (readResolveValue != null) { @@ -527,54 +585,94 @@ } } - @Override public void flushCache() { serializationMethodInvoker.flushCache(); } - private Object readResolve() { + protected Object readResolve() { serializationMethodInvoker = new SerializationMethodInvoker(); + serializationMembers = serializationMethodInvoker.serializationMembers; return this; } public static class DuplicateFieldException extends ConversionException { - public DuplicateFieldException(final String msg) { + public DuplicateFieldException(String msg) { super("Duplicate field " + msg); add("field", msg); } } public static class UnknownFieldException extends ConversionException { - public UnknownFieldException(final String type, final String field) { + public UnknownFieldException(String type, String field) { super("No such field " + type + "." + field); add("field", field); } } - private static class FieldInfo { + private static class FieldLocation { final String fieldName; - final Class type; - final Class definedIn; - final Object value; + final Class definedIn; - FieldInfo(final String fieldName, final Class type, final Class definedIn, final Object value) { + FieldLocation(final String fieldName, final Class definedIn) { this.fieldName = fieldName; - this.type = type; this.definedIn = definedIn; + } + + public int hashCode() { + final int prime = 7; + int result = 1; + result = prime * result + (definedIn == null ? 0 : definedIn.getName().hashCode()); + result = prime * result + (fieldName == null ? 0 : fieldName.hashCode()); + return result; + } + + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final FieldLocation other = (FieldLocation)obj; + if (definedIn != other.definedIn) { + return false; + } + if (fieldName == null) { + if (other.fieldName != null) { + return false; + } + } else if (!fieldName.equals(other.fieldName)) { + return false; + } + return true; + } + } + + private static class FieldInfo extends FieldLocation { + final Class type; + final Object value; + + FieldInfo(final String fieldName, final Class type, final Class definedIn, final Object value) { + super(fieldName, definedIn); + this.type = type; this.value = value; } } - private static class ArraysList extends ArrayList { - final Class physicalFieldType; + private static class ArraysList extends ArrayList { + final Class physicalFieldType; - ArraysList(final Class physicalFieldType) { + ArraysList(Class physicalFieldType) { this.physicalFieldType = physicalFieldType; } Object toPhysicalArray() { - final Object[] objects = toArray(); - final Object array = Array.newInstance(physicalFieldType.getComponentType(), objects.length); + Object[] objects = toArray(); + Object array = Array.newInstance( + physicalFieldType.getComponentType(), objects.length); if (physicalFieldType.getComponentType().isPrimitive()) { for (int i = 0; i < objects.length; ++i) { Array.set(array, i, Array.get(objects, i)); @@ -586,65 +684,51 @@ } } - private class MappingList extends AbstractList { + private class MappingList extends AbstractList { - private final Map map; + private final Map map; private final String keyFieldName; - private final Map, Field> fieldCache = new HashMap, Field>(); + private final Map fieldCache = new HashMap(); - public MappingList(final Map map, final String keyFieldName) { + public MappingList(Map map, String keyFieldName) { this.map = map; this.keyFieldName = keyFieldName; } - @Override - public boolean add(final Object object) { + public boolean add(Object object) { if (object == null) { - final boolean containsNull = !map.containsKey(null); + boolean containsNull = !map.containsKey(null); map.put(null, null); return containsNull; } - final Class itemType = object.getClass(); + Class itemType = object.getClass(); + if (keyFieldName != null) { - Field field = fieldCache.get(itemType); + Field field = (Field)fieldCache.get(itemType); if (field == null) { field = reflectionProvider.getField(itemType, keyFieldName); fieldCache.put(itemType, field); } if (field != null) { - try { - final Object key = field.get(object); - return map.put(key, object) == null; - } catch (final IllegalArgumentException e) { - throw new ObjectAccessException("Could not get field " - + field.getClass() - + "." - + field.getName(), e); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Could not get field " - + field.getClass() - + "." - + field.getName(), e); - } + Object key = Fields.read(field, object); + return map.put(key, object) == null; } } else if (object instanceof Map.Entry) { - @SuppressWarnings("unchecked") - final Map.Entry entry = (Map.Entry)object; + final Map.Entry entry = (Map.Entry)object; return map.put(entry.getKey(), entry.getValue()) == null; } - throw new ConversionException("Element of type " - + object.getClass().getName() - + " is not defined as entry for map of type " - + map.getClass().getName()); + ConversionException exception = + new ConversionException("Element is not defined as entry for implicit map"); + exception.add("map-type", map.getClass().getName()); + exception.add("element-type", object.getClass().getName()); + throw exception; } - @Override - public Object get(final int index) { + public Object get(int index) { throw new UnsupportedOperationException(); } - @Override public int size() { return map.size(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/CGLIBEnhancedConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/CGLIBEnhancedConverter.java (.../CGLIBEnhancedConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/CGLIBEnhancedConverter.java (.../CGLIBEnhancedConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,21 +10,6 @@ */ package com.thoughtworks.xstream.converters.reflection; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.Proxy; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; @@ -42,10 +27,25 @@ import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.NoOp; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + /** - * Converts a proxy created by the CGLIB {@link Enhancer}. Such a proxy is recreated while deserializing the proxy. The - * converter does only work, if
    + * Converts a proxy created by the CGLIB {@link Enhancer}. Such a proxy is recreated while + * deserializing the proxy. The converter does only work, if
    *
      *
    • the DefaultNamingPolicy is used for the proxy's name
    • *
    • the proxy uses a factory or only one Callback is registered
    • @@ -59,81 +59,74 @@ public class CGLIBEnhancedConverter extends SerializableConverter { private static String DEFAULT_NAMING_MARKER = "$$EnhancerByCGLIB$$"; private static String CALLBACK_MARKER = "CGLIB$CALLBACK_"; - private transient Map> fieldCache; + private transient Map fieldCache; /** * Construct a CGLIBEnhancedConverter. - * * @param mapper the mapper chain instance * @param reflectionProvider the reflection provider * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance * @since 1.4.5 */ - public CGLIBEnhancedConverter( - final Mapper mapper, final ReflectionProvider reflectionProvider, - final ClassLoaderReference classLoaderReference) { + public CGLIBEnhancedConverter(Mapper mapper, ReflectionProvider reflectionProvider, ClassLoaderReference classLoaderReference) { super(mapper, new CGLIBFilteringReflectionProvider(reflectionProvider), classLoaderReference); - fieldCache = new HashMap>(); + this.fieldCache = new HashMap(); } /** * @deprecated As of 1.4.5 use {@link #CGLIBEnhancedConverter(Mapper, ReflectionProvider, ClassLoaderReference)} */ - @Deprecated - public CGLIBEnhancedConverter( - final Mapper mapper, final ReflectionProvider reflectionProvider, final ClassLoader classLoader) { + public CGLIBEnhancedConverter(Mapper mapper, ReflectionProvider reflectionProvider, ClassLoader classLoader) { super(mapper, new CGLIBFilteringReflectionProvider(reflectionProvider), classLoader); - fieldCache = new HashMap>(); + this.fieldCache = new HashMap(); } /** * @deprecated As of 1.4 use {@link #CGLIBEnhancedConverter(Mapper, ReflectionProvider, ClassLoaderReference)} */ - @Deprecated - public CGLIBEnhancedConverter(final Mapper mapper, final ReflectionProvider reflectionProvider) { - this(mapper, new CGLIBFilteringReflectionProvider(reflectionProvider), CGLIBEnhancedConverter.class - .getClassLoader()); + public CGLIBEnhancedConverter(Mapper mapper, ReflectionProvider reflectionProvider) { + this(mapper, new CGLIBFilteringReflectionProvider(reflectionProvider), CGLIBEnhancedConverter.class.getClassLoader()); } - @Override - public boolean canConvert(final Class type) { - return Enhancer.isEnhanced(type) - && type.getName().indexOf(DEFAULT_NAMING_MARKER) > 0 + public boolean canConvert(Class type) { + return (Enhancer.isEnhanced(type) && type.getName().indexOf(DEFAULT_NAMING_MARKER) > 0) || type == CGLIBMapper.Marker.class; } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final Class type = source.getClass(); - final boolean hasFactory = Factory.class.isAssignableFrom(type); + public void marshal(Object source, HierarchicalStreamWriter writer, + MarshallingContext context) { + Class type = source.getClass(); + boolean hasFactory = Factory.class.isAssignableFrom(type); ExtendedHierarchicalStreamWriterHelper.startNode(writer, "type", type); context.convertAnother(type.getSuperclass()); writer.endNode(); writer.startNode("interfaces"); - final Class[] interfaces = type.getInterfaces(); - for (final Class interface1 : interfaces) { - if (interface1 == Factory.class) { + Class[] interfaces = type.getInterfaces(); + for (int i = 0; i < interfaces.length; i++ ) { + if (interfaces[i] == Factory.class) { continue; } - ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(interface1.getClass()), - interface1.getClass()); - context.convertAnother(interface1); + ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper + .serializedClass(interfaces[i].getClass()), interfaces[i].getClass()); + context.convertAnother(interfaces[i]); writer.endNode(); } writer.endNode(); writer.startNode("hasFactory"); writer.setValue(String.valueOf(hasFactory)); writer.endNode(); - Map callbackIndexMap = null; - final Callback[] callbacks = hasFactory ? ((Factory)source).getCallbacks() : getCallbacks(source); + Map callbackIndexMap = null; + Callback[] callbacks = hasFactory + ? ((Factory)source).getCallbacks() + : getCallbacks(source); if (callbacks.length > 1) { if (hasFactory) { callbackIndexMap = createCallbackIndexMap((Factory)source); } else { - final ConversionException exception = new ConversionException( + ConversionException exception = new ConversionException( "Cannot handle CGLIB enhanced proxies without factory that have multiple callbacks"); - exception.add("proxy superclass", type.getSuperclass().getName()); - exception.add("number of callbacks", String.valueOf(callbacks.length)); + exception.add("proxy-superclass", type.getSuperclass().getName()); + exception.add("number-of-callbacks", String.valueOf(callbacks.length)); throw exception; } writer.startNode("callbacks"); @@ -142,15 +135,17 @@ writer.endNode(); } boolean hasInterceptor = false; - for (final Callback callback : callbacks) { + for (int i = 0; i < callbacks.length; i++ ) { + final Callback callback = callbacks[i]; if (callback == null) { - final String name = mapper.serializedClass(null); + String name = mapper.serializedClass(null); writer.startNode(name); writer.endNode(); } else { - hasInterceptor = hasInterceptor || MethodInterceptor.class.isAssignableFrom(callback.getClass()); - ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(callback.getClass()), - callback.getClass()); + hasInterceptor = hasInterceptor + || MethodInterceptor.class.isAssignableFrom(callback.getClass()); + ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper + .serializedClass(callback.getClass()), callback.getClass()); context.convertAnother(callback); writer.endNode(); } @@ -163,14 +158,17 @@ if (!field.isAccessible()) { field.setAccessible(true); } - final long serialVersionUID = field.getLong(null); - ExtendedHierarchicalStreamWriterHelper.startNode(writer, "serialVersionUID", String.class); + long serialVersionUID = field.getLong(null); + ExtendedHierarchicalStreamWriterHelper.startNode( + writer, "serialVersionUID", String.class); writer.setValue(String.valueOf(serialVersionUID)); writer.endNode(); - } catch (final NoSuchFieldException e) { + } catch (NoSuchFieldException e) { // OK, ignore - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Access to serialVersionUID of " + type.getName() + " not allowed", e); + } catch (IllegalAccessException e) { + ObjectAccessException exception = new ObjectAccessException("Cannot access field", e); + exception.add("field", type.getName() + ".serialVersionUID"); + throw exception; } if (hasInterceptor) { writer.startNode("instance"); @@ -179,78 +177,75 @@ } } - private Callback[] getCallbacks(final Object source) { - final Class type = source.getClass(); - List fields = fieldCache.get(type.getName()); + private Callback[] getCallbacks(Object source) { + Class type = source.getClass(); + List fields = (List)fieldCache.get(type.getName()); if (fields == null) { - fields = new ArrayList(); + fields = new ArrayList(); fieldCache.put(type.getName(), fields); for (int i = 0; true; ++i) { try { - final Field field = type.getDeclaredField(CALLBACK_MARKER + i); + Field field = type.getDeclaredField(CALLBACK_MARKER + i); if (!field.isAccessible()) { field.setAccessible(true); } fields.add(field); - } catch (final NoSuchFieldException e) { + } catch (NoSuchFieldException e) { break; } } } - final List list = new ArrayList(); + List list = new ArrayList(); for (int i = 0; i < fields.size(); ++i) { try { - final Field field = fields.get(i); - final Callback callback = (Callback)field.get(source); + Field field = (Field)fields.get(i); + Object callback = field.get(source); list.add(callback); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Access to " - + type.getName() - + "." - + CALLBACK_MARKER - + i - + " not allowed", e); + } catch (IllegalAccessException e) { + ObjectAccessException exception = new ObjectAccessException("Cannot access field", e); + exception.add("field", type.getName() + "." + CALLBACK_MARKER + i); + throw exception; } } - return list.toArray(new Callback[list.size()]); + return (Callback[])list.toArray(new Callback[list.size()]); } - private Map createCallbackIndexMap(final Factory source) { - final Callback[] originalCallbacks = source.getCallbacks(); - final Callback[] reverseEngineeringCallbacks = new Callback[originalCallbacks.length]; - final Map callbackIndexMap = new HashMap(); + private Map createCallbackIndexMap(Factory source) { + Callback[] originalCallbacks = source.getCallbacks(); + Callback[] reverseEngineeringCallbacks = new Callback[originalCallbacks.length]; + Map callbackIndexMap = new HashMap(); int idxNoOp = -1; - for (int i = 0; i < originalCallbacks.length; i++) { - final Callback callback = originalCallbacks[i]; + for (int i = 0; i < originalCallbacks.length; i++ ) { + Callback callback = originalCallbacks[i]; if (callback == null) { reverseEngineeringCallbacks[i] = null; } else if (NoOp.class.isAssignableFrom(callback.getClass())) { reverseEngineeringCallbacks[i] = NoOp.INSTANCE; idxNoOp = i; } else { - reverseEngineeringCallbacks[i] = createReverseEngineeredCallbackOfProperType(callback, i, - callbackIndexMap); + reverseEngineeringCallbacks[i] = createReverseEngineeredCallbackOfProperType( + callback, i, callbackIndexMap); } } try { source.setCallbacks(reverseEngineeringCallbacks); - final Set> interfaces = new HashSet>(); - final Set methods = new HashSet(); - Class type = source.getClass(); + final Set interfaces = new HashSet(); + final Set methods = new HashSet(); + Class type = source.getClass(); do { methods.addAll(Arrays.asList(type.getDeclaredMethods())); methods.addAll(Arrays.asList(type.getMethods())); - final Class[] implementedInterfaces = type.getInterfaces(); + Class[] implementedInterfaces = type.getInterfaces(); interfaces.addAll(Arrays.asList(implementedInterfaces)); type = type.getSuperclass(); } while (type != null); - for (final Iterator> iterator = interfaces.iterator(); iterator.hasNext();) { - type = iterator.next(); + for (final Iterator iterator = interfaces.iterator(); iterator.hasNext();) { + type = (Class)iterator.next(); methods.addAll(Arrays.asList(type.getDeclaredMethods())); } - for (final Iterator iter = methods.iterator(); iter.hasNext();) { - final Method method = iter.next(); + for (final Iterator iter = methods.iterator(); iter.hasNext();) { + final Method method = (Method)iter.next(); if (!method.isAccessible()) { method.setAccessible(true); } @@ -259,24 +254,27 @@ iter.remove(); continue; } - final Class[] parameterTypes = method.getParameterTypes(); + Class[] parameterTypes = method.getParameterTypes(); Method calledMethod = method; try { if ((method.getModifiers() & Modifier.ABSTRACT) > 0) { - calledMethod = source.getClass().getMethod(method.getName(), method.getParameterTypes()); + calledMethod = source.getClass().getMethod( + method.getName(), method.getParameterTypes()); } callbackIndexMap.put(null, method); calledMethod.invoke(source, parameterTypes == null ? (Object[])null : createNullArguments(parameterTypes)); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Access to " + calledMethod + " not allowed", e); - } catch (final InvocationTargetException e) { + } catch (IllegalAccessException e) { + ObjectAccessException exception = new ObjectAccessException("Cannot access method", e); + exception.add("method", calledMethod.toString()); + throw exception; + } catch (InvocationTargetException e) { // OK, ignore - } catch (final NoSuchMethodException e) { - final ConversionException exception = new ConversionException( + } catch (NoSuchMethodException e) { + ConversionException exception = new ConversionException( "CGLIB enhanced proxies wit abstract nethod that has not been implemented"); - exception.add("proxy superclass", type.getSuperclass().getName()); + exception.add("proxy-superclass", type.getSuperclass().getName()); exception.add("method", method.toString()); throw exception; } @@ -285,9 +283,9 @@ } } if (idxNoOp >= 0) { - final Integer idx = Integer.valueOf(idxNoOp); - for (final Method method : methods) { - callbackIndexMap.put(method, idx); + Integer idx = new Integer(idxNoOp); + for (final Iterator iter = methods.iterator(); iter.hasNext();) { + callbackIndexMap.put(iter.next(), idx); } } } finally { @@ -298,10 +296,10 @@ return callbackIndexMap; } - private Object[] createNullArguments(final Class[] parameterTypes) { - final Object[] arguments = new Object[parameterTypes.length]; - for (int i = 0; i < arguments.length; i++) { - final Class type = parameterTypes[i]; + private Object[] createNullArguments(Class[] parameterTypes) { + Object[] arguments = new Object[parameterTypes.length]; + for (int i = 0; i < arguments.length; i++ ) { + Class type = parameterTypes[i]; if (type.isPrimitive()) { if (type == byte.class) { arguments[i] = new Byte((byte)0); @@ -325,16 +323,17 @@ return arguments; } - private Callback createReverseEngineeredCallbackOfProperType(final Callback callback, final int index, - final Map callbackIndexMap) { - Class iface = null; - Class[] interfaces = callback.getClass().getInterfaces(); - for (int i = 0; i < interfaces.length; i++) { + private Callback createReverseEngineeredCallbackOfProperType(Callback callback, int index, + Map callbackIndexMap) { + Class iface = null; + Class[] interfaces = callback.getClass().getInterfaces(); + for (int i = 0; i < interfaces.length; i++ ) { if (Callback.class.isAssignableFrom(interfaces[i])) { iface = interfaces[i]; if (iface == Callback.class) { - final ConversionException exception = new ConversionException("Cannot handle CGLIB callback"); - exception.add("CGLIB callback type", callback.getClass().getName()); + ConversionException exception = new ConversionException( + "Cannot handle CGLIB callback"); + exception.add("CGLIB-callback-type", callback.getClass().getName()); throw exception; } interfaces = iface.getInterfaces(); @@ -344,39 +343,38 @@ i = -1; } } - return (Callback)Proxy.newProxyInstance(iface.getClassLoader(), new Class[]{iface}, + return (Callback)Proxy.newProxyInstance( + iface.getClassLoader(), new Class[]{iface}, new ReverseEngineeringInvocationHandler(index, callbackIndexMap)); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { final Enhancer enhancer = new Enhancer(); reader.moveDown(); - enhancer.setSuperclass((Class)context.convertAnother(null, Class.class)); + enhancer.setSuperclass((Class)context.convertAnother(null, Class.class)); reader.moveUp(); reader.moveDown(); - final List> interfaces = new ArrayList>(); + List interfaces = new ArrayList(); while (reader.hasMoreChildren()) { reader.moveDown(); - interfaces.add((Class)context.convertAnother(null, mapper.realClass(reader.getNodeName()))); + interfaces + .add(context.convertAnother(null, mapper.realClass(reader.getNodeName()))); reader.moveUp(); } - enhancer.setInterfaces(interfaces.toArray(new Class[interfaces.size()])); + enhancer.setInterfaces((Class[])interfaces.toArray(new Class[interfaces.size()])); reader.moveUp(); reader.moveDown(); - final boolean useFactory = Boolean.valueOf(reader.getValue()).booleanValue(); + boolean useFactory = Boolean.valueOf(reader.getValue()).booleanValue(); enhancer.setUseFactory(useFactory); reader.moveUp(); - final List callbacksToEnhance = new ArrayList(); - final List callbacks = new ArrayList(); - Map callbackIndexMap = null; + List callbacksToEnhance = new ArrayList(); + List callbacks = new ArrayList(); + Map callbackIndexMap = null; reader.moveDown(); if ("callbacks".equals(reader.getNodeName())) { reader.moveDown(); - @SuppressWarnings("unchecked") - final Map typedMap = (Map)context.convertAnother(null, HashMap.class); - callbackIndexMap = typedMap; + callbackIndexMap = (Map)context.convertAnother(null, HashMap.class); reader.moveUp(); while (reader.hasMoreChildren()) { reader.moveDown(); @@ -386,7 +384,8 @@ } else { readCallback(reader, context, callbacksToEnhance, callbacks); } - enhancer.setCallbacks(callbacksToEnhance.toArray(new Callback[callbacksToEnhance.size()])); + enhancer.setCallbacks((Callback[])callbacksToEnhance + .toArray(new Callback[callbacksToEnhance.size()])); if (callbackIndexMap != null) { enhancer.setCallbackFilter(new ReverseEngineeredCallbackFilter(callbackIndexMap)); } @@ -405,12 +404,13 @@ if (result == null) { result = create(enhancer, callbacks, useFactory); } - return serializationMethodInvoker.callReadResolve(result); + return serializationMembers.callReadResolve(result); } - private void readCallback(final HierarchicalStreamReader reader, final UnmarshallingContext context, - final List callbacksToEnhance, final List callbacks) { - final Callback callback = (Callback)context.convertAnother(null, mapper.realClass(reader.getNodeName())); + private void readCallback(HierarchicalStreamReader reader, UnmarshallingContext context, + List callbacksToEnhance, List callbacks) { + Callback callback = (Callback)context.convertAnother(null, mapper.realClass(reader + .getNodeName())); callbacks.add(callback); if (callback == null) { callbacksToEnhance.add(NoOp.INSTANCE); @@ -419,24 +419,25 @@ } } - private Object create(final Enhancer enhancer, final List callbacks, final boolean useFactory) { - final Object result = enhancer.create(); + private Object create(final Enhancer enhancer, List callbacks, boolean useFactory) { + Object result = enhancer.create(); if (useFactory) { - ((Factory)result).setCallbacks(callbacks.toArray(new Callback[callbacks.size()])); + ((Factory)result).setCallbacks((Callback[])callbacks.toArray(new Callback[callbacks + .size()])); } return result; } - @Override - protected List> hierarchyFor(final Class type) { - final List> typeHierarchy = super.hierarchyFor(type); + protected List hierarchyFor(Class type) { + List typeHierarchy = super.hierarchyFor(type); // drop the CGLIB proxy typeHierarchy.remove(typeHierarchy.size() - 1); return typeHierarchy; } - private Object readResolve() { - fieldCache = new HashMap>(); + protected Object readResolve() { + super.readResolve(); + fieldCache = new HashMap(); return this; } @@ -446,11 +447,9 @@ super(reflectionProvider); } - @Override public void visitSerializableFields(final Object object, final Visitor visitor) { wrapped.visitSerializableFields(object, new Visitor() { - @Override - public void visit(final String name, final Class type, final Class definedIn, final Object value) { + public void visit(String name, Class type, Class definedIn, Object value) { if (!name.startsWith("CGLIB$")) { visitor.visit(name, type, definedIn, value); } @@ -461,37 +460,35 @@ private static final class ReverseEngineeringInvocationHandler implements InvocationHandler { private final Integer index; - private final Map indexMap; + private final Map indexMap; - public ReverseEngineeringInvocationHandler(final int index, final Map indexMap) { + public ReverseEngineeringInvocationHandler(int index, Map indexMap) { this.indexMap = indexMap; - this.index = Integer.valueOf(index); + this.index = new Integer(index); } - @Override - public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { indexMap.put(indexMap.get(null), index); return null; } } private static class ReverseEngineeredCallbackFilter implements CallbackFilter { - private final Map callbackIndexMap; + private final Map callbackIndexMap; - public ReverseEngineeredCallbackFilter(final Map callbackIndexMap) { + public ReverseEngineeredCallbackFilter(Map callbackIndexMap) { this.callbackIndexMap = callbackIndexMap; } - @Override - public int accept(final Method method) { + public int accept(Method method) { if (!callbackIndexMap.containsKey(method)) { - final ConversionException exception = new ConversionException( + ConversionException exception = new ConversionException( "CGLIB callback not detected in reverse engineering"); - exception.add("CGLIB callback", method.toString()); + exception.add("CGLIB-callback", method.toString()); throw exception; } - return callbackIndexMap.get(method).intValue(); + return ((Integer)callbackIndexMap.get(method)).intValue(); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ExternalizableConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ExternalizableConverter.java (.../ExternalizableConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ExternalizableConverter.java (.../ExternalizableConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,194 +1,190 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2014, 2015, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 24. August 2004 by Joe Walnes */ package com.thoughtworks.xstream.converters.reflection; -import java.io.Externalizable; -import java.io.IOException; -import java.io.NotActiveException; -import java.io.ObjectInputValidation; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Map; - import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.UnmarshallingContext; import com.thoughtworks.xstream.core.ClassLoaderReference; import com.thoughtworks.xstream.core.JVM; +import com.thoughtworks.xstream.core.ReferencingMarshallingContext; import com.thoughtworks.xstream.core.util.CustomObjectInputStream; import com.thoughtworks.xstream.core.util.CustomObjectOutputStream; import com.thoughtworks.xstream.core.util.HierarchicalStreams; +import com.thoughtworks.xstream.core.util.SerializationMembers; import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.mapper.Mapper; +import java.io.Externalizable; +import java.io.IOException; +import java.io.NotActiveException; +import java.io.ObjectInputValidation; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Map; /** - * Converts any object that implements the {@link Externalizable} interface, allowing compatibility with native Java + * Converts any object that implements the java.io.Externalizable interface, allowing compatibility with native Java * serialization. - * + * * @author Joe Walnes */ public class ExternalizableConverter implements Converter { - private final Mapper mapper; + private Mapper mapper; private final ClassLoaderReference classLoaderReference; + private transient SerializationMembers serializationMembers; /** * Construct an ExternalizableConverter. - * + * * @param mapper the Mapper chain * @param classLoaderReference the reference to XStream's {@link ClassLoader} instance * @since 1.4.5 */ - public ExternalizableConverter(final Mapper mapper, final ClassLoaderReference classLoaderReference) { + public ExternalizableConverter(Mapper mapper, ClassLoaderReference classLoaderReference) { this.mapper = mapper; this.classLoaderReference = classLoaderReference; + serializationMembers = new SerializationMembers(); } /** * @deprecated As of 1.4.5 use {@link #ExternalizableConverter(Mapper, ClassLoaderReference)} */ - @Deprecated - public ExternalizableConverter(final Mapper mapper, final ClassLoader classLoader) { + public ExternalizableConverter(Mapper mapper, ClassLoader classLoader) { this(mapper, new ClassLoaderReference(classLoader)); } /** * @deprecated As of 1.4 use {@link #ExternalizableConverter(Mapper, ClassLoader)} */ - @Deprecated - public ExternalizableConverter(final Mapper mapper) { + public ExternalizableConverter(Mapper mapper) { this(mapper, ExternalizableConverter.class.getClassLoader()); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return JVM.canCreateDerivedObjectOutputStream() && Externalizable.class.isAssignableFrom(type); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - try { - final Externalizable externalizable = (Externalizable)source; - final CustomObjectOutputStream.StreamCallback callback = new CustomObjectOutputStream.StreamCallback() { - @Override - public void writeToStream(final Object object) { - if (object == null) { - writer.startNode("null"); - writer.endNode(); - } else { - ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object - .getClass()), object.getClass()); - context.convertAnother(object); - writer.endNode(); + public void marshal(final Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) { + final Object source = serializationMembers.callWriteReplace(original); + if (source != original && context instanceof ReferencingMarshallingContext) { + ((ReferencingMarshallingContext)context).replace(original, source); + } + if (source.getClass() != original.getClass()) { + final String attributeName = mapper.aliasForSystemAttribute("resolves-to"); + if (attributeName != null) { + writer.addAttribute(attributeName, mapper.serializedClass(source.getClass())); + } + context.convertAnother(source); + } else { + try { + Externalizable externalizable = (Externalizable)source; + CustomObjectOutputStream.StreamCallback callback = new CustomObjectOutputStream.StreamCallback() { + public void writeToStream(final Object object) { + if (object == null) { + writer.startNode("null"); + writer.endNode(); + } else { + ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object.getClass()), object.getClass()); + context.convertAnother(object); + writer.endNode(); + } } - } - @Override - public void writeFieldsToStream(final Map fields) { - throw new UnsupportedOperationException(); - } + public void writeFieldsToStream(final Map fields) { + throw new UnsupportedOperationException(); + } - @Override - public void defaultWriteObject() { - throw new UnsupportedOperationException(); - } + public void defaultWriteObject() { + throw new UnsupportedOperationException(); + } - @Override - public void flush() { - writer.flush(); - } + public void flush() { + writer.flush(); + } - @Override - public void close() { - throw new UnsupportedOperationException( - "Objects are not allowed to call ObjectOutput.close() from writeExternal()"); - } - }; - @SuppressWarnings("resource") - final CustomObjectOutputStream objectOutput = CustomObjectOutputStream.getInstance(context, callback); - externalizable.writeExternal(objectOutput); - objectOutput.popCallback(); - } catch (final IOException e) { - throw new ConversionException("Cannot serialize " + source.getClass().getName() + " using Externalization", - e); + public void close() { + throw new UnsupportedOperationException("Objects are not allowed to call ObjectOutput.close() from writeExternal()"); + } + }; + final CustomObjectOutputStream objectOutput = CustomObjectOutputStream.getInstance(context, callback); + externalizable.writeExternal(objectOutput); + objectOutput.popCallback(); + } catch (IOException e) { + throw new StreamException("Cannot serialize " + source.getClass().getName() + " using Externalization", e); + } } } - @Override public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { - final Class type = context.getRequiredType(); - final Constructor defaultConstructor; + final Class type = context.getRequiredType(); + final Constructor defaultConstructor; try { - defaultConstructor = type.getDeclaredConstructor(); + defaultConstructor = type.getDeclaredConstructor((Class[]) null); if (!defaultConstructor.isAccessible()) { defaultConstructor.setAccessible(true); } - final Externalizable externalizable = (Externalizable)defaultConstructor.newInstance(); - final CustomObjectInputStream.StreamCallback callback = new CustomObjectInputStream.StreamCallback() { - @Override + final Externalizable externalizable = (Externalizable) defaultConstructor.newInstance((Object[]) null); + CustomObjectInputStream.StreamCallback callback = new CustomObjectInputStream.StreamCallback() { public Object readFromStream() { reader.moveDown(); - final Class type = HierarchicalStreams.readClassType(reader, mapper); - final Object streamItem = context.convertAnother(externalizable, type); + Class type = HierarchicalStreams.readClassType(reader, mapper); + Object streamItem = context.convertAnother(externalizable, type); reader.moveUp(); return streamItem; } - @Override - public Map readFieldsFromStream() { + public Map readFieldsFromStream() { throw new UnsupportedOperationException(); } - @Override public void defaultReadObject() { throw new UnsupportedOperationException(); } - @Override - public void registerValidation(final ObjectInputValidation validation, final int priority) - throws NotActiveException { + public void registerValidation(ObjectInputValidation validation, int priority) throws NotActiveException { throw new NotActiveException("stream inactive"); } - @Override public void close() { - throw new UnsupportedOperationException( - "Objects are not allowed to call ObjectInput.close() from readExternal()"); + throw new UnsupportedOperationException("Objects are not allowed to call ObjectInput.close() from readExternal()"); } }; - { - @SuppressWarnings("resource") - final CustomObjectInputStream objectInput = CustomObjectInputStream.getInstance(context, callback, - classLoaderReference); - externalizable.readExternal(objectInput); - objectInput.popCallback(); - } - return externalizable; - } catch (final NoSuchMethodException e) { - throw new ConversionException("Cannot construct " + type.getClass() + ", missing default constructor", e); - } catch (final InvocationTargetException e) { - throw new ConversionException("Cannot construct " + type.getClass(), e); - } catch (final InstantiationException e) { - throw new ConversionException("Cannot construct " + type.getClass(), e); - } catch (final IllegalAccessException e) { - throw new ConversionException("Cannot construct " + type.getClass(), e); - } catch (final IOException e) { - throw new ConversionException("Cannot externalize " + type.getClass(), e); - } catch (final ClassNotFoundException e) { - throw new ConversionException("Cannot externalize " + type.getClass(), e); + CustomObjectInputStream objectInput = CustomObjectInputStream.getInstance(context, callback, classLoaderReference); + externalizable.readExternal(objectInput); + objectInput.popCallback(); + return serializationMembers.callReadResolve(externalizable); + } catch (NoSuchMethodException e) { + throw new ConversionException("Missing default constructor of type", e); + } catch (InvocationTargetException e) { + throw new ConversionException("Cannot construct type", e); + } catch (InstantiationException e) { + throw new ConversionException("Cannot construct type", e); + } catch (IllegalAccessException e) { + throw new ObjectAccessException("Cannot construct type", e); + } catch (IOException e) { + throw new StreamException("Cannot externalize " + type.getClass(), e); + } catch (ClassNotFoundException e) { + throw new ConversionException("Cannot construct type", e); } } + + private Object readResolve() { + serializationMembers = new SerializationMembers(); + return this; + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/FieldDictionary.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/FieldDictionary.java (.../FieldDictionary.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/FieldDictionary.java (.../FieldDictionary.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,42 +1,40 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 XStream Committers. * All rights reserved. - * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * * Created on 14. May 2004 by Joe Walnes */ package com.thoughtworks.xstream.converters.reflection; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; +import java.util.LinkedList; import java.util.Map; -import java.util.Set; import com.thoughtworks.xstream.core.Caching; import com.thoughtworks.xstream.core.JVM; +import com.thoughtworks.xstream.core.util.OrderRetainingMap; /** * A field dictionary instance caches information about classes fields. - * + * * @author Joe Walnes * @author Jörg Schaible * @author Guilherme Silveira */ public class FieldDictionary implements Caching { - private transient Map, Map> keyedByFieldNameCache; - private transient Map, Map> keyedByFieldKeyCache; + private static final DictionaryEntry OBJECT_DICTIONARY_ENTRY = new DictionaryEntry(Collections.EMPTY_MAP, + Collections.EMPTY_MAP); + + private transient Map dictionaryEntries; private final FieldKeySorter sorter; public FieldDictionary() { @@ -49,34 +47,42 @@ } private void init() { - keyedByFieldNameCache = new HashMap, Map>(); - keyedByFieldKeyCache = new HashMap, Map>(); - keyedByFieldNameCache.put(Object.class, Collections.emptyMap()); - keyedByFieldKeyCache.put(Object.class, Collections.emptyMap()); + dictionaryEntries = new HashMap(); } /** * Returns an iterator for all fields for some class - * + * * @param cls the class you are interested on * @return an iterator for its fields + * @deprecated As of 1.3, use {@link #fieldsFor(Class)} instead */ - public Iterator fieldsFor(final Class cls) { + public Iterator serializableFieldsFor(final Class cls) { + return fieldsFor(cls); + } + + /** + * Returns an iterator for all fields for some class + * + * @param cls the class you are interested on + * @return an iterator for its fields + */ + public Iterator fieldsFor(final Class cls) { return buildMap(cls, true).values().iterator(); } /** * Returns an specific field of some class. If definedIn is null, it searches for the field named 'name' inside the * class cls. If definedIn is different than null, tries to find the specified field name in the specified class cls * which should be defined in class definedIn (either equals cls or a one of it's superclasses) - * + * * @param cls the class where the field is to be searched * @param name the field name * @param definedIn the superclass (or the class itself) of cls where the field was defined * @return the field itself * @throws ObjectAccessException if no field can be found */ - public Field field(final Class cls, final String name, final Class definedIn) { + public Field field(final Class cls, final String name, final Class definedIn) { final Field field = fieldOrNull(cls, name, definedIn); if (field == null) { throw new MissingFieldException(cls.getName(), name); @@ -89,83 +95,95 @@ * Returns an specific field of some class. If definedIn is null, it searches for the field named 'name' inside the * class cls. If definedIn is different than null, tries to find the specified field name in the specified class cls * which should be defined in class definedIn (either equals cls or a one of it's superclasses) - * + * * @param cls the class where the field is to be searched * @param name the field name * @param definedIn the superclass (or the class itself) of cls where the field was defined * @return the field itself or null * @since 1.4 */ - public Field fieldOrNull(final Class cls, final String name, final Class definedIn) { - final Map fields = buildMap(cls, definedIn != null); - final Field field = fields.get(definedIn != null ? (Object)new FieldKey(name, definedIn, -1) : (Object)name); + public Field fieldOrNull(final Class cls, final String name, final Class definedIn) { + final Map fields = buildMap(cls, definedIn != null); + final Field field = (Field)fields.get(definedIn != null + ? (Object)new FieldKey(name, definedIn, -1) + : (Object)name); return field; } - private Map buildMap(final Class type, final boolean tupleKeyed) { - Class cls = type; - synchronized (this) { - if (!keyedByFieldNameCache.containsKey(type)) { - final List> superClasses = new ArrayList>(); - while (!Object.class.equals(cls) && cls != null) { - superClasses.add(0, cls); - cls = cls.getSuperclass(); + private Map buildMap(final Class type, final boolean tupleKeyed) { + + Class cls = type; + + DictionaryEntry lastDictionaryEntry = null; + final LinkedList superClasses = new LinkedList(); + while (lastDictionaryEntry == null) { + if (Object.class.equals(cls) || cls == null) { + lastDictionaryEntry = OBJECT_DICTIONARY_ENTRY; + } else { + lastDictionaryEntry = getDictionaryEntry(cls); + } + if (lastDictionaryEntry == null) { + superClasses.addFirst(cls); + cls = cls.getSuperclass(); + } + } + + for (final Iterator iter = superClasses.iterator(); iter.hasNext();) { + cls = (Class)iter.next(); + DictionaryEntry newDictionaryEntry = buildDictionaryEntryForClass(cls, lastDictionaryEntry); + synchronized (this) { + final DictionaryEntry concurrentEntry = getDictionaryEntry(cls); + if (concurrentEntry == null) { + dictionaryEntries.put(cls, newDictionaryEntry); + } else { + newDictionaryEntry = concurrentEntry; } - Map lastKeyedByFieldName = Collections.emptyMap(); - Map lastKeyedByFieldKey = Collections.emptyMap(); - for (final Class element : superClasses) { - cls = element; - if (!keyedByFieldNameCache.containsKey(cls)) { - final Map keyedByFieldName = new HashMap(lastKeyedByFieldName); - final Map keyedByFieldKey = new LinkedHashMap( - lastKeyedByFieldKey); - final Field[] fields = cls.getDeclaredFields(); - if (JVM.reverseFieldDefinition()) { - for (int i = fields.length >> 1; i-- > 0;) { - final int idx = fields.length - i - 1; - final Field field = fields[i]; - fields[i] = fields[idx]; - fields[idx] = field; - } - } - for (int i = 0; i < fields.length; i++) { - final Field field = fields[i]; - if (!field.isAccessible()) { - field.setAccessible(true); - } - final FieldKey fieldKey = new FieldKey(field.getName(), field.getDeclaringClass(), i); - final Field existent = keyedByFieldName.get(field.getName()); - if (existent == null - // do overwrite statics - || (existent.getModifiers() & Modifier.STATIC) != 0 - // overwrite non-statics with non-statics only - || existent != null - && (field.getModifiers() & Modifier.STATIC) == 0) { - keyedByFieldName.put(field.getName(), field); - } - keyedByFieldKey.put(fieldKey, field); - } - final Map sortedFieldKeys = sorter.sort(cls, keyedByFieldKey); - keyedByFieldNameCache.put(cls, keyedByFieldName); - keyedByFieldKeyCache.put(cls, sortedFieldKeys); - lastKeyedByFieldName = keyedByFieldName; - lastKeyedByFieldKey = sortedFieldKeys; - } else { - lastKeyedByFieldName = keyedByFieldNameCache.get(cls); - lastKeyedByFieldKey = keyedByFieldKeyCache.get(cls); - } - } - return tupleKeyed ? lastKeyedByFieldKey : lastKeyedByFieldName; } + lastDictionaryEntry = newDictionaryEntry; } - return tupleKeyed ? keyedByFieldKeyCache.get(type) : keyedByFieldNameCache.get(type); + + return tupleKeyed ? lastDictionaryEntry.getKeyedByFieldKey() : lastDictionaryEntry.getKeyedByFieldName(); + } - @Override + private DictionaryEntry buildDictionaryEntryForClass(final Class cls, final DictionaryEntry lastDictionaryEntry) { + final Map keyedByFieldName = new HashMap(lastDictionaryEntry.getKeyedByFieldName()); + final Map keyedByFieldKey = new OrderRetainingMap(lastDictionaryEntry.getKeyedByFieldKey()); + final Field[] fields = cls.getDeclaredFields(); + if (JVM.reverseFieldDefinition()) { + for (int i = fields.length >> 1; i-- > 0;) { + final int idx = fields.length - i - 1; + final Field field = fields[i]; + fields[i] = fields[idx]; + fields[idx] = field; + } + } + for (int i = 0; i < fields.length; i++) { + final Field field = fields[i]; + if (!field.isAccessible()) { + field.setAccessible(true); + } + final FieldKey fieldKey = new FieldKey(field.getName(), field.getDeclaringClass(), i); + final Field existent = (Field)keyedByFieldName.get(field.getName()); + if (existent == null + // do overwrite statics + || (existent.getModifiers() & Modifier.STATIC) != 0 + // overwrite non-statics with non-statics only + || (existent != null && (field.getModifiers() & Modifier.STATIC) == 0)) { + keyedByFieldName.put(field.getName(), field); + } + keyedByFieldKey.put(fieldKey, field); + } + final Map sortedFieldKeys = sorter.sort(cls, keyedByFieldKey); + return new DictionaryEntry(keyedByFieldName, sortedFieldKeys); + } + + private synchronized DictionaryEntry getDictionaryEntry(final Class cls) { + return (DictionaryEntry)dictionaryEntries.get(cls); + } + public synchronized void flushCache() { - final Set> objectTypeSet = Collections.>singleton(Object.class); - keyedByFieldNameCache.keySet().retainAll(objectTypeSet); - keyedByFieldKeyCache.keySet().retainAll(objectTypeSet); + dictionaryEntries.clear(); if (sorter instanceof Caching) { ((Caching)sorter).flushCache(); } @@ -175,4 +193,24 @@ init(); return this; } + + private static final class DictionaryEntry { + + private final Map keyedByFieldName; + private final Map keyedByFieldKey; + + public DictionaryEntry(final Map keyedByFieldName, final Map keyedByFieldKey) { + super(); + this.keyedByFieldName = keyedByFieldName; + this.keyedByFieldKey = keyedByFieldKey; + } + + public Map getKeyedByFieldName() { + return keyedByFieldName; + } + + public Map getKeyedByFieldKey() { + return keyedByFieldKey; + } + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/FieldKey.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/FieldKey.java (.../FieldKey.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/FieldKey.java (.../FieldKey.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2014 XStream Committers. + * Copyright (C) 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -18,18 +18,18 @@ */ public class FieldKey { final private String fieldName; - final private Class declaringClass; + final private Class declaringClass; final private int depth; final private int order; - public FieldKey(final String fieldName, final Class declaringClass, final int order) { + public FieldKey(String fieldName, Class declaringClass, int order) { if (fieldName == null || declaringClass == null) { throw new IllegalArgumentException("fieldName or declaringClass is null"); } this.fieldName = fieldName; this.declaringClass = declaringClass; this.order = order; - Class c = declaringClass; + Class c = declaringClass; int i = 0; while (c.getSuperclass() != null) { i++; @@ -39,51 +39,42 @@ } public String getFieldName() { - return fieldName; + return this.fieldName; } - public Class getDeclaringClass() { - return declaringClass; + public Class getDeclaringClass() { + return this.declaringClass; } public int getDepth() { - return depth; + return this.depth; } public int getOrder() { - return order; + return this.order; } - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (!(o instanceof FieldKey)) { - return false; - } + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof FieldKey)) return false; final FieldKey fieldKey = (FieldKey)o; - if (!declaringClass.equals(fieldKey.declaringClass)) { + if (!declaringClass.equals(fieldKey.declaringClass)) return false; - } - if (!fieldName.equals(fieldKey.fieldName)) { + if (!fieldName.equals(fieldKey.fieldName)) return false; - } return true; } - @Override public int hashCode() { int result; result = fieldName.hashCode(); - result = 29 * result + declaringClass.hashCode(); + result = 29 * result +declaringClass.hashCode(); return result; } - @Override public String toString() { return "FieldKey{" + "order=" @@ -98,4 +89,4 @@ + "}"; } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/FieldKeySorter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/FieldKeySorter.java (.../FieldKeySorter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/FieldKeySorter.java (.../FieldKeySorter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2014 XStream Committers. + * Copyright (C) 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,36 +10,31 @@ */ package com.thoughtworks.xstream.converters.reflection; -import java.lang.reflect.Field; import java.util.Map; /** - * An interface capable of sorting fields. - *

      - * Implement this interface if you want to customize the field order in which XStream serializes objects. - *

      + * An interface capable of sorting fields. Implement this interface if you want to customize the + * field order in which XStream serializes objects. * * @author Guilherme Silveira * @since 1.2.2 */ public interface FieldKeySorter { /** - * Sort the fields of a type. - *

      - * The method will be called with the class type that contains all the fields and a Map that retains the order in - * which the elements have been added. The sequence in which elements are returned by an iterator defines the - * processing order of the fields. An implementation may create a different Map with similar semantic, add all - * elements of the original map and return the new one. - *

      + * Sort the fields of a type. The method will be called with the class type that contains + * all the fields and a Map that retains the order in which the elements have been added. + * The sequence in which elements are returned by an iterator defines the processing order + * of the fields. An implementation may create a different Map with similar semantic, add + * all elements of the original map and return the new one. * * @param type the class that contains all the fields - * @param keyedByFieldKey a Map containing a {@link FieldKey} as key element and a {@link java.lang.reflect.Field} - * as value. + * @param keyedByFieldKey a Map containing a {@link FieldKey} as key element and a + * {@link java.lang.reflect.Field} as value. * @return a Map with all the entries of the original Map * @since 1.2.2 */ - Map sort(Class type, Map keyedByFieldKey); + Map sort(Class type, Map keyedByFieldKey); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ImmutableFieldKeySorter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ImmutableFieldKeySorter.java (.../ImmutableFieldKeySorter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ImmutableFieldKeySorter.java (.../ImmutableFieldKeySorter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2014 XStream Committers. + * Copyright (C) 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,21 +10,18 @@ */ package com.thoughtworks.xstream.converters.reflection; -import java.lang.reflect.Field; import java.util.Map; - /** * Does not change the order of the fields. - * + * * @author Guilherme Silveira * @since 1.2.2 */ public class ImmutableFieldKeySorter implements FieldKeySorter { - @Override - public Map sort(final Class type, final Map keyedByFieldKey) { - return keyedByFieldKey; - } + public Map sort(Class type, Map keyedByFieldKey) { + return keyedByFieldKey; + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/LambdaConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/LambdaConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/LambdaConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2015 XStream Committer. + * All rights reserved. + * + * Created on 17. January 2015 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.reflection; + +import java.io.Serializable; + +import com.thoughtworks.xstream.converters.MarshallingContext; +import com.thoughtworks.xstream.core.ClassLoaderReference; +import com.thoughtworks.xstream.core.JVM; +import com.thoughtworks.xstream.core.util.Types; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.mapper.Mapper; + + +/** + * Converts a lambda type. + * + * The implementation maps any non-serializable lambda instance to {@code null}. + * + * @author Jörg Schaible + * @since 1.4.8 + */ +public class LambdaConverter extends SerializableConverter { + + /** + * Constructs a LambdaConverter. + * + * @param mapper + * @param reflectionProvider + * @param classLoaderReference + * @since 1.4.8 + */ + public LambdaConverter( + final Mapper mapper, final ReflectionProvider reflectionProvider, + final ClassLoaderReference classLoaderReference) { + super(mapper, reflectionProvider, classLoaderReference); + } + + @Override + public boolean canConvert(final Class type) { + return Types.isLambdaType(type) + && (JVM.canCreateDerivedObjectOutputStream() || !Serializable.class.isAssignableFrom(type)); + } + + @Override + public void marshal(final Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) { + if (original instanceof Serializable) { + super.marshal(original, writer, context); + } + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/MissingFieldException.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/MissingFieldException.java (.../MissingFieldException.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/MissingFieldException.java (.../MissingFieldException.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 XStream Committers. + * Copyright (C) 2011, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -29,9 +29,10 @@ * @since 1.4.2 */ public MissingFieldException(final String className, final String fieldName) { - super("No field '" + fieldName + "' found in class '" + className + "'"); + super("Field not found in class."); this.className = className; this.fieldName = fieldName; + add("field", className + "." + fieldName); } /** Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/NativeFieldKeySorter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/NativeFieldKeySorter.java (.../NativeFieldKeySorter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/NativeFieldKeySorter.java (.../NativeFieldKeySorter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2014 XStream Committers. + * Copyright (C) 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,26 +10,26 @@ */ package com.thoughtworks.xstream.converters.reflection; -import java.lang.reflect.Field; import java.util.Comparator; import java.util.Map; import java.util.TreeMap; /** - * Sort the fields in their natural order. Fields are returned in their declaration order, fields of base classes first. + * Sort the fields in their natural order. Fields are returned in their declaration order, + * fields of base classes first. * * @author Jörg Schaible * @since 1.2.2 */ public class NativeFieldKeySorter implements FieldKeySorter { - @Override - public Map sort(final Class type, final Map keyedByFieldKey) { - final Map map = new TreeMap(new Comparator() { + public Map sort(final Class type, final Map keyedByFieldKey) { + final Map map = new TreeMap(new Comparator() { - @Override - public int compare(final FieldKey fieldKey1, final FieldKey fieldKey2) { + public int compare(final Object o1, final Object o2) { + final FieldKey fieldKey1 = (FieldKey)o1; + final FieldKey fieldKey2 = (FieldKey)o2; int i = fieldKey1.getDepth() - fieldKey2.getDepth(); if (i == 0) { i = fieldKey1.getOrder() - fieldKey2.getOrder(); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ObjectAccessException.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ObjectAccessException.java (.../ObjectAccessException.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ObjectAccessException.java (.../ObjectAccessException.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007 XStream Committers. + * Copyright (C) 2006, 2007, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,9 +11,9 @@ */ package com.thoughtworks.xstream.converters.reflection; -import com.thoughtworks.xstream.XStreamException; +import com.thoughtworks.xstream.converters.ErrorWritingException; -public class ObjectAccessException extends XStreamException { +public class ObjectAccessException extends ErrorWritingException { public ObjectAccessException(String message) { super(message); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/PureJavaReflectionProvider.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/PureJavaReflectionProvider.java (.../PureJavaReflectionProvider.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/PureJavaReflectionProvider.java (.../PureJavaReflectionProvider.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011, 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,6 +11,9 @@ */ package com.thoughtworks.xstream.converters.reflection; +import com.thoughtworks.xstream.core.JVM; +import com.thoughtworks.xstream.core.util.Fields; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -23,44 +26,43 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; -import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.WeakHashMap; - /** - * Pure Java ObjectFactory that instantiates objects using standard Java reflection, however the types of objects that - * can be constructed are limited. + * Pure Java ObjectFactory that instantiates objects using standard Java reflection, however the types of objects + * that can be constructed are limited. *

      - * Can newInstance: classes with public visibility, outer classes, static inner classes, classes with default - * constructors and any class that implements java.io.Serializable. + * Can newInstance: classes with public visibility, outer classes, static inner classes, classes with default constructors + * and any class that implements java.io.Serializable. *

      *

      - * Cannot newInstance: classes without public visibility, non-static inner classes, classes without default - * constructors. Note that any code in the constructor of a class will be executed when the ObjectFactory instantiates - * the object. + * Cannot newInstance: classes without public visibility, non-static inner classes, classes without default constructors. + * Note that any code in the constructor of a class will be executed when the ObjectFactory instantiates the object. *

      - * * @author Joe Walnes */ public class PureJavaReflectionProvider implements ReflectionProvider { - private transient Map, byte[]> serializedDataCache; + private transient Map serializedDataCache; protected FieldDictionary fieldDictionary; public PureJavaReflectionProvider() { this(new FieldDictionary(new ImmutableFieldKeySorter())); } - public PureJavaReflectionProvider(final FieldDictionary fieldDictionary) { + public PureJavaReflectionProvider(FieldDictionary fieldDictionary) { this.fieldDictionary = fieldDictionary; init(); } - @Override - public Object newInstance(final Class type) { + public Object newInstance(Class type) { + ObjectAccessException oaex = null; try { - for (final Constructor constructor : type.getDeclaredConstructors()) { + Constructor[] constructors = type.getDeclaredConstructors(); + for (int i = 0; i < constructors.length; i++) { + final Constructor constructor = constructors[i]; if (constructor.getParameterTypes().length == 0) { if (!constructor.isAccessible()) { constructor.setAccessible(true); @@ -71,134 +73,122 @@ if (Serializable.class.isAssignableFrom(type)) { return instantiateUsingSerialization(type); } else { - throw new ObjectAccessException("Cannot construct " - + type.getName() - + " as it does not have a no-args constructor"); + oaex = new ObjectAccessException("Cannot construct type as it does not have a no-args constructor"); } - } catch (final InstantiationException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); - } catch (final InvocationTargetException e) { + } catch (InstantiationException e) { + oaex = new ObjectAccessException("Cannot construct type", e); + } catch (IllegalAccessException e) { + oaex = new ObjectAccessException("Cannot construct type", e); + } catch (InvocationTargetException e) { if (e.getTargetException() instanceof RuntimeException) { throw (RuntimeException)e.getTargetException(); } else if (e.getTargetException() instanceof Error) { throw (Error)e.getTargetException(); } else { - throw new ObjectAccessException("Constructor for " + type.getName() + " threw an exception", e - .getTargetException()); + oaex = new ObjectAccessException("Constructor for type threw an exception", e.getTargetException()); } } + oaex.add("construction-type", type.getName()); + throw oaex; } - private Object instantiateUsingSerialization(final Class type) { + private Object instantiateUsingSerialization(final Class type) { + ObjectAccessException oaex = null; try { synchronized (serializedDataCache) { - byte[] data = serializedDataCache.get(type); - if (data == null) { - final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - final DataOutputStream stream = new DataOutputStream(bytes); + byte[] data = (byte[]) serializedDataCache.get(type); + if (data == null) { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + DataOutputStream stream = new DataOutputStream(bytes); stream.writeShort(ObjectStreamConstants.STREAM_MAGIC); stream.writeShort(ObjectStreamConstants.STREAM_VERSION); stream.writeByte(ObjectStreamConstants.TC_OBJECT); stream.writeByte(ObjectStreamConstants.TC_CLASSDESC); stream.writeUTF(type.getName()); stream.writeLong(ObjectStreamClass.lookup(type).getSerialVersionUID()); - stream.writeByte(2); // classDescFlags (2 = Serializable) + stream.writeByte(2); // classDescFlags (2 = Serializable) stream.writeShort(0); // field count stream.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA); stream.writeByte(ObjectStreamConstants.TC_NULL); data = bytes.toByteArray(); serializedDataCache.put(type, data); } - - final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)) { - @Override - protected Class resolveClass(final ObjectStreamClass desc) throws ClassNotFoundException { + + ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)) { + protected Class resolveClass(ObjectStreamClass desc) + throws IOException, ClassNotFoundException { return Class.forName(desc.getName(), false, type.getClassLoader()); } }; return in.readObject(); } - } catch (final IOException e) { - throw new ObjectAccessException("Cannot create " + type.getName() + " by JDK serialization", e); - } catch (final ClassNotFoundException e) { - throw new ObjectAccessException("Cannot find class " + e.getMessage(), e); + } catch (IOException e) { + oaex = new ObjectAccessException("Cannot create type by JDK serialization", e); + } catch (ClassNotFoundException e) { + oaex = new ObjectAccessException("Cannot find class", e); } + oaex.add("construction-type", type.getName()); + throw oaex; } - @Override - public void visitSerializableFields(final Object object, final ReflectionProvider.Visitor visitor) { - for (final Iterator iterator = fieldDictionary.fieldsFor(object.getClass()); iterator.hasNext();) { - final Field field = iterator.next(); + public void visitSerializableFields(Object object, ReflectionProvider.Visitor visitor) { + for (Iterator iterator = fieldDictionary.fieldsFor(object.getClass()); iterator.hasNext();) { + Field field = (Field) iterator.next(); if (!fieldModifiersSupported(field)) { continue; } validateFieldAccess(field); - try { - final Object value = field.get(object); - visitor.visit(field.getName(), field.getType(), field.getDeclaringClass(), value); - } catch (final IllegalArgumentException e) { - throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e); - } + Object value = Fields.read(field, object); + visitor.visit(field.getName(), field.getType(), field.getDeclaringClass(), value); } } - @Override - public void writeField(final Object object, final String fieldName, final Object value, final Class definedIn) { - final Field field = fieldDictionary.field(object.getClass(), fieldName, definedIn); + public void writeField(Object object, String fieldName, Object value, Class definedIn) { + Field field = fieldDictionary.field(object.getClass(), fieldName, definedIn); validateFieldAccess(field); - try { - field.set(object, value); - } catch (final IllegalArgumentException e) { - throw new ObjectAccessException("Could not set field " + object.getClass() + "." + field.getName(), e); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Could not set field " + object.getClass() + "." + field.getName(), e); - } + Fields.write(field, object, value); } - @Override - public Class getFieldType(final Object object, final String fieldName, final Class definedIn) { + public Class getFieldType(Object object, String fieldName, Class definedIn) { return fieldDictionary.field(object.getClass(), fieldName, definedIn).getType(); } /** * @deprecated As of 1.4.5, use {@link #getFieldOrNull(Class, String)} instead */ - @Deprecated - @Override - public boolean fieldDefinedInClass(final String fieldName, final Class type) { - final Field field = fieldDictionary.fieldOrNull(type, fieldName, null); + public boolean fieldDefinedInClass(String fieldName, Class type) { + Field field = fieldDictionary.fieldOrNull(type, fieldName, null); return field != null && fieldModifiersSupported(field); } - protected boolean fieldModifiersSupported(final Field field) { - final int modifiers = field.getModifiers(); + protected boolean fieldModifiersSupported(Field field) { + int modifiers = field.getModifiers(); return !(Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)); } - protected void validateFieldAccess(final Field field) { + protected void validateFieldAccess(Field field) { if (Modifier.isFinal(field.getModifiers())) { - if (!field.isAccessible()) { - field.setAccessible(true); + if (JVM.is15()) { + if (!field.isAccessible()) { + field.setAccessible(true); + } + } else { + throw new ObjectAccessException("Invalid final field " + + field.getDeclaringClass().getName() + "." + field.getName()); } } } - @Override - public Field getField(final Class definedIn, final String fieldName) { + public Field getField(Class definedIn, String fieldName) { return fieldDictionary.field(definedIn, fieldName, null); } - @Override - public Field getFieldOrNull(final Class definedIn, final String fieldName) { - return fieldDictionary.fieldOrNull(definedIn, fieldName, null); + public Field getFieldOrNull(Class definedIn, String fieldName) { + return fieldDictionary.fieldOrNull(definedIn, fieldName, null); } - public void setFieldDictionary(final FieldDictionary dictionary) { - fieldDictionary = dictionary; + public void setFieldDictionary(FieldDictionary dictionary) { + this.fieldDictionary = dictionary; } private Object readResolve() { @@ -207,6 +197,6 @@ } protected void init() { - serializedDataCache = new HashMap, byte[]>(); + serializedDataCache = new WeakHashMap(); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ReflectionConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ReflectionConverter.java (.../ReflectionConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ReflectionConverter.java (.../ReflectionConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013, 2014, 2017 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,17 +11,13 @@ */ package com.thoughtworks.xstream.converters.reflection; -import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.mapper.Mapper; - public class ReflectionConverter extends AbstractReflectionConverter { - // Might be missing in Android - private final static Class eventHandlerType = JVM.loadClassForName("java.beans.EventHandler"); - private Class type; + private Class type; - public ReflectionConverter(final Mapper mapper, final ReflectionProvider reflectionProvider) { + public ReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider) { super(mapper, reflectionProvider); } @@ -33,14 +29,12 @@ * @param type the explicit type to handle * @since 1.4.7 */ - public ReflectionConverter(final Mapper mapper, final ReflectionProvider reflectionProvider, final Class type) { + public ReflectionConverter(Mapper mapper, ReflectionProvider reflectionProvider, Class type) { this(mapper, reflectionProvider); this.type = type; } - @Override - public boolean canConvert(final Class type) { - return (this.type != null && this.type == type || this.type == null && type != null && type != eventHandlerType) - && canAccess(type); + public boolean canConvert(Class type) { + return (this.type != null && this.type == type || this.type == null && type != null) && canAccess(type); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ReflectionProvider.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ReflectionProvider.java (.../ReflectionProvider.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ReflectionProvider.java (.../ReflectionProvider.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -22,25 +22,24 @@ public interface ReflectionProvider { /** - * Creates a new instance of the specified type. It is in the responsibility of the implementation how such an - * instance is created. + * Creates a new instance of the specified type. It is in the responsibility of the + * implementation how such an instance is created. * * @param type the type to instantiate * @return a new instance of this type */ - Object newInstance(Class type); + Object newInstance(Class type); void visitSerializableFields(Object object, Visitor visitor); - void writeField(Object object, String fieldName, Object value, Class definedIn); + void writeField(Object object, String fieldName, Object value, Class definedIn); - Class getFieldType(Object object, String fieldName, Class definedIn); + Class getFieldType(Object object, String fieldName, Class definedIn); /** * @deprecated As of 1.4.5, use {@link #getFieldOrNull(Class, String)} instead */ - @Deprecated - boolean fieldDefinedInClass(String fieldName, Class type); + boolean fieldDefinedInClass(String fieldName, Class type); /** * A visitor interface for serializable fields defined in a class. @@ -55,7 +54,7 @@ * @param definedIn where the field was defined * @param value field value */ - void visit(String name, Class type, Class definedIn, Object value); + void visit(String name, Class type, Class definedIn, Object value); } /** @@ -66,7 +65,7 @@ * @return the field itself * @throws ObjectAccessException if field does not exist */ - Field getField(Class definedIn, String fieldName); + Field getField(Class definedIn, String fieldName); /** * Returns a field defined in some class. @@ -76,5 +75,5 @@ * @return the field itself or null * @since 1.4.5 */ - Field getFieldOrNull(Class definedIn, String fieldName); + Field getFieldOrNull(Class definedIn, String fieldName); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ReflectionProviderWrapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ReflectionProviderWrapper.java (.../ReflectionProviderWrapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/ReflectionProviderWrapper.java (.../ReflectionProviderWrapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,58 +12,49 @@ import java.lang.reflect.Field; - /** * A wrapper implementation for the ReflectionProvider. - * + * * @author Jörg Schaible * @since 1.2 */ public class ReflectionProviderWrapper implements ReflectionProvider { final protected ReflectionProvider wrapped; - public ReflectionProviderWrapper(final ReflectionProvider wrapper) { - wrapped = wrapper; + public ReflectionProviderWrapper(ReflectionProvider wrapper) { + this.wrapped = wrapper; } /** * @deprecated As of 1.4.5, use {@link #getFieldOrNull(Class, String)} instead */ - @Deprecated - @Override - public boolean fieldDefinedInClass(final String fieldName, final Class type) { - return wrapped.fieldDefinedInClass(fieldName, type); + public boolean fieldDefinedInClass(String fieldName, Class type) { + return this.wrapped.fieldDefinedInClass(fieldName, type); } - @Override - public Field getField(final Class definedIn, final String fieldName) { - return wrapped.getField(definedIn, fieldName); + public Field getField(Class definedIn, String fieldName) { + return this.wrapped.getField(definedIn, fieldName); } - @Override - public Field getFieldOrNull(final Class definedIn, final String fieldName) { - return wrapped.getFieldOrNull(definedIn, fieldName); + public Field getFieldOrNull(Class definedIn, String fieldName) { + return this.wrapped.getFieldOrNull(definedIn, fieldName); } - @Override - public Class getFieldType(final Object object, final String fieldName, final Class definedIn) { - return wrapped.getFieldType(object, fieldName, definedIn); + public Class getFieldType(Object object, String fieldName, Class definedIn) { + return this.wrapped.getFieldType(object, fieldName, definedIn); } - @Override - public Object newInstance(final Class type) { - return wrapped.newInstance(type); + public Object newInstance(Class type) { + return this.wrapped.newInstance(type); } - @Override - public void visitSerializableFields(final Object object, final Visitor visitor) { - wrapped.visitSerializableFields(object, visitor); + public void visitSerializableFields(Object object, Visitor visitor) { + this.wrapped.visitSerializableFields(object, visitor); } - @Override - public void writeField(final Object object, final String fieldName, final Object value, final Class definedIn) { - wrapped.writeField(object, fieldName, value, definedIn); + public void writeField(Object object, String fieldName, Object value, Class definedIn) { + this.wrapped.writeField(object, fieldName, value, definedIn); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SelfStreamingInstanceChecker.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SelfStreamingInstanceChecker.java (.../SelfStreamingInstanceChecker.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SelfStreamingInstanceChecker.java (.../SelfStreamingInstanceChecker.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -12,19 +12,18 @@ import com.thoughtworks.xstream.converters.Converter; - /** - * A special converter that prevents self-serialization. The serializing XStream instance adds a converter of this type - * to prevent self-serialization and will throw an exception instead. + * A special converter that prevents self-serialization. The serializing XStream instance + * adds a converter of this type to prevent self-serialization and will throw an + * exception instead. * * @author Jörg Schaible * @since 1.2 * @deprecated As of 1.4.5 use {@link com.thoughtworks.xstream.core.util.SelfStreamingInstanceChecker} */ -@Deprecated public class SelfStreamingInstanceChecker extends com.thoughtworks.xstream.core.util.SelfStreamingInstanceChecker { - public SelfStreamingInstanceChecker(final Converter defaultConverter, final Object xstream) { + public SelfStreamingInstanceChecker(Converter defaultConverter, Object xstream) { super(defaultConverter, xstream); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SerializableConverter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SerializableConverter.java (.../SerializableConverter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SerializableConverter.java (.../SerializableConverter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013, 2014, 2015, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -31,28 +32,28 @@ import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.core.util.CustomObjectInputStream; import com.thoughtworks.xstream.core.util.CustomObjectOutputStream; +import com.thoughtworks.xstream.core.util.Fields; import com.thoughtworks.xstream.core.util.HierarchicalStreams; import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.mapper.Mapper; - /** * Emulates the mechanism used by standard Java Serialization for classes that implement java.io.Serializable AND - * implement or inherit a custom readObject()/writeObject() method.

      Supported features of serialization

      + * implement or inherit a custom readObject()/writeObject() method. + * + *

      Supported features of serialization

      *
        - *
      • readObject(), writeObject()
      • - *
      • class inheritance
      • - *
      • readResolve(), writeReplace()
      • + *
      • readObject(), writeObject()
      • + *
      • class inheritance
      • + *
      • readResolve(), writeReplace()
      • + *
      • getFields(), putFields(), writeFields(), readFields()
      • + *
      • ObjectStreamField[] serialPersistentFields
      • + *
      • ObjectInputValidation
      • *
      - *

      Currently unsupported features

      - *
        - *
      • putFields(), writeFields(), readFields()
      • - *
      • ObjectStreamField[] serialPersistentFields
      • - *
      • ObjectInputValidation
      • - *
      - * + * * @author Joe Walnes * @author Jörg Schaible */ @@ -67,54 +68,48 @@ private static final String ELEMENT_FIELDS = "fields"; private static final String ELEMENT_FIELD = "field"; private static final String ATTRIBUTE_NAME = "name"; - + private final ClassLoaderReference classLoaderReference; /** * Construct a SerializableConverter. - * + * * @param mapper the mapper chain instance * @param reflectionProvider the reflection provider * @param classLoaderReference the reference to the {@link ClassLoader} of the XStream instance * @since 1.4.5 */ - public SerializableConverter( - final Mapper mapper, final ReflectionProvider reflectionProvider, - final ClassLoaderReference classLoaderReference) { + public SerializableConverter(Mapper mapper, ReflectionProvider reflectionProvider, ClassLoaderReference classLoaderReference) { super(mapper, new UnserializableParentsReflectionProvider(reflectionProvider)); this.classLoaderReference = classLoaderReference; } /** * @deprecated As of 1.4.5 use {@link #SerializableConverter(Mapper, ReflectionProvider, ClassLoaderReference)} */ - @Deprecated - public SerializableConverter( - final Mapper mapper, final ReflectionProvider reflectionProvider, final ClassLoader classLoader) { + public SerializableConverter(Mapper mapper, ReflectionProvider reflectionProvider, ClassLoader classLoader) { this(mapper, reflectionProvider, new ClassLoaderReference(classLoader)); } /** * @deprecated As of 1.4 use {@link #SerializableConverter(Mapper, ReflectionProvider, ClassLoaderReference)} */ - @Deprecated - public SerializableConverter(final Mapper mapper, final ReflectionProvider reflectionProvider) { + public SerializableConverter(Mapper mapper, ReflectionProvider reflectionProvider) { this(mapper, new UnserializableParentsReflectionProvider(reflectionProvider), new ClassLoaderReference(null)); } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return JVM.canCreateDerivedObjectOutputStream() && isSerializable(type); } - private boolean isSerializable(final Class type) { + private boolean isSerializable(Class type) { if (type != null && Serializable.class.isAssignableFrom(type) && !type.isInterface() - && (serializationMethodInvoker.supportsReadObject(type, true) || serializationMethodInvoker - .supportsWriteObject(type, true))) { - for (final Class clazz : hierarchyFor(type)) { - if (!Serializable.class.isAssignableFrom(clazz)) { + && (serializationMembers.supportsReadObject(type, true) || serializationMembers.supportsWriteObject(type, + true))) { + for (Iterator iter = hierarchyFor(type).iterator(); iter.hasNext();) { + if (!Serializable.class.isAssignableFrom((Class)iter.next())) { return canAccess(type); } } @@ -123,56 +118,49 @@ return false; } - @Override public void doMarshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { - final String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_SERIALIZATION); + String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_SERIALIZATION); if (attributeName != null) { writer.addAttribute(attributeName, ATTRIBUTE_VALUE_CUSTOM); } // this is an array as it's a non final value that's accessed from an anonymous inner class. - final Class[] currentTypeRef = new Class[1]; + final Class[] currentType = new Class[1]; final boolean[] writtenClassWrapper = {false}; - final CustomObjectOutputStream.StreamCallback callback = new CustomObjectOutputStream.StreamCallback() { + CustomObjectOutputStream.StreamCallback callback = new CustomObjectOutputStream.StreamCallback() { - @Override - public void writeToStream(final Object object) { + public void writeToStream(Object object) { if (object == null) { writer.startNode(ELEMENT_NULL); writer.endNode(); } else { - ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object.getClass()), - object.getClass()); + ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object.getClass()), object.getClass()); context.convertAnother(object); writer.endNode(); } } - @Override - public void writeFieldsToStream(final Map fields) { - final Class currentType = currentTypeRef[0]; - final ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType); + public void writeFieldsToStream(Map fields) { + ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]); writer.startNode(ELEMENT_DEFAULT); - for (final String name : fields.keySet()) { - if (!mapper.shouldSerializeMember(currentType, name)) { + for (Iterator iterator = fields.keySet().iterator(); iterator.hasNext();) { + String name = (String) iterator.next(); + if (!mapper.shouldSerializeMember(currentType[0], name)) { continue; } - final ObjectStreamField field = objectStreamClass.getField(name); - final Object value = fields.get(name); + ObjectStreamField field = objectStreamClass.getField(name); + Object value = fields.get(name); if (field == null) { - throw new ObjectAccessException("Class " - + value.getClass().getName() - + " may not write a field named '" - + name - + "'"); + throw new MissingFieldException(value.getClass().getName(), name); } if (value != null) { - ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(source - .getClass(), name), value.getClass()); + ExtendedHierarchicalStreamWriterHelper.startNode( + writer, mapper.serializedMember(source.getClass(), name), + value.getClass()); if (field.getType() != value.getClass() && !field.getType().isPrimitive()) { - final String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); + String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(value.getClass())); } @@ -184,37 +172,38 @@ writer.endNode(); } - @Override public void defaultWriteObject() { boolean writtenDefaultFields = false; - final Class currentType = currentTypeRef[0]; - final ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType); + ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]); + if (objectStreamClass == null) { return; } - for (final ObjectStreamField field : objectStreamClass.getFields()) { - final Object value = readField(field, currentType, source); + ObjectStreamField[] fields = objectStreamClass.getFields(); + for (int i = 0; i < fields.length; i++) { + ObjectStreamField field = fields[i]; + Object value = readField(field, currentType[0], source); if (value != null) { if (!writtenClassWrapper[0]) { - writer.startNode(mapper.serializedClass(currentType)); + writer.startNode(mapper.serializedClass(currentType[0])); writtenClassWrapper[0] = true; } if (!writtenDefaultFields) { writer.startNode(ELEMENT_DEFAULT); writtenDefaultFields = true; } - if (!mapper.shouldSerializeMember(currentType, field.getName())) { + if (!mapper.shouldSerializeMember(currentType[0], field.getName())) { continue; } - final Class actualType = value.getClass(); - ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(source - .getClass(), field.getName()), actualType); - final Class defaultType = mapper.defaultImplementationOf(field.getType()); + Class actualType = value.getClass(); + ExtendedHierarchicalStreamWriterHelper.startNode( + writer, mapper.serializedMember(source.getClass(), field.getName()), actualType); + Class defaultType = mapper.defaultImplementationOf(field.getType()); if (!actualType.equals(defaultType)) { - final String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); + String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(actualType)); } @@ -233,55 +222,51 @@ } } - @Override public void flush() { writer.flush(); } - @Override public void close() { - throw new UnsupportedOperationException( - "Objects are not allowed to call ObjectOutputStream.close() from writeObject()"); + throw new UnsupportedOperationException("Objects are not allowed to call ObjectOutputStream.close() from writeObject()"); } }; try { boolean mustHandleUnserializableParent = false; - for (final Class currentType : hierarchyFor(source.getClass())) { - currentTypeRef[0] = currentType; - if (!Serializable.class.isAssignableFrom(currentType)) { + Iterator classHieararchy = hierarchyFor(source.getClass()).iterator(); + while (classHieararchy.hasNext()) { + currentType[0] = (Class) classHieararchy.next(); + if (!Serializable.class.isAssignableFrom(currentType[0])) { mustHandleUnserializableParent = true; continue; } else { if (mustHandleUnserializableParent) { marshalUnserializableParent(writer, context, source); mustHandleUnserializableParent = false; } - if (serializationMethodInvoker.supportsWriteObject(currentType, false)) { + if (serializationMembers.supportsWriteObject(currentType[0], false)) { writtenClassWrapper[0] = true; - writer.startNode(mapper.serializedClass(currentType)); - if (currentType != mapper.defaultImplementationOf(currentType)) { - final String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); + writer.startNode(mapper.serializedClass(currentType[0])); + if (currentType[0] != mapper.defaultImplementationOf(currentType[0])) { + String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); if (classAttributeName != null) { - writer.addAttribute(classAttributeName, currentType.getName()); + writer.addAttribute(classAttributeName, currentType[0].getName()); } } - @SuppressWarnings("resource") - final CustomObjectOutputStream objectOutputStream = CustomObjectOutputStream.getInstance( - context, callback); - serializationMethodInvoker.callWriteObject(currentType, source, objectOutputStream); + CustomObjectOutputStream objectOutputStream = CustomObjectOutputStream.getInstance(context, callback); + serializationMembers.callWriteObject(currentType[0], source, objectOutputStream); objectOutputStream.popCallback(); writer.endNode(); - } else if (serializationMethodInvoker.supportsReadObject(currentType, false)) { + } else if (serializationMembers.supportsReadObject(currentType[0], false)) { // Special case for objects that have readObject(), but not writeObject(). // The class wrapper is always written, whether or not this class in the hierarchy has // serializable fields. This guarantees that readObject() will be called upon deserialization. writtenClassWrapper[0] = true; - writer.startNode(mapper.serializedClass(currentType)); - if (currentType != mapper.defaultImplementationOf(currentType)) { - final String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); + writer.startNode(mapper.serializedClass(currentType[0])); + if (currentType[0] != mapper.defaultImplementationOf(currentType[0])) { + String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); if (classAttributeName != null) { - writer.addAttribute(classAttributeName, currentType.getName()); + writer.addAttribute(classAttributeName, currentType[0].getName()); } } callback.defaultWriteObject(); @@ -295,39 +280,25 @@ } } } - } catch (final IOException e) { - throw new ObjectAccessException("Could not call defaultWriteObject()", e); + } catch (IOException e) { + throw new StreamException("Cannot write defaults", e); } } - protected void marshalUnserializableParent(final HierarchicalStreamWriter writer, final MarshallingContext context, - final Object replacedSource) { + protected void marshalUnserializableParent(final HierarchicalStreamWriter writer, final MarshallingContext context, final Object replacedSource) { writer.startNode(ELEMENT_UNSERIALIZABLE_PARENTS); super.doMarshal(replacedSource, writer, context); writer.endNode(); } - private Object readField(final ObjectStreamField field, final Class type, final Object instance) { - try { - final Field javaField = type.getDeclaredField(field.getName()); - if (!javaField.isAccessible()) { - javaField.setAccessible(true); - } - return javaField.get(instance); - } catch (final IllegalArgumentException e) { - throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e); - } catch (final NoSuchFieldException e) { - throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e); - } catch (final SecurityException e) { - throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e); - } + private Object readField(ObjectStreamField field, Class type, Object instance) { + Field javaField = Fields.find(type, field.getName()); + return Fields.read(javaField, instance); } - protected List> hierarchyFor(Class type) { - final List> result = new ArrayList>(); - while (type != Object.class && type != null) { + protected List hierarchyFor(Class type) { + List result = new ArrayList(); + while(type != Object.class && type != null) { result.add(type); type = type.getSuperclass(); } @@ -338,84 +309,76 @@ return result; } - @Override - public Object doUnmarshal(final Object result, final HierarchicalStreamReader reader, - final UnmarshallingContext context) { + public Object doUnmarshal(final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context) { // this is an array as it's a non final value that's accessed from an anonymous inner class. - final Class[] currentType = new Class[1]; + final Class[] currentType = new Class[1]; - final String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_SERIALIZATION); + String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_SERIALIZATION); if (attributeName != null && !ATTRIBUTE_VALUE_CUSTOM.equals(reader.getAttribute(attributeName))) { throw new ConversionException("Cannot deserialize object with new readObject()/writeObject() methods"); } - final CustomObjectInputStream.StreamCallback callback = new CustomObjectInputStream.StreamCallback() { - @Override + CustomObjectInputStream.StreamCallback callback = new CustomObjectInputStream.StreamCallback() { public Object readFromStream() { reader.moveDown(); - final Class type = HierarchicalStreams.readClassType(reader, mapper); - final Object value = context.convertAnother(result, type); + Class type = HierarchicalStreams.readClassType(reader, mapper); + Object value = context.convertAnother(result, type); reader.moveUp(); return value; } - @Override - public Map readFieldsFromStream() { - final Map fields = new HashMap(); + public Map readFieldsFromStream() { + final Map fields = new HashMap(); reader.moveDown(); if (reader.getNodeName().equals(ELEMENT_FIELDS)) { // Maintain compatibility with XStream 1.1.0 while (reader.hasMoreChildren()) { reader.moveDown(); if (!reader.getNodeName().equals(ELEMENT_FIELD)) { - throw new ConversionException("Expected <" - + ELEMENT_FIELD - + "/> element inside <" - + ELEMENT_FIELD - + "/>"); + throw new ConversionException("Expected <" + ELEMENT_FIELD + "/> element inside <" + ELEMENT_FIELD + "/>"); } - final String name = reader.getAttribute(ATTRIBUTE_NAME); - final Class type = mapper.realClass(reader.getAttribute(ATTRIBUTE_CLASS)); - final Object value = context.convertAnother(result, type); + String name = reader.getAttribute(ATTRIBUTE_NAME); + Class type = mapper.realClass(reader.getAttribute(ATTRIBUTE_CLASS)); + Object value = context.convertAnother(result, type); fields.put(name, value); reader.moveUp(); } } else if (reader.getNodeName().equals(ELEMENT_DEFAULT)) { // New format introduced in XStream 1.1.1 - final ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]); + ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]); while (reader.hasMoreChildren()) { reader.moveDown(); - final String name = mapper.realMember(currentType[0], reader.getNodeName()); + String name = mapper.realMember(currentType[0], reader.getNodeName()); if (mapper.shouldSerializeMember(currentType[0], name)) { - final String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); - Class type; + String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); + Class type; if (classAttribute != null) { type = mapper.realClass(classAttribute); } else { - final ObjectStreamField field = objectStreamClass.getField(name); + ObjectStreamField field = objectStreamClass.getField(name); if (field == null) { throw new MissingFieldException(currentType[0].getName(), name); } type = field.getType(); } - final Object value = context.convertAnother(result, type); + Object value = context.convertAnother(result, type); fields.put(name, value); } reader.moveUp(); } } else { - throw new ConversionException("Expected <" - + ELEMENT_FIELDS - + "/> or <" - + ELEMENT_DEFAULT - + "/> element when calling ObjectInputStream.readFields()"); + throw new ConversionException("Expected <" + ELEMENT_FIELDS + "/> or <" + + ELEMENT_DEFAULT + "/> element when calling ObjectInputStream.readFields()"); } reader.moveUp(); return fields; } - @Override public void defaultReadObject() { + if (serializationMembers.getSerializablePersistentFields(currentType[0]) != null) { + readFieldsFromStream(); + return; + } if (!reader.hasMoreChildren()) { return; } @@ -426,18 +389,17 @@ while (reader.hasMoreChildren()) { reader.moveDown(); - final String fieldName = mapper.realMember(currentType[0], reader.getNodeName()); + String fieldName = mapper.realMember(currentType[0], reader.getNodeName()); if (mapper.shouldSerializeMember(currentType[0], fieldName)) { - final String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); - final Class type; + String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); + final Class type; if (classAttribute != null) { type = mapper.realClass(classAttribute); } else { - type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, - currentType[0])); + type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, currentType[0])); } - final Object value = context.convertAnother(result, type); + Object value = context.convertAnother(result, type); reflectionProvider.writeField(result, fieldName, value, currentType[0]); } @@ -446,50 +408,45 @@ reader.moveUp(); } - @Override - public void registerValidation(final ObjectInputValidation validation, final int priority) { + public void registerValidation(final ObjectInputValidation validation, int priority) { context.addCompletionCallback(new Runnable() { - @Override public void run() { try { validation.validateObject(); - } catch (final InvalidObjectException e) { - throw new ObjectAccessException("Cannot validate object : " + e.getMessage(), e); + } catch (InvalidObjectException e) { + throw new ObjectAccessException("Cannot validate object", e); } } }, priority); } - @Override public void close() { - throw new UnsupportedOperationException( - "Objects are not allowed to call ObjectInputStream.close() from readObject()"); + throw new UnsupportedOperationException("Objects are not allowed to call ObjectInputStream.close() from readObject()"); } }; while (reader.hasMoreChildren()) { reader.moveDown(); - final String nodeName = reader.getNodeName(); + String nodeName = reader.getNodeName(); if (nodeName.equals(ELEMENT_UNSERIALIZABLE_PARENTS)) { super.doUnmarshal(result, reader, context); } else { - final String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); + String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); if (classAttribute == null) { currentType[0] = mapper.defaultImplementationOf(mapper.realClass(nodeName)); } else { currentType[0] = mapper.realClass(classAttribute); } - if (serializationMethodInvoker.supportsReadObject(currentType[0], false)) { - @SuppressWarnings("resource") - final CustomObjectInputStream objectInputStream = CustomObjectInputStream.getInstance(context, - callback, classLoaderReference); - serializationMethodInvoker.callReadObject(currentType[0], result, objectInputStream); + if (serializationMembers.supportsReadObject(currentType[0], false)) { + CustomObjectInputStream objectInputStream = + CustomObjectInputStream.getInstance(context, callback, classLoaderReference); + serializationMembers.callReadObject(currentType[0], result, objectInputStream); objectInputStream.popCallback(); } else { try { callback.defaultReadObject(); - } catch (final IOException e) { - throw new ObjectAccessException("Could not call defaultWriteObject()", e); + } catch (IOException e) { + throw new StreamException("Cannot read defaults", e); } } } @@ -498,20 +455,17 @@ return result; } - - protected void doMarshalConditionally(final Object source, final HierarchicalStreamWriter writer, - final MarshallingContext context) { - if (isSerializable(source.getClass())) { + + protected void doMarshalConditionally(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { + if(isSerializable(source.getClass())) { doMarshal(source, writer, context); } else { super.doMarshal(source, writer, context); } } - - protected Object doUnmarshalConditionally(final Object result, final HierarchicalStreamReader reader, - final UnmarshallingContext context) { - return isSerializable(result.getClass()) ? doUnmarshal(result, reader, context) : super.doUnmarshal(result, - reader, context); + + protected Object doUnmarshalConditionally(final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context) { + return isSerializable(result.getClass()) ? doUnmarshal(result, reader, context) : super.doUnmarshal(result, reader, context); } private static class UnserializableParentsReflectionProvider extends ReflectionProviderWrapper { @@ -520,11 +474,9 @@ super(reflectionProvider); } - @Override public void visitSerializableFields(final Object object, final Visitor visitor) { wrapped.visitSerializableFields(object, new Visitor() { - @Override - public void visit(final String name, final Class type, final Class definedIn, final Object value) { + public void visit(String name, Class type, Class definedIn, Object value) { if (!Serializable.class.isAssignableFrom(definedIn)) { visitor.visit(name, type, definedIn, value); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SerializationMethodInvoker.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SerializationMethodInvoker.java (.../SerializationMethodInvoker.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SerializationMethodInvoker.java (.../SerializationMethodInvoker.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,159 +1,82 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2014, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 23. August 2004 by Joe Walnes */ package com.thoughtworks.xstream.converters.reflection; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.core.Caching; -import com.thoughtworks.xstream.core.util.FastField; +import com.thoughtworks.xstream.core.util.SerializationMembers; - /** - * Convenience wrapper to invoke special serialization methods on objects (and perform reflection caching). - * + * Convenience wrapper to invoke special serialization methods on objects (and perform + * reflection caching). + * * @author Joe Walnes * @author Jörg Schaible + * @deprecated As of 1.4.8, moved into internal util package. */ public class SerializationMethodInvoker implements Caching { - private static final Method NO_METHOD = new Object() { - @SuppressWarnings("unused") - private void noMethod() { - } - }.getClass().getDeclaredMethods()[0]; - private static final FastField[] OBJECT_TYPE_FIELDS = new FastField[]{ - new FastField(Object.class, "readResolve"), new FastField(Object.class, "writeReplace"), - new FastField(Object.class, "readObject"), new FastField(Object.class, "writeObject")}; - private final Map cache = Collections.synchronizedMap(new HashMap()); - { - for (final FastField element : OBJECT_TYPE_FIELDS) { - cache.put(element, NO_METHOD); - } - } + SerializationMembers serializationMembers = new SerializationMembers(); /** * Resolves an object as native serialization does by calling readResolve(), if available. + * + * @deprecated As of 1.4.8, moved into internal util package. */ - public Object callReadResolve(final Object result) { - if (result == null) { - return null; - } else { - final Method readResolveMethod = getMethod(result.getClass(), "readResolve", true); - if (readResolveMethod != null) { - try { - return readResolveMethod.invoke(result); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Could not call " + result.getClass().getName() + ".readResolve()", - e); - } catch (final InvocationTargetException e) { - throw new ObjectAccessException("Could not call " + result.getClass().getName() + ".readResolve()", - e.getTargetException()); - } - } else { - return result; - } - } + public Object callReadResolve(Object result) { + return serializationMembers.callReadResolve(result); } - public Object callWriteReplace(final Object object) { - if (object == null) { - return null; - } else { - final Method writeReplaceMethod = getMethod(object.getClass(), "writeReplace", true); - if (writeReplaceMethod != null) { - try { - return writeReplaceMethod.invoke(object); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException( - "Could not call " + object.getClass().getName() + ".writeReplace()", e); - } catch (final InvocationTargetException e) { - throw new ObjectAccessException( - "Could not call " + object.getClass().getName() + ".writeReplace()", e.getTargetException()); - } - } else { - return object; - } - } + /** + * @deprecated As of 1.4.8, moved into internal util package. + */ + public Object callWriteReplace(Object object) { + return serializationMembers.callWriteReplace(object); } - public boolean supportsReadObject(final Class type, final boolean includeBaseClasses) { - return getMethod(type, "readObject", includeBaseClasses, ObjectInputStream.class) != null; + /** + * @deprecated As of 1.4.8, moved into internal util package. + */ + public boolean supportsReadObject(Class type, boolean includeBaseClasses) { + return serializationMembers.supportsReadObject(type, includeBaseClasses); } - public void callReadObject(final Class type, final Object object, final ObjectInputStream stream) { - try { - final Method readObjectMethod = getMethod(type, "readObject", false, ObjectInputStream.class); - readObjectMethod.invoke(object, stream); - } catch (final IllegalAccessException e) { - throw new ConversionException("Could not call " + object.getClass().getName() + ".readObject()", e); - } catch (final InvocationTargetException e) { - throw new ConversionException("Could not call " + object.getClass().getName() + ".readObject()", e - .getTargetException()); - } + /** + * @deprecated As of 1.4.8, moved into internal util package. + */ + public void callReadObject(Class type, Object object, ObjectInputStream stream) { + serializationMembers.callReadObject(type, object, stream); } - public boolean supportsWriteObject(final Class type, final boolean includeBaseClasses) { - return getMethod(type, "writeObject", includeBaseClasses, ObjectOutputStream.class) != null; + /** + * @deprecated As of 1.4.8, moved into internal util package. + */ + public boolean supportsWriteObject(Class type, boolean includeBaseClasses) { + return serializationMembers.supportsWriteObject(type, includeBaseClasses); } - public void callWriteObject(final Class type, final Object instance, final ObjectOutputStream stream) { - try { - final Method readObjectMethod = getMethod(type, "writeObject", false, ObjectOutputStream.class); - readObjectMethod.invoke(instance, stream); - } catch (final IllegalAccessException e) { - throw new ConversionException("Could not call " + instance.getClass().getName() + ".writeObject()", e); - } catch (final InvocationTargetException e) { - throw new ConversionException("Could not call " + instance.getClass().getName() + ".writeObject()", e - .getTargetException()); - } + /** + * @deprecated As of 1.4.8, moved into internal util package. + */ + public void callWriteObject(Class type, Object instance, ObjectOutputStream stream) { + serializationMembers.callWriteObject(type, instance, stream); } - private Method getMethod(final Class type, final String name, final boolean includeBaseclasses, - final Class... parameterTypes) { - final Method method = getMethod(type, name, parameterTypes); - return method == NO_METHOD || !includeBaseclasses && !method.getDeclaringClass().equals(type) ? null : method; - } - - private Method getMethod(final Class type, final String name, final Class... parameterTypes) { - if (type == null) { - return null; - } - final FastField method = new FastField(type, name); - Method result = cache.get(method); - - if (result == null) { - try { - result = type.getDeclaredMethod(name, parameterTypes); - if (!result.isAccessible()) { - result.setAccessible(true); - } - } catch (final NoSuchMethodException e) { - result = getMethod(type.getSuperclass(), name, parameterTypes); - } - cache.put(method, result); - } - return result; - } - - @Override + /** + * @deprecated As of 1.4.8, moved into internal util package. + */ public void flushCache() { - cache.keySet().retainAll(Arrays.asList(OBJECT_TYPE_FIELDS)); + serializationMembers.flushCache(); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SortableFieldKeySorter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SortableFieldKeySorter.java (.../SortableFieldKeySorter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SortableFieldKeySorter.java (.../SortableFieldKeySorter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,45 +1,44 @@ /* - * Copyright (C) 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2007, 2009, 2011, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 10. April 2007 by Guilherme Silveira */ package com.thoughtworks.xstream.converters.reflection; -import java.lang.reflect.Field; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; +import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.core.Caching; -import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.core.util.OrderRetainingMap; /** * The default implementation for sorting fields. Invoke registerFieldOrder in order to set the field order for an * specific type. - * + * * @author Guilherme Silveira * @since 1.2.2 */ public class SortableFieldKeySorter implements FieldKeySorter, Caching { - private final Map, Comparator> map = new HashMap, Comparator>(); + private final static FieldKey[] EMPTY_FIELD_KEY_ARRAY = {}; + private final Map map = new HashMap(); - @Override - public Map sort(final Class type, final Map keyedByFieldKey) { + public Map sort(final Class type, final Map keyedByFieldKey) { if (map.containsKey(type)) { - final Map result = new LinkedHashMap(); - final FieldKey[] fieldKeys = keyedByFieldKey.keySet().toArray(new FieldKey[keyedByFieldKey.size()]); - Arrays.sort(fieldKeys, map.get(type)); - for (final FieldKey fieldKey : fieldKeys) { - result.put(fieldKey, keyedByFieldKey.get(fieldKey)); + final Map result = new OrderRetainingMap(); + final FieldKey[] fieldKeys = (FieldKey[])keyedByFieldKey.keySet().toArray(EMPTY_FIELD_KEY_ARRAY); + Arrays.sort(fieldKeys, (Comparator)map.get(type)); + for (int i = 0; i < fieldKeys.length; i++ ) { + result.put(fieldKeys[i], keyedByFieldKey.get(fieldKeys[i])); } return result; } else { @@ -49,25 +48,27 @@ /** * Registers the field order to use for a specific type. This will not affect any of the type's super or sub - * classes. If you skip a field which will be serialized, XStream will thrown an StreamException during the - * serialization process. - * + * classes. If you skip a field which will be serialized, XStream will thrown a {@link ConversionException} during + * the serialization process. + * * @param type the type * @param fields the field order */ - public void registerFieldOrder(final Class type, final String[] fields) { - map.put(type, new FieldComparator(fields)); + public void registerFieldOrder(final Class type, final String[] fields) { + map.put(type, new FieldComparator(type, fields)); } - private class FieldComparator implements Comparator { + private class FieldComparator implements Comparator { private final String[] fieldOrder; + private final Class type; - public FieldComparator(final String[] fields) { + public FieldComparator(final Class type, final String[] fields) { + this.type = type; fieldOrder = fields; } - private int compare(final String first, final String second) { + public int compare(final String first, final String second) { int firstPosition = -1, secondPosition = -1; for (int i = 0; i < fieldOrder.length; i++) { if (fieldOrder[i].equals(first)) { @@ -79,19 +80,21 @@ } if (firstPosition == -1 || secondPosition == -1) { // field not defined!!! - throw new StreamException("You have not given XStream a list of all fields to be serialized."); + final ConversionException exception = new ConversionException( + "Incomplete list of serialized fields for type"); + exception.add("sort-type", type.getName()); + throw exception; } return firstPosition - secondPosition; } - @Override - public int compare(final FieldKey first, final FieldKey second) { + public int compare(final Object firstObject, final Object secondObject) { + final FieldKey first = (FieldKey)firstObject, second = (FieldKey)secondObject; return compare(first.getFieldName(), second.getFieldName()); } } - @Override public void flushCache() { map.clear(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/Sun14ReflectionProvider.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/Sun14ReflectionProvider.java (.../Sun14ReflectionProvider.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/Sun14ReflectionProvider.java (.../Sun14ReflectionProvider.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -18,26 +18,23 @@ * * @author Joe Walnes * @author Brian Slesinsky - * @deprecated As of upcoming use {@link SunUnsafeReflectionProvider} + * @deprecated As of 1.4.7 use {@link SunUnsafeReflectionProvider} */ -@Deprecated public class Sun14ReflectionProvider extends SunUnsafeReflectionProvider { /** - * @deprecated As of upcoming use {@link SunUnsafeReflectionProvider#SunUnsafeReflectionProvider()} + * @deprecated As of 1.4.7 use {@link SunUnsafeReflectionProvider#SunUnsafeReflectionProvider()} */ - @Deprecated public Sun14ReflectionProvider() { super(); } /** - * @deprecated As of upcoming use {@link SunUnsafeReflectionProvider#SunUnsafeReflectionProvider(FieldDictionary)} + * @deprecated As of 1.4.7 use {@link SunUnsafeReflectionProvider#SunUnsafeReflectionProvider(FieldDictionary)} */ - @Deprecated - public Sun14ReflectionProvider(final FieldDictionary dic) { + public Sun14ReflectionProvider(FieldDictionary dic) { super(dic); } - + private Object readResolve() { init(); return this; Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SunLimitedUnsafeReflectionProvider.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SunLimitedUnsafeReflectionProvider.java (.../SunLimitedUnsafeReflectionProvider.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SunLimitedUnsafeReflectionProvider.java (.../SunLimitedUnsafeReflectionProvider.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014, 2016, 2017 XStream Committers. * All rights reserved. * * Created on 08. January 2014 by Joerg Schaible, factored out from SunUnsafeReflectionProvider @@ -9,6 +9,9 @@ import java.lang.reflect.Field; +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.ErrorWritingException; + import sun.misc.Unsafe; @@ -38,16 +41,16 @@ Unsafe u = null; Exception ex = null; try { - final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); + Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); unsafeField.setAccessible(true); u = (Unsafe)unsafeField.get(null); - } catch (final SecurityException e) { + } catch (SecurityException e) { ex = e; - } catch (final NoSuchFieldException e) { + } catch (NoSuchFieldException e) { ex = e; - } catch (final IllegalArgumentException e) { + } catch (IllegalArgumentException e) { ex = e; - } catch (final IllegalAccessException e) { + } catch (IllegalAccessException e) { ex = e; } exception = ex; @@ -64,28 +67,35 @@ /** * @since 1.4.7 */ - public SunLimitedUnsafeReflectionProvider(final FieldDictionary fieldDictionary) { + public SunLimitedUnsafeReflectionProvider(FieldDictionary fieldDictionary) { super(fieldDictionary); } - @Override - public Object newInstance(final Class type) { + public Object newInstance(Class type) { if (exception != null) { - throw new ObjectAccessException("Cannot construct " + type.getName(), exception); + ObjectAccessException ex = new ObjectAccessException("Cannot construct type", exception); + ex.add("construction-type", type.getName()); + throw ex; } - try { - return unsafe.allocateInstance(type); - } catch (final SecurityException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); - } catch (final InstantiationException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); - } catch (final IllegalArgumentException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); + ErrorWritingException ex = null; + if (type == void.class || type == Void.class) { + ex = new ConversionException("Type void cannot have an instance"); + } else { + try { + return unsafe.allocateInstance(type); + } catch (final SecurityException e) { + ex = new ObjectAccessException("Cannot construct type", e); + } catch (final InstantiationException e) { + ex = new ConversionException("Cannot construct type", e); + } catch (final IllegalArgumentException e) { + ex = new ObjectAccessException("Cannot construct type", e); + } } + ex.add("construction-type", type.getName()); + throw ex; } - @Override - protected void validateFieldAccess(final Field field) { + protected void validateFieldAccess(Field field) { // (overriden) don't mind final fields. } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SunUnsafeReflectionProvider.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SunUnsafeReflectionProvider.java (.../SunUnsafeReflectionProvider.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/SunUnsafeReflectionProvider.java (.../SunUnsafeReflectionProvider.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2011, 2013, 2014, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,8 +12,8 @@ package com.thoughtworks.xstream.converters.reflection; import java.lang.reflect.Field; -import java.util.HashMap; import java.util.Map; +import java.util.WeakHashMap; /** @@ -36,7 +36,7 @@ public class SunUnsafeReflectionProvider extends SunLimitedUnsafeReflectionProvider { // references to the Field key are kept in the FieldDictionary - private transient Map fieldOffsetCache; + private transient Map fieldOffsetCache; /** * @since 1.4.7 @@ -48,23 +48,23 @@ /** * @since 1.4.7 */ - public SunUnsafeReflectionProvider(final FieldDictionary dic) { + public SunUnsafeReflectionProvider(FieldDictionary dic) { super(dic); } - @Override - public void writeField(final Object object, final String fieldName, final Object value, final Class definedIn) { + public void writeField(Object object, String fieldName, Object value, Class definedIn) { write(fieldDictionary.field(object.getClass(), fieldName, definedIn), object, value); } - private void write(final Field field, final Object object, final Object value) { + private void write(Field field, Object object, Object value) { if (exception != null) { - throw new ObjectAccessException("Could not set field " + object.getClass() + "." + field.getName(), - exception); + ObjectAccessException ex = new ObjectAccessException("Cannot set field", exception); + ex.add("field", object.getClass() + "." + field.getName()); + throw ex; } try { - final long offset = getFieldOffset(field); - final Class type = field.getType(); + long offset = getFieldOffset(field); + Class type = field.getType(); if (type.isPrimitive()) { if (type.equals(Integer.TYPE)) { unsafe.putInt(object, offset, ((Integer)value).intValue()); @@ -83,26 +83,26 @@ } else if (type.equals(Boolean.TYPE)) { unsafe.putBoolean(object, offset, ((Boolean)value).booleanValue()); } else { - throw new ObjectAccessException("Could not set field " - + object.getClass() - + "." - + field.getName() - + ": Unknown type " - + type); + ObjectAccessException ex = new ObjectAccessException("Cannot set field of unknown type", exception); + ex.add("field", object.getClass() + "." + field.getName()); + ex.add("unknown-type", type.getName()); + throw ex; } } else { unsafe.putObject(object, offset, value); } - } catch (final IllegalArgumentException e) { - throw new ObjectAccessException("Could not set field " + object.getClass() + "." + field.getName(), e); + } catch (IllegalArgumentException e) { + ObjectAccessException ex = new ObjectAccessException("Cannot set field", e); + ex.add("field", object.getClass() + "." + field.getName()); + throw ex; } } - private synchronized long getFieldOffset(final Field f) { - Long l = fieldOffsetCache.get(f); + private synchronized long getFieldOffset(Field f) { + Long l = (Long)fieldOffsetCache.get(f); if (l == null) { - l = Long.valueOf(unsafe.objectFieldOffset(f)); + l = new Long(unsafe.objectFieldOffset(f)); fieldOffsetCache.put(f, l); } @@ -114,9 +114,8 @@ return this; } - @Override protected void init() { super.init(); - fieldOffsetCache = new HashMap(); + fieldOffsetCache = new WeakHashMap(); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/XStream12FieldKeySorter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/XStream12FieldKeySorter.java (.../XStream12FieldKeySorter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/reflection/XStream12FieldKeySorter.java (.../XStream12FieldKeySorter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2013, 2014 XStream Committers. + * Copyright (C) 2007, 2008, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,27 +10,26 @@ */ package com.thoughtworks.xstream.converters.reflection; -import java.lang.reflect.Field; import java.util.Comparator; import java.util.Map; import java.util.TreeMap; /** - * Sort the fields in the order of XStream 1.2.x. Fields are returned in their declaration order, fields of base classes - * last. + * Sort the fields in the order of XStream 1.2.x. Fields are returned in their declaration order, + * fields of base classes last. * * @author Jörg Schaible * @since 1.3 */ public class XStream12FieldKeySorter implements FieldKeySorter { - @Override - public Map sort(final Class type, final Map keyedByFieldKey) { - final Map map = new TreeMap(new Comparator() { + public Map sort(final Class type, final Map keyedByFieldKey) { + final Map map = new TreeMap(new Comparator() { - @Override - public int compare(final FieldKey fieldKey1, final FieldKey fieldKey2) { + public int compare(final Object o1, final Object o2) { + final FieldKey fieldKey1 = (FieldKey)o1; + final FieldKey fieldKey2 = (FieldKey)o2; int i = fieldKey2.getDepth() - fieldKey1.getDepth(); if (i == 0) { i = fieldKey1.getOrder() - fieldKey2.getOrder(); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/AbstractChronoLocalDateConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/AbstractChronoLocalDateConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/AbstractChronoLocalDateConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 22. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.DateTimeException; +import java.time.chrono.ChronoLocalDate; +import java.time.chrono.Chronology; +import java.time.chrono.Era; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * Abstract base class for converters handling derived classes of {@link java.time.chrono.ChronoLocalDate} instances. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +abstract class AbstractChronoLocalDateConverter extends AbstractSingleValueConverter { + protected abstract ChronoLocalDate chronoLocalDateOf(final E era, final int prolepticYear, final int month, + final int dayOfMonth); + + protected abstract E eraOf(final String id); + + private final static Pattern CHRONO_DATE_PATTERN = Pattern.compile("^ (\\w+) (\\d+)-(\\d+)-(\\d+)$"); + + protected ChronoLocalDate parseChronoLocalDate(final String str, final String dateTypeName, + final Set chronologies) { + if (str == null) { + return null; + } + + ConversionException exception = null; + for (final Chronology chronology : chronologies) { + final String id = chronology.getId(); + if (str.startsWith(id + ' ')) { + final Matcher matcher = CHRONO_DATE_PATTERN.matcher(str.subSequence(id.length(), str.length())); + if (matcher.matches()) { + E era = null; + try { + era = eraOf(matcher.group(1)); + } catch (final IllegalArgumentException e) { + exception = new ConversionException("Cannot parse value as " + dateTypeName + " date", e); + break; + } + if (era != null) { + try { + return chronoLocalDateOf(era, Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher + .group(3)), Integer.parseInt(matcher.group(4))); + } catch (final DateTimeException e) { + exception = new ConversionException("Cannot parse value as " + dateTypeName + " date", e); + break; + } + } + } + } + } + if (exception == null) { + exception = new ConversionException("Cannot parse value as " + dateTypeName + " date"); + } + exception.add("value", str); + throw exception; + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ChronologyConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ChronologyConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ChronologyConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 19. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.DateTimeException; +import java.time.chrono.Chronology; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.SingleValueConverter; + + +/** + * Converts a {@link Chronology} instance to a string using its id. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class ChronologyConverter implements SingleValueConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return Chronology.class.isAssignableFrom(type); + } + + @Override + public Chronology fromString(final String str) { + if (str == null) { + return null; + } + try { + return Chronology.of(str); + } catch (final DateTimeException e) { + final ConversionException exception = new ConversionException("Cannot parse value as chronology", e); + exception.add("value", str); + throw exception; + } + } + + @Override + public String toString(final Object obj) { + return obj == null ? null : ((Chronology)obj).getId(); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/DurationConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/DurationConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/DurationConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 13. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.Duration; +import java.time.format.DateTimeParseException; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * Converts a {@link Duration} instance to string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class DurationConverter extends AbstractSingleValueConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return Duration.class == type; + } + + @Override + public Duration fromString(final String str) { + try { + return Duration.parse(str); + } catch (final DateTimeParseException ex) { + final ConversionException exception = new ConversionException("Cannot parse value as duration", ex); + exception.add("value", str); + throw exception; + } + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/HijrahDateConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/HijrahDateConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/HijrahDateConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 21. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.chrono.ChronoLocalDate; +import java.time.chrono.Chronology; +import java.time.chrono.HijrahChronology; +import java.time.chrono.HijrahDate; +import java.time.chrono.HijrahEra; +import java.util.HashSet; +import java.util.Set; + + +/** + * Converts a {@link java.time.chrono.HijrahDate} to a string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class HijrahDateConverter extends AbstractChronoLocalDateConverter { + + private final Set hijrahChronologies; + + /** + * Constructs a HijrahDateConverter instance. + */ + public HijrahDateConverter() { + hijrahChronologies = new HashSet<>(); + final Set chronologies = Chronology.getAvailableChronologies(); + for (final Chronology chronology : chronologies) { + if (chronology instanceof HijrahChronology) { + hijrahChronologies.add(chronology); + } + } + } + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return HijrahDate.class == type; + } + + @Override + public Object fromString(final String str) { + return parseChronoLocalDate(str, "Hijrah", hijrahChronologies); + } + + @Override + protected ChronoLocalDate chronoLocalDateOf(final HijrahEra era, final int prolepticYear, final int month, + final int dayOfMonth) { + return era != null ? HijrahDate.of(prolepticYear, month, dayOfMonth) : null; + } + + @Override + protected HijrahEra eraOf(final String id) { + return HijrahEra.valueOf(id); + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/InstantConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/InstantConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/InstantConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 15. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.Instant; +import java.time.format.DateTimeParseException; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * Converts a {@link Instant} instance to string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class InstantConverter extends AbstractSingleValueConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return Instant.class == type; + } + + @Override + public Instant fromString(final String str) { + try { + return Instant.parse(str); + } catch (final DateTimeParseException ex) { + final ConversionException exception = new ConversionException("Cannot parse value as instant", ex); + exception.add("value", str); + throw exception; + } + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/JapaneseDateConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/JapaneseDateConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/JapaneseDateConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 22. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.chrono.ChronoLocalDate; +import java.time.chrono.JapaneseChronology; +import java.time.chrono.JapaneseDate; +import java.time.chrono.JapaneseEra; +import java.util.Collections; + + +/** + * Converts a {@link java.time.chrono.JapaneseDate} to a string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class JapaneseDateConverter extends AbstractChronoLocalDateConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return JapaneseDate.class == type; + } + + @Override + public Object fromString(final String str) { + return parseChronoLocalDate(str, "Japanese", Collections.singleton(JapaneseChronology.INSTANCE)); + } + + @Override + protected ChronoLocalDate chronoLocalDateOf(final JapaneseEra era, final int prolepticYear, final int month, + final int dayOfMonth) { + return JapaneseDate.of(era, prolepticYear, month, dayOfMonth); + } + + @Override + protected JapaneseEra eraOf(final String id) { + return JapaneseEra.valueOf(id); + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/JapaneseEraConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/JapaneseEraConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/JapaneseEraConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 22. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.chrono.JapaneseEra; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * Converts a {@link JapaneseEra} instance to a string using its id. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class JapaneseEraConverter extends AbstractSingleValueConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return JapaneseEra.class.isAssignableFrom(type); + } + + @Override + public JapaneseEra fromString(final String str) { + if (str == null) { + return null; + } + try { + return JapaneseEra.valueOf(str); + } catch (final IllegalArgumentException e) { + final ConversionException exception = new ConversionException("Cannot parse value as Japanese era", e); + exception.add("value", str); + throw exception; + } + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/LocalDateConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/LocalDateConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/LocalDateConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 13. January 2017 by Matej Cimbora + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.LocalDate; +import java.time.format.DateTimeParseException; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * Converts a {@link java.time.LocalDate} to a string. + * + * @author Matej Cimbora + * @since 1.4.10 + */ +public class LocalDateConverter extends AbstractSingleValueConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return LocalDate.class == type; + } + + @Override + public Object fromString(final String str) { + try { + return LocalDate.parse(str); + } catch (final DateTimeParseException e) { + final ConversionException exception = new ConversionException("Cannot parse value as local date", e); + exception.add("value", str); + throw exception; + } + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/LocalDateTimeConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/LocalDateTimeConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/LocalDateTimeConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 13. January 2017 by Matej Cimbora + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.SingleValueConverter; + + +/** + * Converts a {@link LocalDateTime} to a string. + * + * @author Matej Cimbora + * @since 1.4.10 + */ +public class LocalDateTimeConverter implements SingleValueConverter { + + private static final DateTimeFormatter FORMATTER; + + static { + FORMATTER = new DateTimeFormatterBuilder() + .appendPattern("uuuu-MM-dd'T'HH:mm:ss") + .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true) + .toFormatter(); + } + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return LocalDateTime.class == type; + } + + @Override + public Object fromString(final String str) { + try { + return LocalDateTime.parse(str); + } catch (final DateTimeParseException e) { + final ConversionException exception = new ConversionException("Cannot parse value as local date time", e); + exception.add("value", str); + throw exception; + } + } + + @Override + public String toString(final Object obj) { + if (obj == null) { + return null; + } + + final LocalDateTime localDateTime = (LocalDateTime)obj; + return FORMATTER.format(localDateTime); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/LocalTimeConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/LocalTimeConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/LocalTimeConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 13. January 2017 by Matej Cimbora + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.SingleValueConverter; + + +/** + * Converts a {@link LocalTime} to a string. + * + * @author Matej Cimbora + * @since 1.4.10 + */ +public class LocalTimeConverter implements SingleValueConverter { + + private static final DateTimeFormatter FORMATTER; + + static { + FORMATTER = new DateTimeFormatterBuilder() + .appendPattern("HH:mm:ss") + .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true) + .toFormatter(); + } + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return LocalTime.class == type; + } + + @Override + public Object fromString(final String str) { + try { + return LocalTime.parse(str); + } catch (final DateTimeParseException e) { + final ConversionException exception = new ConversionException("Cannot parse value as local time", e); + exception.add("value", str); + throw exception; + } + } + + @Override + public String toString(final Object obj) { + if (obj == null) { + return null; + } + + final LocalTime localTime = (LocalTime)obj; + return FORMATTER.format(localTime); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/MinguoDateConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/MinguoDateConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/MinguoDateConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 22. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.chrono.ChronoLocalDate; +import java.time.chrono.MinguoChronology; +import java.time.chrono.MinguoDate; +import java.time.chrono.MinguoEra; +import java.util.Collections; + + +/** + * Converts a {@link java.time.chrono.MinguoDate} to a string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class MinguoDateConverter extends AbstractChronoLocalDateConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return MinguoDate.class == type; + } + + @Override + public Object fromString(final String str) { + return parseChronoLocalDate(str, "Minguo", Collections.singleton(MinguoChronology.INSTANCE)); + } + + @Override + protected ChronoLocalDate chronoLocalDateOf(final MinguoEra era, final int prolepticYear, final int month, + final int dayOfMonth) { + return MinguoDate.of(prolepticYear, month, dayOfMonth); + } + + @Override + protected MinguoEra eraOf(final String id) { + return MinguoEra.valueOf(id); + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/MonthDayConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/MonthDayConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/MonthDayConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 13. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.MonthDay; +import java.time.format.DateTimeParseException; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * Converts a {@link MonthDay} instance to string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class MonthDayConverter extends AbstractSingleValueConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return MonthDay.class == type; + } + + @Override + public MonthDay fromString(final String str) { + try { + return MonthDay.parse(str); + } catch (final DateTimeParseException ex) { + final ConversionException exception = new ConversionException("Cannot parse value as month day", ex); + exception.add("value", str); + throw exception; + } + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/OffsetDateTimeConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/OffsetDateTimeConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/OffsetDateTimeConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 13. January 2017 by Matej Cimbora + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.SingleValueConverter; + + +/** + * Converts a {@link OffsetDateTime} to a string. + * + * @author Matej Cimbora + * @since 1.4.10 + */ +public class OffsetDateTimeConverter implements SingleValueConverter { + + private static final DateTimeFormatter FORMATTER; + + static { + FORMATTER = new DateTimeFormatterBuilder() + .appendPattern("uuuu-MM-dd'T'HH:mm:ss") + .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true) + .appendOffsetId() + .toFormatter(); + } + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return OffsetDateTime.class == type; + } + + @Override + public Object fromString(final String str) { + try { + return OffsetDateTime.parse(str); + } catch (final DateTimeParseException e) { + final ConversionException exception = new ConversionException("Cannot parse value as offset date time", e); + exception.add("value", str); + throw exception; + } + } + + @Override + public String toString(final Object obj) { + if (obj == null) { + return null; + } + + final OffsetDateTime offsetDateTime = (OffsetDateTime)obj; + return FORMATTER.format(offsetDateTime); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/OffsetTimeConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/OffsetTimeConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/OffsetTimeConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 11. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.OffsetTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.SingleValueConverter; + + +/** + * Converts a {@link OffsetTime} to a string. + * + * @author Matej Cimbora + * @author Jörg Schaible + * @since 1.4.10 + */ +public class OffsetTimeConverter implements SingleValueConverter { + + private static final DateTimeFormatter FORMATTER; + + static { + FORMATTER = new DateTimeFormatterBuilder() + .appendPattern("HH:mm:ss") + .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true) + .appendOffsetId() + .toFormatter(); + } + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return OffsetTime.class == type; + } + + @Override + public Object fromString(final String str) { + try { + return OffsetTime.parse(str); + } catch (final DateTimeParseException e) { + final ConversionException exception = new ConversionException("Cannot parse value as offset time", e); + exception.add("value", str); + throw exception; + } + } + + @Override + public String toString(final Object obj) { + if (obj == null) { + return null; + } + + final OffsetTime offsetTime = (OffsetTime)obj; + return FORMATTER.format(offsetTime); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/PeriodConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/PeriodConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/PeriodConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 13. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.Period; +import java.time.format.DateTimeParseException; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * Converts a {@link Period} instance to string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class PeriodConverter extends AbstractSingleValueConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return Period.class == type; + } + + @Override + public Period fromString(final String str) { + try { + return Period.parse(str); + } catch (final DateTimeParseException ex) { + final ConversionException exception = new ConversionException("Cannot parse period value", ex); + exception.add("period", str); + throw exception; + } + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/SystemClockConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/SystemClockConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/SystemClockConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 06. March 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.Clock; +import java.time.ZoneId; + +import com.thoughtworks.xstream.converters.Converter; +import com.thoughtworks.xstream.converters.MarshallingContext; +import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.mapper.Mapper; + + +/** + * Converts a system {@link Clock}, using zone as nested element. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class SystemClockConverter implements Converter { + + private final Mapper mapper; + private final Class type; + + /** + * Constructs a SystemClockConverter instance. + * + * @param mapper the Mapper instance + */ + public SystemClockConverter(final Mapper mapper) { + this.mapper = mapper; + type = Clock.systemUTC().getClass(); + } + + @Override + public boolean canConvert(final Class type) { + return type == this.type; + } + + @Override + public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { + final Clock clock = (Clock)source; + ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(Clock.class, "zone"), null); + context.convertAnother(clock.getZone()); + writer.endNode(); + } + + @Override + public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + reader.moveDown(); + final ZoneId zone = (ZoneId)context.convertAnother(null, ZoneId.class); + reader.moveUp(); + return Clock.system(zone); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ThaiBuddhistDateConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ThaiBuddhistDateConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ThaiBuddhistDateConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 22. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.chrono.ChronoLocalDate; +import java.time.chrono.ThaiBuddhistChronology; +import java.time.chrono.ThaiBuddhistDate; +import java.time.chrono.ThaiBuddhistEra; +import java.util.Collections; + + +/** + * Converts a {@link java.time.chrono.ThaiBuddhistDate} to a string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class ThaiBuddhistDateConverter extends AbstractChronoLocalDateConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return ThaiBuddhistDate.class == type; + } + + @Override + public Object fromString(final String str) { + return parseChronoLocalDate(str, "Thai Buddhist", Collections.singleton(ThaiBuddhistChronology.INSTANCE)); + } + + @Override + protected ChronoLocalDate chronoLocalDateOf(final ThaiBuddhistEra era, final int prolepticYear, final int month, + final int dayOfMonth) { + return ThaiBuddhistDate.of(prolepticYear, month, dayOfMonth); + } + + @Override + protected ThaiBuddhistEra eraOf(final String id) { + return ThaiBuddhistEra.valueOf(id); + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ValueRangeConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ValueRangeConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ValueRangeConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 22. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.temporal.ValueRange; +import java.util.HashMap; +import java.util.Map; + +import com.thoughtworks.xstream.converters.Converter; +import com.thoughtworks.xstream.converters.MarshallingContext; +import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.mapper.Mapper; + + +/** + * Converts a temporal {@link ValueRange}, using four nested elements: maxLargest, maxSmallest, minLargest, and + * minSmallest. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class ValueRangeConverter implements Converter { + + private final Mapper mapper; + + /** + * Constructs a ValueRangeConverter instance. + * + * @param mapper the Mapper instance + */ + public ValueRangeConverter(final Mapper mapper) { + this.mapper = mapper; + + } + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return type == ValueRange.class; + } + + @Override + public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { + final ValueRange valueRange = (ValueRange)source; + write("maxLargest", valueRange.getMaximum(), writer); + write("maxSmallest", valueRange.getSmallestMaximum(), writer); + write("minLargest", valueRange.getLargestMinimum(), writer); + write("minSmallest", valueRange.getMinimum(), writer); + } + + @Override + public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + final boolean oldFormat = "custom".equals(reader.getAttribute(mapper.aliasForSystemAttribute("serialization"))); + if (oldFormat) { + reader.moveDown(); + reader.moveDown(); + } + final Map elements = new HashMap<>(); + while (reader.hasMoreChildren()) { + reader.moveDown(); + + final String name = reader.getNodeName(); + elements.put(oldFormat ? name : mapper.realMember(ValueRange.class, name), Long.valueOf(reader.getValue())); + reader.moveUp(); + } + if (oldFormat) { + reader.moveUp(); + reader.moveUp(); + } + return ValueRange.of(elements.get("minSmallest").longValue(), elements.get("minLargest").longValue(), elements + .get("maxSmallest") + .longValue(), elements.get("maxLargest").longValue()); + } + + private void write(final String fieldName, final long value, final HierarchicalStreamWriter writer) { + ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(ValueRange.class, fieldName), + long.class); + writer.setValue(String.valueOf(value)); + writer.endNode(); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/WeekFieldsConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/WeekFieldsConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/WeekFieldsConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 22. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.DayOfWeek; +import java.time.temporal.WeekFields; + +import com.thoughtworks.xstream.converters.Converter; +import com.thoughtworks.xstream.converters.MarshallingContext; +import com.thoughtworks.xstream.converters.UnmarshallingContext; +import com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.UnknownFieldException; +import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.mapper.Mapper; + + +/** + * Converts a {@link WeekFields} instance, using two nested elements: minimalDays and minSmallest. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class WeekFieldsConverter implements Converter { + + private final Mapper mapper; + + /** + * Constructs a WeekFieldsConverter instance. + * + * @param mapper the Mapper instance + */ + public WeekFieldsConverter(final Mapper mapper) { + this.mapper = mapper; + + } + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return type == WeekFields.class; + } + + @Override + public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { + final WeekFields weekFields = (WeekFields)source; + ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(WeekFields.class, + "minimalDays"), int.class); + writer.setValue(String.valueOf(weekFields.getMinimalDaysInFirstWeek())); + writer.endNode(); + ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(WeekFields.class, + "firstDayOfWeek"), DayOfWeek.class); + context.convertAnother(weekFields.getFirstDayOfWeek()); + writer.endNode(); + } + + @Override + public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + final boolean oldFormat = "custom".equals(reader.getAttribute(mapper.aliasForSystemAttribute("serialization"))); + if (oldFormat) { + reader.moveDown(); + reader.moveDown(); + } + + int minimalDays = 0; + DayOfWeek firstDayOfWeek = null; + while (reader.hasMoreChildren()) { + reader.moveDown(); + final String name = oldFormat + ? reader.getNodeName() + : mapper.realMember(WeekFields.class, reader.getNodeName()); + if ("minimalDays".equals(name)) { + minimalDays = Integer.parseInt(reader.getValue()); + } else if ("firstDayOfWeek".equals(name)) { + firstDayOfWeek = (DayOfWeek)context.convertAnother(null, DayOfWeek.class); + } else { + throw new UnknownFieldException(WeekFields.class.getName(), name); + } + reader.moveUp(); + } + if (oldFormat) { + reader.moveUp(); + reader.moveUp(); + } + return WeekFields.of(firstDayOfWeek, minimalDays); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/YearConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/YearConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/YearConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 11. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.Year; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * Converts a {@link Year} instance to string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class YearConverter extends AbstractSingleValueConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return Year.class == type; + } + + @Override + public Year fromString(final String str) { + try { + return Year.of(Integer.parseInt(str)); + } catch (final NumberFormatException ex) { + final ConversionException exception = new ConversionException("Cannot parse value as year", ex); + exception.add("value", str); + throw exception; + } + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/YearMonthConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/YearMonthConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/YearMonthConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 11. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.YearMonth; +import java.time.format.DateTimeParseException; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * Converts a {@link YearMonth} instance to string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class YearMonthConverter extends AbstractSingleValueConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return YearMonth.class == type; + } + + @Override + public YearMonth fromString(final String str) { + try { + return YearMonth.parse(str); + } catch (final DateTimeParseException ex) { + final ConversionException exception = new ConversionException("Cannot parse value as year month", ex); + exception.add("value", str); + throw exception; + } + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ZoneIdConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ZoneIdConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ZoneIdConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 8. February 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.DateTimeException; +import java.time.ZoneId; +import java.time.zone.ZoneRulesException; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.SingleValueConverter; + + +/** + * Converts a {@link ZoneId} instance to string. + * + * @author Jörg Schaible + * @since 1.4.10 + */ +public class ZoneIdConverter implements SingleValueConverter { + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return ZoneId.class.isAssignableFrom(type); + } + + @Override + public ZoneId fromString(final String str) { + ConversionException exception; + try { + return ZoneId.of(str); + } catch (final ZoneRulesException e) { + exception = new ConversionException("Not a valid zone id", e); + } catch (final DateTimeException e) { + exception = new ConversionException("Cannot parse value as zone id", e); + } + exception.add("value", str); + throw exception; + } + + @Override + public String toString(final Object obj) { + if (obj == null) { + return null; + } + final ZoneId zoneId = (ZoneId)obj; + return zoneId.getId(); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ZonedDateTimeConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ZonedDateTimeConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/ZonedDateTimeConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 13. January 2017 by Matej Cimbora + */ +package com.thoughtworks.xstream.converters.time; + +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.SingleValueConverter; + + +/** + * Converts a {@link ZonedDateTime} to a string. + * + * @author Matej Cimbora + * @since 1.4.10 + */ +public class ZonedDateTimeConverter implements SingleValueConverter { + + private static final DateTimeFormatter FORMATTER; + + static { + FORMATTER = new DateTimeFormatterBuilder() + .appendPattern("uuuu-MM-dd'T'HH:mm:ss") + .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true) + .appendOffsetId() + .appendLiteral("[") + .appendZoneId() + .appendLiteral("]") + .toFormatter(); + } + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return ZonedDateTime.class == type; + } + + @Override + public String toString(final Object obj) { + if (obj == null) { + return null; + } + + final ZonedDateTime zonedDateTime = (ZonedDateTime)obj; + return FORMATTER.format(zonedDateTime); + } + + @Override + public Object fromString(final String str) { + try { + return ZonedDateTime.parse(str); + } catch (final DateTimeParseException e) { + final ConversionException exception = new ConversionException("Cannot parse value as zoned date time", e); + exception.add("value", str); + throw exception; + } + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/package.html =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/package.html (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/converters/time/package.html (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,13 @@ + + +

      Extra converters for the java.time package.

      + Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/AbstractReferenceMarshaller.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/AbstractReferenceMarshaller.java (.../AbstractReferenceMarshaller.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/AbstractReferenceMarshaller.java (.../AbstractReferenceMarshaller.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,8 +10,6 @@ */ package com.thoughtworks.xstream.core; -import java.util.Iterator; - import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.ConverterLookup; @@ -23,6 +21,7 @@ import com.thoughtworks.xstream.io.path.PathTrackingWriter; import com.thoughtworks.xstream.mapper.Mapper; +import java.util.Iterator; /** * Abstract base class for a TreeMarshaller, that can build references. @@ -32,90 +31,80 @@ * @author Mauro Talevi * @since 1.2 */ -public abstract class AbstractReferenceMarshaller extends TreeMarshaller implements MarshallingContext { +public abstract class AbstractReferenceMarshaller extends TreeMarshaller implements MarshallingContext { - private final ObjectIdDictionary> references = new ObjectIdDictionary>(); - private final ObjectIdDictionary implicitElements = new ObjectIdDictionary(); - private final PathTracker pathTracker = new PathTracker(); + private ObjectIdDictionary references = new ObjectIdDictionary(); + private ObjectIdDictionary implicitElements = new ObjectIdDictionary(); + private PathTracker pathTracker = new PathTracker(); private Path lastPath; - public AbstractReferenceMarshaller( - final HierarchicalStreamWriter writer, final ConverterLookup converterLookup, final Mapper mapper) { + public AbstractReferenceMarshaller(HierarchicalStreamWriter writer, + ConverterLookup converterLookup, + Mapper mapper) { super(writer, converterLookup, mapper); this.writer = new PathTrackingWriter(writer, pathTracker); } - @Override - public void convert(final Object item, final Converter converter) { + public void convert(Object item, Converter converter) { if (getMapper().isImmutableValueType(item.getClass())) { // strings, ints, dates, etc... don't bother using references. converter.marshal(item, writer, this); } else { final Path currentPath = pathTracker.getPath(); - final Id existingReference = references.lookupId(item); + Id existingReference = (Id)references.lookupId(item); if (existingReference != null && existingReference.getPath() != currentPath) { - final String attributeName = getMapper().aliasForSystemAttribute("reference"); + String attributeName = getMapper().aliasForSystemAttribute("reference"); if (attributeName != null) { writer.addAttribute(attributeName, createReference(currentPath, existingReference.getItem())); } } else { - final R newReferenceKey = existingReference == null - ? createReferenceKey(currentPath, item) + final Object newReferenceKey = existingReference == null + ? createReferenceKey(currentPath, item) : existingReference.getItem(); if (lastPath == null || !currentPath.isAncestor(lastPath)) { fireValidReference(newReferenceKey); lastPath = currentPath; - references.associateId(item, new Id(newReferenceKey, currentPath)); + references.associateId(item, new Id(newReferenceKey, currentPath)); } - converter.marshal(item, writer, new ReferencingMarshallingContext() { - - @Override - public void put(final Object key, final Object value) { + converter.marshal(item, writer, new ReferencingMarshallingContext() { + + public void put(Object key, Object value) { AbstractReferenceMarshaller.this.put(key, value); } - - @Override - public Iterator keys() { + + public Iterator keys() { return AbstractReferenceMarshaller.this.keys(); } - - @Override - public Object get(final Object key) { + + public Object get(Object key) { return AbstractReferenceMarshaller.this.get(key); } - - @Override - public void convertAnother(final Object nextItem, final Converter converter) { + + public void convertAnother(Object nextItem, Converter converter) { AbstractReferenceMarshaller.this.convertAnother(nextItem, converter); } - - @Override - public void convertAnother(final Object nextItem) { + + public void convertAnother(Object nextItem) { AbstractReferenceMarshaller.this.convertAnother(nextItem); } - - @Override - public void replace(final Object original, final Object replacement) { - references.associateId(replacement, new Id(newReferenceKey, currentPath)); + + public void replace(Object original, Object replacement) { + references.associateId(replacement, new Id(newReferenceKey, currentPath)); } - - @Override - public R lookupReference(final Object item) { - final Id id = references.lookupId(item); + + public Object lookupReference(Object item) { + Id id = (Id)references.lookupId(item); return id.getItem(); } - + /** - * @deprecated As of 1.4.2 + * @deprecated As of 1.4.2 */ - @Deprecated - @Override public Path currentPath() { return pathTracker.getPath(); } - @Override - public void registerImplicit(final Object item) { + public void registerImplicit(Object item) { if (implicitElements.containsId(item)) { throw new ReferencedImplicitElementException(item, currentPath); } @@ -125,31 +114,26 @@ } } } - - protected abstract String createReference(Path currentPath, R existingReferenceKey); - - protected abstract R createReferenceKey(Path currentPath, Object item); - - protected abstract void fireValidReference(R referenceKey); - - private static class Id { - private final R item; - private final Path path; - - public Id(final R item, final Path path) { + + protected abstract String createReference(Path currentPath, Object existingReferenceKey); + protected abstract Object createReferenceKey(Path currentPath, Object item); + protected abstract void fireValidReference(Object referenceKey); + + private static class Id { + private Object item; + private Path path; + public Id(Object item, Path path) { this.item = item; this.path = path; } - - protected R getItem() { - return item; + protected Object getItem() { + return this.item; } - protected Path getPath() { - return path; + return this.path; } } - + public static class ReferencedImplicitElementException extends ConversionException { public ReferencedImplicitElementException(final Object item, final Path path) { super("Cannot reference implicit element"); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/AbstractReferenceUnmarshaller.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/AbstractReferenceUnmarshaller.java (.../AbstractReferenceUnmarshaller.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/AbstractReferenceUnmarshaller.java (.../AbstractReferenceUnmarshaller.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,11 +1,11 @@ /* - * Copyright (C) 2006, 2007, 2008, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2011, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 15. March 2007 by Joerg Schaible */ package com.thoughtworks.xstream.core; @@ -20,51 +20,52 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.mapper.Mapper; - /** * Abstract base class for a TreeUnmarshaller, that resolves references. - * + * * @author Joe Walnes * @author Jörg Schaible * @author Mauro Talevi * @since 1.2 */ -public abstract class AbstractReferenceUnmarshaller extends TreeUnmarshaller { +public abstract class AbstractReferenceUnmarshaller extends TreeUnmarshaller { private static final Object NULL = new Object(); - private final Map values = new HashMap(); - private final FastStack parentStack = new FastStack(16); + private Map values = new HashMap(); + private FastStack parentStack = new FastStack(16); - public AbstractReferenceUnmarshaller( - final Object root, final HierarchicalStreamReader reader, final ConverterLookup converterLookup, - final Mapper mapper) { + public AbstractReferenceUnmarshaller(Object root, HierarchicalStreamReader reader, + ConverterLookup converterLookup, Mapper mapper) { super(root, reader, converterLookup, mapper); } - @Override - protected Object convert(final Object parent, final Class type, final Converter converter) { + protected Object convert(Object parent, Class type, Converter converter) { if (parentStack.size() > 0) { // handles circular references - final R parentReferenceKey = parentStack.peek(); + Object parentReferenceKey = parentStack.peek(); if (parentReferenceKey != null) { - // see AbstractCircularReferenceTest.testWeirdCircularReference() - if (!values.containsKey(parentReferenceKey)) { + if (!values.containsKey(parentReferenceKey)) { // see AbstractCircularReferenceTest.testWeirdCircularReference() values.put(parentReferenceKey, parent); } } } final Object result; final String attributeName = getMapper().aliasForSystemAttribute("reference"); final String reference = attributeName == null ? null : reader.getAttribute(attributeName); + final boolean isReferenceable = getMapper().isReferenceable(type); if (reference != null) { - final Object cache = values.get(getReferenceKey(reference)); + final Object cache = isReferenceable ? values.get(getReferenceKey(reference)) : null; if (cache == null) { final ConversionException ex = new ConversionException("Invalid reference"); ex.add("reference", reference); + ex.add("referenced-type", type.getName()); + ex.add("referenceable", Boolean.toString(isReferenceable)); throw ex; - } + } result = cache == NULL ? null : cache; + } else if (!isReferenceable) { + result = super.convert(parent, type, converter); } else { - final R currentReferenceKey = getCurrentReferenceKey(); + Object currentReferenceKey = getCurrentReferenceKey(); parentStack.push(currentReferenceKey); result = super.convert(parent, type, converter); if (currentReferenceKey != null) { @@ -74,8 +75,7 @@ } return result; } - - protected abstract R getReferenceKey(String reference); - - protected abstract R getCurrentReferenceKey(); + + protected abstract Object getReferenceKey(String reference); + protected abstract Object getCurrentReferenceKey(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/AbstractTreeMarshallingStrategy.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/AbstractTreeMarshallingStrategy.java (.../AbstractTreeMarshallingStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/AbstractTreeMarshallingStrategy.java (.../AbstractTreeMarshallingStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -27,23 +27,19 @@ */ public abstract class AbstractTreeMarshallingStrategy implements MarshallingStrategy { - @Override - public Object unmarshal(final Object root, final HierarchicalStreamReader reader, final DataHolder dataHolder, - final ConverterLookup converterLookup, final Mapper mapper) { - final TreeUnmarshaller context = createUnmarshallingContext(root, reader, converterLookup, mapper); + public Object unmarshal(Object root, HierarchicalStreamReader reader, DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper) { + TreeUnmarshaller context = createUnmarshallingContext(root, reader, converterLookup, mapper); return context.start(dataHolder); } - @Override - public void marshal(final HierarchicalStreamWriter writer, final Object obj, final ConverterLookup converterLookup, - final Mapper mapper, final DataHolder dataHolder) { - final TreeMarshaller context = createMarshallingContext(writer, converterLookup, mapper); + public void marshal(HierarchicalStreamWriter writer, Object obj, ConverterLookup converterLookup, Mapper mapper, DataHolder dataHolder) { + TreeMarshaller context = createMarshallingContext(writer, converterLookup, mapper); context.start(obj, dataHolder); } + + protected abstract TreeUnmarshaller createUnmarshallingContext(Object root, + HierarchicalStreamReader reader, ConverterLookup converterLookup, Mapper mapper); - protected abstract TreeUnmarshaller createUnmarshallingContext(Object root, HierarchicalStreamReader reader, - ConverterLookup converterLookup, Mapper mapper); - - protected abstract TreeMarshaller createMarshallingContext(HierarchicalStreamWriter writer, - ConverterLookup converterLookup, Mapper mapper); + protected abstract TreeMarshaller createMarshallingContext( + HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/BaseException.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/BaseException.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/BaseException.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2004 Joe Walnes. + * Copyright (C) 2006, 2007, 2008, 2009, 2016 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 14. September 2004 by Joe Walnes + */ +package com.thoughtworks.xstream.core; + +import com.thoughtworks.xstream.XStreamException; + +/** + * @deprecated As of 1.3, use {@link XStreamException} instead + */ +public abstract class BaseException extends RuntimeException { + + protected BaseException(String message) { + super(message); + } + + protected BaseException(String message, Throwable cause) { + super(message, cause); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/DefaultConverterLookup.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/DefaultConverterLookup.java (.../DefaultConverterLookup.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/DefaultConverterLookup.java (.../DefaultConverterLookup.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2016, 2017 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,17 +11,18 @@ */ package com.thoughtworks.xstream.core; -import java.util.Collections; -import java.util.Iterator; -import java.util.Map; -import java.util.WeakHashMap; - import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.ConverterLookup; import com.thoughtworks.xstream.converters.ConverterRegistry; import com.thoughtworks.xstream.core.util.PrioritizedList; +import com.thoughtworks.xstream.mapper.Mapper; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.WeakHashMap; /** * The default implementation of converters lookup. @@ -32,51 +33,83 @@ */ public class DefaultConverterLookup implements ConverterLookup, ConverterRegistry, Caching { - private final PrioritizedList converters = new PrioritizedList(); - private transient Map, Converter> typeToConverterMap; + private final PrioritizedList converters = new PrioritizedList(); + private transient Map typeToConverterMap; public DefaultConverterLookup() { - readResolve(); + readResolve(); } - @Override - public Converter lookupConverterForType(final Class type) { - final Converter cachedConverter = typeToConverterMap.get(type); + /** + * @deprecated As of 1.3, use {@link #DefaultConverterLookup()} + */ + public DefaultConverterLookup(Mapper mapper) { + } + + public Converter lookupConverterForType(Class type) { + Converter cachedConverter = (Converter) typeToConverterMap.get(type); if (cachedConverter != null) { return cachedConverter; } - for (final Converter converter : converters) { - if (converter.canConvert(type)) { - return converter; + + final Map errors = new LinkedHashMap(); + Iterator iterator = converters.iterator(); + while (iterator.hasNext()) { + Converter converter = (Converter) iterator.next(); + try { + if (converter.canConvert(type)) { + typeToConverterMap.put(type, converter); + return converter; + } + } catch (final RuntimeException e) { + errors.put(converter.getClass().getName(), e.getMessage()); + } catch (final LinkageError e) { + errors.put(converter.getClass().getName(), e.getMessage()); } } - throw new ConversionException("No converter specified for " + type); - } - @Override - public void registerConverter(final Converter converter, final int priority) { + final ConversionException exception = new ConversionException(errors.isEmpty() + ? "No converter specified" + : "No converter available"); + exception.add("type", type.getName()); + iterator = errors.entrySet().iterator(); + while (iterator.hasNext()) { + final Map.Entry entry = (Map.Entry)iterator.next(); + exception.add("converter", entry.getKey().toString()); + exception.add("message", entry.getValue().toString()); + } + throw exception; + } + + public void registerConverter(Converter converter, int priority) { converters.add(converter, priority); - for (final Iterator> iter = typeToConverterMap.keySet().iterator(); iter.hasNext();) { - final Class type = iter.next(); - if (converter.canConvert(type)) { - iter.remove(); + for (Iterator iter = typeToConverterMap.keySet().iterator(); iter.hasNext();) { + Class type = (Class) iter.next(); + try { + if (converter.canConvert(type)) { + iter.remove(); + } + } catch (final RuntimeException e) { + // ignore + } catch (final LinkageError e) { + // ignore } } } - - @Override + public void flushCache() { typeToConverterMap.clear(); - for (final Converter converter : converters) { + Iterator iterator = converters.iterator(); + while (iterator.hasNext()) { + Converter converter = (Converter) iterator.next(); if (converter instanceof Caching) { ((Caching)converter).flushCache(); } } } private Object readResolve() { - // TODO: Use ConcurrentMap - typeToConverterMap = Collections.synchronizedMap(new WeakHashMap, Converter>()); + typeToConverterMap = Collections.synchronizedMap(new WeakHashMap()); return this; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/JVM.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/JVM.java (.../JVM.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/JVM.java (.../JVM.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,6 +11,15 @@ */ package com.thoughtworks.xstream.core; +import com.thoughtworks.xstream.converters.reflection.FieldDictionary; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; +import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider; +import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; +import com.thoughtworks.xstream.core.util.CustomObjectOutputStream; +import com.thoughtworks.xstream.core.util.DependencyInjectionFactory; +import com.thoughtworks.xstream.core.util.PresortedMap; +import com.thoughtworks.xstream.core.util.PresortedSet; + import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -23,23 +32,10 @@ import java.util.TreeMap; import java.util.TreeSet; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; - -import com.thoughtworks.xstream.converters.reflection.FieldDictionary; -import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; -import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider; -import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; -import com.thoughtworks.xstream.core.util.CustomObjectOutputStream; -import com.thoughtworks.xstream.core.util.DependencyInjectionFactory; -import com.thoughtworks.xstream.core.util.PresortedMap; -import com.thoughtworks.xstream.core.util.PresortedSet; - - public class JVM implements Caching { private ReflectionProvider reflectionProvider; - + private static final boolean isAWTAvailable; private static final boolean isSwingAvailable; private static final boolean isSQLAvailable; @@ -48,64 +44,55 @@ private static final boolean optimizedTreeSetAddAll; private static final boolean optimizedTreeMapPutAll; private static final boolean canParseUTCDateFormat; + private static final boolean canParseISO8601TimeZoneInDateFormat; private static final boolean canCreateDerivedObjectOutputStream; private static final String vendor = System.getProperty("java.vm.vendor"); private static final float majorJavaVersion = getMajorJavaVersion(); private static final float DEFAULT_JAVA_VERSION = 1.4f; private static final boolean reverseFieldOrder = false; - private static final Class reflectionProviderType; + private static final Class reflectionProviderType; static class Test { - @SuppressWarnings("unused") private Object o; - @SuppressWarnings("unused") private char c; - @SuppressWarnings("unused") private byte b; - @SuppressWarnings("unused") private short s; - @SuppressWarnings("unused") private int i; - @SuppressWarnings("unused") private long l; - @SuppressWarnings("unused") private float f; - @SuppressWarnings("unused") private double d; - @SuppressWarnings("unused") private boolean bool; - Test() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } } static { boolean test = true; Object unsafe = null; try { - final Class unsafeClass = Class.forName("sun.misc.Unsafe"); - final Field unsafeField = unsafeClass.getDeclaredField("theUnsafe"); + Class unsafeClass = Class.forName("sun.misc.Unsafe"); + Field unsafeField = unsafeClass.getDeclaredField("theUnsafe"); unsafeField.setAccessible(true); unsafe = unsafeField.get(null); - final Method allocateInstance = unsafeClass.getDeclaredMethod("allocateInstance", new Class[]{Class.class}); + Method allocateInstance = unsafeClass.getDeclaredMethod("allocateInstance", new Class[]{Class.class}); allocateInstance.setAccessible(true); test = allocateInstance.invoke(unsafe, new Object[]{Test.class}) != null; - } catch (final Exception e) { + } catch (Exception e) { test = false; - } catch (final Error e) { + } catch (Error e) { test = false; } canAllocateWithUnsafe = test; test = false; - Class type = PureJavaReflectionProvider.class; + Class type = PureJavaReflectionProvider.class; if (canUseSunUnsafeReflectionProvider()) { - Class cls = loadClassForName("com.thoughtworks.xstream.converters.reflection.SunUnsafeReflectionProvider"); + Class cls = loadClassForName("com.thoughtworks.xstream.converters.reflection.SunUnsafeReflectionProvider"); if (cls != null) { try { - final ReflectionProvider provider = DependencyInjectionFactory.newInstance(cls); - final Test t = (Test)provider.newInstance(Test.class); + ReflectionProvider provider = (ReflectionProvider)DependencyInjectionFactory.newInstance(cls, null); + Test t = (Test)provider.newInstance(Test.class); try { provider.writeField(t, "o", "object", Test.class); provider.writeField(t, "c", new Character('c'), Test.class); @@ -117,83 +104,91 @@ provider.writeField(t, "d", new Double(1), Test.class); provider.writeField(t, "bool", Boolean.TRUE, Test.class); test = true; - } catch (final IncompatibleClassChangeError e) { + } catch(IncompatibleClassChangeError e) { cls = null; - } catch (final ObjectAccessException e) { + } catch (ObjectAccessException e) { cls = null; } if (cls == null) { cls = loadClassForName("com.thoughtworks.xstream.converters.reflection.SunLimitedUnsafeReflectionProvider"); } type = cls; - } catch (final ObjectAccessException e) { + } catch (ObjectAccessException e) { } } } reflectionProviderType = type; canWriteWithUnsafe = test; - final Comparator comparator = new Comparator() { - @Override - public int compare(final Object o1, final Object o2) { + Comparator comparator = new Comparator() { + public int compare(Object o1, Object o2) { throw new RuntimeException(); } }; - final SortedMap map = new PresortedMap(comparator); + SortedMap map = new PresortedMap(comparator); map.put("one", null); map.put("two", null); try { - new TreeMap(comparator).putAll(map); + new TreeMap(comparator).putAll(map); test = true; - } catch (final RuntimeException e) { + } catch (RuntimeException e) { test = false; } optimizedTreeMapPutAll = test; - final SortedSet set = new PresortedSet(comparator); + SortedSet set = new PresortedSet(comparator); set.addAll(map.keySet()); try { - new TreeSet(comparator).addAll(set); + new TreeSet(comparator).addAll(set); test = true; - } catch (final RuntimeException e) { + } catch (RuntimeException e) { test = false; } optimizedTreeSetAddAll = test; try { new SimpleDateFormat("z").parse("UTC"); test = true; - } catch (final ParseException e) { + } catch (ParseException e) { test = false; } canParseUTCDateFormat = test; try { + new SimpleDateFormat("X").parse("Z"); + test = true; + } catch (final ParseException e) { + test = false; + } catch (final IllegalArgumentException e) { + test = false; + } + canParseISO8601TimeZoneInDateFormat = test; + try { test = new CustomObjectOutputStream(null) != null; - } catch (final RuntimeException e) { + } catch (RuntimeException e) { test = false; - } catch (final IOException e) { + } catch (IOException e) { test = false; } canCreateDerivedObjectOutputStream = test; - + isAWTAvailable = loadClassForName("java.awt.Color", false) != null; isSwingAvailable = loadClassForName("javax.swing.LookAndFeel", false) != null; isSQLAvailable = loadClassForName("java.sql.Date") != null; } - + /** * @deprecated As of 1.4.5 use the static methods of JVM. */ - @Deprecated public JVM() { } - + /** - * Parses the java version system property to determine the major java version, i.e. 1.x - * + * Parses the java version system property to determine the major java version, + * i.e. 1.x + * * @return A float of the form 1.x */ private static final float getMajorJavaVersion() { try { return isAndroid() ? 1.5f : Float.parseFloat(System.getProperty("java.specification.version")); - } catch (final NumberFormatException e) { + } catch ( NumberFormatException e ){ // Some JVMs may not conform to the x.y.z java.version format return DEFAULT_JAVA_VERSION; } @@ -202,29 +197,27 @@ /** * @deprecated As of 1.4.4, minimal JDK version is 1.4 already */ - @Deprecated public static boolean is14() { return majorJavaVersion >= 1.4f; } /** - * @deprecated As of 1.4.4, minimal JDK version will be 1.6 for next major release + * @deprecated As of 1.4.4, minimal JDK version will be 1.7 for next major release */ - @Deprecated public static boolean is15() { return majorJavaVersion >= 1.5f; } /** - * @deprecated As of 1.4.4, minimal JDK version will be 1.6 for next major release + * @deprecated As of 1.4.4, minimal JDK version will be 1.7 for next major release */ - @Deprecated public static boolean is16() { return majorJavaVersion >= 1.6f; } /** * @since 1.4 + * @deprecated As of 1.4.10, minimal JDK version will be 1.7 for next major release */ public static boolean is17() { return majorJavaVersion >= 1.7f; @@ -237,8 +230,23 @@ return majorJavaVersion >= 1.8f; } + /** + * @since 1.4.8 + * @deprecated As of upcoming use {@link #is9()} + */ + public static boolean is19() { + return majorJavaVersion >= 1.9f; + } + + /** + * @since 1.4.10 + */ + public static boolean is9() { + return majorJavaVersion >= 9f; + } + private static boolean isIBM() { - return vendor.indexOf("IBM") != -1; + return vendor.indexOf("IBM") != -1; } /** @@ -247,46 +255,41 @@ private static boolean isAndroid() { return vendor.indexOf("Android") != -1; } - + /** * Load a XStream class for the given name. - *

      - * This method is not meant to use loading arbitrary classes. It is used by XStream bootstrap until it is able to - * use the user provided or the default {@link ClassLoader}. - *

      * + *

      This method is not meant to use loading arbitrary classes. It is used by XStream bootstrap + * until it is able to use the user provided or the default {@link ClassLoader}.

      + * * @since 1.4.5 */ - public static Class loadClassForName(final String name) { + public static Class loadClassForName(String name) { return loadClassForName(name, true); } /** * @deprecated As of 1.4.5 use {@link #loadClassForName(String)} */ - @Deprecated - public Class loadClass(final String name) { + public Class loadClass(String name) { return loadClassForName(name, true); } /** * Load a XStream class for the given name. - *

      - * This method is not meant to use loading arbitrary classes. It is used by XStream bootstrap until it is able to - * use the user provided or the default {@link ClassLoader}. - *

      * + *

      This method is not meant to use loading arbitrary classes. It is used by XStream bootstrap + * until it is able to use the user provided or the default {@link ClassLoader}.

      + * * @since 1.4.5 */ - public static Class loadClassForName(final String name, final boolean initialize) { + public static Class loadClassForName(String name, boolean initialize) { try { - @SuppressWarnings("unchecked") - final Class clazz = (Class)Class.forName(name, initialize, JVM.class - .getClassLoader()); + Class clazz = Class.forName(name, initialize, JVM.class.getClassLoader()); return clazz; - } catch (final LinkageError e) { + } catch (LinkageError e) { return null; - } catch (final ClassNotFoundException e) { + } catch (ClassNotFoundException e) { return null; } } @@ -295,87 +298,84 @@ * @since 1.4.4 * @deprecated As of 1.4.5 use {@link #loadClassForName(String, boolean)} */ - @Deprecated - public Class loadClass(final String name, final boolean initialize) { + public Class loadClass(String name, boolean initialize) { return loadClassForName(name, initialize); } - + /** * Create the best matching ReflectionProvider. * * @return a new instance * @since 1.4.5 */ public static ReflectionProvider newReflectionProvider() { - return DependencyInjectionFactory.newInstance(reflectionProviderType); + return (ReflectionProvider)DependencyInjectionFactory.newInstance(reflectionProviderType, null); } - + /** * Create the best matching ReflectionProvider. - * + * * @param dictionary the FieldDictionary to use by the ReflectionProvider * @return a new instance * @since 1.4.5 */ - public static ReflectionProvider newReflectionProvider(final FieldDictionary dictionary) { - return DependencyInjectionFactory.newInstance(reflectionProviderType, dictionary); + public static ReflectionProvider newReflectionProvider(FieldDictionary dictionary) { + return (ReflectionProvider)DependencyInjectionFactory.newInstance(reflectionProviderType, new Object[]{ dictionary }); } - + /** - * Get the XMLInputFactory implementation used normally by the current Java runtime as standard. + * Get the XMLInputFactory implementation used normally by the current Java runtime as + * standard. *

      - * In contrast to XMLInputFactory.newFactory() this method will ignore any implementations provided with the system - * property javax.xml.stream.XMLInputFactory, implementations configured in lib/stax.properties or - * registered with the Service API. + * In contrast to XMLInputFactory.newFactory() this method will ignore any implementations + * provided with the system property javax.xml.stream.XMLInputFactory, + * implementations configured in lib/stax.properties or registered with the Service + * API. *

      * * @return the XMLInputFactory implementation or null * @throws ClassNotFoundException if the standard class cannot be found * @since 1.4.5 */ - @SuppressWarnings("unchecked") - public static Class getStaxInputFactory() throws ClassNotFoundException { + public static Class getStaxInputFactory() throws ClassNotFoundException { if (is16()) { if (isIBM()) { - return (Class)Class.forName("com.ibm.xml.xlxp.api.stax.XMLInputFactoryImpl"); + return Class.forName("com.ibm.xml.xlxp.api.stax.XMLInputFactoryImpl"); } else { - return (Class)Class - .forName("com.sun.xml.internal.stream.XMLInputFactoryImpl"); + return Class.forName("com.sun.xml.internal.stream.XMLInputFactoryImpl"); } } return null; } - + /** - * Get the XMLOutputFactory implementation used normally by the current Java runtime as standard. + * Get the XMLOutputFactory implementation used normally by the current Java runtime as + * standard. *

      - * In contrast to XMLOutputFactory.newFactory() this method will ignore any implementations provided with the system - * property javax.xml.stream.XMLOutputFactory, implementations configured in lib/stax.properties - * or registered with the Service API. + * In contrast to XMLOutputFactory.newFactory() this method will ignore any implementations + * provided with the system property javax.xml.stream.XMLOutputFactory, + * implementations configured in lib/stax.properties or registered with the Service + * API. *

      * * @return the XMLOutputFactory implementation or null * @throws ClassNotFoundException if the standard class cannot be found * @since 1.4.5 */ - @SuppressWarnings("unchecked") - public static Class getStaxOutputFactory() throws ClassNotFoundException { + public static Class getStaxOutputFactory() throws ClassNotFoundException { if (is16()) { if (isIBM()) { - return (Class)Class - .forName("com.ibm.xml.xlxp.api.stax.XMLOutputFactoryImpl"); + return Class.forName("com.ibm.xml.xlxp.api.stax.XMLOutputFactoryImpl"); } else { - return (Class)Class - .forName("com.sun.xml.internal.stream.XMLOutputFactoryImpl"); + return Class.forName("com.sun.xml.internal.stream.XMLOutputFactoryImpl"); } } return null; } - + /** * @deprecated As of 1.4.5 use {@link #newReflectionProvider()} */ - @Deprecated public synchronized ReflectionProvider bestReflectionProvider() { if (reflectionProvider == null) { reflectionProvider = newReflectionProvider(); @@ -394,14 +394,12 @@ /** * @deprecated As of 1.4.5 */ - @Deprecated public static boolean reverseFieldDefinition() { return reverseFieldOrder; } /** * Checks if AWT is available. - * * @since 1.4.5 */ public static boolean isAWTAvailable() { @@ -410,17 +408,14 @@ /** * Checks if the jvm supports awt. - * * @deprecated As of 1.4.5 use {@link #isAWTAvailable()} */ - @Deprecated public boolean supportsAWT() { - return isAWTAvailable; + return this.isAWTAvailable; } /** * Checks if Swing is available. - * * @since 1.4.5 */ public static boolean isSwingAvailable() { @@ -429,17 +424,14 @@ /** * Checks if the jvm supports swing. - * * @deprecated As of 1.4.5 use {@link #isSwingAvailable()} */ - @Deprecated public boolean supportsSwing() { - return isSwingAvailable; + return this.isSwingAvailable; } /** * Checks if SQL is available. - * * @since 1.4.5 */ public static boolean isSQLAvailable() { @@ -448,12 +440,10 @@ /** * Checks if the jvm supports sql. - * * @deprecated As of 1.4.5 use {@link #isSQLAvailable()} */ - @Deprecated public boolean supportsSQL() { - return isSQLAvailable; + return this.isSQLAvailable; } /** @@ -464,7 +454,7 @@ public static boolean hasOptimizedTreeSetAddAll() { return optimizedTreeSetAddAll; } - + /** * Checks if TreeMap.putAll is optimized for SortedMap argument. * @@ -479,6 +469,13 @@ } /** + * @since 1.4.8 + */ + public static boolean canParseISO8601TimeZoneInDateFormat() { + return canParseISO8601TimeZoneInDateFormat; + } + + /** * @since 1.4.6 */ public static boolean canCreateDerivedObjectOutputStream() { @@ -488,12 +485,10 @@ /** * @deprecated As of 1.4.5 no functionality */ - @Deprecated - @Override public void flushCache() { } - - public static void main(final String... args) { + + public static void main(String[] args) { boolean reverseJDK = false; Field[] fields = AttributedString.class.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { @@ -515,19 +510,19 @@ String staxInputFactory = null; try { staxInputFactory = getStaxInputFactory().getName(); - } catch (final ClassNotFoundException e) { + } catch (ClassNotFoundException e) { staxInputFactory = e.getMessage(); - } catch (final NullPointerException e) { + } catch (NullPointerException e) { } - + String staxOutputFactory = null; try { staxOutputFactory = getStaxOutputFactory().getName(); - } catch (final ClassNotFoundException e) { + } catch (ClassNotFoundException e) { staxOutputFactory = e.getMessage(); - } catch (final NullPointerException e) { + } catch (NullPointerException e) { } - + System.out.println("XStream JVM diagnostics"); System.out.println("java.specification.version: " + System.getProperty("java.specification.version")); System.out.println("java.specification.vendor: " + System.getProperty("java.specification.vendor")); @@ -549,7 +544,6 @@ System.out.println("Can parse UTC date format: " + canParseUTCDateFormat()); System.out.println("Can create derive ObjectOutputStream: " + canCreateDerivedObjectOutputStream()); System.out.println("Reverse field order detected for JDK: " + reverseJDK); - System.out - .println("Reverse field order detected (only if JVM class itself has been compiled): " + reverseLocal); + System.out.println("Reverse field order detected (only if JVM class itself has been compiled): " + reverseLocal); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/MapBackedDataHolder.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/MapBackedDataHolder.java (.../MapBackedDataHolder.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/MapBackedDataHolder.java (.../MapBackedDataHolder.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,37 +11,33 @@ */ package com.thoughtworks.xstream.core; +import com.thoughtworks.xstream.converters.DataHolder; + import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import com.thoughtworks.xstream.converters.DataHolder; - - public class MapBackedDataHolder implements DataHolder { - private final Map map; + private final Map map; public MapBackedDataHolder() { - this(new HashMap()); + this(new HashMap()); } - public MapBackedDataHolder(final Map map) { + public MapBackedDataHolder(Map map) { this.map = map; } - @Override - public Object get(final Object key) { + public Object get(Object key) { return map.get(key); } - @Override - public void put(final Object key, final Object value) { + public void put(Object key, Object value) { map.put(key, value); } - @Override - public Iterator keys() { + public Iterator keys() { return Collections.unmodifiableCollection(map.keySet()).iterator(); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByIdMarshaller.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByIdMarshaller.java (.../ReferenceByIdMarshaller.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByIdMarshaller.java (.../ReferenceByIdMarshaller.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,40 +16,38 @@ import com.thoughtworks.xstream.io.path.Path; import com.thoughtworks.xstream.mapper.Mapper; +public class ReferenceByIdMarshaller extends AbstractReferenceMarshaller { -public class ReferenceByIdMarshaller extends AbstractReferenceMarshaller { - private final IDGenerator idGenerator; public static interface IDGenerator { String next(Object item); } - public ReferenceByIdMarshaller( - final HierarchicalStreamWriter writer, final ConverterLookup converterLookup, final Mapper mapper, - final IDGenerator idGenerator) { + public ReferenceByIdMarshaller(HierarchicalStreamWriter writer, + ConverterLookup converterLookup, + Mapper mapper, + IDGenerator idGenerator) { super(writer, converterLookup, mapper); this.idGenerator = idGenerator; } - public ReferenceByIdMarshaller( - final HierarchicalStreamWriter writer, final ConverterLookup converterLookup, final Mapper mapper) { + public ReferenceByIdMarshaller(HierarchicalStreamWriter writer, + ConverterLookup converterLookup, + Mapper mapper) { this(writer, converterLookup, mapper, new SequenceGenerator(1)); } - @Override - protected String createReference(final Path currentPath, final String existingReferenceKey) { + protected String createReference(Path currentPath, Object existingReferenceKey) { return existingReferenceKey.toString(); } - @Override - protected String createReferenceKey(final Path currentPath, final Object item) { + protected Object createReferenceKey(Path currentPath, Object item) { return idGenerator.next(item); } - @Override - protected void fireValidReference(final String referenceKey) { - final String attributeName = getMapper().aliasForSystemAttribute("id"); + protected void fireValidReference(Object referenceKey) { + String attributeName = getMapper().aliasForSystemAttribute("id"); if (attributeName != null) { writer.addAttribute(attributeName, referenceKey.toString()); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByIdMarshallingStrategy.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByIdMarshallingStrategy.java (.../ReferenceByIdMarshallingStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByIdMarshallingStrategy.java (.../ReferenceByIdMarshallingStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,18 +16,15 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; - public class ReferenceByIdMarshallingStrategy extends AbstractTreeMarshallingStrategy { - @Override - protected TreeUnmarshaller createUnmarshallingContext(final Object root, final HierarchicalStreamReader reader, - final ConverterLookup converterLookup, final Mapper mapper) { + protected TreeUnmarshaller createUnmarshallingContext(Object root, + HierarchicalStreamReader reader, ConverterLookup converterLookup, Mapper mapper) { return new ReferenceByIdUnmarshaller(root, reader, converterLookup, mapper); } - @Override - protected TreeMarshaller createMarshallingContext(final HierarchicalStreamWriter writer, - final ConverterLookup converterLookup, final Mapper mapper) { + protected TreeMarshaller createMarshallingContext( + HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper) { return new ReferenceByIdMarshaller(writer, converterLookup, mapper); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByIdUnmarshaller.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByIdUnmarshaller.java (.../ReferenceByIdUnmarshaller.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByIdUnmarshaller.java (.../ReferenceByIdUnmarshaller.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -15,23 +15,19 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.mapper.Mapper; +public class ReferenceByIdUnmarshaller extends AbstractReferenceUnmarshaller { -public class ReferenceByIdUnmarshaller extends AbstractReferenceUnmarshaller { - - public ReferenceByIdUnmarshaller( - final Object root, final HierarchicalStreamReader reader, final ConverterLookup converterLookup, - final Mapper mapper) { + public ReferenceByIdUnmarshaller(Object root, HierarchicalStreamReader reader, + ConverterLookup converterLookup, Mapper mapper) { super(root, reader, converterLookup, mapper); } - @Override - protected String getReferenceKey(final String reference) { + protected Object getReferenceKey(String reference) { return reference; } - @Override - protected String getCurrentReferenceKey() { - final String attributeName = getMapper().aliasForSystemAttribute("id"); + protected Object getCurrentReferenceKey() { + String attributeName = getMapper().aliasForSystemAttribute("id"); return attributeName == null ? null : reader.getAttribute(attributeName); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByXPathMarshaller.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByXPathMarshaller.java (.../ReferenceByXPathMarshaller.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByXPathMarshaller.java (.../ReferenceByXPathMarshaller.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,35 +16,26 @@ import com.thoughtworks.xstream.io.path.Path; import com.thoughtworks.xstream.mapper.Mapper; +public class ReferenceByXPathMarshaller extends AbstractReferenceMarshaller { -public class ReferenceByXPathMarshaller extends AbstractReferenceMarshaller { - private final int mode; - public ReferenceByXPathMarshaller( - final HierarchicalStreamWriter writer, final ConverterLookup converterLookup, final Mapper mapper, - final int mode) { + public ReferenceByXPathMarshaller(HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper, int mode) { super(writer, converterLookup, mapper); this.mode = mode; } - @Override - protected String createReference(final Path currentPath, final Path existingReferenceKey) { - final Path existingPath = existingReferenceKey; - final Path referencePath = (mode & ReferenceByXPathMarshallingStrategy.ABSOLUTE) > 0 - ? existingPath - : currentPath.relativeTo(existingPath); - return (mode & ReferenceByXPathMarshallingStrategy.SINGLE_NODE) > 0 ? referencePath.explicit() : referencePath - .toString(); + protected String createReference(Path currentPath, Object existingReferenceKey) { + Path existingPath = (Path)existingReferenceKey; + Path referencePath = (mode & ReferenceByXPathMarshallingStrategy.ABSOLUTE) > 0 ? existingPath : currentPath.relativeTo(existingPath); + return (mode & ReferenceByXPathMarshallingStrategy.SINGLE_NODE) > 0 ? referencePath.explicit() : referencePath.toString(); } - @Override - protected Path createReferenceKey(final Path currentPath, final Object item) { + protected Object createReferenceKey(Path currentPath, Object item) { return currentPath; } - @Override - protected void fireValidReference(final Path referenceKey) { + protected void fireValidReference(Object referenceKey) { // nothing to do } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByXPathMarshallingStrategy.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByXPathMarshallingStrategy.java (.../ReferenceByXPathMarshallingStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByXPathMarshallingStrategy.java (.../ReferenceByXPathMarshallingStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,27 +16,24 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; - public class ReferenceByXPathMarshallingStrategy extends AbstractTreeMarshallingStrategy { public static int RELATIVE = 0; public static int ABSOLUTE = 1; public static int SINGLE_NODE = 2; private final int mode; - public ReferenceByXPathMarshallingStrategy(final int mode) { + public ReferenceByXPathMarshallingStrategy(int mode) { this.mode = mode; } - @Override - protected TreeUnmarshaller createUnmarshallingContext(final Object root, final HierarchicalStreamReader reader, - final ConverterLookup converterLookup, final Mapper mapper) { + protected TreeUnmarshaller createUnmarshallingContext(Object root, + HierarchicalStreamReader reader, ConverterLookup converterLookup, Mapper mapper) { return new ReferenceByXPathUnmarshaller(root, reader, converterLookup, mapper); } - @Override - protected TreeMarshaller createMarshallingContext(final HierarchicalStreamWriter writer, - final ConverterLookup converterLookup, final Mapper mapper) { + protected TreeMarshaller createMarshallingContext( + HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper) { return new ReferenceByXPathMarshaller(writer, converterLookup, mapper, mode); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByXPathUnmarshaller.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByXPathUnmarshaller.java (.../ReferenceByXPathUnmarshaller.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferenceByXPathUnmarshaller.java (.../ReferenceByXPathUnmarshaller.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -19,31 +19,25 @@ import com.thoughtworks.xstream.io.path.PathTrackingReader; import com.thoughtworks.xstream.mapper.Mapper; +public class ReferenceByXPathUnmarshaller extends AbstractReferenceUnmarshaller { -public class ReferenceByXPathUnmarshaller extends AbstractReferenceUnmarshaller { - - private final PathTracker pathTracker = new PathTracker(); + private PathTracker pathTracker = new PathTracker(); protected boolean isNameEncoding; - public ReferenceByXPathUnmarshaller( - final Object root, final HierarchicalStreamReader reader, final ConverterLookup converterLookup, - final Mapper mapper) { + public ReferenceByXPathUnmarshaller(Object root, HierarchicalStreamReader reader, + ConverterLookup converterLookup, Mapper mapper) { super(root, reader, converterLookup, mapper); this.reader = new PathTrackingReader(reader, pathTracker); isNameEncoding = reader.underlyingReader() instanceof AbstractReader; } - @Override - protected Path getReferenceKey(final String reference) { - final Path path = new Path(isNameEncoding - ? ((AbstractReader)reader.underlyingReader()).decodeNode(reference) - : reference); + protected Object getReferenceKey(String reference) { + final Path path = new Path(isNameEncoding ? ((AbstractReader)reader.underlyingReader()).decodeNode(reference) : reference); // We have absolute references, if path starts with '/' return reference.charAt(0) != '/' ? pathTracker.getPath().apply(path) : path; } - @Override - protected Path getCurrentReferenceKey() { + protected Object getCurrentReferenceKey() { return pathTracker.getPath(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferencingMarshallingContext.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferencingMarshallingContext.java (.../ReferencingMarshallingContext.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/ReferencingMarshallingContext.java (.../ReferencingMarshallingContext.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,41 +13,38 @@ import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.io.path.Path; - /** - * A {@link MarshallingContext} that manages references. + * A {@link MarshallingContext} that manages references. * * @author Jörg Schaible * @since 1.4 */ -public interface ReferencingMarshallingContext extends MarshallingContext { - +public interface ReferencingMarshallingContext extends MarshallingContext { + /** * Retrieve the current path. * * @return the current path * @since 1.4 * @deprecated As of 1.4.2 */ - @Deprecated Path currentPath(); - + /** - * Request the reference key for the given item + * Request the reference key for the given item * * @param item the item to lookup * @return the reference key or null * @since 1.4 */ - K lookupReference(Object item); - + Object lookupReference(Object item); + /** * Replace the currently marshalled item. - *

      - * Use this method only, if you know exactly what you do! It is a special solution for Serializable - * types that make usage of the writeReplace method where the replacing object itself is referenced. - *

      * + *

      Use this method only, if you know exactly what you do! It is a special solution for + * Serializable types that make usage of the writeReplace method where the replacing object itself is referenced.

      + * * @param original the original item to convert * @param replacement the replacement item that is converted instead * @since 1.4 Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/SequenceGenerator.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/SequenceGenerator.java (.../SequenceGenerator.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/SequenceGenerator.java (.../SequenceGenerator.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -15,12 +15,11 @@ private int counter; - public SequenceGenerator(final int startsAt) { - counter = startsAt; + public SequenceGenerator(int startsAt) { + this.counter = startsAt; } - @Override - public String next(final Object item) { + public String next(Object item) { return String.valueOf(counter++); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/TreeMarshaller.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/TreeMarshaller.java (.../TreeMarshaller.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/TreeMarshaller.java (.../TreeMarshaller.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,46 +11,45 @@ */ package com.thoughtworks.xstream.core; -import java.util.Iterator; - import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.ConverterLookup; import com.thoughtworks.xstream.converters.DataHolder; import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.core.util.ObjectIdDictionary; -import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper; import com.thoughtworks.xstream.mapper.Mapper; +import java.util.Iterator; + public class TreeMarshaller implements MarshallingContext { protected HierarchicalStreamWriter writer; protected ConverterLookup converterLookup; - private final Mapper mapper; - private final ObjectIdDictionary parentObjects = new ObjectIdDictionary(); + private Mapper mapper; + private ObjectIdDictionary parentObjects = new ObjectIdDictionary(); private DataHolder dataHolder; public TreeMarshaller( - final HierarchicalStreamWriter writer, final ConverterLookup converterLookup, final Mapper mapper) { + HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper) { this.writer = writer; this.converterLookup = converterLookup; this.mapper = mapper; } - @Override - public void convertAnother(final Object item) { + public void convertAnother(Object item) { convertAnother(item, null); } - @Override - public void convertAnother(final Object item, Converter converter) { + public void convertAnother(Object item, Converter converter) { if (converter == null) { converter = converterLookup.lookupConverterForType(item.getClass()); } else { if (!converter.canConvert(item.getClass())) { - final ConversionException e = new ConversionException("Explicit selected converter cannot handle item"); + ConversionException e = new ConversionException( + "Explicit selected converter cannot handle item"); e.add("item-type", item.getClass().getName()); e.add("converter-type", converter.getClass().getName()); throw e; @@ -59,9 +58,10 @@ convert(item, converter); } - protected void convert(final Object item, final Converter converter) { + protected void convert(Object item, Converter converter) { if (parentObjects.containsId(item)) { - final ConversionException e = new CircularReferenceException("Recursive reference to parent object"); + ConversionException e = new CircularReferenceException( + "Recursive reference to parent object"); e.add("item-type", item.getClass().getName()); e.add("converter-type", converter.getClass().getName()); throw e; @@ -71,33 +71,30 @@ parentObjects.removeId(item); } - public void start(final Object item, final DataHolder dataHolder) { + 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()); + ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper + .serializedClass(item.getClass()), item.getClass()); convertAnother(item); writer.endNode(); } } - @Override - public Object get(final Object key) { + public Object get(Object key) { lazilyCreateDataHolder(); return dataHolder.get(key); } - @Override - public void put(final Object key, final Object value) { + public void put(Object key, Object value) { lazilyCreateDataHolder(); dataHolder.put(key, value); } - @Override - public Iterator keys() { + public Iterator keys() { lazilyCreateDataHolder(); return dataHolder.keys(); } @@ -109,12 +106,12 @@ } protected Mapper getMapper() { - return mapper; + return this.mapper; } public static class CircularReferenceException extends ConversionException { - public CircularReferenceException(final String msg) { + public CircularReferenceException(String msg) { super(msg); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/TreeMarshallingStrategy.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/TreeMarshallingStrategy.java (.../TreeMarshallingStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/TreeMarshallingStrategy.java (.../TreeMarshallingStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,18 +16,15 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; - public class TreeMarshallingStrategy extends AbstractTreeMarshallingStrategy { - @Override - protected TreeUnmarshaller createUnmarshallingContext(final Object root, final HierarchicalStreamReader reader, - final ConverterLookup converterLookup, final Mapper mapper) { + protected TreeUnmarshaller createUnmarshallingContext(Object root, + HierarchicalStreamReader reader, ConverterLookup converterLookup, Mapper mapper) { return new TreeUnmarshaller(root, reader, converterLookup, mapper); } - @Override - protected TreeMarshaller createMarshallingContext(final HierarchicalStreamWriter writer, - final ConverterLookup converterLookup, final Mapper mapper) { + protected TreeMarshaller createMarshallingContext( + HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper) { return new TreeMarshaller(writer, converterLookup, mapper); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/TreeUnmarshaller.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/TreeUnmarshaller.java (.../TreeUnmarshaller.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/TreeUnmarshaller.java (.../TreeUnmarshaller.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -29,36 +29,35 @@ public class TreeUnmarshaller implements UnmarshallingContext { - private final Object root; + private Object root; protected HierarchicalStreamReader reader; - private final ConverterLookup converterLookup; - private final Mapper mapper; - private final FastStack> types = new FastStack>(16); + private ConverterLookup converterLookup; + private Mapper mapper; + private FastStack types = new FastStack(16); private DataHolder dataHolder; - private final PrioritizedList validationList = new PrioritizedList(); + private final PrioritizedList validationList = new PrioritizedList(); public TreeUnmarshaller( - final Object root, final HierarchicalStreamReader reader, final ConverterLookup converterLookup, - final Mapper mapper) { + Object root, HierarchicalStreamReader reader, ConverterLookup converterLookup, + Mapper mapper) { this.root = root; this.reader = reader; this.converterLookup = converterLookup; this.mapper = mapper; } - @Override - public Object convertAnother(final Object parent, final Class type) { + public Object convertAnother(Object parent, Class type) { return convertAnother(parent, type, null); } - @Override - public Object convertAnother(final Object parent, Class type, Converter converter) { + public Object convertAnother(Object parent, Class type, Converter converter) { type = mapper.defaultImplementationOf(type); if (converter == null) { converter = converterLookup.lookupConverterForType(type); } else { if (!converter.canConvert(type)) { - final ConversionException e = new ConversionException("Explicit selected converter cannot handle type"); + ConversionException e = new ConversionException( + "Explicit selected converter cannot handle type"); e.add("item-type", type.getName()); e.add("converter-type", converter.getClass().getName()); throw e; @@ -67,24 +66,23 @@ return convert(parent, type, converter); } - protected Object convert(final Object parent, final Class type, final Converter converter) { + protected Object convert(Object parent, Class type, Converter converter) { try { types.push(type); - final Object result = converter.unmarshal(reader, this); + Object result = converter.unmarshal(reader, this); types.popSilently(); return result; - } catch (final ConversionException conversionException) { + } catch (ConversionException conversionException) { addInformationTo(conversionException, type, converter, parent); throw conversionException; - } catch (final RuntimeException e) { - final ConversionException conversionException = new ConversionException(e); + } catch (RuntimeException e) { + ConversionException conversionException = new ConversionException(e); addInformationTo(conversionException, type, converter, parent); throw conversionException; } } - private void addInformationTo(final ErrorWriter errorWriter, final Class type, final Converter converter, - final Object parent) { + private void addInformationTo(ErrorWriter errorWriter, Class type, Converter converter, Object parent) { errorWriter.add("class", type.getName()); errorWriter.add("required-type", getRequiredType().getName()); errorWriter.add("converter-type", converter.getClass().getName()); @@ -97,35 +95,29 @@ reader.appendErrors(errorWriter); } - @Override - public void addCompletionCallback(final Runnable work, final int priority) { + public void addCompletionCallback(Runnable work, int priority) { validationList.add(work, priority); } - @Override public Object currentObject() { return types.size() == 1 ? root : null; } - @Override - public Class getRequiredType() { - return types.peek(); + public Class getRequiredType() { + return (Class)types.peek(); } - @Override - public Object get(final Object key) { + public Object get(Object key) { lazilyCreateDataHolder(); return dataHolder.get(key); } - @Override - public void put(final Object key, final Object value) { + public void put(Object key, Object value) { lazilyCreateDataHolder(); dataHolder.put(key, value); } - @Override - public Iterator keys() { + public Iterator keys() { lazilyCreateDataHolder(); return dataHolder.keys(); } @@ -136,18 +128,20 @@ } } - public Object start(final DataHolder dataHolder) { + public Object start(DataHolder dataHolder) { this.dataHolder = dataHolder; - final Class type = HierarchicalStreams.readClassType(reader, mapper); - final Object result = convertAnother(null, type); - for (final Runnable runnable : validationList) { + 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; } protected Mapper getMapper() { - return mapper; + return this.mapper; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ArrayIterator.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ArrayIterator.java (.../ArrayIterator.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ArrayIterator.java (.../ArrayIterator.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2014 XStream Committers. + * Copyright (C) 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,35 +13,29 @@ import java.lang.reflect.Array; import java.util.Iterator; - /** - * Iterator for an array of arbitrary type. - * * @author Jörg Schaible + * * @since 1.4 */ -public class ArrayIterator implements Iterator { +public class ArrayIterator implements Iterator { private final Object array; private int idx; - private final int length; - - public ArrayIterator(final Object array) { + private int length; + public ArrayIterator(Object array) { this.array = array; length = Array.getLength(array); } - @Override public boolean hasNext() { return idx < length; } - @Override public Object next() { return Array.get(array, idx++); } - @Override public void remove() { - throw new UnsupportedOperationException("Remove from array"); + throw new UnsupportedOperationException("Remove from array"); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ClassLoaderReference.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ClassLoaderReference.java (.../ClassLoaderReference.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ClassLoaderReference.java (.../ClassLoaderReference.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,64 +12,63 @@ package com.thoughtworks.xstream.core.util; /** - * ClassLoader that refers to another ClassLoader, allowing a single instance to be passed around the codebase that can - * later have its destination changed. - * + * ClassLoader that refers to another ClassLoader, allowing a single instance to be passed around the codebase that + * can later have its destination changed. + * * @author Joe Walnes * @author Jörg Schaible * @since 1.1.1 * @deprecated As of 1.4.5 use {@link com.thoughtworks.xstream.core.ClassLoaderReference} instead */ -@Deprecated public class ClassLoaderReference extends ClassLoader { private transient ClassLoader reference; /** * @deprecated As of 1.4.5 use - * {@link com.thoughtworks.xstream.core.ClassLoaderReference#ClassLoaderReference(ClassLoader)} instead + * {@link com.thoughtworks.xstream.core.ClassLoaderReference#ClassLoaderReference(ClassLoader)} + * instead */ - @Deprecated - public ClassLoaderReference(final ClassLoader reference) { + public ClassLoaderReference(ClassLoader reference) { this.reference = reference; } /** - * @deprecated As of 1.4.5 use {@link com.thoughtworks.xstream.core.ClassLoaderReference#getReference()} + * @deprecated As of 1.4.5 use + * {@link com.thoughtworks.xstream.core.ClassLoaderReference#getReference()} * .loadClass(String) instead */ - @Deprecated - @Override - public Class loadClass(final String name) throws ClassNotFoundException { + public Class loadClass(String name) throws ClassNotFoundException { return reference.loadClass(name); } /** - * @deprecated As of 1.4.5 use {@link com.thoughtworks.xstream.core.ClassLoaderReference#getReference()} instead + * @deprecated As of 1.4.5 use + * {@link com.thoughtworks.xstream.core.ClassLoaderReference#getReference()} + * instead */ - @Deprecated public ClassLoader getReference() { return reference; } /** - * @deprecated As of 1.4.5 use {@link com.thoughtworks.xstream.core.ClassLoaderReference#setReference(ClassLoader)} + * @deprecated As of 1.4.5 use + * {@link com.thoughtworks.xstream.core.ClassLoaderReference#setReference(ClassLoader)} * instead */ - @Deprecated - public void setReference(final ClassLoader reference) { + public void setReference(ClassLoader reference) { this.reference = reference; } - + private Object writeReplace() { return new Replacement(); } - + static class Replacement { - + private Object readResolve() { return new ClassLoaderReference(new CompositeClassLoader()); } - + }; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Cloneables.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Cloneables.java (.../Cloneables.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Cloneables.java (.../Cloneables.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2010, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2010, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -23,40 +23,40 @@ * @since 1.4 */ public class Cloneables { - - @SuppressWarnings("unchecked") - public static T clone(final T o) { + + public static Object clone(Object o) { if (o instanceof Cloneable) { if (o.getClass().isArray()) { - final Class componentType = o.getClass().getComponentType(); + final Class componentType = o.getClass().getComponentType(); if (!componentType.isPrimitive()) { - return (T)((Object[])o).clone(); + return ((Object[])o).clone(); } else { int length = Array.getLength(o); final Object clone = Array.newInstance(componentType, length); while (length-- > 0) { Array.set(clone, length, Array.get(o, length)); } - return (T)clone; + + return clone; } } else { try { - final Method clone = o.getClass().getMethod("clone"); - return (T)clone.invoke(o); - } catch (final NoSuchMethodException e) { + Method clone = o.getClass().getMethod("clone", (Class[])null); + return clone.invoke(o, (Object[])null); + } catch (NoSuchMethodException e) { throw new ObjectAccessException("Cloneable type has no clone method", e); - } catch (final IllegalAccessException e) { + } catch (IllegalAccessException e) { throw new ObjectAccessException("Cannot clone Cloneable type", e); - } catch (final InvocationTargetException e) { + } catch (InvocationTargetException e) { throw new ObjectAccessException("Exception cloning Cloneable type", e.getCause()); } } } return null; } - - public static T cloneIfPossible(final T o) { - final T clone = clone(o); + + public static Object cloneIfPossible(Object o) { + Object clone = clone(o); return clone == null ? o : clone; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/CompositeClassLoader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/CompositeClassLoader.java (.../CompositeClassLoader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/CompositeClassLoader.java (.../CompositeClassLoader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2011, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,11 +11,11 @@ */ package com.thoughtworks.xstream.core.util; -import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -56,19 +56,19 @@ if (JVM.is17()) { // see http://www.cs.duke.edu/csed/java/jdk1.7/technotes/guides/lang/cl-mt.html try { - final Method m = ClassLoader.class.getDeclaredMethod("registerAsParallelCapable"); + Method m = ClassLoader.class.getDeclaredMethod("registerAsParallelCapable", (Class[])null); if (!m.isAccessible()) { m.setAccessible(true); } - m.invoke(null); - } catch (final Exception e) { + m.invoke(null, (Object[])null); + } catch (Exception e) { // ignore errors, JVM will synchronize class for Java 7 or higher } } } - private final ReferenceQueue queue = new ReferenceQueue(); - private final List> classLoaders = new ArrayList>(); + private final ReferenceQueue queue = new ReferenceQueue(); + private final List classLoaders = new ArrayList(); public CompositeClassLoader() { addInternal(Object.class.getClassLoader()); // bootstrap loader. @@ -79,53 +79,66 @@ * Add a loader to the n * @param classLoader */ - public synchronized void add(final ClassLoader classLoader) { + public synchronized void add(ClassLoader classLoader) { cleanup(); if (classLoader != null) { addInternal(classLoader); } } - private void addInternal(final ClassLoader classLoader) { - WeakReference refClassLoader = null; - for (final Iterator> iterator = classLoaders.iterator(); iterator.hasNext();) { - final WeakReference ref = iterator.next(); - final ClassLoader cl = ref.get(); + private void addInternal(ClassLoader classLoader) { + WeakReference refClassLoader = null; + for (Iterator iterator = classLoaders.iterator(); iterator.hasNext();) { + WeakReference ref = (WeakReference) iterator.next(); + ClassLoader cl = (ClassLoader)ref.get(); if (cl == null) { iterator.remove(); } else if (cl == classLoader) { iterator.remove(); refClassLoader = ref; } } - classLoaders.add(0, refClassLoader != null ? refClassLoader : new WeakReference(classLoader, queue)); + classLoaders.add(0, refClassLoader != null ? refClassLoader : new WeakReference(classLoader, queue)); } - @Override - public Class loadClass(final String name) throws ClassNotFoundException { - final List copy = new ArrayList(classLoaders.size()); - synchronized(this) { - cleanup(); - for(final WeakReference ref : classLoaders) { - final ClassLoader cl = ref.get(); - if (cl != null) { - copy.add(cl); + public Class loadClass(String name) throws ClassNotFoundException { + List copy = new ArrayList(classLoaders.size()) { + + public boolean addAll(Collection c) { + boolean result = false; + for(Iterator iter = c.iterator(); iter.hasNext(); ) { + result |= add(iter.next()); } + return result; } - } + public boolean add(Object ref) { + Object classLoader = ((WeakReference)ref).get(); + if (classLoader != null) { + return super.add(classLoader); + } + return false; + } + + }; + synchronized(this) { + cleanup(); + copy.addAll(classLoaders); + } + ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - for (final ClassLoader classLoader : copy) { + for (Iterator iterator = copy.iterator(); iterator.hasNext();) { + ClassLoader classLoader = (ClassLoader) iterator.next(); if (classLoader == contextClassLoader) { contextClassLoader = null; } try { return classLoader.loadClass(name); - } catch (final ClassNotFoundException notFound) { + } catch (ClassNotFoundException notFound) { // ok.. try another one } } - + // One last try - the context class loader associated with the current thread. Often used in j2ee servers. // Note: The contextClassLoader cannot be added to the classLoaders list up front as the thread that constructs // XStream is potentially different to thread that uses it. @@ -137,8 +150,8 @@ } private void cleanup() { - Reference ref; - while ((ref = queue.poll()) != null) + WeakReference ref; + while ((ref = (WeakReference)queue.poll()) != null) { classLoaders.remove(ref); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/CustomObjectInputStream.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/CustomObjectInputStream.java (.../CustomObjectInputStream.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/CustomObjectInputStream.java (.../CustomObjectInputStream.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2010, 2011, 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -20,138 +20,121 @@ import java.io.StreamCorruptedException; import java.util.Map; -import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.DataHolder; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; import com.thoughtworks.xstream.core.ClassLoaderReference; +import com.thoughtworks.xstream.io.StreamException; - public class CustomObjectInputStream extends ObjectInputStream { - private final FastStack callbacks = new FastStack(1); + private FastStack callbacks = new FastStack(1); private final ClassLoaderReference classLoaderReference; private static final String DATA_HOLDER_KEY = CustomObjectInputStream.class.getName(); public static interface StreamCallback { Object readFromStream() throws IOException; - - Map readFieldsFromStream() throws IOException; - + Map readFieldsFromStream() throws IOException; void defaultReadObject() throws IOException; - - void registerValidation(ObjectInputValidation validation, int priority) - throws NotActiveException, InvalidObjectException; - + void registerValidation(ObjectInputValidation validation, int priority) throws NotActiveException, InvalidObjectException; void close() throws IOException; } /** * @deprecated As of 1.4 use {@link #getInstance(DataHolder, StreamCallback, ClassLoader)} */ - @Deprecated - public static CustomObjectInputStream getInstance(final DataHolder whereFrom, - final CustomObjectInputStream.StreamCallback callback) { + public static CustomObjectInputStream getInstance(DataHolder whereFrom, CustomObjectInputStream.StreamCallback callback) { return getInstance(whereFrom, callback, (ClassLoader)null); } /** * @deprecated As of 1.4.5 use {@link #getInstance(DataHolder, StreamCallback, ClassLoaderReference)} */ - @Deprecated - public static synchronized CustomObjectInputStream getInstance(final DataHolder whereFrom, - final CustomObjectInputStream.StreamCallback callback, final ClassLoader classLoader) { + public static synchronized CustomObjectInputStream getInstance(DataHolder whereFrom, CustomObjectInputStream.StreamCallback callback, ClassLoader classLoader) { return getInstance(whereFrom, callback, new ClassLoaderReference(classLoader)); } - public static synchronized CustomObjectInputStream getInstance(final DataHolder whereFrom, - final CustomObjectInputStream.StreamCallback callback, final ClassLoaderReference classLoaderReference) { + public static synchronized CustomObjectInputStream getInstance(DataHolder whereFrom, CustomObjectInputStream.StreamCallback callback, ClassLoaderReference classLoaderReference) { try { - CustomObjectInputStream result = (CustomObjectInputStream)whereFrom.get(DATA_HOLDER_KEY); + CustomObjectInputStream result = (CustomObjectInputStream) whereFrom.get(DATA_HOLDER_KEY); if (result == null) { result = new CustomObjectInputStream(callback, classLoaderReference); whereFrom.put(DATA_HOLDER_KEY, result); } else { result.pushCallback(callback); } return result; - } catch (final IOException e) { - throw new ConversionException("Cannot create CustomObjectStream", e); + } catch (SecurityException e) { + throw new ObjectAccessException("Cannot create CustomObjectStream", e); + } catch (IOException e) { + throw new StreamException("Cannot create CustomObjectStream", e); } } /** - * Warning, this object is expensive to create (due to functionality inherited from superclass). Use the static - * fetch() method instead, wherever possible. - * + * Warning, this object is expensive to create (due to functionality inherited from superclass). + * Use the static fetch() method instead, wherever possible. + * * @see #getInstance(DataHolder, StreamCallback, ClassLoaderReference) */ - public CustomObjectInputStream(final StreamCallback callback, final ClassLoaderReference classLoaderReference) - throws IOException, SecurityException { + public CustomObjectInputStream(StreamCallback callback, ClassLoaderReference classLoaderReference) throws IOException, SecurityException { super(); - callbacks.push(callback); + this.callbacks.push(callback); this.classLoaderReference = classLoaderReference; } /** * @deprecated As of 1.4.5 use {@link #CustomObjectInputStream(StreamCallback, ClassLoaderReference)} */ - @Deprecated - public CustomObjectInputStream(final StreamCallback callback, final ClassLoader classLoader) - throws IOException, SecurityException { + public CustomObjectInputStream(StreamCallback callback, ClassLoader classLoader) throws IOException, SecurityException { this(callback, new ClassLoaderReference(classLoader)); } /** * Allows the CustomObjectInputStream (which is expensive to create) to be reused. */ - public void pushCallback(final StreamCallback callback) { - callbacks.push(callback); + public void pushCallback(StreamCallback callback) { + this.callbacks.push(callback); } - - public StreamCallback popCallback() { - return callbacks.pop(); + + public StreamCallback popCallback(){ + return (StreamCallback) this.callbacks.pop(); } - - public StreamCallback peekCallback() { - return callbacks.peek(); + + public StreamCallback peekCallback(){ + return (StreamCallback) this.callbacks.peek(); } - - @Override - protected Class resolveClass(final ObjectStreamClass desc) throws IOException, ClassNotFoundException { - final ClassLoader classLoader = classLoaderReference.getReference(); + + protected Class resolveClass(ObjectStreamClass desc) + throws IOException, ClassNotFoundException { + ClassLoader classLoader = classLoaderReference.getReference(); if (classLoader == null) { return super.resolveClass(desc); } else { return Class.forName(desc.getName(), false, classLoader); } } - @Override public void defaultReadObject() throws IOException { peekCallback().defaultReadObject(); } - @Override protected Object readObjectOverride() throws IOException { return peekCallback().readFromStream(); } - @Override public Object readUnshared() throws IOException, ClassNotFoundException { return readObject(); } - @Override public boolean readBoolean() throws IOException { return ((Boolean)peekCallback().readFromStream()).booleanValue(); } - @Override public byte readByte() throws IOException { return ((Byte)peekCallback().readFromStream()).byteValue(); } - @Override public int readUnsignedByte() throws IOException { int b = ((Byte)peekCallback().readFromStream()).byteValue(); if (b < 0) { @@ -160,37 +143,30 @@ return b; } - @Override public int readInt() throws IOException { return ((Integer)peekCallback().readFromStream()).intValue(); } - @Override public char readChar() throws IOException { return ((Character)peekCallback().readFromStream()).charValue(); } - @Override public float readFloat() throws IOException { return ((Float)peekCallback().readFromStream()).floatValue(); } - @Override public double readDouble() throws IOException { return ((Double)peekCallback().readFromStream()).doubleValue(); } - @Override public long readLong() throws IOException { return ((Long)peekCallback().readFromStream()).longValue(); } - @Override public short readShort() throws IOException { return ((Short)peekCallback().readFromStream()).shortValue(); } - @Override public int readUnsignedShort() throws IOException { int b = ((Short)peekCallback().readFromStream()).shortValue(); if (b < 0) { @@ -199,160 +175,132 @@ return b; } - @Override public String readUTF() throws IOException { return (String)peekCallback().readFromStream(); } - @Override - public void readFully(final byte[] buf) throws IOException { + public void readFully(byte[] buf) throws IOException { readFully(buf, 0, buf.length); } - @Override - public void readFully(final byte[] buf, final int off, final int len) throws IOException { - final byte[] b = (byte[])peekCallback().readFromStream(); + public void readFully(byte[] buf, int off, int len) throws IOException { + byte[] b = (byte[])peekCallback().readFromStream(); System.arraycopy(b, 0, buf, off, len); } - @Override public int read() throws IOException { return readUnsignedByte(); } - @Override - public int read(final byte[] buf, final int off, final int len) throws IOException { - final byte[] b = (byte[])peekCallback().readFromStream(); + public int read(byte[] buf, int off, int len) throws IOException { + byte[] b = (byte[])peekCallback().readFromStream(); if (b.length != len) { throw new StreamCorruptedException("Expected " + len + " bytes from stream, got " + b.length); } System.arraycopy(b, 0, buf, off, len); return len; } - @Override - public int read(final byte b[]) throws IOException { + public int read(byte b[]) throws IOException { return read(b, 0, b.length); } - @Override public GetField readFields() throws IOException { return new CustomGetField(peekCallback().readFieldsFromStream()); } private class CustomGetField extends GetField { - private final Map fields; + private Map fields; - public CustomGetField(final Map fields) { + public CustomGetField(Map fields) { this.fields = fields; } - @Override public ObjectStreamClass getObjectStreamClass() { throw new UnsupportedOperationException(); } - private Object get(final String name) { + private Object get(String name) { return fields.get(name); } - @Override - public boolean defaulted(final String name) { + public boolean defaulted(String name) { return !fields.containsKey(name); } - @Override - public byte get(final String name, final byte val) { + public byte get(String name, byte val) { return defaulted(name) ? val : ((Byte)get(name)).byteValue(); } - @Override - public char get(final String name, final char val) { + public char get(String name, char val) { return defaulted(name) ? val : ((Character)get(name)).charValue(); } - @Override - public double get(final String name, final double val) { + public double get(String name, double val) { return defaulted(name) ? val : ((Double)get(name)).doubleValue(); } - @Override - public float get(final String name, final float val) { + public float get(String name, float val) { return defaulted(name) ? val : ((Float)get(name)).floatValue(); } - @Override - public int get(final String name, final int val) { + public int get(String name, int val) { return defaulted(name) ? val : ((Integer)get(name)).intValue(); } - @Override - public long get(final String name, final long val) { + public long get(String name, long val) { return defaulted(name) ? val : ((Long)get(name)).longValue(); } - @Override - public short get(final String name, final short val) { + public short get(String name, short val) { return defaulted(name) ? val : ((Short)get(name)).shortValue(); } - @Override - public boolean get(final String name, final boolean val) { + public boolean get(String name, boolean val) { return defaulted(name) ? val : ((Boolean)get(name)).booleanValue(); } - @Override - public Object get(final String name, final Object val) { + public Object get(String name, Object val) { return defaulted(name) ? val : get(name); } } - @Override - public void registerValidation(final ObjectInputValidation validation, final int priority) - throws NotActiveException, InvalidObjectException { + public void registerValidation(ObjectInputValidation validation, int priority) throws NotActiveException, InvalidObjectException { peekCallback().registerValidation(validation, priority); } - @Override public void close() throws IOException { peekCallback().close(); } /****** Unsupported methods ******/ - @Override public int available() { throw new UnsupportedOperationException(); } - @Override public String readLine() { throw new UnsupportedOperationException(); } - @Override - public int skipBytes(final int len) { + public int skipBytes(int len) { throw new UnsupportedOperationException(); } - @Override - public long skip(final long n) { + public long skip(long n) { throw new UnsupportedOperationException(); } - @Override - public synchronized void mark(final int readlimit) { + public void mark(int readlimit) { throw new UnsupportedOperationException(); } - @Override - public synchronized void reset() { + public void reset() { throw new UnsupportedOperationException(); } - @Override public boolean markSupported() { return false; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/CustomObjectOutputStream.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/CustomObjectOutputStream.java (.../CustomObjectOutputStream.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/CustomObjectOutputStream.java (.../CustomObjectOutputStream.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,255 +14,217 @@ import java.io.IOException; import java.io.ObjectOutput; import java.io.ObjectOutputStream; -import java.util.LinkedHashMap; import java.util.Map; -import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.DataHolder; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; +import com.thoughtworks.xstream.io.StreamException; - public class CustomObjectOutputStream extends ObjectOutputStream { - private final FastStack callbacks = new FastStack(1); - private final FastStack customFields = new FastStack(1); + private FastStack callbacks = new FastStack(1); + private FastStack customFields = new FastStack(1); private static final String DATA_HOLDER_KEY = CustomObjectOutputStream.class.getName(); - public static synchronized CustomObjectOutputStream getInstance(final DataHolder whereFrom, - final StreamCallback callback) { + public static synchronized CustomObjectOutputStream getInstance(DataHolder whereFrom, StreamCallback callback) { try { - CustomObjectOutputStream result = (CustomObjectOutputStream)whereFrom.get(DATA_HOLDER_KEY); + CustomObjectOutputStream result = (CustomObjectOutputStream) whereFrom.get(DATA_HOLDER_KEY); if (result == null) { result = new CustomObjectOutputStream(callback); whereFrom.put(DATA_HOLDER_KEY, result); } else { result.pushCallback(callback); } return result; - } catch (final IOException e) { - throw new ConversionException("Cannot create CustomObjectStream", e); + } catch (SecurityException e) { + throw new ObjectAccessException("Cannot create CustomObjectStream", e); + } catch (IOException e) { + throw new StreamException("Cannot create CustomObjectStream", e); } } public static interface StreamCallback { void writeToStream(Object object) throws IOException; - - void writeFieldsToStream(Map fields) throws IOException; - + void writeFieldsToStream(Map fields) throws IOException; void defaultWriteObject() throws IOException; - void flush() throws IOException; - void close() throws IOException; } /** - * Warning, this object is expensive to create (due to functionality inherited from superclass). Use the static - * fetch() method instead, wherever possible. - * - * @see #getInstance(com.thoughtworks.xstream.converters.DataHolder, - * com.thoughtworks.xstream.core.util.CustomObjectOutputStream.StreamCallback) + * Warning, this object is expensive to create (due to functionality inherited from superclass). + * Use the static fetch() method instead, wherever possible. + * + * @see #getInstance(com.thoughtworks.xstream.converters.DataHolder, com.thoughtworks.xstream.core.util.CustomObjectOutputStream.StreamCallback) */ - public CustomObjectOutputStream(final StreamCallback callback) throws IOException, SecurityException { - callbacks.push(callback); + public CustomObjectOutputStream(StreamCallback callback) throws IOException, SecurityException { + this.callbacks.push(callback); } /** * Allows the CustomObjectOutputStream (which is expensive to create) to be reused. */ - public void pushCallback(final StreamCallback callback) { - callbacks.push(callback); + public void pushCallback(StreamCallback callback) { + this.callbacks.push(callback); } - - public StreamCallback popCallback() { - return callbacks.pop(); + + public StreamCallback popCallback(){ + return (StreamCallback) this.callbacks.pop(); } - - public StreamCallback peekCallback() { - return callbacks.peek(); + + public StreamCallback peekCallback(){ + return (StreamCallback) this.callbacks.peek(); } - + /*** Methods to delegate to callback ***/ - @Override public void defaultWriteObject() throws IOException { peekCallback().defaultWriteObject(); } - @Override - protected void writeObjectOverride(final Object obj) throws IOException { + protected void writeObjectOverride(Object obj) throws IOException { peekCallback().writeToStream(obj); } - @Override - public void writeBoolean(final boolean val) throws IOException { - peekCallback().writeToStream(Boolean.valueOf(val)); + public void writeBoolean(boolean val) throws IOException { + peekCallback().writeToStream(val ? Boolean.TRUE : Boolean.FALSE); // JDK 1.3 friendly } - @Override - public void writeByte(final int val) throws IOException { - peekCallback().writeToStream(Byte.valueOf((byte)val)); + public void writeByte(int val) throws IOException { + peekCallback().writeToStream(new Byte((byte) val)); } - @Override - public void writeInt(final int val) throws IOException { - peekCallback().writeToStream(Integer.valueOf(val)); + public void writeInt(int val) throws IOException { + peekCallback().writeToStream(new Integer(val)); } - @Override - public void writeChar(final int val) throws IOException { - peekCallback().writeToStream(Character.valueOf((char)val)); + public void writeChar(int val) throws IOException { + peekCallback().writeToStream(new Character((char)val)); } - @Override - public void writeDouble(final double val) throws IOException { - peekCallback().writeToStream(Double.valueOf(val)); + public void writeDouble(double val) throws IOException { + peekCallback().writeToStream(new Double(val)); } - @Override - public void writeFloat(final float val) throws IOException { - peekCallback().writeToStream(Float.valueOf(val)); + public void writeFloat(float val) throws IOException { + peekCallback().writeToStream(new Float(val)); } - @Override - public void writeLong(final long val) throws IOException { - peekCallback().writeToStream(Long.valueOf(val)); + public void writeLong(long val) throws IOException { + peekCallback().writeToStream(new Long(val)); } - @Override - public void writeShort(final int val) throws IOException { - peekCallback().writeToStream(Short.valueOf((short)val)); + public void writeShort(int val) throws IOException { + peekCallback().writeToStream(new Short((short) val)); } - @Override - public void write(final byte[] buf) throws IOException { + public void write(byte[] buf) throws IOException { peekCallback().writeToStream(buf); } - @Override - public void writeChars(final String str) throws IOException { + public void writeChars(String str) throws IOException { peekCallback().writeToStream(str.toCharArray()); } - @Override - public void writeUTF(final String str) throws IOException { + public void writeUTF(String str) throws IOException { peekCallback().writeToStream(str); } - @Override - public void write(final int val) throws IOException { - peekCallback().writeToStream(Byte.valueOf((byte)val)); + public void write(int val) throws IOException { + peekCallback().writeToStream(new Byte((byte) val)); } - @Override - public void write(final byte[] buf, final int off, final int len) throws IOException { - final byte[] b = new byte[len]; + public void write(byte[] buf, int off, int len) throws IOException { + byte[] b = new byte[len]; System.arraycopy(buf, off, b, 0, len); peekCallback().writeToStream(b); } - @Override public void flush() throws IOException { peekCallback().flush(); } - @Override public void close() throws IOException { peekCallback().close(); } - @Override public PutField putFields() { - final CustomPutField result = new CustomPutField(); + CustomPutField result = new CustomPutField(); customFields.push(result); return result; } - @Override public void writeFields() throws IOException { - final CustomPutField customPutField = customFields.pop(); + CustomPutField customPutField = (CustomPutField) customFields.pop(); peekCallback().writeFieldsToStream(customPutField.asMap()); } private class CustomPutField extends PutField { - private final Map fields = new LinkedHashMap(); + private final Map fields = new OrderRetainingMap(); - public Map asMap() { + public Map asMap() { return fields; } - @Override - public void write(final ObjectOutput out) throws IOException { + public void write(ObjectOutput out) throws IOException { peekCallback().writeToStream(asMap()); } - @Override - public void put(final String name, final Object val) { + public void put(String name, Object val) { fields.put(name, val); } - @Override - public void put(final String name, final byte val) { - put(name, Byte.valueOf(val)); + public void put(String name, byte val) { + put(name, new Byte(val)); } - @Override - public void put(final String name, final char val) { - put(name, Character.valueOf(val)); + public void put(String name, char val) { + put(name, new Character(val)); } - @Override - public void put(final String name, final double val) { - put(name, Double.valueOf(val)); + public void put(String name, double val) { + put(name, new Double(val)); } - @Override - public void put(final String name, final float val) { - put(name, Float.valueOf(val)); + public void put(String name, float val) { + put(name, new Float(val)); } - @Override - public void put(final String name, final int val) { - put(name, Integer.valueOf(val)); + public void put(String name, int val) { + put(name, new Integer(val)); } - @Override - public void put(final String name, final long val) { - put(name, Long.valueOf(val)); + public void put(String name, long val) { + put(name, new Long(val)); } - @Override - public void put(final String name, final short val) { - put(name, Short.valueOf(val)); + public void put(String name, short val) { + put(name, new Short(val)); } - @Override - public void put(final String name, final boolean val) { - put(name, Boolean.valueOf(val)); + public void put(String name, boolean val) { + put(name, val ? Boolean.TRUE : Boolean.FALSE); // JDK 1.3 friendly } } /****** Unsupported methods ******/ - @Override public void reset() { throw new UnsupportedOperationException(); } - @Override - public void useProtocolVersion(final int version) { + public void useProtocolVersion(int version) { throw new UnsupportedOperationException(); } - @Override - public void writeBytes(final String str) { + public void writeBytes(String str) { throw new UnsupportedOperationException(); } - @Override - public void writeUnshared(final Object obj) { + public void writeUnshared(Object obj) { throw new UnsupportedOperationException(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/DependencyInjectionFactory.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/DependencyInjectionFactory.java (.../DependencyInjectionFactory.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/DependencyInjectionFactory.java (.../DependencyInjectionFactory.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,11 +1,11 @@ /* - * Copyright (c) 2007, 2009, 2010, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (c) 2007, 2009, 2010, 2011, 2012, 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 30. March 2007 by Joerg Schaible */ package com.thoughtworks.xstream.core.util; @@ -23,7 +23,7 @@ /** * A dependency injection factory. - * + * * @author Jörg Schaible * @since 1.2.2 */ @@ -35,16 +35,16 @@ * matching the sequence of the dependencies' types match first. Otherwise all the types of the dependencies must * match one of the the parameters although no dependency is used twice. Use a {@link TypedNull} instance to inject * null as parameter. - * + * * @param type the type to create an instance of * @param dependencies the possible dependencies * @return the instantiated object * @throws ObjectAccessException if no instance can be generated * @throws IllegalArgumentException if more than 63 dependencies have been provided * @since 1.2.2 */ - public static T newInstance(final Class type, final Object... dependencies) { - return newInstance(null, type, dependencies); + public static Object newInstance(final Class type, final Object[] dependencies) { + return newInstance(type, dependencies, null); } /** @@ -53,76 +53,56 @@ * matching the sequence of the dependencies' types match first. Otherwise all the types of the dependencies must * match one of the the parameters although no dependency is used twice. Use a {@link TypedNull} instance to inject * null as parameter. - * + * * @param type the type to create an instance of * @param dependencies the possible dependencies * @param usedDependencies bit mask set by the method for all used dependencies (may be null) * @return the instantiated object * @throws ObjectAccessException if no instance can be generated * @throws IllegalArgumentException if more than 63 dependencies have been provided * @since 1.4 - * @deprecated As of upcoming use {@link #newInstance(BitSet, Class, Object...)} */ - @Deprecated - public static T newInstance(final Class type, final Object[] dependencies, final BitSet usedDependencies) { - return newInstance(usedDependencies, type, dependencies); - } - - /** - * Create an instance with dependency injection. The given dependencies are used to match the parameters of the - * constructors of the type. Constructors with most parameters are examined first. A parameter type sequence - * matching the sequence of the dependencies' types match first. Otherwise all the types of the dependencies must - * match one of the the parameters although no dependency is used twice. Use a {@link TypedNull} instance to inject - * null as parameter. - * - * @param usedDependencies bit mask set by the method for all used dependencies (may be null) - * @param type the type to create an instance of - * @param dependencies the possible dependencies - * @return the instantiated object - * @throws ObjectAccessException if no instance can be generated - * @throws IllegalArgumentException if more than 63 dependencies have been provided - * @since upcoming - */ - public static T newInstance(final BitSet usedDependencies, final Class type, final Object... dependencies) { + public static Object newInstance(final Class type, final Object[] dependencies, final BitSet usedDependencies) { if (dependencies != null && dependencies.length > 63) { throw new IllegalArgumentException("More than 63 arguments are not supported"); } - Constructor bestMatchingCtor = null; - final ArrayList matchingDependencies = new ArrayList(); - List possibleMatchingDependencies = null; + Constructor bestMatchingCtor = null; + final ArrayList matchingDependencies = new ArrayList(); + List possibleMatchingDependencies = null; long usedDeps = 0; long possibleUsedDeps = 0; if (dependencies != null && dependencies.length > 0) { // sort available ctors according their arity - final Constructor[] ctors = type.getConstructors(); + final Constructor[] ctors = type.getConstructors(); if (ctors.length > 1) { - Arrays.sort(ctors, new Comparator>() { - @Override - public int compare(final Constructor o1, final Constructor o2) { - return o2.getParameterTypes().length - o1.getParameterTypes().length; + Arrays.sort(ctors, new Comparator() { + public int compare(final Object o1, final Object o2) { + return ((Constructor)o2).getParameterTypes().length + - ((Constructor)o1).getParameterTypes().length; } }); } final TypedValue[] typedDependencies = new TypedValue[dependencies.length]; for (int i = 0; i < dependencies.length; i++) { Object dependency = dependencies[i]; - Class depType = dependency.getClass(); + Class depType = dependency.getClass(); if (depType.isPrimitive()) { depType = Primitives.box(depType); } else if (depType == TypedNull.class) { - depType = ((TypedNull)dependency).getType(); + depType = ((TypedNull)dependency).getType(); dependency = null; } + typedDependencies[i] = new TypedValue(depType, dependency); } - Constructor possibleCtor = null; + Constructor possibleCtor = null; int arity = Integer.MAX_VALUE; for (int i = 0; bestMatchingCtor == null && i < ctors.length; i++) { - final Constructor constructor = ctors[i]; - final Class[] parameterTypes = constructor.getParameterTypes(); + final Constructor constructor = ctors[i]; + final Class[] parameterTypes = constructor.getParameterTypes(); if (parameterTypes.length > dependencies.length) { continue; } else if (parameterTypes.length == 0) { @@ -131,7 +111,6 @@ } break; } - if (arity > parameterTypes.length) { if (possibleCtor != null) { continue; @@ -145,12 +124,12 @@ } } - // first approach: test the ctor params against the dependencies in the sequence of the parameter - // declaration + // first approach: test the ctor params against the dependencies in the sequence + // of the parameter declaration matchingDependencies.clear(); usedDeps = 0; for (int j = 0, k = 0; j < parameterTypes.length - && parameterTypes.length + k - j <= typedDependencies.length; k++) { + && parameterTypes.length + k - j <= typedDependencies.length; k++) { if (parameterTypes[j].isAssignableFrom(typedDependencies[k].type)) { matchingDependencies.add(typedDependencies[k].value); usedDeps |= 1L << k; @@ -164,26 +143,26 @@ if (bestMatchingCtor == null) { boolean possible = true; // assumption - // try to match all dependencies in the sequence of the parameter declaration + // try to match all dependencies in the sequence of the parameter + // declaration final TypedValue[] deps = new TypedValue[typedDependencies.length]; System.arraycopy(typedDependencies, 0, deps, 0, deps.length); matchingDependencies.clear(); usedDeps = 0; - for (final Class parameterType : parameterTypes) { + for (int j = 0; j < parameterTypes.length; j++ ) { int assignable = -1; for (int k = 0; k < deps.length; k++) { if (deps[k] == null) { continue; } - - if (deps[k].type == parameterType) { + if (deps[k].type == parameterTypes[j]) { assignable = k; // optimal match break; - } else if (parameterType.isAssignableFrom(deps[k].type)) { + } else if (parameterTypes[j].isAssignableFrom(deps[k].type)) { // use most specific type if (assignable < 0 - || deps[assignable].type != deps[k].type + || deps[assignable].type != deps[k].type && deps[assignable].type.isAssignableFrom(deps[k].type)) { assignable = k; } @@ -206,9 +185,7 @@ continue; } possibleCtor = constructor; - @SuppressWarnings("unchecked") - final List clone = (List)matchingDependencies.clone(); - possibleMatchingDependencies = clone; + possibleMatchingDependencies = (List)matchingDependencies.clone(); possibleUsedDeps = usedDeps; } } @@ -217,9 +194,10 @@ if (bestMatchingCtor == null) { if (possibleCtor == null) { usedDeps = 0; - throw new ObjectAccessException("Cannot construct " - + type.getName() - + ", none of the dependencies match any constructor's parameters"); + final ObjectAccessException ex = new ObjectAccessException( + "Cannot construct type, none of the arguments match any constructor's parameters"); + ex.add("construction-type", type.getName()); + throw ex; } else { bestMatchingCtor = possibleCtor; matchingDependencies.clear(); @@ -229,50 +207,50 @@ } } + Throwable th = null; try { - final T instance; + final Object instance; if (bestMatchingCtor == null) { instance = type.newInstance(); } else { - @SuppressWarnings("unchecked") - final T obj = (T)bestMatchingCtor.newInstance(matchingDependencies.toArray()); - instance = obj; + instance = bestMatchingCtor.newInstance(matchingDependencies.toArray()); } if (usedDependencies != null) { usedDependencies.clear(); int i = 0; - for(long l = 1; l < usedDeps; l <<= 1, ++i) { + for (long l = 1; l < usedDeps; l <<= 1, ++i) { if ((usedDeps & l) > 0) { usedDependencies.set(i); } } } - return instance; } catch (final InstantiationException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); + th = e; } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); + th = e; } catch (final InvocationTargetException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); + th = e.getCause(); } catch (final SecurityException e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); + th = e; } catch (final ExceptionInInitializerError e) { - throw new ObjectAccessException("Cannot construct " + type.getName(), e); + th = e; } + final ObjectAccessException ex = new ObjectAccessException("Cannot construct type", th); + ex.add("construction-type", type.getName()); + throw ex; } private static class TypedValue { - final Class type; + final Class type; final Object value; - public TypedValue(final Class type, final Object value) { + public TypedValue(final Class type, final Object value) { super(); this.type = type; this.value = value; } - @Override public String toString() { return type.getName() + ":" + value; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/FastField.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/FastField.java (.../FastField.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/FastField.java (.../FastField.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2010, 2014 XStream Committers. + * Copyright (C) 2008, 2010 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,25 +14,24 @@ private final String name; private final String declaringClass; - public FastField(final String definedIn, final String name) { + public FastField(String definedIn, String name) { this.name = name; - declaringClass = definedIn; + this.declaringClass = definedIn; } - public FastField(final Class definedIn, final String name) { + public FastField(Class definedIn, String name) { this(definedIn == null ? null : definedIn.getName(), name); } public String getName() { - return name; + return this.name; } public String getDeclaringClass() { - return declaringClass; + return this.declaringClass; } - @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (this == obj) { return true; } @@ -41,22 +40,20 @@ } if (obj instanceof FastField) { final FastField field = (FastField)obj; - if (declaringClass == null && field.declaringClass != null - || declaringClass != null && field.declaringClass == null) { + if ((declaringClass == null && field.declaringClass != null) + || (declaringClass != null && field.declaringClass == null)) { return false; } return name.equals(field.getName()) - && (declaringClass == null || declaringClass.equals(field.getDeclaringClass())); + && (declaringClass == null || declaringClass.equals(field.getDeclaringClass())); } return false; } - @Override public int hashCode() { return name.hashCode() ^ (declaringClass == null ? 0 : declaringClass.hashCode()); } - @Override public String toString() { return (declaringClass == null ? "" : declaringClass + ".") + name; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/FastStack.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/FastStack.java (.../FastStack.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/FastStack.java (.../FastStack.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,31 +11,22 @@ */ package com.thoughtworks.xstream.core.util; -import java.util.Arrays; - - /** * An array-based stack implementation. * * @author Joe Walnes * @author Jörg Schaible */ -public final class FastStack { +public final class FastStack { - private T[] stack; + private Object[] stack; private int pointer; - public FastStack(final int initialCapacity) { - @SuppressWarnings("unchecked") - final T[] array = getArray(initialCapacity); - stack = array; + public FastStack(int initialCapacity) { + stack = new Object[initialCapacity]; } - private T[] getArray(final int capacity, final T... t) { - return Arrays.copyOf(t, capacity); - } - - public T push(final T value) { + public Object push(Object value) { if (pointer + 1 >= stack.length) { resizeStack(stack.length * 2); } @@ -47,23 +38,23 @@ stack[--pointer] = null; } - public T pop() { - final T result = stack[--pointer]; - stack[pointer] = null; + public Object pop() { + final Object result = stack[--pointer]; + stack[pointer] = null; return result; } - public T peek() { + public Object peek() { return pointer == 0 ? null : stack[pointer - 1]; } - public Object replace(final T value) { - final T result = stack[pointer - 1]; + public Object replace(Object value) { + final Object result = stack[pointer - 1]; stack[pointer - 1] = value; return result; } - public void replaceSilently(final T value) { + public void replaceSilently(Object value) { stack[pointer - 1] = value; } @@ -75,20 +66,18 @@ return pointer > 0; } - public T get(final int i) { + public Object get(int i) { return stack[i]; } - private void resizeStack(final int newCapacity) { - @SuppressWarnings("unchecked") - final T[] newStack = getArray(newCapacity); + private void resizeStack(int newCapacity) { + Object[] newStack = new Object[newCapacity]; System.arraycopy(stack, 0, newStack, 0, Math.min(pointer, newCapacity)); stack = newStack; } - @Override public String toString() { - final StringBuffer result = new StringBuffer("["); + StringBuffer result = new StringBuffer("["); for (int i = 0; i < pointer; i++) { if (i > 0) { result.append(", "); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Fields.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Fields.java (.../Fields.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Fields.java (.../Fields.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,12 +1,12 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 06. April 2004 by Joe Walnes */ package com.thoughtworks.xstream.core.util; @@ -18,21 +18,21 @@ /** - * Slightly nicer way to find, get and set fields in classes. Wraps standard java.lang.reflect.Field calls but wraps - * wraps exception in XStreamExceptions. - * + * Slightly nicer way to find, get and set fields in classes. Wraps standard java.lang.reflect.Field calls and turns + * exceptions into XStreamExceptions. + * * @author Joe Walnes * @author Jörg Schaible */ public class Fields { - public static Field locate(final Class definedIn, final Class fieldType, final boolean isStatic) { + public static Field locate(final Class definedIn, final Class fieldType, final boolean isStatic) { Field field = null; try { final Field[] fields = definedIn.getDeclaredFields(); - for (final Field field2 : fields) { - if (Modifier.isStatic(field2.getModifiers()) == isStatic) { - if (fieldType.isAssignableFrom(field2.getType())) { - field = field2; + for(int i = 0; i < fields.length; ++i) { + if (Modifier.isStatic(fields[i].getModifiers()) == isStatic) { + if (fieldType.isAssignableFrom(fields[i].getType())) { + field = fields[i]; } } } @@ -47,43 +47,54 @@ return field; } - public static Field find(final Class type, final String name) { + public static Field find(final Class type, final String name) { try { final Field result = type.getDeclaredField(name); if (!result.isAccessible()) { result.setAccessible(true); } return result; + } catch (final SecurityException e) { + throw wrap("Cannot access field", type, name, e); } catch (final NoSuchFieldException e) { - final String message = "Could not access " + type.getName() + "." + name + " field: " + e.getMessage(); - throw new IllegalArgumentException(message); + throw wrap("Cannot access field", type, name, e); } catch (final NoClassDefFoundError e) { - final String message = "Could not access " + type.getName() + "." + name + " field: " + e.getMessage(); - throw new ObjectAccessException(message); + throw wrap("Cannot access field", type, name, e); } } public static void write(final Field field, final Object instance, final Object value) { try { field.set(instance, value); + } catch (final SecurityException e) { + throw wrap("Cannot write field", field.getType(), field.getName(), e); + } catch (final IllegalArgumentException e) { + throw wrap("Cannot write field", field.getType(), field.getName(), e); } catch (final IllegalAccessException e) { - final String message = "Could not write " + field.getType().getName() + "." + field.getName() + " field"; - throw new ObjectAccessException(message, e); + throw wrap("Cannot write field", field.getType(), field.getName(), e); } catch (final NoClassDefFoundError e) { - final String message = "Could not write " + field.getType().getName() + "." + field.getName() + " field"; - throw new ObjectAccessException(message, e); + throw wrap("Cannot write field", field.getType(), field.getName(), e); } } public static Object read(final Field field, final Object instance) { try { return field.get(instance); + } catch (final SecurityException e) { + throw wrap("Cannot read field", field.getType(), field.getName(), e); + } catch (final IllegalArgumentException e) { + throw wrap("Cannot read field", field.getType(), field.getName(), e); } catch (final IllegalAccessException e) { - final String message = "Could not read " + field.getType().getName() + "." + field.getName() + " field"; - throw new ObjectAccessException(message, e); + throw wrap("Cannot read field", field.getType(), field.getName(), e); } catch (final NoClassDefFoundError e) { - final String message = "Could not read " + field.getType().getName() + "." + field.getName() + " field"; - throw new ObjectAccessException(message, e); + throw wrap("Cannot read field", field.getType(), field.getName(), e); } } + + private static ObjectAccessException wrap(final String message, final Class type, final String name, + final Throwable ex) { + final ObjectAccessException exception = new ObjectAccessException(message, ex); + exception.add("field", type.getName() + "." + name); + return exception; + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/HierarchicalStreams.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/HierarchicalStreams.java (.../HierarchicalStreams.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/HierarchicalStreams.java (.../HierarchicalStreams.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2014 XStream Committers. + * Copyright (C) 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,7 +14,6 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.Mapper; - /** * Helper methods for {@link HierarchicalStreamReader} and {@link HierarchicalStreamWriter}. * @@ -23,9 +22,9 @@ */ public class HierarchicalStreams { - public static Class readClassType(final HierarchicalStreamReader reader, final Mapper mapper) { - final String classAttribute = readClassAttribute(reader, mapper); - Class type; + public static Class readClassType(HierarchicalStreamReader reader, Mapper mapper) { + String classAttribute = readClassAttribute(reader, mapper); + Class type; if (classAttribute == null) { type = mapper.realClass(reader.getNodeName()); } else { @@ -34,7 +33,7 @@ return type; } - public static String readClassAttribute(final HierarchicalStreamReader reader, final Mapper mapper) { + public static String readClassAttribute(HierarchicalStreamReader reader, Mapper mapper) { String attributeName = mapper.aliasForSystemAttribute("resolves-to"); String classAttribute = attributeName == null ? null : reader.getAttribute(attributeName); if (classAttribute == null) { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ISO8601JavaTimeConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ISO8601JavaTimeConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ISO8601JavaTimeConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,291 @@ +/* + * Copyright (C) 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 05. May 2017 by Joerg Schaible + */ +package com.thoughtworks.xstream.core.util; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.MonthDay; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.Year; +import java.time.YearMonth; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.time.temporal.IsoFields; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.WeekFields; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.Locale; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * A converter for {@link GregorianCalendar} conforming to the ISO8601 standard based on java.time. + *

      + * The converter will always serialize the calendar value in UTC and deserialize it to a value in the current default + * time zone. + *

      + * + * @author Jörg Schaible + * @see ISO 8601 + * @since 1.4.10 + */ +public class ISO8601JavaTimeConverter extends AbstractSingleValueConverter { + private static final DateTimeFormatter STD_DATE_TIME = new DateTimeFormatterBuilder() + .appendPattern("yyyy-MM-dd'T'HH:mm:ss") + .appendFraction(ChronoField.NANO_OF_SECOND, 3, 9, true) + .appendOffsetId() + .toFormatter(); + private static final DateTimeFormatter STD_ORDINAL_DATE_TIME = new DateTimeFormatterBuilder() + .appendPattern("yyyy-DDD'T'HH:mm:ss") + .appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true) + .appendOffsetId() + .toFormatter(); + private static final DateTimeFormatter BASIC_DATE_TIME = new DateTimeFormatterBuilder() + .appendPattern("yyyyMMdd'T'HHmmss") + .appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true) + .appendOffsetId() + .toFormatter(); + private static final DateTimeFormatter BASIC_ORDINAL_DATE_TIME = new DateTimeFormatterBuilder() + .appendPattern("yyyyDDD'T'HHmmss") + .appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true) + .appendOffsetId() + .toFormatter(); + private static final DateTimeFormatter BASIC_TIME = new DateTimeFormatterBuilder() + .appendPattern("HHmmss") + .appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true) + .appendOffsetId() + .toFormatter(); + private static final DateTimeFormatter ISO_TTIME = new DateTimeFormatterBuilder() + .appendPattern("'T'HH:mm:ss") + .appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true) + .appendOffsetId() + .toFormatter(); + private static final DateTimeFormatter BASIC_TTIME = new DateTimeFormatterBuilder() + .appendPattern("'T'HHmmss") + .appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true) + .appendOffsetId() + .toFormatter(); + private static final DateTimeFormatter ISO_WEEK_DATE_TIME = new DateTimeFormatterBuilder() + .appendPattern("YYYY-'W'ww-e'T'HH:mm:ss") + .appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true) + .appendOffsetId() + .toFormatter(); + private static final DateTimeFormatter BASIC_WEEK_DATE_TIME = new DateTimeFormatterBuilder() + .appendPattern("YYYY'W'wwe'T'HHmmss") + .appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true) + .appendOffsetId() + .toFormatter(); + private static final DateTimeFormatter BASIC_ORDINAL_DATE = new DateTimeFormatterBuilder() + .appendPattern("yyyyDDD") + .toFormatter(); + private static final DateTimeFormatter BASIC_WEEK_DATE = new DateTimeFormatterBuilder() + .appendPattern("YYYY'W'wwe") + .toFormatter(); + private static final DateTimeFormatter STD_DATE_HOUR = new DateTimeFormatterBuilder() + .appendPattern("yyyy-MM-dd'T'HH") + .toFormatter(); + private static final DateTimeFormatter STD_HOUR = new DateTimeFormatterBuilder().appendPattern("HH").toFormatter(); + private static final DateTimeFormatter STD_YEAR_WEEK = new DateTimeFormatterBuilder() + .appendPattern("YYYY-'W'ww") + .parseDefaulting(ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR, 1) + .toFormatter(); + + @Override + public boolean canConvert(@SuppressWarnings("rawtypes") final Class type) { + return false; + } + + @Override + public Object fromString(final String str) { + try { + final OffsetDateTime odt = OffsetDateTime.parse(str); + return GregorianCalendar.from(odt.atZoneSameInstant(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final LocalDateTime ldt = LocalDateTime.parse(str); + return GregorianCalendar.from(ldt.atZone(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final Instant instant = Instant.parse(str); + return GregorianCalendar.from(instant.atZone(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final OffsetDateTime odt = BASIC_DATE_TIME.parse(str, OffsetDateTime::from); + return GregorianCalendar.from(odt.atZoneSameInstant(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final OffsetDateTime odt = STD_ORDINAL_DATE_TIME.parse(str, OffsetDateTime::from); + return GregorianCalendar.from(odt.atZoneSameInstant(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final OffsetDateTime odt = BASIC_ORDINAL_DATE_TIME.parse(str, OffsetDateTime::from); + return GregorianCalendar.from(odt.atZoneSameInstant(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final OffsetTime ot = OffsetTime.parse(str); + return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final OffsetTime ot = BASIC_TIME.parse(str, OffsetTime::from); + return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final OffsetTime ot = ISO_TTIME.parse(str, OffsetTime::from); + return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final OffsetTime ot = BASIC_TTIME.parse(str, OffsetTime::from); + return GregorianCalendar.from(ot.atDate(LocalDate.ofEpochDay(0)).atZoneSameInstant(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final TemporalAccessor ta = ISO_WEEK_DATE_TIME.withLocale(Locale.getDefault()).parse(str); + final Year y = Year.from(ta); + final MonthDay md = MonthDay.from(ta); + final OffsetTime ot = OffsetTime.from(ta); + return GregorianCalendar.from(ot.atDate(y.atMonthDay(md)).atZoneSameInstant(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final TemporalAccessor ta = BASIC_WEEK_DATE_TIME.withLocale(Locale.getDefault()).parse(str); + final Year y = Year.from(ta); + final MonthDay md = MonthDay.from(ta); + final OffsetTime ot = OffsetTime.from(ta); + return GregorianCalendar.from(ot.atDate(y.atMonthDay(md)).atZoneSameInstant(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final LocalDate ld = LocalDate.parse(str); + return GregorianCalendar.from(ld.atStartOfDay(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final LocalDate ld = LocalDate.parse(str, DateTimeFormatter.BASIC_ISO_DATE); + return GregorianCalendar.from(ld.atStartOfDay(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final LocalDate ld = LocalDate.parse(str, DateTimeFormatter.ISO_ORDINAL_DATE); + return GregorianCalendar.from(ld.atStartOfDay(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final LocalDate ld = BASIC_ORDINAL_DATE.parse(str, LocalDate::from); + return GregorianCalendar.from(ld.atStartOfDay(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final LocalDate ld = LocalDate.parse(str, DateTimeFormatter.ISO_WEEK_DATE.withLocale(Locale.getDefault())); + return GregorianCalendar.from(ld.atStartOfDay(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final TemporalAccessor ta = BASIC_WEEK_DATE.withLocale(Locale.getDefault()).parse(str); + final Year y = Year.from(ta); + final MonthDay md = MonthDay.from(ta); + return GregorianCalendar.from(y.atMonthDay(md).atStartOfDay(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final LocalDateTime ldt = STD_DATE_HOUR.parse(str, LocalDateTime::from); + return GregorianCalendar.from(ldt.atZone(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final LocalTime lt = STD_HOUR.parse(str, LocalTime::from); + return GregorianCalendar.from(lt.atDate(LocalDate.ofEpochDay(0)).atZone(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final LocalTime lt = LocalTime.parse(str); + return GregorianCalendar.from(lt.atDate(LocalDate.ofEpochDay(0)).atZone(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final YearMonth ym = YearMonth.parse(str); + return GregorianCalendar.from(ym.atDay(1).atStartOfDay(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final Year y = Year.parse(str); + return GregorianCalendar.from(y.atDay(1).atStartOfDay(ZoneId.systemDefault())); + } catch (final DateTimeParseException e) { + // try with next formatter + } + try { + final TemporalAccessor ta = STD_YEAR_WEEK.withLocale(Locale.getDefault()).parse(str); + final int y = ta.get(WeekFields.ISO.weekBasedYear()); + final int w = ta.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR); + return GregorianCalendar.from(LocalDateTime + .from(ta) + .with(WeekFields.ISO.weekOfYear(), y) + .with(WeekFields.ISO.weekOfWeekBasedYear(), w) + .atZone(ZoneId.systemDefault())); +// } catch (final IllegalArgumentException e) { // TODO: DateTimeParseException + } catch (final DateTimeParseException e) { + // try with next formatter + } + final ConversionException exception = new ConversionException("Cannot parse date"); + exception.add("date", str); + throw exception; + } + + @Override + public String toString(final Object obj) { + final Calendar calendar = (Calendar)obj; + final Instant instant = Instant.ofEpochMilli(calendar.getTimeInMillis()); + final int offsetInMillis = calendar.getTimeZone().getOffset(calendar.getTimeInMillis()); + final OffsetDateTime offsetDateTime = OffsetDateTime.ofInstant(instant, ZoneOffset.ofTotalSeconds(offsetInMillis + / 1000)); + return STD_DATE_TIME.format(offsetDateTime); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ISO8601JodaTimeConverter.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ISO8601JodaTimeConverter.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ISO8601JodaTimeConverter.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2005 Joe Walnes. + * Copyright (C) 2006, 2007, 2011, 2013, 2014, 2015, 2016, 2017 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 05. May 2017 by Joerg Schaible, copied from ISO8601GregorianCalendarConverter + */ +package com.thoughtworks.xstream.core.util; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.ISODateTimeFormat; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter; + + +/** + * A converter for {@link GregorianCalendar} conforming to the ISO8601 standard based on Joda-Time. + *

      + * The converter will always serialize the calendar value in UTC and deserialize it to a value in the current default + * time zone. + *

      + * + * @author Mauro Talevi + * @author Jörg Schaible + * @see ISO 8601 + * @since 1.4.10 + */ +public class ISO8601JodaTimeConverter extends AbstractSingleValueConverter { + private static final DateTimeFormatter[] formattersUTC = { // + ISODateTimeFormat.dateTime(), // + ISODateTimeFormat.dateTimeNoMillis(), // + ISODateTimeFormat.basicDateTime(), // + ISODateTimeFormat.basicDateTimeNoMillis(), // + ISODateTimeFormat.basicOrdinalDateTime(), // + ISODateTimeFormat.basicOrdinalDateTimeNoMillis(), // + ISODateTimeFormat.basicTime(), // + ISODateTimeFormat.basicTimeNoMillis(), // + ISODateTimeFormat.basicTTime(), // + ISODateTimeFormat.basicTTimeNoMillis(), // + ISODateTimeFormat.basicWeekDateTime(), // + ISODateTimeFormat.basicWeekDateTimeNoMillis(), // + ISODateTimeFormat.ordinalDateTime(), // + ISODateTimeFormat.ordinalDateTimeNoMillis(), // + ISODateTimeFormat.time(), // + ISODateTimeFormat.timeNoMillis(), // + ISODateTimeFormat.tTime(), // + ISODateTimeFormat.tTimeNoMillis(), // + ISODateTimeFormat.weekDateTime(), // + ISODateTimeFormat.weekDateTimeNoMillis() // + }; + private static final DateTimeFormatter[] formattersNoUTC = { // + ISODateTimeFormat.basicDate(), // + ISODateTimeFormat.basicOrdinalDate(), // + ISODateTimeFormat.basicWeekDate(), // + ISODateTimeFormat.date(), // + ISODateTimeFormat.dateHour(), // + ISODateTimeFormat.dateHourMinute(), // + ISODateTimeFormat.dateHourMinuteSecond(), // + ISODateTimeFormat.dateHourMinuteSecondFraction(), // + ISODateTimeFormat.dateHourMinuteSecondMillis(), // + ISODateTimeFormat.hour(), // + ISODateTimeFormat.hourMinute(), // + ISODateTimeFormat.hourMinuteSecond(), // + ISODateTimeFormat.hourMinuteSecondFraction(), // + ISODateTimeFormat.hourMinuteSecondMillis(), // + ISODateTimeFormat.ordinalDate(), // + ISODateTimeFormat.weekDate(), // + ISODateTimeFormat.year(), // + ISODateTimeFormat.yearMonth(), // + ISODateTimeFormat.yearMonthDay(), // + ISODateTimeFormat.weekyear(), // + ISODateTimeFormat.weekyearWeek(), // + ISODateTimeFormat.weekyearWeekDay() // + }; + + public boolean canConvert(final Class type) { + return false; + } + + public Object fromString(final String str) { + for (int i = 0; i < formattersUTC.length ; ++i) { + final DateTimeFormatter formatter = formattersUTC[i]; + try { + final DateTime dt = formatter.parseDateTime(str); + final Calendar calendar = dt.toGregorianCalendar(); + calendar.setTimeZone(TimeZone.getDefault()); + return calendar; + } catch (final IllegalArgumentException e) { + // try with next formatter + } + } + final DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TimeZone.getDefault()); + for (int i = 0; i < formattersNoUTC.length ; ++i) { + final DateTimeFormatter element = formattersNoUTC[i]; + try { + final DateTimeFormatter formatter = element.withZone(dateTimeZone); + final DateTime dt = formatter.parseDateTime(str); + final Calendar calendar = dt.toGregorianCalendar(); + calendar.setTimeZone(TimeZone.getDefault()); + return calendar; + } catch (final IllegalArgumentException e) { + // try with next formatter + } + } + final ConversionException exception = new ConversionException("Cannot parse date"); + exception.add("date", str); + throw exception; + } + + public String toString(final Object obj) { + final DateTime dt = new DateTime(obj); + return dt.toString(formattersUTC[0]); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ObjectIdDictionary.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ObjectIdDictionary.java (.../ObjectIdDictionary.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ObjectIdDictionary.java (.../ObjectIdDictionary.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2010, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2010 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -20,25 +20,20 @@ /** * Store IDs against given object references. *

      - * Behaves similar to java.util.IdentityHashMap, but in JDK1.3 as well. Additionally the implementation keeps track of - * orphaned IDs by using a WeakReference to store the reference object. + * Behaves similar to java.util.IdentityHashMap, but in JDK1.3 as well. Additionally the + * implementation keeps track of orphaned IDs by using a WeakReference to store the reference + * object. *

      */ -public class ObjectIdDictionary { +public class ObjectIdDictionary { - private final Map map = new HashMap(); - private final ReferenceQueue queue = new ReferenceQueue(); + private final Map map = new HashMap(); + private final ReferenceQueue queue = new ReferenceQueue(); private static interface Wrapper { - @Override int hashCode(); - - @Override boolean equals(Object obj); - - @Override String toString(); - Object get(); } @@ -47,74 +42,67 @@ private final Object obj; private final int hashCode; - public IdWrapper(final Object obj) { + public IdWrapper(Object obj) { hashCode = System.identityHashCode(obj); this.obj = obj; } - @Override public int hashCode() { return hashCode; } - @Override - public boolean equals(final Object other) { + public boolean equals(Object other) { return obj == ((Wrapper)other).get(); } - @Override public String toString() { return obj.toString(); } - @Override public Object get() { return obj; } } - private class WeakIdWrapper extends WeakReference implements Wrapper { + private class WeakIdWrapper extends WeakReference implements Wrapper { private final int hashCode; - public WeakIdWrapper(final Object obj) { + public WeakIdWrapper(Object obj) { super(obj, queue); hashCode = System.identityHashCode(obj); } - @Override public int hashCode() { return hashCode; } - @Override - public boolean equals(final Object other) { + public boolean equals(Object other) { return get() == ((Wrapper)other).get(); } - @Override public String toString() { - final Object obj = get(); + Object obj = get(); return obj == null ? "(null)" : obj.toString(); } } - public void associateId(final Object obj, final E id) { + public void associateId(Object obj, Object id) { map.put(new WeakIdWrapper(obj), id); cleanup(); } - public E lookupId(final Object obj) { - final E id = map.get(new IdWrapper(obj)); + public Object lookupId(Object obj) { + Object id = map.get(new IdWrapper(obj)); return id; } - public boolean containsId(final Object item) { - final boolean b = map.containsKey(new IdWrapper(item)); + public boolean containsId(Object item) { + boolean b = map.containsKey(new IdWrapper(item)); return b; } - public void removeId(final Object item) { + public void removeId(Object item) { map.remove(new IdWrapper(item)); cleanup(); } @@ -124,10 +112,10 @@ return map.size(); } - @SuppressWarnings("unchecked") private void cleanup() { WeakIdWrapper wrapper; - while ((wrapper = (WeakIdWrapper)queue.poll()) != null) { + while ((wrapper = (WeakIdWrapper)queue.poll()) != null) + { map.remove(wrapper); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/OrderRetainingMap.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/OrderRetainingMap.java (.../OrderRetainingMap.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/OrderRetainingMap.java (.../OrderRetainingMap.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -16,39 +16,38 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; /** - * @deprecated As of upcoming use {@link java.util.LinkedHashMap} + * @deprecated As of 1.4.8 use {@link java.util.LinkedHashMap} */ -@Deprecated -public class OrderRetainingMap extends HashMap { +public class OrderRetainingMap extends HashMap { - private final ArraySet keyOrder = new ArraySet(); - private final List valueOrder = new ArrayList(); + private ArraySet keyOrder = new ArraySet(); + private List valueOrder = new ArrayList(); public OrderRetainingMap() { super(); } - public OrderRetainingMap(final Map m) { + public OrderRetainingMap(Map m) { super(); putAll(m); } - @Override - public void putAll(final Map m) { - for (final Map.Entry entry : m.entrySet()) { + public void putAll(Map m) { + for(Iterator iter = m.entrySet().iterator(); iter.hasNext(); ) { + Map.Entry entry = (Map.Entry)iter.next(); put(entry.getKey(), entry.getValue()); } } - @Override - public V put(final K key, final V value) { - final int idx = keyOrder.lastIndexOf(key); + public Object put(Object key, Object value) { + int idx = keyOrder.lastIndexOf(key); if (idx < 0) { keyOrder.add(key); valueOrder.add(value); @@ -58,44 +57,40 @@ return super.put(key, value); } - @Override - public V remove(final Object key) { - final int idx = keyOrder.lastIndexOf(key); + public Object remove(Object key) { + int idx = keyOrder.lastIndexOf(key); if (idx != 0) { keyOrder.remove(idx); valueOrder.remove(idx); } return super.remove(key); } - @Override public void clear() { keyOrder.clear(); valueOrder.clear(); super.clear(); } - @Override - public Collection values() { + public Collection values() { return Collections.unmodifiableList(valueOrder); } - @Override - public Set keySet() { + public Set keySet() { return Collections.unmodifiableSet(keyOrder); } - @Override - public Set> entrySet() { - @SuppressWarnings("unchecked") - final Map.Entry[] entries = new Map.Entry[size()]; - for (final Map.Entry entry : super.entrySet()) { + public Set entrySet() { + Map.Entry[] entries = new Map.Entry[size()]; + for (Iterator iter = super.entrySet().iterator(); iter.hasNext();) { + Map.Entry entry = (Map.Entry)iter.next(); entries[keyOrder.indexOf(entry.getKey())] = entry; } - final Set> set = new ArraySet>(); + Set set = new ArraySet(); set.addAll(Arrays.asList(entries)); return Collections.unmodifiableSet(set); } - private static class ArraySet extends ArrayList implements Set {} + private static class ArraySet extends ArrayList implements Set { + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Pool.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Pool.java (.../Pool.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Pool.java (.../Pool.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2014 XStream Committers. + * Copyright (c) 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,54 +10,46 @@ */ package com.thoughtworks.xstream.core.util; -import java.util.Arrays; - - /** * A simple pool implementation. - * + * * @author Jörg Schaible * @author Joe Walnes */ -public class Pool { - - public interface Factory { - public T newInstance(); +public class Pool { + + public interface Factory { + public Object newInstance(); } private final int initialPoolSize; private final int maxPoolSize; - private final Factory factory; - private transient T[] pool; + private final Factory factory; + private transient Object[] pool; private transient int nextAvailable; + private transient Object mutex = new Object(); - public Pool(final int initialPoolSize, final int maxPoolSize, final Factory factory) { + public Pool(int initialPoolSize, int maxPoolSize, Factory factory) { this.initialPoolSize = initialPoolSize; this.maxPoolSize = maxPoolSize; this.factory = factory; } - private T[] newArray(final int capacity, final T... t) { - return Arrays.copyOf(t, capacity); - } - - public T fetchFromPool() { - T result; - synchronized (this) { + public Object fetchFromPool() { + Object result; + synchronized (mutex) { if (pool == null) { - @SuppressWarnings("unchecked") - final T[] all = newArray(maxPoolSize); - pool = all; - for (nextAvailable = initialPoolSize; nextAvailable > 0;) { + pool = new Object[maxPoolSize]; + for (nextAvailable = initialPoolSize; nextAvailable > 0; ) { putInPool(factory.newInstance()); } } while (nextAvailable == maxPoolSize) { try { - wait(); - } catch (final InterruptedException e) { - throw new RuntimeException("Interrupted whilst waiting for a free item in the pool: " - + e.getMessage()); + mutex.wait(); + } catch (InterruptedException e) { + throw new RuntimeException("Interrupted whilst waiting " + + "for a free item in the pool : " + e.getMessage()); } } result = pool[nextAvailable++]; @@ -70,25 +62,15 @@ return result; } - protected void putInPool(final T object) { - synchronized (this) { - if (nextAvailable == 0) { - throw new IllegalStateException("Cannot put more objects than " - + maxPoolSize - + " elements into this pool"); - } + protected void putInPool(Object object) { + synchronized (mutex) { pool[--nextAvailable] = object; - if (object == null) { - for (int i = maxPoolSize; i > nextAvailable;) { - if (pool[--i] != null) { - pool[nextAvailable] = pool[i]; - pool[i] = null; - break; - } - } - } - - notify(); + mutex.notify(); } } + + private Object readResolve() { + mutex = new Object(); + return this; + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/PresortedMap.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/PresortedMap.java (.../PresortedMap.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/PresortedMap.java (.../PresortedMap.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2010, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2010 XStream Committers. * All rights reserved. * * Created on 12.10.2010 by Joerg Schaible, extracted from TreeMapConverter. @@ -9,177 +9,154 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; +import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.SortedMap; - /** * @author Jörg Schaible */ -public class PresortedMap implements SortedMap { +public class PresortedMap implements SortedMap { - private static class ArraySet extends ArrayList implements Set {} + private static class ArraySet extends ArrayList implements Set { + } - private final PresortedMap.ArraySet> set; - private final Comparator comparator; - + private final PresortedMap.ArraySet set; + private final Comparator comparator; + public PresortedMap() { - this(null, new ArraySet>()); + this(null, new ArraySet()); } - public PresortedMap(final Comparator comparator) { - this(comparator, new ArraySet>()); + public PresortedMap(Comparator comparator) { + this(comparator, new ArraySet()); } - private PresortedMap(final Comparator comparator, final PresortedMap.ArraySet> set) { - this.comparator = comparator != null ? comparator : new ArraySetComparator(set); + private PresortedMap(Comparator comparator, PresortedMap.ArraySet set) { + this.comparator = comparator != null ? comparator : new ArraySetComparator(set); this.set = set; } - @Override - public Comparator comparator() { + public Comparator comparator() { return comparator; } - @Override - public Set> entrySet() { + public Set entrySet() { return set; } - @Override - public K firstKey() { + public Object firstKey() { throw new UnsupportedOperationException(); } - @Override - public SortedMap headMap(final Object toKey) { + public SortedMap headMap(Object toKey) { throw new UnsupportedOperationException(); } - @Override - public Set keySet() { - final Set keySet = new ArraySet(); - for (final Map.Entry entry : set) { + public Set keySet() { + Set keySet = new ArraySet(); + for (final Iterator iterator = set.iterator(); iterator.hasNext();) { + final Entry entry = (Entry)iterator.next(); keySet.add(entry.getKey()); } return keySet; } - @Override - public K lastKey() { + public Object lastKey() { throw new UnsupportedOperationException(); } - @Override - public SortedMap subMap(final Object fromKey, final Object toKey) { + public SortedMap subMap(Object fromKey, Object toKey) { throw new UnsupportedOperationException(); } - @Override - public SortedMap tailMap(final Object fromKey) { + public SortedMap tailMap(Object fromKey) { throw new UnsupportedOperationException(); } - @Override - public Collection values() { - final Set values = new ArraySet(); - for (final Map.Entry entry : set) { + public Collection values() { + Set values = new ArraySet(); + for (final Iterator iterator = set.iterator(); iterator.hasNext();) { + final Entry entry = (Entry)iterator.next(); values.add(entry.getValue()); } return values; } - @Override public void clear() { throw new UnsupportedOperationException(); } - @Override - public boolean containsKey(final Object key) { + public boolean containsKey(Object key) { return false; } - @Override - public boolean containsValue(final Object value) { + public boolean containsValue(Object value) { throw new UnsupportedOperationException(); } - @Override - public V get(final Object key) { + public Object get(Object key) { throw new UnsupportedOperationException(); } - @Override public boolean isEmpty() { return set.isEmpty(); } - @Override - public V put(final K key, final V value) { - set.add(new Map.Entry() { + public Object put(final Object key, final Object value) { + set.add(new Entry(){ - @Override - public K getKey() { + public Object getKey() { return key; } - @Override - public V getValue() { + public Object getValue() { return value; } - @Override - public V setValue(final V value) { + public Object setValue(Object value) { throw new UnsupportedOperationException(); - } - }); + }}); return null; } - @Override - public void putAll(final Map m) { - for (final Map.Entry entry : m.entrySet()) { - @SuppressWarnings("unchecked") - final Map.Entry e = (Map.Entry)entry; - set.add(e); + public void putAll(Map m) { + for (final Iterator iter = m.entrySet().iterator(); iter.hasNext();) { + set.add(iter.next()); } } - @Override - public V remove(final Object key) { + public Object remove(Object key) { throw new UnsupportedOperationException(); } - @Override public int size() { return set.size(); } + + private static class ArraySetComparator implements Comparator { - private static class ArraySetComparator implements Comparator { + private final ArrayList list; + private Map.Entry[] array; - private final ArrayList> list; - private Map.Entry[] array; - - ArraySetComparator(final ArrayList> list) { + ArraySetComparator(ArrayList list) { this.list = list; } - - @Override - public int compare(final K object1, final K object2) { + + public int compare(Object object1, Object object2) { if (array == null || list.size() != array.length) { - @SuppressWarnings("unchecked") - final Map.Entry[] a = new Map.Entry[list.size()]; + Map.Entry[] a = new Map.Entry[list.size()]; if (array != null) { System.arraycopy(array, 0, a, 0, array.length); } for (int i = array == null ? 0 : array.length; i < list.size(); ++i) { - a[i] = list.get(i); + a[i] = (Map.Entry)list.get(i); } array = a; } int idx1 = Integer.MAX_VALUE, idx2 = Integer.MAX_VALUE; - for (int i = 0; i < array.length && !(idx1 < Integer.MAX_VALUE && idx2 < Integer.MAX_VALUE); ++i) { + for(int i = 0; i < array.length && !(idx1 < Integer.MAX_VALUE && idx2 < Integer.MAX_VALUE); ++i) { if (idx1 == Integer.MAX_VALUE && object1 == array[i].getKey()) { idx1 = i; } @@ -190,4 +167,4 @@ return idx1 - idx2; } } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/PresortedSet.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/PresortedSet.java (.../PresortedSet.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/PresortedSet.java (.../PresortedSet.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2010, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2010 XStream Committers. * All rights reserved. * * Created on 12.10.2010 by Joerg Schaible, extracted from TreeSetConverter. @@ -13,131 +13,113 @@ import java.util.List; import java.util.SortedSet; - /** * @author Jörg Schaible */ -public class PresortedSet implements SortedSet { - private final List list = new ArrayList(); - private final Comparator comparator; +public class PresortedSet implements SortedSet { + private final List list = new ArrayList(); + private final Comparator comparator; public PresortedSet() { this(null); } - public PresortedSet(final Comparator comparator) { + public PresortedSet(Comparator comparator) { this(comparator, null); } - public PresortedSet(final Comparator comparator, final Collection c) { + public PresortedSet(Comparator comparator, Collection c) { this.comparator = comparator; if (c != null) { addAll(c); } } - @Override - public boolean add(final E e) { + public boolean add(Object e) { return this.list.add(e); } - @Override - public boolean addAll(final Collection c) { + public boolean addAll(Collection c) { return this.list.addAll(c); } - @Override public void clear() { this.list.clear(); } - @Override - public boolean contains(final Object o) { + public boolean contains(Object o) { return this.list.contains(o); } - @Override - public boolean containsAll(final Collection c) { + public boolean containsAll(Collection c) { return this.list.containsAll(c); } - @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { return this.list.equals(o); } - @Override public int hashCode() { return this.list.hashCode(); } - @Override public boolean isEmpty() { return this.list.isEmpty(); } - @Override - public Iterator iterator() { + public Iterator iterator() { return this.list.iterator(); } - @Override - public boolean remove(final Object o) { + public boolean remove(Object o) { return this.list.remove(o); } - @Override - public boolean removeAll(final Collection c) { + public boolean removeAll(Collection c) { return this.list.removeAll(c); } - @Override - public boolean retainAll(final Collection c) { + public boolean retainAll(Collection c) { return this.list.retainAll(c); } - @Override public int size() { return this.list.size(); } - @Override + public List subList(int fromIndex, int toIndex) { + return this.list.subList(fromIndex, toIndex); + } + public Object[] toArray() { return this.list.toArray(); } - @Override - public T[] toArray(final T[] a) { + public Object[] toArray(Object[] a) { return this.list.toArray(a); } - @Override - public Comparator comparator() { + public Comparator comparator() { return comparator; } - @Override - public E first() { + public Object first() { return list.isEmpty() ? null : list.get(0); } - @Override - public SortedSet headSet(final Object toElement) { + public SortedSet headSet(Object toElement) { throw new UnsupportedOperationException(); } - @Override - public E last() { + public Object last() { return list.isEmpty() ? null : list.get(list.size() - 1); } - @Override - public SortedSet subSet(final Object fromElement, final Object toElement) { + public SortedSet subSet(Object fromElement, Object toElement) { throw new UnsupportedOperationException(); } - @Override - public SortedSet tailSet(final Object fromElement) { + public SortedSet tailSet(Object fromElement) { throw new UnsupportedOperationException(); } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Primitives.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Primitives.java (.../Primitives.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Primitives.java (.../Primitives.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2007, 2011, 2014 XStream Committers. + * Copyright (c) 2006, 2007, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,30 +13,44 @@ import java.util.HashMap; import java.util.Map; - /** * Utility class for primitives. * * @author Jörg Schaible * @since 1.2.1 */ public final class Primitives { - private final static Map, Class> BOX = new HashMap, Class>(); - private final static Map, Class> UNBOX = new HashMap, Class>(); - private final static Map> NAMED_PRIMITIVE = new HashMap>(); - private final static Map, Character> REPRESENTING_CHAR = new HashMap, Character>(); - + private final static Map BOX = new HashMap(); + private final static Map UNBOX = new HashMap(); + private final static Map NAMED_PRIMITIVE = new HashMap(); + private final static Map REPRESENTING_CHAR = new HashMap(); + static { - final Class[][] boxing = new Class[][]{ - {Byte.TYPE, Byte.class}, {Character.TYPE, Character.class}, {Short.TYPE, Short.class}, - {Integer.TYPE, Integer.class}, {Long.TYPE, Long.class}, {Float.TYPE, Float.class}, - {Double.TYPE, Double.class}, {Boolean.TYPE, Boolean.class}, {Void.TYPE, Void.class},}; - final Character[] representingChars = { - new Character('B'), new Character('C'), new Character('S'), new Character('I'), new Character('J'), - new Character('F'), new Character('D'), new Character('Z'), null}; + final Class[][] boxing = new Class[][]{ + { Byte.TYPE, Byte.class}, + { Character.TYPE, Character.class}, + { Short.TYPE, Short.class}, + { Integer.TYPE, Integer.class}, + { Long.TYPE, Long.class}, + { Float.TYPE, Float.class}, + { Double.TYPE, Double.class}, + { Boolean.TYPE, Boolean.class}, + { Void.TYPE, Void.class}, + }; + final Character[] representingChars = { + new Character('B'), + new Character('C'), + new Character('S'), + new Character('I'), + new Character('J'), + new Character('F'), + new Character('D'), + new Character('Z'), + null + }; for (int i = 0; i < boxing.length; i++) { - final Class primitiveType = boxing[i][0]; - final Class boxedType = boxing[i][1]; + final Class primitiveType = boxing[i][0]; + final Class boxedType = boxing[i][1]; BOX.put(primitiveType, boxedType); UNBOX.put(boxedType, primitiveType); NAMED_PRIMITIVE.put(primitiveType.getName(), primitiveType); @@ -50,18 +64,18 @@ * @param type the primitive type * @return the boxed type or null */ - static public Class box(final Class type) { - return BOX.get(type); + static public Class box(final Class type) { + return (Class)BOX.get(type); } - + /** * Get the primitive type for a boxed one. * * @param type the boxed type * @return the primitive type or null */ - static public Class unbox(final Class type) { - return UNBOX.get(type); + static public Class unbox(final Class type) { + return (Class)UNBOX.get(type); } /** @@ -71,7 +85,7 @@ * @return true if the type is boxed * @since 1.4 */ - static public boolean isBoxed(final Class type) { + static public boolean isBoxed(final Class type) { return UNBOX.containsKey(type); } @@ -82,8 +96,8 @@ * @return the Java type or null * @since 1.4 */ - static public Class primitiveType(final String name) { - return NAMED_PRIMITIVE.get(name); + static public Class primitiveType(final String name) { + return (Class)NAMED_PRIMITIVE.get(name); } /** @@ -93,8 +107,8 @@ * @return the representing character or 0 * @since 1.4 */ - static public char representingChar(final Class type) { - final Character ch = REPRESENTING_CHAR.get(type); + static public char representingChar(final Class type) { + Character ch = (Character)REPRESENTING_CHAR.get(type); return ch == null ? 0 : ch.charValue(); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/PrioritizedList.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/PrioritizedList.java (.../PrioritizedList.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/PrioritizedList.java (.../PrioritizedList.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -25,82 +25,70 @@ * @author Joe Walnes * @author Guilherme Silveira */ -public class PrioritizedList implements Iterable { +public class PrioritizedList { - private final Set> set = new TreeSet>(); + private final Set set = new TreeSet(); + private int lowestPriority = Integer.MAX_VALUE; + private int lastId = 0; - public void add(final E item, final int priority) { + public void add(Object item, int priority) { if (this.lowestPriority > priority) { this.lowestPriority = priority; } - this.set.add(new PrioritizedItem(item, priority, ++lastId)); + this.set.add(new PrioritizedItem(item, priority, ++lastId)); } - @Override - public Iterator iterator() { - return new PrioritizedItemIterator(this.set.iterator()); + public Iterator iterator() { + return new PrioritizedItemIterator(this.set.iterator()); } - private static class PrioritizedItem implements Comparable> { + private static class PrioritizedItem implements Comparable { - final V value; + final Object value; final int priority; final int id; - public PrioritizedItem(final V value, final int priority, final int id) { + public PrioritizedItem(Object value, int priority, int id) { this.value = value; this.priority = priority; this.id = id; } - @Override - public int compareTo(final PrioritizedItem other) { + public int compareTo(Object o) { + PrioritizedItem other = (PrioritizedItem)o; if (this.priority != other.priority) { - return other.priority - this.priority; + return (other.priority - this.priority); } - return other.id - this.id; + return (other.id - this.id); } - @Override - public int hashCode() { - return Integer.valueOf(id).hashCode(); + public boolean equals(Object obj) { + return this.id == ((PrioritizedItem)obj).id; } - @Override - public boolean equals(final Object obj) { - if (!(obj instanceof PrioritizedItem)) { - return false; - } - @SuppressWarnings("unchecked") - final PrioritizedItem other = (PrioritizedItem)obj; - return this.id == other.id; - } - } - private static class PrioritizedItemIterator implements Iterator { + private static class PrioritizedItemIterator implements Iterator { - private final Iterator> iterator; + private Iterator iterator; - public PrioritizedItemIterator(final Iterator> iterator) { + public PrioritizedItemIterator(Iterator iterator) { this.iterator = iterator; } - @Override public void remove() { + // call iterator.remove()? throw new UnsupportedOperationException(); } - @Override public boolean hasNext() { return iterator.hasNext(); } - @Override - public V next() { - return iterator.next().value; + public Object next() { + return ((PrioritizedItem)iterator.next()).value; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/QuickWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/QuickWriter.java (.../QuickWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/QuickWriter.java (.../QuickWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,30 +11,28 @@ */ package com.thoughtworks.xstream.core.util; -import java.io.Closeable; +import com.thoughtworks.xstream.io.StreamException; + import java.io.IOException; import java.io.Writer; -import com.thoughtworks.xstream.io.StreamException; +public class QuickWriter { - -public class QuickWriter implements Closeable { - private final Writer writer; - private final char[] buffer; + private char[] buffer; private int pointer; - public QuickWriter(final Writer writer) { + public QuickWriter(Writer writer) { this(writer, 1024); } - public QuickWriter(final Writer writer, final int bufferSize) { + public QuickWriter(Writer writer, int bufferSize) { this.writer = writer; buffer = new char[bufferSize]; } - public void write(final String str) { - final int len = str.length(); + public void write(String str) { + int len = str.length(); if (pointer + len >= buffer.length) { flush(); if (len > buffer.length) { @@ -46,7 +44,7 @@ pointer += len; } - public void write(final char c) { + public void write(char c) { if (pointer + 1 >= buffer.length) { flush(); if (buffer.length == 0) { @@ -57,8 +55,8 @@ buffer[pointer++] = c; } - public void write(final char[] c) { - final int len = c.length; + public void write(char[] c) { + int len = c.length; if (pointer + len >= buffer.length) { flush(); if (len > buffer.length) { @@ -75,36 +73,35 @@ writer.write(buffer, 0, pointer); pointer = 0; writer.flush(); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override public void close() { try { writer.write(buffer, 0, pointer); pointer = 0; writer.close(); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - private void raw(final char[] c) { + private void raw(char[] c) { try { writer.write(c); writer.flush(); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - private void raw(final char c) { + private void raw(char c) { try { writer.write(c); writer.flush(); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/SelfStreamingInstanceChecker.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/SelfStreamingInstanceChecker.java (.../SelfStreamingInstanceChecker.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/SelfStreamingInstanceChecker.java (.../SelfStreamingInstanceChecker.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -19,10 +19,10 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; - /** - * A special converter that prevents self-serialization. The serializing XStream instance adds a converter of this type - * to prevent self-serialization and will throw an exception instead. + * A special converter that prevents self-serialization. The serializing XStream instance + * adds a converter of this type to prevent self-serialization and will throw an + * exception instead. * * @author Jörg Schaible * @since 1.2 @@ -36,36 +36,32 @@ /** * @since 1.4.5 */ - public SelfStreamingInstanceChecker(final ConverterLookup lookup, final Object xstream) { + public SelfStreamingInstanceChecker(ConverterLookup lookup, Object xstream) { this.lookup = lookup; - self = xstream; + this.self = xstream; } /** * @deprecated As of 1.4.5 use {@link #SelfStreamingInstanceChecker(ConverterLookup, Object)} */ - @Deprecated - public SelfStreamingInstanceChecker(final Converter defaultConverter, final Object xstream) { + public SelfStreamingInstanceChecker(Converter defaultConverter, Object xstream) { this.defaultConverter = defaultConverter; - self = xstream; + this.self = xstream; lookup = null; } - @Override - public boolean canConvert(final Class type) { + public boolean canConvert(Class type) { return type == self.getClass(); } - @Override - public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { + public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { if (source == self) { throw new ConversionException("Cannot marshal the XStream instance in action"); } getConverter().marshal(source, writer, context); } - @Override - public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { + public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { return getConverter().unmarshal(reader, context); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/SerializationMembers.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/SerializationMembers.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/SerializationMembers.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2004, 2005 Joe Walnes. + * Copyright (C) 2006, 2007, 2008, 2010, 2011, 2014, 2015, 2016 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 12. February 2015 by Joerg Schaible, copied from c.t.x.converters.reflection.SerializationMemberInvoker. + */ +package com.thoughtworks.xstream.core.util; + +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamField; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.ErrorWritingException; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; +import com.thoughtworks.xstream.core.Caching; + + +/** + * Convenience wrapper to invoke special serialization methods on objects (and perform reflection caching). + * + * @author Joe Walnes + * @author Jörg Schaible + */ +public class SerializationMembers implements Caching { + + private static final Method NO_METHOD = (new Object() { + private void noMethod() { + } + }).getClass().getDeclaredMethods()[0]; + private static final Object[] EMPTY_ARGS = new Object[0]; + private static final Class[] EMPTY_CLASSES = new Class[0]; + private static final Map NO_FIELDS = Collections.EMPTY_MAP; + private static final int PERSISTENT_FIELDS_MODIFIER = Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL; + private static final FastField[] OBJECT_TYPE_FIELDS = { + new FastField(Object.class, "readResolve"), + new FastField(Object.class, "writeReplace"), + new FastField(Object.class, "readObject"), + new FastField(Object.class, "writeObject") + }; + private Map declaredCache = Collections.synchronizedMap(new HashMap()); + private Map resRepCache = Collections.synchronizedMap(new HashMap()); + private final Map fieldCache = Collections.synchronizedMap(new HashMap()); + { + for(int i = 0; i < OBJECT_TYPE_FIELDS.length; ++i) { + declaredCache.put(OBJECT_TYPE_FIELDS[i], NO_METHOD); + } + for(int i = 0; i < 2; ++i) { + resRepCache.put(OBJECT_TYPE_FIELDS[i], NO_METHOD); + } + } + + /** + * Resolves an object as native serialization does by calling readResolve(), if available. + */ + public Object callReadResolve(final Object result) { + if (result == null) { + return null; + } else { + final Class resultType = result.getClass(); + final Method readResolveMethod = getRRMethod(resultType, "readResolve"); + if (readResolveMethod != null) { + ErrorWritingException ex = null; + try { + return readResolveMethod.invoke(result, EMPTY_ARGS); + } catch (IllegalAccessException e) { + ex = new ObjectAccessException("Cannot access method", e); + } catch (InvocationTargetException e) { + ex = new ConversionException("Failed calling method", e.getTargetException()); + } + ex.add("method", resultType.getName() + ".readResolve()"); + throw ex; + } else { + return result; + } + } + } + + public Object callWriteReplace(final Object object) { + if (object == null) { + return null; + } else { + final Class objectType = object.getClass(); + final Method writeReplaceMethod = getRRMethod(objectType, "writeReplace"); + if (writeReplaceMethod != null) { + ErrorWritingException ex = null; + try { + Object replaced = writeReplaceMethod.invoke(object, EMPTY_ARGS); + if (replaced != null && !object.getClass().equals(replaced.getClass())) { + // call further writeReplace methods on replaced + replaced = callWriteReplace(replaced); + } + return replaced; + } catch (final IllegalAccessException e) { + ex = new ObjectAccessException("Cannot access method", e); + } catch (InvocationTargetException e) { + ex = new ConversionException("Failed calling method", e.getTargetException()); + } catch (final ErrorWritingException e) { + ex = e; + } + ex.add("method", objectType.getName() + ".writeReplace()"); + throw ex; + } else { + return object; + } + } + } + + public boolean supportsReadObject(final Class type, final boolean includeBaseClasses) { + return getMethod( + type, "readObject", new Class[]{ObjectInputStream.class}, includeBaseClasses) != null; + } + + public void callReadObject(final Class type, final Object object, final ObjectInputStream stream) { + ErrorWritingException ex = null; + try { + Method readObjectMethod = getMethod( + type, "readObject", new Class[]{ObjectInputStream.class}, false); + readObjectMethod.invoke(object, new Object[]{stream}); + } catch (IllegalAccessException e) { + ex = new ObjectAccessException("Cannot access method", e); + } catch (InvocationTargetException e) { + ex = new ConversionException("Failed calling method", e.getTargetException()); + } + if (ex != null) { + ex.add("method", object.getClass().getName() + ".readObject()"); + throw ex; + } + } + + public boolean supportsWriteObject(final Class type, final boolean includeBaseClasses) { + return getMethod( + type, "writeObject", new Class[]{ObjectOutputStream.class}, includeBaseClasses) != null; + } + + public void callWriteObject(final Class type, final Object instance, final ObjectOutputStream stream) { + ErrorWritingException ex = null; + try { + Method readObjectMethod = getMethod( + type, "writeObject", new Class[]{ObjectOutputStream.class}, false); + readObjectMethod.invoke(instance, new Object[]{stream}); + } catch (IllegalAccessException e) { + ex = new ObjectAccessException("Cannot access method", e); + } catch (InvocationTargetException e) { + ex = new ConversionException("Failed calling method", e.getTargetException()); + } + if (ex != null) { + ex.add("method", instance.getClass().getName() + ".writeObject()"); + throw ex; + } + } + + private Method getMethod(Class type, String name, Class[] parameterTypes, + boolean includeBaseclasses) { + Method method = getMethod(type, name, parameterTypes); + return method == NO_METHOD + || (!includeBaseclasses && !method.getDeclaringClass().equals(type)) + ? null + : method; + } + + private Method getMethod(Class type, String name, Class[] parameterTypes) { + if (type == null) { + return null; + } + FastField method = new FastField(type, name); + Method result = (Method)declaredCache.get(method); + if (result == null) { + try { + result = type.getDeclaredMethod(name, parameterTypes); + if (!result.isAccessible()) { + result.setAccessible(true); + } + } catch (NoSuchMethodException e) { + result = getMethod(type.getSuperclass(), name, parameterTypes); + } + declaredCache.put(method, result); + } + return result; + } + + private Method getRRMethod(final Class type, final String name) { + final FastField method = new FastField(type, name); + Method result = (Method)resRepCache.get(method); + if (result == null) { + result = getMethod(type, name, EMPTY_CLASSES, true); + if (result != null && result.getDeclaringClass() != type) { + if ((result.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0) { + if ((result.getModifiers() & Modifier.PRIVATE) > 0 + || type.getPackage() != result.getDeclaringClass().getPackage()) { + result = NO_METHOD; + } + } + } else if (result == null) { + result = NO_METHOD; + } + resRepCache.put(method, result); + } + return result == NO_METHOD ? null : result; + } + + public Map getSerializablePersistentFields(final Class type) { + if (type == null) { + return null; + } + Map result = (Map)fieldCache.get(type.getName()); + if (result == null) { + ErrorWritingException ex = null; + try { + final Field field = type.getDeclaredField("serialPersistentFields"); + if ((field.getModifiers() & PERSISTENT_FIELDS_MODIFIER) == PERSISTENT_FIELDS_MODIFIER) { + field.setAccessible(true); + final ObjectStreamField[] fields = (ObjectStreamField[])field.get(null); + if (fields != null) { + result = new HashMap(); + for (int i = 0; i < fields.length; ++i) { + result.put(fields[i].getName(), fields[i]); + } + } + } + } catch (final NoSuchFieldException e) { + } catch (final IllegalAccessException e) { + ex = new ObjectAccessException("Cannot get field", e); + } catch (final ClassCastException e) { + ex = new ConversionException("Incompatible field type", e); + } + if (ex != null) { + ex.add("field", type.getName() + ".serialPersistentFields"); + throw ex; + } + if (result == null) { + result = NO_FIELDS; + } + fieldCache.put(type.getName(), result); + } + return result == NO_FIELDS ? null : result; + } + + public void flushCache() { + declaredCache.keySet().retainAll(Arrays.asList(OBJECT_TYPE_FIELDS)); + resRepCache.keySet().retainAll(Arrays.asList(OBJECT_TYPE_FIELDS)); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ThreadSafePropertyEditor.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ThreadSafePropertyEditor.java (.../ThreadSafePropertyEditor.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ThreadSafePropertyEditor.java (.../ThreadSafePropertyEditor.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2008, 2014 XStream Committers. + * Copyright (c) 2007, 2008, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,53 +10,59 @@ */ package com.thoughtworks.xstream.core.util; -import java.beans.PropertyEditor; - +import com.thoughtworks.xstream.converters.ConversionException; +import com.thoughtworks.xstream.converters.ErrorWritingException; import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; +import java.beans.PropertyEditor; + /** * Wrapper around {@link PropertyEditor} that can be called by multiple threads concurrently. *

      - * A PropertyEditor is not thread safe. To make best use of resources, the PropertyEditor provides a dynamically sizing - * pool of instances, each of which will only be called by a single thread at a time. + * A PropertyEditor is not thread safe. To make best use of resources, the PropertyEditor + * provides a dynamically sizing pool of instances, each of which will only be called by a + * single thread at a time. *

      *

      - * The pool has a maximum capacity, to limit overhead. If all instances in the pool are in use and another is required, - * it shall block until one becomes available. + * The pool has a maximum capacity, to limit overhead. If all instances in the pool are in use + * and another is required, it shall block until one becomes available. *

      * * @author Jörg Schaible * @since 1.3 */ public class ThreadSafePropertyEditor { - private final Class editorType; - private final Pool pool; + private final Class editorType; + private final Pool pool; - public ThreadSafePropertyEditor( - final Class type, final int initialPoolSize, final int maxPoolSize) { + public ThreadSafePropertyEditor(Class type, int initialPoolSize, int maxPoolSize) { if (!PropertyEditor.class.isAssignableFrom(type)) { - throw new IllegalArgumentException(type.getName() + " is not a " + PropertyEditor.class.getName()); + throw new IllegalArgumentException(type.getName() + + " is not a " + + PropertyEditor.class.getName()); } editorType = type; - pool = new Pool(initialPoolSize, maxPoolSize, new Pool.Factory() { - @Override - public PropertyEditor newInstance() { + pool = new Pool(initialPoolSize, maxPoolSize, new Pool.Factory() { + public Object newInstance() { + ErrorWritingException ex = null; try { return editorType.newInstance(); - } catch (final InstantiationException e) { - throw new ObjectAccessException("Could not call default constructor of " + editorType.getName(), e); - } catch (final IllegalAccessException e) { - throw new ObjectAccessException("Could not call default constructor of " + editorType.getName(), e); + } catch (InstantiationException e) { + ex = new ConversionException("Faild to call default constructor", e); + } catch (IllegalAccessException e) { + ex = new ObjectAccessException("Cannot call default constructor", e); } + ex.add("construction-type", editorType.getName()); + throw ex; } }); } - public String getAsText(final Object object) { - final PropertyEditor editor = fetchFromPool(); + public String getAsText(Object object) { + PropertyEditor editor = fetchFromPool(); try { editor.setValue(object); return editor.getAsText(); @@ -65,8 +71,8 @@ } } - public Object setAsText(final String str) { - final PropertyEditor editor = fetchFromPool(); + public Object setAsText(String str) { + PropertyEditor editor = fetchFromPool(); try { editor.setAsText(str); return editor.getValue(); @@ -76,6 +82,7 @@ } private PropertyEditor fetchFromPool() { - return pool.fetchFromPool(); + PropertyEditor editor = (PropertyEditor)pool.fetchFromPool(); + return editor; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ThreadSafeSimpleDateFormat.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ThreadSafeSimpleDateFormat.java (.../ThreadSafeSimpleDateFormat.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/ThreadSafeSimpleDateFormat.java (.../ThreadSafeSimpleDateFormat.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2012, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011, 2012 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -18,61 +18,59 @@ import java.util.Locale; import java.util.TimeZone; - /** - * Wrapper around java.text.SimpleDateFormat that can be called by multiple threads concurrently. - *

      - * SimpleDateFormat has a high overhead in creating and is not thread safe. To make best use of resources, the - * ThreadSafeSimpleDateFormat provides a dynamically sizing pool of instances, each of which will only be called by a - * single thread at a time. - *

      - *

      - * The pool has a maximum capacity, to limit overhead. If all instances in the pool are in use and another is required, - * it shall block until one becomes available. - *

      - * + * Wrapper around java.text.SimpleDateFormat that can + * be called by multiple threads concurrently. + *

      SimpleDateFormat has a high overhead in creating + * and is not thread safe. To make best use of resources, + * the ThreadSafeSimpleDateFormat provides a dynamically + * sizing pool of instances, each of which will only + * be called by a single thread at a time.

      + *

      The pool has a maximum capacity, to limit overhead. + * If all instances in the pool are in use and another is + * required, it shall block until one becomes available.

      + * * @author Joe Walnes * @author Jörg Schaible */ public class ThreadSafeSimpleDateFormat { private final String formatString; - private final Pool pool; + private final Pool pool; private final TimeZone timeZone; public ThreadSafeSimpleDateFormat( - final String format, final TimeZone timeZone, final int initialPoolSize, final int maxPoolSize, - final boolean lenient) { + String format, TimeZone timeZone, int initialPoolSize, int maxPoolSize, + final boolean lenient) { this(format, timeZone, Locale.ENGLISH, initialPoolSize, maxPoolSize, lenient); } public ThreadSafeSimpleDateFormat( - final String format, final TimeZone timeZone, final Locale locale, final int initialPoolSize, - final int maxPoolSize, final boolean lenient) { + String format, TimeZone timeZone, final Locale locale, int initialPoolSize, + int maxPoolSize, final boolean lenient) { formatString = format; this.timeZone = timeZone; - pool = new Pool(initialPoolSize, maxPoolSize, new Pool.Factory() { - @Override - public SimpleDateFormat newInstance() { - final SimpleDateFormat dateFormat = new SimpleDateFormat(formatString, locale); + pool = new Pool(initialPoolSize, maxPoolSize, new Pool.Factory() { + public Object newInstance() { + SimpleDateFormat dateFormat = new SimpleDateFormat(formatString, locale); dateFormat.setLenient(lenient); return dateFormat; } }); } - public String format(final Date date) { - final DateFormat format = fetchFromPool(); + public String format(Date date) { + DateFormat format = fetchFromPool(); try { return format.format(date); } finally { pool.putInPool(format); } } - public Date parse(final String date) throws ParseException { - final DateFormat format = fetchFromPool(); + public Date parse(String date) throws ParseException { + DateFormat format = fetchFromPool(); try { return format.parse(date); } finally { @@ -81,15 +79,14 @@ } private DateFormat fetchFromPool() { - final DateFormat format = pool.fetchFromPool(); - final TimeZone tz = timeZone != null ? timeZone : TimeZone.getDefault(); + DateFormat format = (DateFormat)pool.fetchFromPool(); + TimeZone tz = timeZone != null ? timeZone : TimeZone.getDefault(); if (!tz.equals(format.getTimeZone())) { format.setTimeZone(tz); } return format; } - @Override public String toString() { return formatString; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/TypedNull.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/TypedNull.java (.../TypedNull.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/TypedNull.java (.../TypedNull.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2014 XStream Committers. + * Copyright (c) 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,19 +12,22 @@ /** * A placeholder for a null value of a specific type. - * - * @author Jörg Schaible + * + * @author Jörg Schaible * @since 1.2.2 */ -public class TypedNull { - private final Class type; - - public TypedNull(final Class type) { - super(); - this.type = type; - } - - public Class getType() { - return this.type; - } +public class TypedNull +{ + private final Class type; + + public TypedNull(Class type) + { + super(); + this.type = type; + } + + public Class getType() + { + return this.type; + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Types.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Types.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/Types.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2015 XStream Committers. + * All rights reserved. + * + * Created on 17. January 2015 by Joerg Schaible + */ +package com.thoughtworks.xstream.core.util; + +import java.util.regex.Pattern; + + +/** + * Helper methods for class types. + * + * @author Jörg Schaible + * @since 1.4.8 + */ +public class Types { + private static final Pattern lambdaPattern = Pattern.compile(".*\\$\\$Lambda\\$[0-9]+/.*"); + + public static final boolean isLambdaType(final Class type) { + return type != null && type.isSynthetic() && lambdaPattern.matcher(type.getSimpleName()).matches(); + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/WeakCache.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/WeakCache.java (.../WeakCache.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/WeakCache.java (.../WeakCache.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -23,26 +23,26 @@ /** - * A HashMap implementation with weak references values and by default for the key. When the value is garbage collected, - * the key will also vanish from the map. + * A HashMap implementation with weak references values and by default for the key. When the + * value is garbage collected, the key will also vanish from the map. * * @author Jörg Schaible * @since 1.4 */ -public class WeakCache extends AbstractMap { +public class WeakCache extends AbstractMap { - private final Map> map; + private final Map map; /** * Construct a WeakCache with weak keys. - *

      - * Note, that the internally used WeakHashMap is not thread-safe. - *

      * + *

      Note, that the internally used WeakHashMap is not thread-safe.

      + * + * @param map the map to use * @since 1.4 */ public WeakCache() { - this(new WeakHashMap>()); + this(new WeakHashMap()); } /** @@ -51,46 +51,40 @@ * @param map the map to use * @since 1.4 */ - public WeakCache(final Map> map) { + public WeakCache(Map map) { this.map = map; } - @Override - public V get(final Object key) { - final Reference reference = map.get(key); + public Object get(Object key) { + Reference reference = (Reference)map.get(key); return reference != null ? reference.get() : null; } - @Override - public V put(final K key, final V value) { - final Reference ref = map.put(key, createReference(value)); + public Object put(Object key, Object value) { + Reference ref = (Reference)map.put(key, createReference(value)); return ref == null ? null : ref.get(); } - @Override - public V remove(final Object key) { - final Reference ref = map.remove(key); + public Object remove(Object key) { + Reference ref = (Reference)map.remove(key); return ref == null ? null : ref.get(); } - protected Reference createReference(final V value) { - return new WeakReference(value); + protected Reference createReference(Object value) { + return new WeakReference(value); } - @Override public boolean containsValue(final Object value) { - final Boolean result = (Boolean)iterate(new Visitor() { + Boolean result = (Boolean)iterate(new Visitor() { - @Override - public Object visit(final Object element) { + public Object visit(Object element) { return element.equals(value) ? Boolean.TRUE : null; } - }, Visitor.Type.value); + }, 0); return result == Boolean.TRUE; } - @Override public int size() { if (map.size() == 0) { return 0; @@ -99,130 +93,111 @@ i[0] = 0; iterate(new Visitor() { - @Override - public Object visit(final Object element) { + public Object visit(Object element) { ++i[0]; return null; } - }, Visitor.Type.key); + }, 0); return i[0]; } - @Override - public Collection values() { - final Collection collection = new ArrayList(); + public Collection values() { + final Collection collection = new ArrayList(); if (map.size() != 0) { iterate(new Visitor() { - @Override - public Object visit(final Object element) { - @SuppressWarnings("unchecked") - final V value = (V)element; - collection.add(value); + public Object visit(Object element) { + collection.add(element); return null; } - }, Visitor.Type.value); + }, 0); } return collection; } - @Override - public Set> entrySet() { - final Set> set = new HashSet>(); + public Set entrySet() { + final Set set = new HashSet(); if (map.size() != 0) { iterate(new Visitor() { - @Override - public Object visit(final Object element) { - @SuppressWarnings("unchecked") - final Map.Entry> entry = (Map.Entry>)element; - set.add(new Map.Entry() { + public Object visit(Object element) { + final Map.Entry entry = (Map.Entry)element; + set.add(new Map.Entry() { - @Override - public K getKey() { + public Object getKey() { return entry.getKey(); } - @Override - public V getValue() { - return entry.getValue().get(); + public Object getValue() { + return ((Reference)entry.getValue()).get(); } - @Override - public V setValue(final V value) { - final Reference reference = entry.setValue(createReference(value)); + public Object setValue(Object value) { + Reference reference = (Reference)entry.setValue(createReference(value)); return reference != null ? reference.get() : null; } }); return null; } - }, Visitor.Type.entry); + }, 2); } return set; } - private Object iterate(final Visitor visitor, final Visitor.Type type) { + private Object iterate(Visitor visitor, int type) { Object result = null; - for (final Iterator>> iter = map.entrySet().iterator(); result == null - && iter.hasNext();) { - final Map.Entry> entry = iter.next(); - final Reference reference = entry.getValue(); - final V element = reference.get(); + for (Iterator iter = map.entrySet().iterator(); result == null && iter.hasNext();) { + Map.Entry entry = (Map.Entry)iter.next(); + Reference reference = (Reference)entry.getValue(); + Object element = reference.get(); if (element == null) { iter.remove(); continue; } switch (type) { - case value: + case 0: result = visitor.visit(element); break; - case key: + case 1: result = visitor.visit(entry.getKey()); break; - case entry: + case 2: result = visitor.visit(entry); break; } } return result; } - + private interface Visitor { - enum Type {key, value, entry}; Object visit(Object element); } - @Override - public boolean containsKey(final Object key) { + public boolean containsKey(Object key) { return map.containsKey(key); } - @Override public void clear() { map.clear(); } - @Override - public Set keySet() { + public Set keySet() { return map.keySet(); } - @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { return map.equals(o); } - @Override public int hashCode() { return map.hashCode(); } - @Override public String toString() { return map.toString(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/XmlHeaderAwareReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/XmlHeaderAwareReader.java (.../XmlHeaderAwareReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/core/util/XmlHeaderAwareReader.java (.../XmlHeaderAwareReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2010, 2014 XStream Committers. + * Copyright (C) 2007, 2008, 2010 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -18,7 +18,6 @@ import java.io.PushbackInputStream; import java.io.Reader; import java.io.UnsupportedEncodingException; -import java.nio.CharBuffer; import java.util.HashMap; import java.util.Map; @@ -59,13 +58,13 @@ final PushbackInputStream[] pin = new PushbackInputStream[]{in instanceof PushbackInputStream ? (PushbackInputStream)in : new PushbackInputStream(in, 64)}; - final Map header = getHeader(pin); - version = Double.parseDouble(header.get(KEY_VERSION)); - reader = new InputStreamReader(pin[0], header.get(KEY_ENCODING)); + final Map header = getHeader(pin); + version = Double.parseDouble((String)header.get(KEY_VERSION)); + reader = new InputStreamReader(pin[0], (String)header.get(KEY_ENCODING)); } - private Map getHeader(final PushbackInputStream[] in) throws IOException { - final Map header = new HashMap(); + private Map getHeader(final PushbackInputStream[] in) throws IOException { + final Map header = new HashMap(); header.put(KEY_ENCODING, "utf-8"); header.put(KEY_VERSION, "1.0"); @@ -82,7 +81,9 @@ ch = (char)i; switch (state) { case STATE_BOM: - if (ch == 0xEF && out.size() == 1 || ch == 0xBB && out.size() == 2 || ch == 0xBF && out.size() == 3) { + if ((ch == 0xEF && out.size() == 1) + || (ch == 0xBB && out.size() == 2) + || (ch == 0xBF && out.size() == 3)) { if (ch == 0xBF) { out.reset(); state = STATE_START; @@ -94,7 +95,7 @@ } else { state = STATE_START; } - //$FALL-THROUGH$ + // fall through case STATE_START: if (!Character.isWhitespace(ch)) { if (ch == '<') { @@ -166,12 +167,12 @@ } } - final byte[] pushbackData = out.toByteArray(); + byte[] pushbackData = out.toByteArray(); for (i = pushbackData.length; i-- > 0;) { final byte b = pushbackData[i]; try { in[0].unread(b); - } catch (final IOException ex) { + } catch (IOException ex) { in[0] = new PushbackInputStream(in[0], ++i); } } @@ -187,74 +188,98 @@ } /** - * @return the XML version + * @see InputStreamReader#getEncoding() * @since 1.3 */ public double getVersion() { return version; } - @Override + /** + * @see java.io.Reader#mark(int) + */ public void mark(final int readAheadLimit) throws IOException { reader.mark(readAheadLimit); } - @Override + /** + * @see java.io.Reader#markSupported() + */ public boolean markSupported() { return reader.markSupported(); } - @Override + /** + * @see java.io.Reader#read() + */ public int read() throws IOException { return reader.read(); } - @Override + /** + * @see java.io.Reader#read(char[], int, int) + */ public int read(final char[] cbuf, final int offset, final int length) throws IOException { return reader.read(cbuf, offset, length); } - @Override + /** + * @see java.io.Reader#read(char[]) + */ public int read(final char[] cbuf) throws IOException { return reader.read(cbuf); } - @Override - public int read(final CharBuffer target) throws IOException { - return reader.read(target); - } +// TODO: This is JDK 1.5 +// public int read(final CharBuffer target) throws IOException { +// return reader.read(target); +// } - @Override + /** + * @see java.io.Reader#ready() + */ public boolean ready() throws IOException { return reader.ready(); } - @Override + /** + * @see java.io.Reader#reset() + */ public void reset() throws IOException { reader.reset(); } - @Override + /** + * @see java.io.Reader#skip(long) + */ public long skip(final long n) throws IOException { return reader.skip(n); } - @Override + /** + * @see java.io.Reader#close() + */ public void close() throws IOException { reader.close(); } - @Override + /** + * @see java.lang.Object#equals(java.lang.Object) + */ public boolean equals(final Object obj) { return reader.equals(obj); } - @Override + /** + * @see java.lang.Object#hashCode() + */ public int hashCode() { return reader.hashCode(); } - @Override + /** + * @see java.lang.Object#toString() + */ public String toString() { return reader.toString(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AbstractDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AbstractDriver.java (.../AbstractDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AbstractDriver.java (.../AbstractDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,6 +14,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.net.URL; import com.thoughtworks.xstream.io.naming.NameCoder; @@ -22,14 +23,15 @@ /** * Abstract base class for all HierarchicalStreamDriver implementations. Implementations of - * {@link HierarchicalStreamDriver} should rather be derived from this class then implementing the interface directly. + * {@link HierarchicalStreamDriver} should rather be derived from this class then implementing + * the interface directly. * * @author Jörg Schaible * @since 1.4 */ public abstract class AbstractDriver implements HierarchicalStreamDriver { - private final NameCoder replacer; + private NameCoder replacer; /** * Creates an AbstractDriver with a NameCoder that does nothing. @@ -43,28 +45,34 @@ * * @param nameCoder the name coder for the target format */ - public AbstractDriver(final NameCoder nameCoder) { - replacer = nameCoder; + public AbstractDriver(NameCoder nameCoder) { + this.replacer = nameCoder; } protected NameCoder getNameCoder() { return replacer; } - @Override - public HierarchicalStreamReader createReader(final URL in) { + /** + * {@inheritDoc} + */ + public HierarchicalStreamReader createReader(URL in) { + InputStream stream = null; try { - return createReader(in.openStream()); - } catch (final IOException e) { + stream = in.openStream(); + } catch (IOException e) { throw new StreamException(e); } + return createReader(stream); } - @Override - public HierarchicalStreamReader createReader(final File in) { + /** + * {@inheritDoc} + */ + public HierarchicalStreamReader createReader(File in) { try { return createReader(new FileInputStream(in)); - } catch (final FileNotFoundException e) { + } catch (FileNotFoundException e) { throw new StreamException(e); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AbstractReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AbstractReader.java (.../AbstractReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AbstractReader.java (.../AbstractReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -17,14 +17,15 @@ /** * Abstract base class for all HierarchicalStreamReader implementations. Implementations of - * {@link HierarchicalStreamReader} should rather be derived from this class then implementing the interface directly. + * {@link HierarchicalStreamReader} should rather be derived from this class then implementing + * the interface directly. * * @author Jörg Schaible * @since 1.4 */ public abstract class AbstractReader implements ExtendedHierarchicalStreamReader { - private final NameCoder nameCoder; + private NameCoder nameCoder; /** * Creates an AbstractReader with a NameCoder that does nothing. @@ -41,11 +42,13 @@ * @param nameCoder the name coder used to read names from the incoming format * @since 1.4 */ - protected AbstractReader(final NameCoder nameCoder) { - this.nameCoder = Cloneables.cloneIfPossible(nameCoder); + protected AbstractReader(NameCoder nameCoder) { + this.nameCoder = (NameCoder)Cloneables.cloneIfPossible(nameCoder); } - @Override + /** + * {@inheritDoc} + */ public HierarchicalStreamReader underlyingReader() { return this; } @@ -57,7 +60,7 @@ * @return the original name * @since 1.4 */ - public String decodeNode(final String name) { + public String decodeNode(String name) { return nameCoder.decodeNode(name); } @@ -68,7 +71,7 @@ * @return the original name * @since 1.4 */ - public String decodeAttribute(final String name) { + public String decodeAttribute(String name) { return nameCoder.decodeAttribute(name); } @@ -79,7 +82,7 @@ * @return the name in the target format * @since 1.4 */ - protected String encodeNode(final String name) { + protected String encodeNode(String name) { return nameCoder.encodeNode(name); } @@ -90,11 +93,10 @@ * @return the name in the target format * @since 1.4 */ - protected String encodeAttribute(final String name) { + protected String encodeAttribute(String name) { return nameCoder.encodeAttribute(name); } - @Override public String peekNextChild() { throw new UnsupportedOperationException("peekNextChild"); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AbstractWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AbstractWriter.java (.../AbstractWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AbstractWriter.java (.../AbstractWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -17,14 +17,15 @@ /** * Abstract base class for all HierarchicalStreamWriter implementations. Implementations of - * {@link HierarchicalStreamWriter} should rather be derived from this class then implementing the interface directly. + * {@link HierarchicalStreamWriter} should rather be derived from this class then implementing + * the interface directly. * * @author Jörg Schaible * @since 1.4 */ public abstract class AbstractWriter implements ExtendedHierarchicalStreamWriter { - private final NameCoder nameCoder; + private NameCoder nameCoder; /** * Creates an AbstractWriter with a NameCoder that does nothing. @@ -41,16 +42,20 @@ * @param nameCoder the name coder used to write names in the target format * @since 1.4 */ - protected AbstractWriter(final NameCoder nameCoder) { - this.nameCoder = Cloneables.cloneIfPossible(nameCoder); + protected AbstractWriter(NameCoder nameCoder) { + this.nameCoder = (NameCoder)Cloneables.cloneIfPossible(nameCoder); } - @Override - public void startNode(final String name, final Class clazz) { + /** + * {@inheritDoc} + */ + public void startNode(String name, Class clazz) { startNode(name); } - @Override + /** + * {@inheritDoc} + */ public HierarchicalStreamWriter underlyingWriter() { return this; } @@ -62,7 +67,7 @@ * @return the name in the target format * @since 1.4 */ - public String encodeNode(final String name) { + public String encodeNode(String name) { return nameCoder.encodeNode(name); } @@ -73,7 +78,7 @@ * @return the name in the target format * @since 1.4 */ - public String encodeAttribute(final String name) { + public String encodeAttribute(String name) { return nameCoder.encodeAttribute(name); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AttributeNameIterator.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AttributeNameIterator.java (.../AttributeNameIterator.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/AttributeNameIterator.java (.../AttributeNameIterator.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -13,36 +13,31 @@ import java.util.Iterator; - /** * Provide an iterator over the attribute names of the current node of a reader. - * + * * @author Joe Walnes - * @deprecated As of upcoming, it is an internal helper class only + * @deprecated As of 1.4.8, it is an internal helper class only */ -@Deprecated -public class AttributeNameIterator implements Iterator { +public class AttributeNameIterator implements Iterator { private int current; private final int count; private final HierarchicalStreamReader reader; - public AttributeNameIterator(final HierarchicalStreamReader reader) { + public AttributeNameIterator(HierarchicalStreamReader reader) { this.reader = reader; count = reader.getAttributeCount(); } - @Override public boolean hasNext() { return current < count; } - @Override - public String next() { + public Object next() { return reader.getAttributeName(current++); } - @Override public void remove() { throw new UnsupportedOperationException(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/ExtendedHierarchicalStreamWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/ExtendedHierarchicalStreamWriter.java (.../ExtendedHierarchicalStreamWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/ExtendedHierarchicalStreamWriter.java (.../ExtendedHierarchicalStreamWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,6 +16,6 @@ */ public interface ExtendedHierarchicalStreamWriter extends HierarchicalStreamWriter { - void startNode(String name, Class clazz); + void startNode(String name, Class clazz); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/ExtendedHierarchicalStreamWriterHelper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/ExtendedHierarchicalStreamWriterHelper.java (.../ExtendedHierarchicalStreamWriterHelper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/ExtendedHierarchicalStreamWriterHelper.java (.../ExtendedHierarchicalStreamWriterHelper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,9 +12,9 @@ package com.thoughtworks.xstream.io; public class ExtendedHierarchicalStreamWriterHelper { - public static void startNode(final HierarchicalStreamWriter writer, final String name, final Class clazz) { + public static void startNode(HierarchicalStreamWriter writer, String name, Class clazz) { if (writer instanceof ExtendedHierarchicalStreamWriter) { - ((ExtendedHierarchicalStreamWriter)writer).startNode(name, clazz); + ((ExtendedHierarchicalStreamWriter) writer).startNode(name, clazz); } else { writer.startNode(name); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/HierarchicalStreamReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/HierarchicalStreamReader.java (.../HierarchicalStreamReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/HierarchicalStreamReader.java (.../HierarchicalStreamReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2011, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,26 +11,24 @@ */ package com.thoughtworks.xstream.io; -import java.io.Closeable; -import java.util.Iterator; - import com.thoughtworks.xstream.converters.ErrorReporter; import com.thoughtworks.xstream.converters.ErrorWriter; +import java.util.Iterator; /** * @author Joe Walnes */ -public interface HierarchicalStreamReader extends ErrorReporter, Closeable { +public interface HierarchicalStreamReader extends ErrorReporter { /** * Does the node have any more children remaining that have not yet been read? */ boolean hasMoreChildren(); /** - * Select the current child as current node. A call to this function must be balanced with a call to - * {@link #moveUp()}. + * Select the current child as current node. + * A call to this function must be balanced with a call to {@link #moveUp()}. */ void moveDown(); @@ -51,67 +49,72 @@ /** * Get the value of an attribute of the current node. + *

      + * If no such attribute exists, the method returns null. + *

      */ String getAttribute(String name); /** * Get the value of an attribute of the current node, by index. + *

      + * Note, the behavior of this method is dependent on the underlying parser when calling it with a non-existing + * index. Typically some kind of RuntimeException is thrown. + *

      */ String getAttribute(int index); - + /** * Number of attributes in current node. */ int getAttributeCount(); /** * Name of attribute in current node. + *

      + * Note, the behavior of this method is dependent on the underlying parser when calling it with a non-existing + * index. Typically some kind of RuntimeException is thrown. + *

      */ String getAttributeName(int index); /** - * Names of attributes. + * Iterator with the names of the attributes. + *

      + * Note, the iterator is only valid as long as the internal state of the underlying parser is still at the start of + * the current element. The behavior is undefined if the parser moved on. + *

      */ - Iterator getAttributeNames(); + Iterator getAttributeNames(); /** - * If any errors are detected, allow the reader to add any additional information that can aid debugging (such as - * line numbers, XPath expressions, etc). + * If any errors are detected, allow the reader to add any additional information that can aid debugging + * (such as line numbers, XPath expressions, etc). */ - @Override void appendErrors(ErrorWriter errorWriter); /** * Close the reader, if necessary. */ - @Override void close(); /** * Return the underlying HierarchicalStreamReader implementation. - *

      - * If a Converter needs to access methods of a specific HierarchicalStreamReader implementation that are not defined - * in the HierarchicalStreamReader interface, it should call this method before casting. This is because the reader - * passed to the Converter is often wrapped/decorated by another implementation to provide additional functionality - * (such as XPath tracking). - *

      - *

      - * For example: - *

      - * - *
      -     * MySpecificReader mySpecificReader = (MySpecificReader)reader; // INCORRECT!
      -     * mySpecificReader.doSomethingSpecific();
      -     * 
      - * - *
      -     * MySpecificReader mySpecificReader = (MySpecificReader)reader.underlyingReader();  // CORRECT!
      -     * mySpecificReader.doSomethingSpecific();
      -     * 
      - *

      - * Implementations of HierarchicalStreamReader should return 'this', unless they are a decorator, in which case they - * should delegate to whatever they are wrapping. - *

      + * + *

      If a Converter needs to access methods of a specific HierarchicalStreamReader implementation that are not + * defined in the HierarchicalStreamReader interface, it should call this method before casting. This is because + * the reader passed to the Converter is often wrapped/decorated by another implementation to provide additional + * functionality (such as XPath tracking).

      + * + *

      For example:

      + *
      MySpecificReader mySpecificReader = (MySpecificReader)reader; // INCORRECT!
      +     * mySpecificReader.doSomethingSpecific();
      + + *
      MySpecificReader mySpecificReader = (MySpecificReader)reader.underlyingReader();  // CORRECT!
      +     * mySpecificReader.doSomethingSpecific();
      + * + *

      Implementations of HierarchicalStreamReader should return 'this', unless they are a decorator, in which case + * they should delegate to whatever they are wrapping.

      */ HierarchicalStreamReader underlyingReader(); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/HierarchicalStreamWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/HierarchicalStreamWriter.java (.../HierarchicalStreamWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/HierarchicalStreamWriter.java (.../HierarchicalStreamWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,13 +11,10 @@ */ package com.thoughtworks.xstream.io; -import java.io.Closeable; - - /** * @author Joe Walnes */ -public interface HierarchicalStreamWriter extends Closeable { +public interface HierarchicalStreamWriter { void startNode(String name); @@ -38,34 +35,25 @@ /** * Close the writer, if necessary. */ - @Override void close(); /** * Return the underlying HierarchicalStreamWriter implementation. - *

      - * If a Converter needs to access methods of a specific HierarchicalStreamWriter implementation that are not defined - * in the HierarchicalStreamWriter interface, it should call this method before casting. This is because the writer - * passed to the Converter is often wrapped/decorated by another implementation to provide additional functionality - * (such as XPath tracking). - *

      - *

      - * For example: - *

      - * - *
      -     * MySpecificWriter mySpecificWriter = (MySpecificWriter)writer; // INCORRECT!
      -     * mySpecificWriter.doSomethingSpecific();
      -     * 
      - * - *
      -     * MySpecificWriter mySpecificWriter = (MySpecificWriter)writer.underlyingWriter();  // CORRECT!
      -     * mySpecificWriter.doSomethingSpecific();
      -     * 
      - *

      - * Implementations of HierarchicalStreamWriter should return 'this', unless they are a decorator, in which case they - * should delegate to whatever they are wrapping. - *

      + * + *

      If a Converter needs to access methods of a specific HierarchicalStreamWriter implementation that are not + * defined in the HierarchicalStreamWriter interface, it should call this method before casting. This is because + * the writer passed to the Converter is often wrapped/decorated by another implementation to provide additional + * functionality (such as XPath tracking).

      + * + *

      For example:

      + *
      MySpecificWriter mySpecificWriter = (MySpecificWriter)writer; // INCORRECT!
      +     * mySpecificWriter.doSomethingSpecific();
      + + *
      MySpecificWriter mySpecificWriter = (MySpecificWriter)writer.underlyingWriter();  // CORRECT!
      +     * mySpecificWriter.doSomethingSpecific();
      + * + *

      Implementations of HierarchicalStreamWriter should return 'this', unless they are a decorator, in which case + * they should delegate to whatever they are wrapping.

      */ HierarchicalStreamWriter underlyingWriter(); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/ReaderWrapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/ReaderWrapper.java (.../ReaderWrapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/ReaderWrapper.java (.../ReaderWrapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,93 +11,78 @@ */ package com.thoughtworks.xstream.io; -import java.util.Iterator; - import com.thoughtworks.xstream.converters.ErrorWriter; +import java.util.Iterator; /** * Base class to make it easy to create wrappers (decorators) for HierarchicalStreamReader. - * + * * @author Joe Walnes */ public abstract class ReaderWrapper implements ExtendedHierarchicalStreamReader { protected HierarchicalStreamReader wrapped; - protected ReaderWrapper(final HierarchicalStreamReader reader) { - wrapped = reader; + protected ReaderWrapper(HierarchicalStreamReader reader) { + this.wrapped = reader; } - @Override public boolean hasMoreChildren() { return wrapped.hasMoreChildren(); } - @Override public void moveDown() { wrapped.moveDown(); } - @Override public void moveUp() { wrapped.moveUp(); } - @Override public String getNodeName() { return wrapped.getNodeName(); } - @Override public String getValue() { return wrapped.getValue(); } - @Override - public String getAttribute(final String name) { + public String getAttribute(String name) { return wrapped.getAttribute(name); } - @Override - public String getAttribute(final int index) { + public String getAttribute(int index) { return wrapped.getAttribute(index); } - @Override public int getAttributeCount() { return wrapped.getAttributeCount(); } - @Override - public String getAttributeName(final int index) { + public String getAttributeName(int index) { return wrapped.getAttributeName(index); } - @Override - public Iterator getAttributeNames() { + public Iterator getAttributeNames() { return wrapped.getAttributeNames(); } - @Override - public void appendErrors(final ErrorWriter errorWriter) { + public void appendErrors(ErrorWriter errorWriter) { wrapped.appendErrors(errorWriter); } - @Override public void close() { wrapped.close(); } - @Override public String peekNextChild() { - if (!(wrapped instanceof ExtendedHierarchicalStreamReader)) { + if (! (wrapped instanceof ExtendedHierarchicalStreamReader)) { throw new UnsupportedOperationException("peekNextChild"); } return ((ExtendedHierarchicalStreamReader)wrapped).peekNextChild(); } - @Override public HierarchicalStreamReader underlyingReader() { return wrapped.underlyingReader(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/StatefulWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/StatefulWriter.java (.../StatefulWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/StatefulWriter.java (.../StatefulWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,20 +11,18 @@ */ package com.thoughtworks.xstream.io; +import com.thoughtworks.xstream.core.util.FastStack; + import java.io.IOException; import java.util.HashSet; import java.util.Set; -import com.thoughtworks.xstream.core.util.FastStack; - /** * An wrapper for all {@link HierarchicalStreamWriter} implementations, that keeps the state. - *

      - * Writing in a wrong state will throw a {@link StreamException}, that wraps either an {@link IOException} (writing to a - * closed writer) or an {@link IllegalStateException}. The implementation will also track unbalanced nodes or multiple - * attributes with the same name. - *

      + * Writing in a wrong state will throw a {@link StreamException}, that wraps either an + * {@link IOException} (writing to a closed writer) or an {@link IllegalStateException}. The + * implementation will also track unbalanced nodes or multiple attributes with the same name. * * @author Jörg Schaible * @since 1.2 @@ -64,7 +62,7 @@ private transient int state = STATE_OPEN; private transient int balance; - private transient FastStack> attributes; + private transient FastStack attributes; /** * Constructs a StatefulWriter. @@ -74,17 +72,15 @@ */ public StatefulWriter(final HierarchicalStreamWriter wrapped) { super(wrapped); - attributes = new FastStack>(16); + attributes = new FastStack(16); } - @Override public void startNode(final String name) { startNodeCommon(); super.startNode(name); } - @Override - public void startNode(final String name, final Class clazz) { + public void startNode(final String name, final Class clazz) { startNodeCommon(); super.startNode(name, clazz); } @@ -97,37 +93,37 @@ } state = STATE_NODE_START; ++balance; - attributes.push(new HashSet()); + attributes.push(new HashSet()); } - @Override - public void addAttribute(final String name, final String value) { + public void addAttribute(String name, String value) { checkClosed(); if (state != STATE_NODE_START) { throw new StreamException(new IllegalStateException("Writing attribute '" - + name - + "' without an opened node")); + + name + + "' without an opened node")); } - final Set currentAttributes = attributes.peek(); + Set currentAttributes = (Set)attributes.peek(); if (currentAttributes.contains(name)) { - throw new StreamException(new IllegalStateException("Writing attribute '" + name + "' twice")); + throw new StreamException(new IllegalStateException("Writing attribute '" + + name + + "' twice")); } currentAttributes.add(name); super.addAttribute(name, value); } - @Override - public void setValue(final String text) { + public void setValue(String text) { checkClosed(); if (state != STATE_NODE_START) { // STATE_NODE_END is legal XML, but not in XStream ... ? - throw new StreamException(new IllegalStateException("Writing text without an opened node")); + throw new StreamException(new IllegalStateException( + "Writing text without an opened node")); } state = STATE_VALUE; super.setValue(text); } - @Override public void endNode() { checkClosed(); if (balance-- == 0) { @@ -138,13 +134,11 @@ super.endNode(); } - @Override public void flush() { checkClosed(); super.flush(); } - @Override public void close() { if (state != STATE_NODE_END && state != STATE_OPEN) { // calling close in a finally block should not throw again @@ -176,7 +170,7 @@ } private Object readResolve() { - attributes = new FastStack>(16); + attributes = new FastStack(16); return this; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/WriterWrapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/WriterWrapper.java (.../WriterWrapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/WriterWrapper.java (.../WriterWrapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,54 +13,46 @@ /** * Base class to make it easy to create wrappers (decorators) for HierarchicalStreamWriter. - * + * * @author Joe Walnes */ public abstract class WriterWrapper implements ExtendedHierarchicalStreamWriter { protected HierarchicalStreamWriter wrapped; - protected WriterWrapper(final HierarchicalStreamWriter wrapped) { + protected WriterWrapper(HierarchicalStreamWriter wrapped) { this.wrapped = wrapped; } - @Override - public void startNode(final String name) { + public void startNode(String name) { wrapped.startNode(name); } - @Override - public void startNode(final String name, final Class clazz) { + public void startNode(String name, Class clazz) { - ((ExtendedHierarchicalStreamWriter)wrapped).startNode(name, clazz); + ((ExtendedHierarchicalStreamWriter) wrapped).startNode(name, clazz); } - @Override public void endNode() { wrapped.endNode(); } - @Override - public void addAttribute(final String key, final String value) { + public void addAttribute(String key, String value) { wrapped.addAttribute(key, value); } - @Override - public void setValue(final String text) { + public void setValue(String text) { wrapped.setValue(text); } - @Override public void flush() { wrapped.flush(); } - @Override public void close() { wrapped.close(); } - @Override public HierarchicalStreamWriter underlyingWriter() { return wrapped.underlyingWriter(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/BinaryStreamDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/BinaryStreamDriver.java (.../BinaryStreamDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/BinaryStreamDriver.java (.../BinaryStreamDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2014 XStream Committers. + * Copyright (C) 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -21,9 +21,10 @@ /** - * HierarchicalStreamDriver for binary input and output. The driver uses an optimized binary format to store an object - * graph. The format is not as compact as Java serialization, but a lot more than typical text-based formats like XML. - * However, due to its nature it cannot use a {@link Reader} for input or a {@link Writer} for output. + * HierarchicalStreamDriver for binary input and output. The driver uses an optimized binary + * format to store an object graph. The format is not as compact as Java serialization, but a + * lot more than typical text-based formats like XML. However, due to its nature it cannot use a + * {@link Reader} for input or a {@link Writer} for output. * * @author Jörg Schaible * @since 1.4.2 @@ -33,26 +34,24 @@ /** * @throws UnsupportedOperationException if called */ - @Override - public HierarchicalStreamReader createReader(final Reader in) { - throw new UnsupportedOperationException("The BinaryDriver cannot use character-oriented input streams."); + public HierarchicalStreamReader createReader(Reader in) { + throw new UnsupportedOperationException( + "The BinaryDriver cannot use character-oriented input streams."); } - @Override - public HierarchicalStreamReader createReader(final InputStream in) { + public HierarchicalStreamReader createReader(InputStream in) { return new BinaryStreamReader(in); } /** * @throws UnsupportedOperationException if called */ - @Override - public HierarchicalStreamWriter createWriter(final Writer out) { - throw new UnsupportedOperationException("The BinaryDriver cannot use character-oriented output streams."); + public HierarchicalStreamWriter createWriter(Writer out) { + throw new UnsupportedOperationException( + "The BinaryDriver cannot use character-oriented output streams."); } - @Override - public HierarchicalStreamWriter createWriter(final OutputStream out) { + public HierarchicalStreamWriter createWriter(OutputStream out) { return new BinaryStreamWriter(out); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/BinaryStreamReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/BinaryStreamReader.java (.../BinaryStreamReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/BinaryStreamReader.java (.../BinaryStreamReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2011, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,22 +11,22 @@ */ package com.thoughtworks.xstream.io.binary; +import com.thoughtworks.xstream.converters.ErrorWriter; +import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.StreamException; + import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import com.thoughtworks.xstream.converters.ErrorWriter; -import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamReader; -import com.thoughtworks.xstream.io.HierarchicalStreamReader; -import com.thoughtworks.xstream.io.StreamException; - - /** - * A HierarchicalStreamReader that reads from a binary stream created by {@link BinaryStreamWriter}. - * + * A HierarchicalStreamReader that reads from a binary stream created by + * {@link BinaryStreamWriter}. + * * @author Joe Walnes * @see BinaryStreamReader * @since 1.2 @@ -40,145 +40,135 @@ private Token pushback; private final Token.Formatter tokenFormatter = new Token.Formatter(); - public BinaryStreamReader(final InputStream inputStream) { + public BinaryStreamReader(InputStream inputStream) { in = new DataInputStream(inputStream); moveDown(); } - @Override public boolean hasMoreChildren() { return depthState.hasMoreChildren(); } - @Override public String getNodeName() { return depthState.getName(); } - @Override public String getValue() { return depthState.getValue(); } - @Override - public String getAttribute(final String name) { + public String getAttribute(String name) { return depthState.getAttribute(name); } - @Override - public String getAttribute(final int index) { + public String getAttribute(int index) { return depthState.getAttribute(index); } - @Override public int getAttributeCount() { return depthState.getAttributeCount(); } - @Override - public String getAttributeName(final int index) { + public String getAttributeName(int index) { return depthState.getAttributeName(index); } - @Override - public Iterator getAttributeNames() { + public Iterator getAttributeNames() { return depthState.getAttributeNames(); } - @Override public void moveDown() { depthState.push(); - final Token firstToken = readToken(); + Token firstToken = readToken(); switch (firstToken.getType()) { - case Token.TYPE_START_NODE: - depthState.setName(idRegistry.get(firstToken.getId())); - break; - default: - throw new StreamException("Expected StartNode"); + case Token.TYPE_START_NODE: + depthState.setName(idRegistry.get(firstToken.getId())); + break; + default: + throw new StreamException("Expected StartNode"); } while (true) { - final Token nextToken = readToken(); + Token nextToken = readToken(); switch (nextToken.getType()) { - case Token.TYPE_ATTRIBUTE: - depthState.addAttribute(idRegistry.get(nextToken.getId()), nextToken.getValue()); - break; - case Token.TYPE_VALUE: - depthState.setValue(nextToken.getValue()); - break; - case Token.TYPE_END_NODE: - depthState.setHasMoreChildren(false); - pushBack(nextToken); - return; - case Token.TYPE_START_NODE: - depthState.setHasMoreChildren(true); - pushBack(nextToken); - return; - default: - throw new StreamException("Unexpected token " + nextToken); + case Token.TYPE_ATTRIBUTE: + depthState.addAttribute(idRegistry.get(nextToken.getId()), nextToken.getValue()); + break; + case Token.TYPE_VALUE: + depthState.setValue(nextToken.getValue()); + break; + case Token.TYPE_END_NODE: + depthState.setHasMoreChildren(false); + pushBack(nextToken); + return; + case Token.TYPE_START_NODE: + depthState.setHasMoreChildren(true); + pushBack(nextToken); + return; + default: + throw new StreamException("Unexpected token " + nextToken); } } } - @Override public void moveUp() { depthState.pop(); // We're done with this depth. Skip over all tokens until we get to the end. int depth = 0; slurp: while (true) { - final Token nextToken = readToken(); - switch (nextToken.getType()) { + Token nextToken = readToken(); + switch(nextToken.getType()) { + case Token.TYPE_END_NODE: + if (depth == 0) { + break slurp; + } else { + depth--; + } + break; + case Token.TYPE_START_NODE: + depth++; + break; + default: + // Ignore other tokens + } + } + // Peek ahead to determine if there are any more kids at this level. + Token nextToken = readToken(); + switch(nextToken.getType()) { case Token.TYPE_END_NODE: - if (depth == 0) { - break slurp; - } else { - depth--; - } + depthState.setHasMoreChildren(false); break; case Token.TYPE_START_NODE: - depth++; + depthState.setHasMoreChildren(true); break; default: - // Ignore other tokens - } + throw new StreamException("Unexpected token " + nextToken); } - // Peek ahead to determine if there are any more kids at this level. - final Token nextToken = readToken(); - switch (nextToken.getType()) { - case Token.TYPE_END_NODE: - depthState.setHasMoreChildren(false); - break; - case Token.TYPE_START_NODE: - depthState.setHasMoreChildren(true); - break; - default: - throw new StreamException("Unexpected token " + nextToken); - } pushBack(nextToken); } private Token readToken() { if (pushback == null) { try { - final Token token = tokenFormatter.read(in); + Token token = tokenFormatter.read(in); switch (token.getType()) { - case Token.TYPE_MAP_ID_TO_VALUE: - idRegistry.put(token.getId(), token.getValue()); - return readToken(); // Next one please. - default: - return token; + case Token.TYPE_MAP_ID_TO_VALUE: + idRegistry.put(token.getId(), token.getValue()); + return readToken(); // Next one please. + default: + return token; } - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } else { - final Token result = pushback; + Token result = pushback; pushback = null; return result; } } - public void pushBack(final Token token) { + public void pushBack(Token token) { if (pushback == null) { pushback = token; } else { @@ -187,43 +177,39 @@ } } - @Override public void close() { try { in.close(); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override public String peekNextChild() { if (depthState.hasMoreChildren()) { return idRegistry.get(pushback.getId()); } return null; } - @Override public HierarchicalStreamReader underlyingReader() { return this; } - @Override - public void appendErrors(final ErrorWriter errorWriter) { + public void appendErrors(ErrorWriter errorWriter) { // TODO: When things go bad, it would be good to know where! } private static class IdRegistry { - private final Map map = new HashMap(); + private Map map = new HashMap(); - public void put(final long id, final String value) { - map.put(Long.valueOf(id), value); + public void put(long id, String value) { + map.put(new Long(id), value); } - public String get(final long id) { - final String result = map.get(Long.valueOf(id)); + public String get(long id) { + String result = (String) map.get(new Long(id)); if (result == null) { throw new StreamException("Unknown ID : " + id); } else { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/BinaryStreamWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/BinaryStreamWriter.java (.../BinaryStreamWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/BinaryStreamWriter.java (.../BinaryStreamWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,17 +11,16 @@ */ package com.thoughtworks.xstream.io.binary; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriter; + import java.io.DataOutputStream; -import java.io.IOException; import java.io.OutputStream; -import java.util.HashMap; +import java.io.IOException; import java.util.Map; +import java.util.HashMap; -import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriter; -import com.thoughtworks.xstream.io.HierarchicalStreamWriter; -import com.thoughtworks.xstream.io.StreamException; - - /** * @since 1.2 */ @@ -31,75 +30,67 @@ private final DataOutputStream out; private final Token.Formatter tokenFormatter = new Token.Formatter(); - public BinaryStreamWriter(final OutputStream outputStream) { + public BinaryStreamWriter(OutputStream outputStream) { out = new DataOutputStream(outputStream); } - @Override - public void startNode(final String name) { + public void startNode(String name) { write(new Token.StartNode(idRegistry.getId(name))); } - @Override - public void startNode(final String name, final Class clazz) { + public void startNode(String name, Class clazz) { startNode(name); } - @Override - public void addAttribute(final String name, final String value) { + public void addAttribute(String name, String value) { write(new Token.Attribute(idRegistry.getId(name), value)); } - @Override - public void setValue(final String text) { + public void setValue(String text) { write(new Token.Value(text)); } - @Override public void endNode() { write(new Token.EndNode()); } - @Override public void flush() { try { out.flush(); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override public void close() { try { out.close(); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override public HierarchicalStreamWriter underlyingWriter() { return this; } - private void write(final Token token) { + private void write(Token token) { try { tokenFormatter.write(out, token); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } private class IdRegistry { private long nextId = 0; - private final Map ids = new HashMap(); + private Map ids = new HashMap(); - public long getId(final String value) { - Long id = ids.get(value); + public long getId(String value) { + Long id = (Long) ids.get(value); if (id == null) { - id = Long.valueOf(++nextId); + id = new Long(++nextId); ids.put(value, id); write(new Token.MapIdToValue(id.longValue(), value)); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/ReaderDepthState.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/ReaderDepthState.java (.../ReaderDepthState.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/ReaderDepthState.java (.../ReaderDepthState.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,15 +11,16 @@ */ package com.thoughtworks.xstream.io.binary; +import java.util.List; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; -import java.util.List; +import java.util.Collections; - /** - * Maintains the state of a pull reader at various states in the document depth. Used by the {@link BinaryStreamReader} - * + * Maintains the state of a pull reader at various states in the document depth. + * + * Used by the {@link BinaryStreamReader} + * * @author Joe Walnes * @since 1.2 */ @@ -30,7 +31,7 @@ private static class State { String name; String value; - List attributes; + List attributes; boolean hasMoreChildren; State parent; } @@ -43,7 +44,7 @@ private State current; public void push() { - final State newState = new State(); + State newState = new State(); newState.parent = current; current = newState; } @@ -56,42 +57,43 @@ return current.name; } - public void setName(final String name) { + public void setName(String name) { current.name = name; } public String getValue() { return current.value == null ? EMPTY_STRING : current.value; } - public void setValue(final String value) { + public void setValue(String value) { current.value = value; } public boolean hasMoreChildren() { return current.hasMoreChildren; } - public void setHasMoreChildren(final boolean hasMoreChildren) { + public void setHasMoreChildren(boolean hasMoreChildren) { current.hasMoreChildren = hasMoreChildren; } - public void addAttribute(final String name, final String value) { - final Attribute attribute = new Attribute(); + public void addAttribute(String name, String value) { + Attribute attribute = new Attribute(); attribute.name = name; attribute.value = value; if (current.attributes == null) { - current.attributes = new ArrayList(); + current.attributes = new ArrayList(); } current.attributes.add(attribute); } - public String getAttribute(final String name) { + public String getAttribute(String name) { if (current.attributes == null) { return null; } else { // For short maps, it's faster to iterate then do a hashlookup. - for (final Attribute attribute : current.attributes) { + for (Iterator iterator = current.attributes.iterator(); iterator.hasNext();) { + Attribute attribute = (Attribute) iterator.next(); if (attribute.name.equals(name)) { return attribute.value; } @@ -100,20 +102,20 @@ } } - public String getAttribute(final int index) { + public String getAttribute(int index) { if (current.attributes == null) { return null; } else { - final Attribute attribute = current.attributes.get(index); + Attribute attribute = (Attribute) current.attributes.get(index); return attribute.value; } } - public String getAttributeName(final int index) { + public String getAttributeName(int index) { if (current.attributes == null) { return null; } else { - final Attribute attribute = current.attributes.get(index); + Attribute attribute = (Attribute) current.attributes.get(index); return attribute.name; } } @@ -122,24 +124,21 @@ return current.attributes == null ? 0 : current.attributes.size(); } - public Iterator getAttributeNames() { + public Iterator getAttributeNames() { if (current.attributes == null) { - return Collections.emptySet().iterator(); + return Collections.EMPTY_SET.iterator(); } else { - final Iterator attributeIterator = current.attributes.iterator(); - return new Iterator() { - @Override + final Iterator attributeIterator = current.attributes.iterator(); + return new Iterator() { public boolean hasNext() { return attributeIterator.hasNext(); } - @Override - public String next() { - final Attribute attribute = attributeIterator.next(); + public Object next() { + Attribute attribute = (Attribute) attributeIterator.next(); return attribute.name; } - @Override public void remove() { throw new UnsupportedOperationException(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/Token.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/Token.java (.../Token.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/binary/Token.java (.../Token.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,23 +11,23 @@ */ package com.thoughtworks.xstream.io.binary; -import java.io.DataInput; +import com.thoughtworks.xstream.io.StreamException; + import java.io.DataOutput; import java.io.IOException; +import java.io.DataInput; -import com.thoughtworks.xstream.io.StreamException; - - /** - * Represents the Tokens stored in the binary stream used by {@link BinaryStreamReader} and {@link BinaryStreamWriter}. + * Represents the Tokens stored in the binary stream used by + * {@link BinaryStreamReader} and {@link BinaryStreamWriter}. *

      - * A token consists of a type and (depending on this type) it may additionally have an ID (positive long number) and/or - * a value (String). - *

      + * A token consists of a type and (depending on this type) + * it may additionally have an ID (positive long number) + * and/or a value (String).

      *

      - * The first byte of the token represents how many subsequent bytes are used by the ID. - *

      - * + * The first byte of the token represents how many subsequent + * bytes are used by the ID.

      + * * @author Joe Walnes * @see BinaryStreamReader * @see BinaryStreamWriter @@ -49,15 +49,15 @@ private static final byte ID_FOUR_BYTES = 0x18; private static final byte ID_EIGHT_BYTES = 0x20; - private static final String ID_SPLITTED = "\u0000\u2021\u0000"; + private static final String ID_SPLITTED = "\u0000\u2021\u0000"; private static final int MAX_UTF8_LENGTH = 0xffff; private final byte type; protected long id = -1; protected String value; - public Token(final byte type) { + public Token(byte type) { this.type = type; } @@ -73,36 +73,25 @@ return value; } - @Override public String toString() { return getClass().getName() + " [id=" + id + ", value='" + value + "']"; } - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - final Token token = (Token)o; + final Token token = (Token) o; - if (id != token.id) { - return false; - } - if (type != token.type) { - return false; - } + if (id != token.id) return false; + if (type != token.type) return false; return !(value != null ? !value.equals(token.value) : token.value != null); } - @Override public int hashCode() { int result; result = type; - result = 29 * result + (int)(id ^ id >>> 32); + result = 29 * result + (int) (id ^ (id >>> 32)); result = 29 * result + (value != null ? value.hashCode() : 0); return result; } @@ -111,31 +100,31 @@ public abstract void readFrom(DataInput in, byte idType) throws IOException; - protected void writeId(final DataOutput out, final long id, final byte idType) throws IOException { + protected void writeId(DataOutput out, long id, byte idType) throws IOException { if (id < 0) { throw new IOException("id must not be negative " + id); } switch (idType) { - case ID_ONE_BYTE: - out.writeByte((byte)id + Byte.MIN_VALUE); - break; - case ID_TWO_BYTES: - out.writeShort((short)id + Short.MIN_VALUE); - break; - case ID_FOUR_BYTES: - out.writeInt((int)id + Integer.MIN_VALUE); - break; - case ID_EIGHT_BYTES: - out.writeLong(id + Long.MIN_VALUE); - break; - default: - throw new Error("Unknown idType " + idType); + case ID_ONE_BYTE: + out.writeByte((byte) id + Byte.MIN_VALUE); + break; + case ID_TWO_BYTES: + out.writeShort((short) id + Short.MIN_VALUE); + break; + case ID_FOUR_BYTES: + out.writeInt((int) id + Integer.MIN_VALUE); + break; + case ID_EIGHT_BYTES: + out.writeLong(id + Long.MIN_VALUE); + break; + default: + throw new Error("Unknown idType " + idType); } } - protected void writeString(final DataOutput out, final String string) throws IOException { - final byte[] bytes = string.length() > MAX_UTF8_LENGTH / 4 ? string.getBytes("utf-8") : new byte[0]; - final int length = bytes.length; + protected void writeString(DataOutput out, String string) throws IOException { + final byte[] bytes = (string.length() > MAX_UTF8_LENGTH / 4) ? string.getBytes("utf-8") : new byte[0]; + int length = bytes.length; if (length <= MAX_UTF8_LENGTH) { out.writeUTF(string); } else { @@ -145,22 +134,22 @@ } } - protected long readId(final DataInput in, final byte idType) throws IOException { + protected long readId(DataInput in, byte idType) throws IOException { switch (idType) { - case ID_ONE_BYTE: - return in.readByte() - Byte.MIN_VALUE; - case ID_TWO_BYTES: - return in.readShort() - Short.MIN_VALUE; - case ID_FOUR_BYTES: - return in.readInt() - Integer.MIN_VALUE; - case ID_EIGHT_BYTES: - return in.readLong() - Long.MIN_VALUE; - default: - throw new Error("Unknown idType " + idType); + case ID_ONE_BYTE: + return in.readByte() - Byte.MIN_VALUE; + case ID_TWO_BYTES: + return in.readShort() - Short.MIN_VALUE; + case ID_FOUR_BYTES: + return in.readInt() - Integer.MIN_VALUE; + case ID_EIGHT_BYTES: + return in.readLong() - Long.MIN_VALUE; + default: + throw new Error("Unknown idType " + idType); } } - protected String readString(final DataInput in) throws IOException { + protected String readString(DataInput in) throws IOException { final String string = in.readUTF(); if (!ID_SPLITTED.equals(string)) { return string; @@ -173,14 +162,14 @@ public static class Formatter { - public void write(final DataOutput out, final Token token) throws IOException { - final long id = token.getId(); + public void write(DataOutput out, Token token) throws IOException { + long id = token.getId(); byte idType; if (id <= Byte.MAX_VALUE - Byte.MIN_VALUE) { idType = ID_ONE_BYTE; } else if (id <= Short.MAX_VALUE - Short.MIN_VALUE) { idType = ID_TWO_BYTES; - } else if (id <= (long)Integer.MAX_VALUE - (long)Integer.MIN_VALUE) { // cast to long to prevent overflow + } else if (id <= (long) Integer.MAX_VALUE - (long) Integer.MIN_VALUE) { // cast to long to prevent overflow idType = ID_FOUR_BYTES; } else { idType = ID_EIGHT_BYTES; @@ -189,36 +178,36 @@ token.writeTo(out, idType); } - public Token read(final DataInput in) throws IOException { - final byte nextByte = in.readByte(); - final byte type = (byte)(nextByte & TYPE_MASK); - final byte idType = (byte)(nextByte & ID_MASK); - final Token token = contructToken(type); + public Token read(DataInput in) throws IOException { + byte nextByte = in.readByte(); + byte type = (byte) (nextByte & TYPE_MASK); + byte idType = (byte) (nextByte & ID_MASK); + Token token = contructToken(type); token.readFrom(in, idType); return token; } - private Token contructToken(final byte type) { + private Token contructToken(byte type) { switch (type) { - case Token.TYPE_START_NODE: - return new StartNode(); - case Token.TYPE_MAP_ID_TO_VALUE: - return new MapIdToValue(); - case Token.TYPE_ATTRIBUTE: - return new Attribute(); - case Token.TYPE_END_NODE: - return new EndNode(); - case Token.TYPE_VALUE: - return new Value(); - default: - throw new StreamException("Unknown token type"); + case Token.TYPE_START_NODE: + return new StartNode(); + case Token.TYPE_MAP_ID_TO_VALUE: + return new MapIdToValue(); + case Token.TYPE_ATTRIBUTE: + return new Attribute(); + case Token.TYPE_END_NODE: + return new EndNode(); + case Token.TYPE_VALUE: + return new Value(); + default: + throw new StreamException("Unknown token type"); } } } public static class MapIdToValue extends Token { - public MapIdToValue(final long id, final String value) { + public MapIdToValue(long id, String value) { super(TYPE_MAP_ID_TO_VALUE); this.id = id; this.value = value; @@ -228,14 +217,12 @@ super(TYPE_MAP_ID_TO_VALUE); } - @Override - public void writeTo(final DataOutput out, final byte idType) throws IOException { + public void writeTo(DataOutput out, byte idType) throws IOException { writeId(out, id, idType); writeString(out, value); } - @Override - public void readFrom(final DataInput in, final byte idType) throws IOException { + public void readFrom(DataInput in, byte idType) throws IOException { id = readId(in, idType); value = readString(in); } @@ -244,7 +231,7 @@ public static class StartNode extends Token { - public StartNode(final long id) { + public StartNode(long id) { super(TYPE_START_NODE); this.id = id; } @@ -253,13 +240,11 @@ super(TYPE_START_NODE); } - @Override - public void writeTo(final DataOutput out, final byte idType) throws IOException { + public void writeTo(DataOutput out, byte idType) throws IOException { writeId(out, id, idType); } - @Override - public void readFrom(final DataInput in, final byte idType) throws IOException { + public void readFrom(DataInput in, byte idType) throws IOException { id = readId(in, idType); } @@ -271,19 +256,17 @@ super(TYPE_END_NODE); } - @Override - public void writeTo(final DataOutput out, final byte idType) { + public void writeTo(DataOutput out, byte idType) { } - @Override - public void readFrom(final DataInput in, final byte idType) { + public void readFrom(DataInput in, byte idType) { } } public static class Attribute extends Token { - public Attribute(final long id, final String value) { + public Attribute(long id, String value) { super(TYPE_ATTRIBUTE); this.id = id; this.value = value; @@ -293,23 +276,21 @@ super(TYPE_ATTRIBUTE); } - @Override - public void writeTo(final DataOutput out, final byte idType) throws IOException { + public void writeTo(DataOutput out, byte idType) throws IOException { writeId(out, id, idType); writeString(out, value); } - @Override - public void readFrom(final DataInput in, final byte idType) throws IOException { - id = readId(in, idType); - value = readString(in); + public void readFrom(DataInput in, byte idType) throws IOException { + this.id = readId(in, idType); + this.value = readString(in); } } public static class Value extends Token { - public Value(final String value) { + public Value(String value) { super(TYPE_VALUE); this.value = value; } @@ -318,13 +299,11 @@ super(TYPE_VALUE); } - @Override - public void writeTo(final DataOutput out, final byte idType) throws IOException { + public void writeTo(DataOutput out, byte idType) throws IOException { writeString(out, value); } - @Override - public void readFrom(final DataInput in, final byte idType) throws IOException { + public void readFrom(DataInput in, byte idType) throws IOException { value = readString(in); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/AbstractJsonWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/AbstractJsonWriter.java (.../AbstractJsonWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/AbstractJsonWriter.java (.../AbstractJsonWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2009, 2010, 2011, 2012, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -28,8 +28,9 @@ /** - * An abstract implementation of a writer that calls abstract methods to build JSON structures. Note, that XStream's - * implicit collection feature is only compatible with the syntax in {@link #EXPLICIT_MODE}. + * An abstract implementation of a writer that calls abstract methods to build JSON structures. + * Note, that XStream's implicit collection feature is only compatible with the syntax in + * {@link #EXPLICIT_MODE}. * * @author Jörg Schaible * @since 1.4 @@ -38,76 +39,75 @@ /** * DROP_ROOT_MODE drops the JSON root node. *

      - * The root node is the first level of the JSON object i.e. - *

      + * The root node is the first level of the JSON object i.e.

      * *
            * { "person": {
            *     "name": "Joe"
            * }}
            * 
      - *

      - * will be written without root simply as - *

      * + *

      will be written without root simply as

      + * *
            * {
            *     "name": "Joe"
            * }
            * 
      + * *

      - * Without a root node, the top level element might now also be an array. However, it is possible to generate - * invalid JSON unless {@link #STRICT_MODE} is also set. - *

      + * Without a root node, the top level element might now also be an array. However, it is + * possible to generate invalid JSON unless {@link #STRICT_MODE} is also set.

      * * @since 1.3.1 */ public static final int DROP_ROOT_MODE = 1; /** * STRICT_MODE prevents invalid JSON for single value objects when dropping the root. *

      - * The mode is only useful in combination with the {@link #DROP_ROOT_MODE}. An object with a single value as first - * node i.e. - *

      + * The mode is only useful in combination with the {@link #DROP_ROOT_MODE}. An object with a + * single value as first node i.e.

      * *
            * { "name": "Joe" }
            * 
      - *

      - * is simply written as - *

      * + *

      is simply written as

      + * *
            * "Joe"
            * 
      + * *

      - * However, this is no longer valid JSON. Therefore you can activate {@link #STRICT_MODE} and a - * {@link ConversionException} is thrown instead. - *

      + * However, this is no longer valid JSON. Therefore you can activate {@link #STRICT_MODE} + * and a {@link ConversionException} is thrown instead.

      * * @since 1.3.1 */ public static final int STRICT_MODE = 2; /** * EXPLICIT_MODE assures that all data has its explicit equivalent in the resulting JSON. *

      - * XStream is normally using attributes in XML that have no real equivalent in JSON. Additionally it is essential in - * XML that the individual child elements of a tag keep order and may have the same tag name. XStream's model relies - * on both characteristics. However, properties of a JSON object do not have a defined order, but their names have - * to be unique. Only a JSON array defines the order of its elements. + * XStream is normally using attributes in XML that have no real equivalent in JSON. + * Additionally it is essential in XML that the individual child elements of a tag keep + * order and may have the same tag name. XStream's model relies on both characteristics. + * However, properties of a JSON object do not have a defined order, but their names have to + * be unique. Only a JSON array defines the order of its elements. *

      *

      - * Therefore XStream uses in explicit mode a JSON format that supports the original requirements at the expense of - * the simplicity of the JSON objects and arrays. Each Java object will be represented by a JSON object with a - * single property representing the name of the object and an array as value that contains two more arrays. The - * first one contains a JSON object with all attributes, the second one the value of the Java object which can be - * null, a string or integer value or again a new JSON object representing a Java object. Here an example of an - * string array with one member, where the array and the string has an additional attribute 'id': - *

      + * Therefore XStream uses in explicit mode a JSON format that supports the original + * requirements at the expense of the simplicity of the JSON objects and arrays. Each Java + * object will be represented by a JSON object with a single property representing the name + * of the object and an array as value that contains two more arrays. The first one contains + * a JSON object with all attributes, the second one the value of the Java object which can + * be null, a string or integer value or again a new JSON object representing a Java object. + * Here an example of an string array with one member, where the array and the string has an + * additional attribute 'id':

      * *
            * {"string-array":[[{"id":"1"}],[{"string":[[{"id":"2"}],["Joe"]]}]]}
            * 
      + * *

      * This format can be used to always deserialize into Java again. *

      @@ -121,10 +121,11 @@ /** * IEEE_754_MODE keeps precision of 64-bit integer values. *

      - * In JavaScript every number is expressed as 64-bit double value with a precision of 53 bits following IEEE 754. - * Therefore it is not possible to represent the complete value range of 64-bit integer values. Any integer value - * > 253 (9007199254740992) or < -253 (-9007199254740992) will therefore be written as - * string value. + * In JavaScript every number is expressed as 64-bit double value with a precision of 53 + * bits following IEEE 754. Therefore it is not possible to represent the complete value + * range of 64-bit integer values. Any integer value > 253 + * (9007199254740992) or < -253 (-9007199254740992) will therefore be + * written as string value. *

      *

      * CAUTION: A client must be aware that the element may contain a number or a string value. @@ -141,52 +142,35 @@ public static Type NUMBER = new Type(); public static Type BOOLEAN = new Type(); } - + private static class StackElement { - final Class type; + final Class type; int status; - - public StackElement(final Class type, final int status) { + public StackElement(Class type, int status) { this.type = type; this.status = status; } } - + private static class IllegalWriterStateException extends IllegalStateException { - public IllegalWriterStateException(final int from, final int to, final String element) { - super("Cannot turn from state " - + getState(from) - + " into state " - + getState(to) - + (element == null ? "" : " for property " + element)); + public IllegalWriterStateException(int from, int to, String element) { + super("Cannot turn from state " + getState(from) + " into state " + getState(to) + + (element == null ? "" : " for property " + element)); } - - private static String getState(final int state) { + private static String getState(int state) { switch (state) { - case STATE_ROOT: - return "ROOT"; - case STATE_END_OBJECT: - return "END_OBJECT"; - case STATE_START_OBJECT: - return "START_OBJECT"; - case STATE_START_ATTRIBUTES: - return "START_ATTRIBUTES"; - case STATE_NEXT_ATTRIBUTE: - return "NEXT_ATTRIBUTE"; - case STATE_END_ATTRIBUTES: - return "END_ATTRIBUTES"; - case STATE_START_ELEMENTS: - return "START_ELEMENTS"; - case STATE_NEXT_ELEMENT: - return "NEXT_ELEMENT"; - case STATE_END_ELEMENTS: - return "END_ELEMENTS"; - case STATE_SET_VALUE: - return "SET_VALUE"; - default: - throw new IllegalArgumentException("Unknown state provided: " - + state - + ", cannot create message for IllegalWriterStateException"); + case STATE_ROOT: return "ROOT"; + case STATE_END_OBJECT: return "END_OBJECT"; + case STATE_START_OBJECT: return "START_OBJECT"; + case STATE_START_ATTRIBUTES: return "START_ATTRIBUTES"; + case STATE_NEXT_ATTRIBUTE: return "NEXT_ATTRIBUTE"; + case STATE_END_ATTRIBUTES: return "END_ATTRIBUTES"; + case STATE_START_ELEMENTS: return "START_ELEMENTS"; + case STATE_NEXT_ELEMENT: return "NEXT_ELEMENT"; + case STATE_END_ELEMENTS: return "END_ELEMENTS"; + case STATE_SET_VALUE: return "SET_VALUE"; + default: throw new IllegalArgumentException("Unknown state provided: " + state + + ", cannot create message for IllegalWriterStateException"); } } } @@ -202,11 +186,12 @@ private static final int STATE_END_ELEMENTS = 1 << 8; private static final int STATE_SET_VALUE = 1 << 9; - private static final Set> NUMBER_TYPES = new HashSet>(Arrays.>asList(byte.class, - Byte.class, short.class, Short.class, int.class, Integer.class, long.class, Long.class, float.class, - Float.class, double.class, Double.class, BigInteger.class, BigDecimal.class)); - private final int mode; - private final FastStack stack = new FastStack(16); + private static final Set NUMBER_TYPES = new HashSet(Arrays.asList(new Class[]{ + byte.class, Byte.class, short.class, Short.class, int.class, Integer.class, long.class, + Long.class, float.class, Float.class, double.class, Double.class, BigInteger.class, + BigDecimal.class})); + private int mode; + private FastStack stack = new FastStack(16); private int expectedStates; /** @@ -224,7 +209,7 @@ * @param mode a bit mask of the mode constants * @since 1.4 */ - public AbstractJsonWriter(final int mode) { + public AbstractJsonWriter(int mode) { this(mode, new NoNameCoder()); } @@ -234,7 +219,7 @@ * @param nameCoder the name coder to use * @since 1.4 */ - public AbstractJsonWriter(final NameCoder nameCoder) { + public AbstractJsonWriter(NameCoder nameCoder) { this(0, nameCoder); } @@ -245,83 +230,78 @@ * @param nameCoder the name coder to use * @since 1.4 */ - public AbstractJsonWriter(final int mode, final NameCoder nameCoder) { + public AbstractJsonWriter(int mode, NameCoder nameCoder) { super(nameCoder); this.mode = (mode & EXPLICIT_MODE) > 0 ? EXPLICIT_MODE : mode; stack.push(new StackElement(null, STATE_ROOT)); expectedStates = STATE_START_OBJECT; } - @Override - public void startNode(final String name, final Class clazz) { + public void startNode(String name, Class clazz) { if (name == null) { throw new NullPointerException("name"); } - stack.push(new StackElement(clazz, stack.peek().status)); + stack.push(new StackElement(clazz, ((StackElement)stack.peek()).status)); handleCheckedStateTransition(STATE_START_OBJECT, name, null); expectedStates = STATE_SET_VALUE | STATE_NEXT_ATTRIBUTE | STATE_START_OBJECT | STATE_NEXT_ELEMENT | STATE_ROOT; } - @Override - public void startNode(final String name) { + public void startNode(String name) { startNode(name, null); } - @Override - public void addAttribute(final String name, final String value) { + public void addAttribute(String name, String value) { handleCheckedStateTransition(STATE_NEXT_ATTRIBUTE, name, value); expectedStates = STATE_SET_VALUE | STATE_NEXT_ATTRIBUTE | STATE_START_OBJECT | STATE_NEXT_ELEMENT | STATE_ROOT; } - @Override public void setValue(String text) { - final Class type = stack.peek().type; + Class type = ((StackElement)stack.peek()).type; if ((type == Character.class || type == Character.TYPE) && "".equals(text)) { text = "\u0000"; } handleCheckedStateTransition(STATE_SET_VALUE, null, text); expectedStates = STATE_NEXT_ELEMENT | STATE_ROOT; } - @Override public void endNode() { - final int size = stack.size(); - final int nextState = size > 2 ? STATE_NEXT_ELEMENT : STATE_ROOT; + int size = stack.size(); + int nextState = size > 2 ? STATE_NEXT_ELEMENT : STATE_ROOT; handleCheckedStateTransition(nextState, null, null); stack.pop(); - stack.peek().status = nextState; + ((StackElement)stack.peek()).status = nextState; expectedStates = STATE_START_OBJECT; - if (size > 2) { + if (size > 2) { expectedStates |= STATE_NEXT_ELEMENT | STATE_ROOT; } } - private void handleCheckedStateTransition(final int requiredState, final String elementToAdd, - final String valueToAdd) { - final StackElement stackElement = stack.peek(); + private void handleCheckedStateTransition(final int requiredState, final String elementToAdd, final String valueToAdd) + { + final StackElement stackElement = (StackElement)stack.peek(); if ((expectedStates & requiredState) == 0) { throw new IllegalWriterStateException(stackElement.status, requiredState, elementToAdd); } - final int currentState = handleStateTransition(stackElement.status, requiredState, elementToAdd, valueToAdd); + int currentState = handleStateTransition(stackElement.status, requiredState, elementToAdd, valueToAdd); stackElement.status = currentState; } - private int handleStateTransition(int currentState, final int requiredState, final String elementToAdd, - final String valueToAdd) { - final int size = stack.size(); - final Class currentType = stack.peek().type; - final boolean isArray = size > 1 && isArray(currentType); - final boolean isArrayElement = size > 1 && isArray(stack.get(size - 2).type); - switch (currentState) { + private int handleStateTransition(int currentState, final int requiredState, final String elementToAdd, final String valueToAdd) + { + int size = stack.size(); + Class currentType = ((StackElement)stack.peek()).type; + boolean isArray = size > 1 && isArray(currentType); + boolean isArrayElement = size > 1 && isArray(((StackElement)stack.get(size-2)).type); + switch(currentState) { case STATE_ROOT: if (requiredState == STATE_START_OBJECT) { currentState = handleStateTransition(STATE_START_ELEMENTS, STATE_START_OBJECT, elementToAdd, null); return requiredState; } throw new IllegalWriterStateException(currentState, requiredState, elementToAdd); - + case STATE_END_OBJECT: - switch (requiredState) { + switch(requiredState) { case STATE_START_OBJECT: currentState = handleStateTransition(currentState, STATE_NEXT_ELEMENT, null, null); currentState = handleStateTransition(currentState, STATE_START_OBJECT, elementToAdd, null); @@ -337,9 +317,9 @@ default: throw new IllegalWriterStateException(currentState, requiredState, elementToAdd); } - + case STATE_START_OBJECT: - switch (requiredState) { + switch(requiredState) { case STATE_SET_VALUE: case STATE_START_OBJECT: case STATE_ROOT: @@ -349,8 +329,8 @@ currentState = handleStateTransition(currentState, STATE_END_ATTRIBUTES, null, null); } currentState = STATE_START_ELEMENTS; - - switch (requiredState) { + + switch(requiredState) { case STATE_SET_VALUE: currentState = handleStateTransition(currentState, STATE_SET_VALUE, null, valueToAdd); break; @@ -380,9 +360,9 @@ default: throw new IllegalWriterStateException(currentState, requiredState, elementToAdd); } - + case STATE_NEXT_ELEMENT: - switch (requiredState) { + switch(requiredState) { case STATE_START_OBJECT: nextElement(); if (!isArrayElement && (mode & EXPLICIT_MODE) == 0) { @@ -413,9 +393,9 @@ default: throw new IllegalWriterStateException(currentState, requiredState, elementToAdd); } - //$FALL-THROUGH$ + // fall through case STATE_START_ELEMENTS: - switch (requiredState) { + switch(requiredState) { case STATE_START_OBJECT: if ((mode & DROP_ROOT_MODE) == 0 || size > 2) { if (!isArrayElement || (mode & EXPLICIT_MODE) != 0) { @@ -440,14 +420,15 @@ } if (valueToAdd == null) { if (currentType == Mapper.Null.class) { - addValue("null", Type.NULL); + addValue("null", Type.NULL); } else if ((mode & EXPLICIT_MODE) == 0 && !isArray) { startObject(); endObject(); } } else { - if ((mode & IEEE_754_MODE) != 0 && (currentType == long.class || currentType == Long.class)) { - final long longValue = Long.parseLong(valueToAdd); + if (((mode & IEEE_754_MODE) != 0) + && (currentType == long.class || currentType == Long.class)) { + long longValue = Long.parseLong(valueToAdd); // JavaScript supports a maximum of 2^53 if (longValue > 9007199254740992L || longValue < -9007199254740992L) { addValue(valueToAdd, Type.STRING); @@ -474,7 +455,7 @@ } case STATE_END_ELEMENTS: - switch (requiredState) { + switch(requiredState) { case STATE_END_OBJECT: if ((mode & EXPLICIT_MODE) != 0) { endArray(); @@ -487,19 +468,19 @@ } case STATE_START_ATTRIBUTES: - switch (requiredState) { + switch(requiredState) { case STATE_NEXT_ATTRIBUTE: if (elementToAdd != null) { - final String name = ((mode & EXPLICIT_MODE) == 0 ? "@" : "") + elementToAdd; + String name = ((mode & EXPLICIT_MODE) == 0 ? "@" : "" ) + elementToAdd; startObject(); addLabel(encodeAttribute(name)); addValue(valueToAdd, Type.STRING); } return requiredState; } - //$FALL-THROUGH$ + // fall through case STATE_NEXT_ATTRIBUTE: - switch (requiredState) { + switch(requiredState) { case STATE_END_ATTRIBUTES: if ((mode & EXPLICIT_MODE) != 0) { if (currentState == STATE_NEXT_ATTRIBUTE) { @@ -513,7 +494,7 @@ case STATE_NEXT_ATTRIBUTE: if (!isArray || (mode & EXPLICIT_MODE) != 0) { nextElement(); - final String name = ((mode & EXPLICIT_MODE) == 0 ? "@" : "") + elementToAdd; + String name = ((mode & EXPLICIT_MODE) == 0 ? "@" : "" ) + elementToAdd; addLabel(encodeAttribute(name)); addValue(valueToAdd, Type.STRING); } @@ -533,8 +514,7 @@ } break; case STATE_START_OBJECT: - currentState = handleStateTransition(currentState, STATE_START_OBJECT, elementToAdd, - (mode & EXPLICIT_MODE) == 0 ? "" : null); + currentState = handleStateTransition(currentState, STATE_START_OBJECT, elementToAdd, (mode & EXPLICIT_MODE) == 0 ? "" : null); break; case STATE_END_OBJECT: currentState = handleStateTransition(currentState, STATE_SET_VALUE, null, null); @@ -556,7 +536,7 @@ } case STATE_END_ATTRIBUTES: - switch (requiredState) { + switch(requiredState) { case STATE_START_ELEMENTS: if ((mode & EXPLICIT_MODE) == 0) { nextElement(); @@ -570,9 +550,9 @@ throw new IllegalWriterStateException(currentState, requiredState, elementToAdd); } return requiredState; - + case STATE_SET_VALUE: - switch (requiredState) { + switch(requiredState) { case STATE_END_ELEMENTS: if ((mode & EXPLICIT_MODE) == 0 && isArray) { endArray(); @@ -602,10 +582,14 @@ * @return One of the {@link Type} instances * @since 1.4.4 */ - protected Type getType(final Class clazz) { - return clazz == Mapper.Null.class ? Type.NULL : clazz == Boolean.class || clazz == Boolean.TYPE - ? Type.BOOLEAN - : NUMBER_TYPES.contains(clazz) ? Type.NUMBER : Type.STRING; + protected Type getType(Class clazz) { + return clazz == Mapper.Null.class + ? Type.NULL + : (clazz == Boolean.class || clazz == Boolean.TYPE) + ? Type.BOOLEAN + : NUMBER_TYPES.contains(clazz) + ? Type.NUMBER + : Type.STRING; } /** @@ -615,12 +599,12 @@ * @return true if handles as array * @since 1.4 */ - protected boolean isArray(final Class clazz) { - return clazz != null - && (clazz.isArray() - || Collection.class.isAssignableFrom(clazz) - || Externalizable.class.isAssignableFrom(clazz) - || Map.class.isAssignableFrom(clazz) || Map.Entry.class.isAssignableFrom(clazz)); + protected boolean isArray(Class clazz) { + return clazz != null && (clazz.isArray() + || Collection.class.isAssignableFrom(clazz) + || Externalizable.class.isAssignableFrom(clazz) + || Map.class.isAssignableFrom(clazz) + || Map.Entry.class.isAssignableFrom(clazz)); } /** Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JettisonMappedXmlDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JettisonMappedXmlDriver.java (.../JettisonMappedXmlDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JettisonMappedXmlDriver.java (.../JettisonMappedXmlDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2013, 2014 XStream Committers. + * Copyright (c) 2007, 2008, 2009, 2010, 2011, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,6 +10,21 @@ */ package com.thoughtworks.xstream.io.json; +import com.thoughtworks.xstream.io.AbstractDriver; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.io.xml.QNameMap; +import com.thoughtworks.xstream.io.xml.StaxReader; +import com.thoughtworks.xstream.io.xml.StaxWriter; + +import org.codehaus.jettison.mapped.Configuration; +import org.codehaus.jettison.mapped.MappedNamespaceConvention; +import org.codehaus.jettison.mapped.MappedXMLInputFactory; +import org.codehaus.jettison.mapped.MappedXMLOutputFactory; + +import javax.xml.stream.XMLStreamException; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -19,24 +34,10 @@ import java.io.Writer; import java.net.URL; -import javax.xml.stream.XMLStreamException; -import org.codehaus.jettison.mapped.Configuration; -import org.codehaus.jettison.mapped.MappedNamespaceConvention; -import org.codehaus.jettison.mapped.MappedXMLInputFactory; -import org.codehaus.jettison.mapped.MappedXMLOutputFactory; - -import com.thoughtworks.xstream.io.AbstractDriver; -import com.thoughtworks.xstream.io.HierarchicalStreamReader; -import com.thoughtworks.xstream.io.HierarchicalStreamWriter; -import com.thoughtworks.xstream.io.StreamException; -import com.thoughtworks.xstream.io.xml.QNameMap; -import com.thoughtworks.xstream.io.xml.StaxReader; -import com.thoughtworks.xstream.io.xml.StaxWriter; - - /** - * Simple XStream driver wrapping Jettison's Mapped reader and writer. Serializes object from and to JSON. + * Simple XStream driver wrapping Jettison's Mapped reader and writer. Serializes object from + * and to JSON. * * @author Dejan Bosanac */ @@ -56,20 +57,17 @@ /** * Construct a JettisonMappedXmlDriver with configuration. - * * @param config the Jettison configuration */ public JettisonMappedXmlDriver(final Configuration config) { this(config, true); } /** - * Construct a JettisonMappedXmlDriver with configuration. - *

      - * This constructor has been added by special request of Jettison users to support JSON generated by older Jettison - * versions. if the driver is setup to ignore the XStream hints for JSON arrays, there is neither support from - * XStream's side nor are there any tests to ensure this mode. - *

      + * Construct a JettisonMappedXmlDriver with configuration. This constructor has been added + * by special request of Jettison users to support JSON generated by older Jettison + * versions. if the driver is setup to ignore the XStream hints for JSON arrays, there is + * neither support from XStream's side nor are there any tests to ensure this mode. * * @param config the Jettison configuration * @param useSerializeAsArray flag to use XStream's hints for collections and arrays @@ -81,8 +79,7 @@ convention = new MappedNamespaceConvention(config); this.useSerializeAsArray = useSerializeAsArray; } - - @Override + public HierarchicalStreamReader createReader(final Reader reader) { try { return new StaxReader(new QNameMap(), mif.createXMLStreamReader(reader), getNameCoder()); @@ -91,7 +88,6 @@ } } - @Override public HierarchicalStreamReader createReader(final InputStream input) { try { return new StaxReader(new QNameMap(), mif.createXMLStreamReader(input), getNameCoder()); @@ -100,56 +96,53 @@ } } - @Override - public HierarchicalStreamReader createReader(final URL in) { + public HierarchicalStreamReader createReader(URL in) { InputStream instream = null; try { instream = in.openStream(); - return new StaxReader(new QNameMap(), mif.createXMLStreamReader(in.toExternalForm(), instream), - getNameCoder()); + return new StaxReader(new QNameMap(), mif.createXMLStreamReader( + in.toExternalForm(), instream), getNameCoder()); } catch (final XMLStreamException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } finally { if (instream != null) { try { instream.close(); - } catch (final IOException e) { + } catch (IOException e) { // ignore } } } } - @Override - public HierarchicalStreamReader createReader(final File in) { + public HierarchicalStreamReader createReader(File in) { InputStream instream = null; try { instream = new FileInputStream(in); - return new StaxReader(new QNameMap(), mif.createXMLStreamReader(in.toURI().toASCIIString(), instream), - getNameCoder()); + return new StaxReader(new QNameMap(), mif.createXMLStreamReader(in + .toURI() + .toASCIIString(), instream), getNameCoder()); } catch (final XMLStreamException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } finally { if (instream != null) { try { instream.close(); - } catch (final IOException e) { + } catch (IOException e) { // ignore } } } } - @Override public HierarchicalStreamWriter createWriter(final Writer writer) { try { if (useSerializeAsArray) { - return new JettisonStaxWriter(new QNameMap(), mof.createXMLStreamWriter(writer), getNameCoder(), - convention); + return new JettisonStaxWriter(new QNameMap(), mof.createXMLStreamWriter(writer), getNameCoder(), convention); } else { return new StaxWriter(new QNameMap(), mof.createXMLStreamWriter(writer), getNameCoder()); } @@ -158,12 +151,10 @@ } } - @Override public HierarchicalStreamWriter createWriter(final OutputStream output) { try { if (useSerializeAsArray) { - return new JettisonStaxWriter(new QNameMap(), mof.createXMLStreamWriter(output), getNameCoder(), - convention); + return new JettisonStaxWriter(new QNameMap(), mof.createXMLStreamWriter(output), getNameCoder(), convention); } else { return new StaxWriter(new QNameMap(), mof.createXMLStreamWriter(output), getNameCoder()); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JettisonStaxWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JettisonStaxWriter.java (.../JettisonStaxWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JettisonStaxWriter.java (.../JettisonStaxWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2014 XStream Committers. + * Copyright (c) 2008, 2009, 2010, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,22 +10,22 @@ */ package com.thoughtworks.xstream.io.json; -import java.util.Collection; -import java.util.Map; +import com.thoughtworks.xstream.io.naming.NameCoder; +import com.thoughtworks.xstream.io.xml.QNameMap; +import com.thoughtworks.xstream.io.xml.StaxWriter; +import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer; +import org.codehaus.jettison.AbstractXMLStreamWriter; +import org.codehaus.jettison.mapped.MappedNamespaceConvention; + import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import org.codehaus.jettison.AbstractXMLStreamWriter; -import org.codehaus.jettison.mapped.MappedNamespaceConvention; +import java.util.Collection; +import java.util.Map; -import com.thoughtworks.xstream.io.naming.NameCoder; -import com.thoughtworks.xstream.io.xml.QNameMap; -import com.thoughtworks.xstream.io.xml.StaxWriter; -import com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer; - /** * A specialized {@link StaxWriter} that makes usage of internal functionality of Jettison. * @@ -40,9 +40,9 @@ * @since 1.4 */ public JettisonStaxWriter( - final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument, - final boolean namespaceRepairingMode, final NameCoder nameCoder, final MappedNamespaceConvention convention) - throws XMLStreamException { + QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument, + boolean namespaceRepairingMode, NameCoder nameCoder, + MappedNamespaceConvention convention) throws XMLStreamException { super(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, nameCoder); this.convention = convention; } @@ -52,24 +52,24 @@ * {@link JettisonStaxWriter#JettisonStaxWriter(QNameMap, XMLStreamWriter, boolean, boolean, NameCoder, MappedNamespaceConvention)} * instead */ - @Deprecated public JettisonStaxWriter( - final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument, - final boolean namespaceRepairingMode, final XmlFriendlyReplacer replacer, - final MappedNamespaceConvention convention) throws XMLStreamException { - this(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, (NameCoder)replacer, convention); + QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument, + boolean namespaceRepairingMode, XmlFriendlyReplacer replacer, + MappedNamespaceConvention convention) throws XMLStreamException { + this(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, (NameCoder) replacer, convention); } public JettisonStaxWriter( - final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument, - final boolean namespaceRepairingMode, final MappedNamespaceConvention convention) throws XMLStreamException { + QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument, + boolean namespaceRepairingMode, MappedNamespaceConvention convention) + throws XMLStreamException { super(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode); this.convention = convention; } public JettisonStaxWriter( - final QNameMap qnameMap, final XMLStreamWriter out, final MappedNamespaceConvention convention) - throws XMLStreamException { + QNameMap qnameMap, XMLStreamWriter out, MappedNamespaceConvention convention) + throws XMLStreamException { super(qnameMap, out); this.convention = convention; } @@ -78,21 +78,22 @@ * @since 1.4 */ public JettisonStaxWriter( - final QNameMap qnameMap, final XMLStreamWriter out, final NameCoder nameCoder, - final MappedNamespaceConvention convention) throws XMLStreamException { + QNameMap qnameMap, XMLStreamWriter out, NameCoder nameCoder, MappedNamespaceConvention convention) + throws XMLStreamException { super(qnameMap, out, nameCoder); this.convention = convention; } - @Override - public void startNode(final String name, final Class clazz) { - final XMLStreamWriter out = getXMLStreamWriter(); + public void startNode(String name, Class clazz) { + XMLStreamWriter out = getXMLStreamWriter(); if (clazz != null && out instanceof AbstractXMLStreamWriter) { - if (Collection.class.isAssignableFrom(clazz) || Map.class.isAssignableFrom(clazz) || clazz.isArray()) { - final QName qname = getQNameMap().getQName(encodeNode(name)); - final String prefix = qname.getPrefix(); - final String uri = qname.getNamespaceURI(); - final String key = convention.createKey(prefix, uri, qname.getLocalPart()); + if (Collection.class.isAssignableFrom(clazz) + || Map.class.isAssignableFrom(clazz) + || clazz.isArray()) { + QName qname = getQNameMap().getQName(encodeNode(name)); + String prefix = qname.getPrefix(); + String uri = qname.getNamespaceURI(); + String key = convention.createKey(prefix, uri, qname.getLocalPart()); if (!((AbstractXMLStreamWriter)out).getSerializedAsArrays().contains(key)) { // Typo is in the API of Jettison ... ((AbstractXMLStreamWriter)out).seriliazeAsArray(key); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JsonHierarchicalStreamDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JsonHierarchicalStreamDriver.java (.../JsonHierarchicalStreamDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JsonHierarchicalStreamDriver.java (.../JsonHierarchicalStreamDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,6 +11,12 @@ */ package com.thoughtworks.xstream.io.json; +import com.thoughtworks.xstream.io.AbstractDriver; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.io.naming.NameCoder; + import java.io.File; import java.io.InputStream; import java.io.OutputStream; @@ -20,13 +26,6 @@ import java.io.Writer; import java.net.URL; -import com.thoughtworks.xstream.io.AbstractDriver; -import com.thoughtworks.xstream.io.HierarchicalStreamReader; -import com.thoughtworks.xstream.io.HierarchicalStreamWriter; -import com.thoughtworks.xstream.io.StreamException; -import com.thoughtworks.xstream.io.naming.NameCoder; - - /** * A driver for JSON that writes optimized JSON format, but is not able to deserialize the result. * @@ -48,44 +47,38 @@ * @param nameCoder the coder to encode and decode the JSON labels. * @since 1.4.2 */ - public JsonHierarchicalStreamDriver(final NameCoder nameCoder) { + public JsonHierarchicalStreamDriver(NameCoder nameCoder) { super(nameCoder); } - @Override - public HierarchicalStreamReader createReader(final Reader in) { + public HierarchicalStreamReader createReader(Reader in) { throw new UnsupportedOperationException("The JsonHierarchicalStreamDriver can only write JSON"); } - @Override - public HierarchicalStreamReader createReader(final InputStream in) { + public HierarchicalStreamReader createReader(InputStream in) { throw new UnsupportedOperationException("The JsonHierarchicalStreamDriver can only write JSON"); } - @Override - public HierarchicalStreamReader createReader(final URL in) { + public HierarchicalStreamReader createReader(URL in) { throw new UnsupportedOperationException("The JsonHierarchicalStreamDriver can only write JSON"); } - @Override - public HierarchicalStreamReader createReader(final File in) { + public HierarchicalStreamReader createReader(File in) { throw new UnsupportedOperationException("The JsonHierarchicalStreamDriver can only write JSON"); } /** * Create a HierarchicalStreamWriter that writes JSON. */ - @Override - public HierarchicalStreamWriter createWriter(final Writer out) { + public HierarchicalStreamWriter createWriter(Writer out) { return new JsonWriter(out); } - @Override - public HierarchicalStreamWriter createWriter(final OutputStream out) { + public HierarchicalStreamWriter createWriter(OutputStream out) { try { // JSON spec requires UTF-8 return createWriter(new OutputStreamWriter(out, "UTF-8")); - } catch (final UnsupportedEncodingException e) { + } catch (UnsupportedEncodingException e) { throw new StreamException(e); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JsonHierarchicalStreamWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JsonHierarchicalStreamWriter.java (.../JsonHierarchicalStreamWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JsonHierarchicalStreamWriter.java (.../JsonHierarchicalStreamWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -15,54 +15,48 @@ /** - * A simple writer that outputs JSON in a pretty-printed indented stream. Arrays, Lists and Sets rely on you NOT using - * XStream.addImplicitCollection(..) + * A simple writer that outputs JSON in a pretty-printed indented stream. Arrays, Lists and Sets + * rely on you NOT using XStream.addImplicitCollection(..) * * @author Paul Hammant * @author Jörg Schaible * @since 1.2 * @deprecated As of 1.3.1, use JsonWriter instead */ -@Deprecated public class JsonHierarchicalStreamWriter extends JsonWriter { /** * @deprecated As of 1.3.1, use JsonWriter instead */ - @Deprecated - public JsonHierarchicalStreamWriter(final Writer writer, final char[] lineIndenter, final String newLine) { + public JsonHierarchicalStreamWriter(Writer writer, char[] lineIndenter, String newLine) { super(writer, lineIndenter, newLine); } /** * @deprecated As of 1.3.1, use JsonWriter instead */ - @Deprecated - public JsonHierarchicalStreamWriter(final Writer writer, final char[] lineIndenter) { + public JsonHierarchicalStreamWriter(Writer writer, char[] lineIndenter) { this(writer, lineIndenter, "\n"); } /** * @deprecated As of 1.3.1, use JsonWriter instead */ - @Deprecated - public JsonHierarchicalStreamWriter(final Writer writer, final String lineIndenter, final String newLine) { + public JsonHierarchicalStreamWriter(Writer writer, String lineIndenter, String newLine) { this(writer, lineIndenter.toCharArray(), newLine); } /** * @deprecated As of 1.3.1, use JsonWriter instead */ - @Deprecated - public JsonHierarchicalStreamWriter(final Writer writer, final String lineIndenter) { + public JsonHierarchicalStreamWriter(Writer writer, String lineIndenter) { this(writer, lineIndenter.toCharArray()); } /** * @deprecated As of 1.3.1, use JsonWriter instead */ - @Deprecated - public JsonHierarchicalStreamWriter(final Writer writer) { + public JsonHierarchicalStreamWriter(Writer writer) { this(writer, new char[]{' ', ' '}); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JsonWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JsonWriter.java (.../JsonWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/json/JsonWriter.java (.../JsonWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -21,8 +21,8 @@ /** - * A simple writer that outputs JSON in a pretty-printed indented stream. Arrays, Lists and Sets rely on you NOT using - * XStream.addImplicitCollection(..). + * A simple writer that outputs JSON in a pretty-printed indented stream. Arrays, Lists and Sets + * rely on you NOT using XStream.addImplicitCollection(..). * * @author Paul Hammant * @author Jörg Schaible @@ -38,52 +38,52 @@ /** * @deprecated As of 1.4 use {@link JsonWriter#JsonWriter(Writer, Format) instead} */ - @Deprecated - public JsonWriter(final Writer writer, final char[] lineIndenter, final String newLine) { - this(writer, 0, new Format(lineIndenter, newLine.toCharArray(), Format.SPACE_AFTER_LABEL - | Format.COMPACT_EMPTY_ELEMENT)); + public JsonWriter(Writer writer, char[] lineIndenter, String newLine) { + this(writer, 0, new Format( + lineIndenter, newLine.toCharArray(), Format.SPACE_AFTER_LABEL + | Format.COMPACT_EMPTY_ELEMENT)); } /** * @deprecated As of 1.4 use {@link JsonWriter#JsonWriter(Writer, Format) instead} */ - @Deprecated - public JsonWriter(final Writer writer, final char[] lineIndenter) { + public JsonWriter(Writer writer, char[] lineIndenter) { this(writer, 0, new Format(lineIndenter, new char[]{'\n'}, Format.SPACE_AFTER_LABEL | Format.COMPACT_EMPTY_ELEMENT)); } /** * @deprecated As of 1.4 use {@link JsonWriter#JsonWriter(Writer, Format) instead} */ - @Deprecated - public JsonWriter(final Writer writer, final String lineIndenter, final String newLine) { - this(writer, 0, new Format(lineIndenter.toCharArray(), newLine.toCharArray(), Format.SPACE_AFTER_LABEL - | Format.COMPACT_EMPTY_ELEMENT)); + public JsonWriter(Writer writer, String lineIndenter, String newLine) { + this(writer, 0, new Format( + lineIndenter.toCharArray(), newLine.toCharArray(), Format.SPACE_AFTER_LABEL + | Format.COMPACT_EMPTY_ELEMENT)); } /** * @deprecated As of 1.4 use {@link JsonWriter#JsonWriter(Writer, Format) instead} */ - @Deprecated - public JsonWriter(final Writer writer, final String lineIndenter) { - this(writer, 0, new Format(lineIndenter.toCharArray(), new char[]{'\n'}, Format.SPACE_AFTER_LABEL - | Format.COMPACT_EMPTY_ELEMENT)); + public JsonWriter(Writer writer, String lineIndenter) { + this(writer, 0, new Format( + lineIndenter.toCharArray(), new char[]{'\n'}, Format.SPACE_AFTER_LABEL + | Format.COMPACT_EMPTY_ELEMENT)); } - public JsonWriter(final Writer writer) { - this(writer, 0, new Format(new char[]{' ', ' '}, new char[]{'\n'}, Format.SPACE_AFTER_LABEL - | Format.COMPACT_EMPTY_ELEMENT)); + public JsonWriter(Writer writer) { + this(writer, 0, new Format( + new char[]{' ', ' '}, new char[]{'\n'}, Format.SPACE_AFTER_LABEL + | Format.COMPACT_EMPTY_ELEMENT)); } /** * @since 1.3.1 * @deprecated As of 1.4 use {@link JsonWriter#JsonWriter(Writer, int, Format) instead} */ - @Deprecated - public JsonWriter(final Writer writer, final char[] lineIndenter, final String newLine, final int mode) { - this(writer, mode, new Format(lineIndenter, newLine.toCharArray(), Format.SPACE_AFTER_LABEL - | Format.COMPACT_EMPTY_ELEMENT)); + public JsonWriter(Writer writer, char[] lineIndenter, String newLine, int mode) { + this(writer, mode, new Format( + lineIndenter, newLine.toCharArray(), Format.SPACE_AFTER_LABEL + | Format.COMPACT_EMPTY_ELEMENT)); } /** @@ -94,7 +94,7 @@ * @since 1.3.1 * @see #JsonWriter(Writer, int, Format) */ - public JsonWriter(final Writer writer, final int mode) { + public JsonWriter(Writer writer, int mode) { this(writer, mode, new Format()); } @@ -106,28 +106,30 @@ * @since 1.4 * @see #JsonWriter(Writer, int, Format) */ - public JsonWriter(final Writer writer, final Format format) { + public JsonWriter(Writer writer, Format format) { this(writer, 0, format); } /** - * Create a JsonWriter where the writer mode can be chosen and the format definition is provided. + * Create a JsonWriter where the writer mode can be chosen and the format definition is + * provided. *

      * Following constants can be used as bit mask for the mode: *

      *
        *
      • {@link #DROP_ROOT_MODE}: drop the root node
      • - *
      • {@link #STRICT_MODE}: do not throw {@link ConversionException}, if writer should generate invalid JSON
      • - *
      • {@link #EXPLICIT_MODE}: ensure that all available data is explicitly written even if addition objects must be - * added
      • + *
      • {@link #STRICT_MODE}: do not throw {@link ConversionException}, if writer should + * generate invalid JSON
      • + *
      • {@link #EXPLICIT_MODE}: ensure that all available data is explicitly written even if + * addition objects must be added
      • *
      * * @param writer the {@link Writer} where the JSON is written to * @param mode the JsonWriter mode * @param format the JSON format definition * @since 1.4 */ - public JsonWriter(final Writer writer, final int mode, final Format format) { + public JsonWriter(Writer writer, int mode, Format format) { this(writer, mode, format, 1024); } @@ -141,29 +143,28 @@ * @see JsonWriter#JsonWriter(Writer, int, Format) * @since 1.4 */ - public JsonWriter(final Writer writer, final int mode, final Format format, final int bufferSize) { + public JsonWriter(Writer writer, int mode, Format format, int bufferSize) { super(mode, format.getNameCoder()); this.writer = new QuickWriter(writer, bufferSize); this.format = format; depth = (mode & DROP_ROOT_MODE) == 0 ? -1 : 0; } - @Override public void flush() { writer.flush(); } - @Override public void close() { writer.close(); } - @Override public HierarchicalStreamWriter underlyingWriter() { return this; } - @Override + /** + * {@inheritDoc} + */ protected void startObject() { if (newLineProposed) { writeNewLine(); @@ -172,8 +173,10 @@ startNewLine(); } - @Override - protected void addLabel(final String name) { + /** + * {@inheritDoc} + */ + protected void addLabel(String name) { if (newLineProposed) { writeNewLine(); } @@ -185,8 +188,10 @@ } } - @Override - protected void addValue(final String value, final Type type) { + /** + * {@inheritDoc} + */ + protected void addValue(String value, Type type) { if (newLineProposed) { writeNewLine(); } @@ -199,7 +204,9 @@ } } - @Override + /** + * {@inheritDoc} + */ protected void startArray() { if (newLineProposed) { writeNewLine(); @@ -208,33 +215,39 @@ startNewLine(); } - @Override + /** + * {@inheritDoc} + */ protected void nextElement() { writer.write(","); writeNewLine(); } - @Override + /** + * {@inheritDoc} + */ protected void endArray() { endNewLine(); writer.write("]"); } - @Override + /** + * {@inheritDoc} + */ protected void endObject() { endNewLine(); writer.write("}"); } private void startNewLine() { - if (++depth > 0) { + if ( ++depth > 0) { newLineProposed = true; } } private void endNewLine() { if (depth-- > 0) { - if ((format.mode() & Format.COMPACT_EMPTY_ELEMENT) != 0 && newLineProposed) { + if (((format.mode() & Format.COMPACT_EMPTY_ELEMENT) != 0) && newLineProposed) { newLineProposed = false; } else { writeNewLine(); @@ -251,43 +264,43 @@ newLineProposed = false; } - private void writeText(final String text) { - final int length = text.length(); - for (int i = 0; i < length; i++) { - final char c = text.charAt(i); + private void writeText(String text) { + int length = text.length(); + for (int i = 0; i < length; i++ ) { + char c = text.charAt(i); switch (c) { case '"': - writer.write("\\\""); + this.writer.write("\\\""); break; case '\\': - writer.write("\\\\"); + this.writer.write("\\\\"); break; // turn this off - it is no CTRL char anyway // case '/': // this.writer.write("\\/"); // break; case '\b': - writer.write("\\b"); + this.writer.write("\\b"); break; case '\f': - writer.write("\\f"); + this.writer.write("\\f"); break; case '\n': - writer.write("\\n"); + this.writer.write("\\n"); break; case '\r': - writer.write("\\r"); + this.writer.write("\\r"); break; case '\t': - writer.write("\\t"); + this.writer.write("\\t"); break; default: if (c > 0x1f) { - writer.write(c); + this.writer.write(c); } else { - writer.write("\\u"); - final String hex = "000" + Integer.toHexString(c); - writer.write(hex.substring(hex.length() - 4)); + this.writer.write("\\u"); + String hex = "000" + Integer.toHexString(c); + this.writer.write(hex.substring(hex.length() - 4)); } } } @@ -304,21 +317,23 @@ public static int SPACE_AFTER_LABEL = 1; public static int COMPACT_EMPTY_ELEMENT = 2; - private final char[] lineIndenter; - private final char[] newLine; + private char[] lineIndenter; + private char[] newLine; private final int mode; private final NameCoder nameCoder; /** - * Create a new default Formatter. The formatter uses two spaces, normal line feed character, adds a space after - * the label and will try to compact the output. + * Create a new default Formatter. The formatter uses two spaces, normal line feed + * character, adds a space after the label and will try to compact the output. * * @since 1.4.2 */ public Format() { - this(new char[]{' ', ' '}, new char[]{'\n'}, Format.SPACE_AFTER_LABEL | Format.COMPACT_EMPTY_ELEMENT); + this(new char[]{' ', ' '}, new char[]{'\n'}, Format.SPACE_AFTER_LABEL + | Format.COMPACT_EMPTY_ELEMENT); } + /** * Create a new Formatter. * @@ -327,7 +342,7 @@ * @param mode the flags for the format modes * @since 1.4 */ - public Format(final char[] lineIndenter, final char[] newLine, final int mode) { + public Format(char[] lineIndenter, char[] newLine, int mode) { this(lineIndenter, newLine, mode, new NoNameCoder()); } @@ -340,7 +355,7 @@ * @param nameCoder the name encoder and decoder * @since 1.4.2 */ - public Format(final char[] lineIndenter, final char[] newLine, final int mode, final NameCoder nameCoder) { + public Format(char[] lineIndenter, char[] newLine, int mode, NameCoder nameCoder) { this.lineIndenter = lineIndenter; this.newLine = newLine; this.mode = mode; @@ -354,7 +369,7 @@ * @since 1.4 */ public char[] getLineIndenter() { - return lineIndenter; + return this.lineIndenter; } /** @@ -364,7 +379,7 @@ * @since 1.4 */ public char[] getNewLine() { - return newLine; + return this.newLine; } /** @@ -374,9 +389,10 @@ * @since 1.4 */ public int mode() { - return mode; + return this.mode; } + /** * Retrieve the NameCoder. * Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/naming/NameCoderWrapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/naming/NameCoderWrapper.java (.../NameCoderWrapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/naming/NameCoderWrapper.java (.../NameCoderWrapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -26,27 +26,35 @@ * @param inner the wrapped NameCoder * @since 1.4 */ - public NameCoderWrapper(final NameCoder inner) { - wrapped = inner; + public NameCoderWrapper(NameCoder inner) { + this.wrapped = inner; } - - @Override - public String decodeAttribute(final String attributeName) { + + /** + * {@inheritDoc} + */ + public String decodeAttribute(String attributeName) { return wrapped.decodeAttribute(attributeName); } - @Override - public String decodeNode(final String nodeName) { + /** + * {@inheritDoc} + */ + public String decodeNode(String nodeName) { return wrapped.decodeNode(nodeName); } - @Override - public String encodeAttribute(final String name) { + /** + * {@inheritDoc} + */ + public String encodeAttribute(String name) { return wrapped.encodeAttribute(name); } - @Override - public String encodeNode(final String name) { + /** + * {@inheritDoc} + */ + public String encodeNode(String name) { return wrapped.encodeNode(name); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/naming/NoNameCoder.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/naming/NoNameCoder.java (.../NoNameCoder.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/naming/NoNameCoder.java (.../NoNameCoder.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,33 +13,41 @@ /** * A NameCoder that does nothing. *

      - * The usage of this implementation implies that the names used for the objects can also be used in the target format - * without any change. This applies also for XML if the object graph contains no object that is an instance of an inner - * class type or is in the default package. + * The usage of this implementation implies that the names used for the objects can also be used + * in the target format without any change. This applies also for XML if the object graph + * contains no object that is an instance of an inner class type or is in the default package. *

      * - * @author Jörg Schaible + * @author Jörg Schaiblea * @since 1.4 */ public class NoNameCoder implements NameCoder { - @Override - public String decodeAttribute(final String attributeName) { + /** + * {@inheritDoc} + */ + public String decodeAttribute(String attributeName) { return attributeName; } - @Override - public String decodeNode(final String nodeName) { + /** + * {@inheritDoc} + */ + public String decodeNode(String nodeName) { return nodeName; } - @Override - public String encodeAttribute(final String name) { + /** + * {@inheritDoc} + */ + public String encodeAttribute(String name) { return name; } - @Override - public String encodeNode(final String name) { + /** + * {@inheritDoc} + */ + public String encodeNode(String name) { return name; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/naming/StaticNameCoder.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/naming/StaticNameCoder.java (.../StaticNameCoder.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/naming/StaticNameCoder.java (.../StaticNameCoder.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,27 +11,29 @@ package com.thoughtworks.xstream.io.naming; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; /** * A NameCoder that encodes and decodes names based on a map. *

      - * The provided map should contain a mapping between the name of the Java type or field to the proper element in the - * target format. If a name cannot be found in the map, it is assumed not to be mapped at all. Note that the values of - * the map should be unique also, otherwise the decoding will produce wrong results. + * The provided map should contain a mapping between the name of the Java type or field to the + * proper element in the target format. If a name cannot be found in the map, it is assumed not + * to be mapped at all. Note that the values of the map should be unique also, otherwise the + * decoding will produce wrong results. *

      * * @author Jörg Schaible * @since 1.4 */ public class StaticNameCoder implements NameCoder { - private final Map java2Node; - private final Map java2Attribute; + private final Map java2Node; + private final Map java2Attribute; - private transient Map node2Java; - private transient Map attribute2Java; + private transient Map node2Java; + private transient Map attribute2Java; /** * Construct a StaticNameCoder. @@ -40,37 +42,45 @@ * @param java2Attribute mapping of Java names to attributes * @since 1.4 */ - public StaticNameCoder(final Map java2Node, final Map java2Attribute) { - this.java2Node = new HashMap(java2Node); + public StaticNameCoder(Map java2Node, Map java2Attribute) { + this.java2Node = new HashMap(java2Node); if (java2Node == java2Attribute || java2Attribute == null) { this.java2Attribute = this.java2Node; } else { - this.java2Attribute = new HashMap(java2Attribute); + this.java2Attribute = new HashMap(java2Attribute); } readResolve(); } - @Override - public String decodeAttribute(final String attributeName) { - final String name = attribute2Java.get(attributeName); + /** + * {@inheritDoc} + */ + public String decodeAttribute(String attributeName) { + String name = (String)attribute2Java.get(attributeName); return name == null ? attributeName : name; } - @Override - public String decodeNode(final String nodeName) { - final String name = node2Java.get(nodeName); + /** + * {@inheritDoc} + */ + public String decodeNode(String nodeName) { + String name = (String)node2Java.get(nodeName); return name == null ? nodeName : name; } - @Override - public String encodeAttribute(final String name) { - final String friendlyName = java2Attribute.get(name); + /** + * {@inheritDoc} + */ + public String encodeAttribute(String name) { + String friendlyName = (String)java2Attribute.get(name); return friendlyName == null ? name : friendlyName; } - @Override - public String encodeNode(final String name) { - final String friendlyName = java2Node.get(name); + /** + * {@inheritDoc} + */ + public String encodeNode(String name) { + String friendlyName = (String)java2Node.get(name); return friendlyName == null ? name : friendlyName; } @@ -84,10 +94,11 @@ return this; } - private Map invertMap(final Map map) { - final Map inverseMap = new HashMap(map.size()); - for (final Map.Entry entry : map.entrySet()) { - inverseMap.put(entry.getValue(), entry.getKey()); + private Map invertMap(Map map) { + Map inverseMap = new HashMap(map.size()); + for (final Iterator iter = map.entrySet().iterator(); iter.hasNext();) { + final Map.Entry entry = (Map.Entry)iter.next(); + inverseMap.put((String)entry.getValue(), (String)entry.getKey()); } return inverseMap; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/Path.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/Path.java (.../Path.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/Path.java (.../Path.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,64 +11,63 @@ */ package com.thoughtworks.xstream.io.path; +import com.thoughtworks.xstream.core.util.FastStack; + import java.util.ArrayList; import java.util.List; -import com.thoughtworks.xstream.core.util.FastStack; - - /** * Represents a path to a single node in the tree. - *

      - * Two absolute paths can also be compared to calculate the relative path between them. A relative path can be applied - * to an absolute path to calculate another absolute path. - *

      - *

      - * Note that the paths are normally XPath compliant, so can be read by other XPath engines. However, {@link #toString()} - * will select a node list while {@link #explicit()} will always select an individual node. If the return type of the - * XPath evaluation is a node, the result will be the same, because XPath will then use the first element of the list. - * The following are examples of path expressions that the Path object supports: - *

      - *

      - * Note that the implementation does not take care if the paths are XPath compliant, it simply manages the values - * between the path separator. However, it normalizes the path if a path element ends with a selector for the first - * element (i.e. "[1]"). Those will be handled transparent i.e. two Paths are treated equal if one was created with path - * elements containing this selector and the other one without. - *

      - *

      - * The following are examples of path expressions that the Path object supports: - *

      + * + *

      Two absolute paths can also be compared to calculate the relative path between them. + * A relative path can be applied to an absolute path to calculate another absolute path.

      + * + *

      Note that the paths are normally XPath compliant, so can be read by other XPath engines. + * However, {@link #toString()} will select a node list while {@link #explicit()} will always select + * an individual node. If the return type of the XPath evaluation is a node, the result will be the same, + * because XPath will then use the first element of the list. The following are examples of path + * expressions that the Path object supports:

      + * + *

      Note that the implementation does not take care if the paths are XPath compliant, it simply + * manages the values between the path separator. However, it normalizes the path if a path element + * ends with a selector for the first element (i.e. "[1]"). Those will be handled transparent i.e. two Paths + * are treated equal if one was created with path elements containing this selector and the other one + * without.

      + * + *

      The following are examples of path expressions that the Path object supports:

      *
        - *
      • /
      • - *
      • /some/node
      • - *
      • /a/b/c/b/a
      • - *
      • /a/b[1]/c[1]/b[1]/a[1]
      • - *
      • /some[3]/node[2]/a
      • - *
      • ../../../another[3]/node
      • + *
      • /
      • + *
      • /some/node
      • + *
      • /a/b/c/b/a
      • + *
      • /a/b[1]/c[1]/b[1]/a[1]
      • + *
      • /some[3]/node[2]/a
      • + *
      • ../../../another[3]/node
      • *
      + * *

      Example

      - * + * *
      - * Path a = new Path("/html/body/div[1]/table[2]/tr[3]/td/div");
      - * Path b = new Path("/html/body/div/table[2]/tr[6]/td/form");
      - * 
      - * Path relativePath = a.relativeTo(b); // produces: "../../../tr[6]/td/form"
      + * Path a = new Path("/html/body/div[1]/table[2]/tr[3]/td/div");
      + * Path b = new Path("/html/body/div/table[2]/tr[6]/td/form");
      + *
      + * Path relativePath = a.relativeTo(b); // produces: "../../../tr[6]/td/form"
        * Path c = a.apply(relativePath); // same as Path b.
        * 
      - * + * * @see PathTracker + * * @author Joe Walnes */ public class Path { private final String[] chunks; private transient String pathAsString; private transient String pathExplicit; - private static final Path DOT = new Path(new String[]{"."}); + private static final Path DOT = new Path(new String[] {"."}); - public Path(final String pathAsString) { + public Path(String pathAsString) { // String.split() too slow. StringTokenizer too crappy. - final List result = new ArrayList(); + List result = new ArrayList(); int currentIndex = 0; int nextSeparator; this.pathAsString = pathAsString; @@ -77,34 +76,34 @@ result.add(normalize(pathAsString, currentIndex, nextSeparator)); currentIndex = nextSeparator + 1; } - result.add(normalize(pathAsString, currentIndex, pathAsString.length())); - final String[] arr = new String[result.size()]; + result.add(normalize(pathAsString,currentIndex,pathAsString.length())); + String[] arr = new String[result.size()]; result.toArray(arr); chunks = arr; } - - private String normalize(final String s, final int start, final int end) { - if (end - start > 3 && s.charAt(end - 3) == '[' && s.charAt(end - 2) == '1' && s.charAt(end - 1) == ']') { - pathAsString = null; - return s.substring(start, end - 3); + + private String normalize(String s, int start, int end) { + if (end - start > 3 + && s.charAt(end-3) == '[' + && s.charAt(end-2) == '1' + && s.charAt(end-1) == ']') { + this.pathAsString = null; + return s.substring(start, end-3); } else { return s.substring(start, end); } - + } - public Path(final String[] chunks) { + public Path(String[] chunks) { this.chunks = chunks; } - @Override public String toString() { if (pathAsString == null) { - final StringBuilder buffer = new StringBuilder(); + StringBuffer buffer = new StringBuffer(); for (int i = 0; i < chunks.length; i++) { - if (i > 0) { - buffer.append('/'); - } + if (i > 0) buffer.append('/'); buffer.append(chunks[i]); } pathAsString = buffer.toString(); @@ -114,16 +113,14 @@ public String explicit() { if (pathExplicit == null) { - final StringBuilder buffer = new StringBuilder(); + StringBuffer buffer = new StringBuffer(); for (int i = 0; i < chunks.length; i++) { - if (i > 0) { - buffer.append('/'); - } - final String chunk = chunks[i]; + if (i > 0) buffer.append('/'); + String chunk = chunks[i]; buffer.append(chunk); - final int length = chunk.length(); + int length = chunk.length(); if (length > 0) { - final char c = chunk.charAt(length - 1); + char c = chunk.charAt(length-1); if (c != ']' && c != '.') { buffer.append("[1]"); } @@ -134,40 +131,30 @@ return pathExplicit; } - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (!(o instanceof Path)) { - return false; - } + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Path)) return false; - final Path other = (Path)o; - if (chunks.length != other.chunks.length) { - return false; - } + final Path other = (Path) o; + if (chunks.length != other.chunks.length) return false; for (int i = 0; i < chunks.length; i++) { - if (!chunks[i].equals(other.chunks[i])) { - return false; - } + if (!chunks[i].equals(other.chunks[i])) return false; } return true; } - @Override public int hashCode() { int result = 543645643; - for (final String chunk : chunks) { - result = 29 * result + chunk.hashCode(); + for (int i = 0; i < chunks.length; i++) { + result = 29 * result + chunks[i].hashCode(); } return result; } - public Path relativeTo(final Path that) { - final int depthOfPathDivergence = depthOfPathDivergence(chunks, that.chunks); - final String[] result = new String[chunks.length + that.chunks.length - 2 * depthOfPathDivergence]; + public Path relativeTo(Path that) { + int depthOfPathDivergence = depthOfPathDivergence(chunks, that.chunks); + String[] result = new String[chunks.length + that.chunks.length - 2 * depthOfPathDivergence]; int count = 0; for (int i = depthOfPathDivergence; i < chunks.length; i++) { @@ -184,8 +171,8 @@ } } - private int depthOfPathDivergence(final String[] path1, final String[] path2) { - final int minLength = Math.min(path1.length, path2.length); + private int depthOfPathDivergence(String[] path1, String[] path2) { + int minLength = Math.min(path1.length, path2.length); for (int i = 0; i < minLength; i++) { if (!path1[i].equals(path2[i])) { return i; @@ -194,30 +181,31 @@ return minLength; } - public Path apply(final Path relativePath) { - final FastStack absoluteStack = new FastStack(16); + public Path apply(Path relativePath) { + FastStack absoluteStack = new FastStack(16); - for (final String chunk : chunks) { - absoluteStack.push(chunk); + for (int i = 0; i < chunks.length; i++) { + absoluteStack.push(chunks[i]); } - for (final String relativeChunk : relativePath.chunks) { + for (int i = 0; i < relativePath.chunks.length; i++) { + String relativeChunk = relativePath.chunks[i]; if (relativeChunk.equals("..")) { absoluteStack.pop(); } else if (!relativeChunk.equals(".")) { absoluteStack.push(relativeChunk); } } - final String[] result = new String[absoluteStack.size()]; + String[] result = new String[absoluteStack.size()]; for (int i = 0; i < result.length; i++) { - result[i] = absoluteStack.get(i); + result[i] = (String) absoluteStack.get(i); } return new Path(result); } - - public boolean isAncestor(final Path child) { + + public boolean isAncestor(Path child) { if (child == null || child.chunks.length < chunks.length) { return false; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/PathTracker.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/PathTracker.java (.../PathTracker.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/PathTracker.java (.../PathTracker.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,41 +14,41 @@ import java.util.HashMap; import java.util.Map; - /** * Maintains the current {@link Path} as a stream is moved through. - *

      - * Can be linked to a {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} or - * {@link com.thoughtworks.xstream.io.HierarchicalStreamReader} by wrapping them with a {@link PathTrackingWriter} or - * {@link PathTrackingReader}. - *

      + * + *

      Can be linked to a {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} or + * {@link com.thoughtworks.xstream.io.HierarchicalStreamReader} by wrapping them with a + * {@link PathTrackingWriter} or {@link PathTrackingReader}.

      + * *

      Example

      - * + * *
        * PathTracker tracker = new PathTracker();
      - * tracker.pushElement("table");
      - * tracker.pushElement("tr");
      - * tracker.pushElement("td");
      - * tracker.pushElement("form");
      - * tracker.popElement("form");
      - * tracker.popElement("td");
      - * tracker.pushElement("td");
      - * tracker.pushElement("div");
      - * 
      - * Path path = tracker.getPath(); // returns "/table/tr/td[2]/div"
      + * tracker.pushElement("table");
      + * tracker.pushElement("tr");
      + * tracker.pushElement("td");
      + * tracker.pushElement("form");
      + * tracker.popElement("form");
      + * tracker.popElement("td");
      + * tracker.pushElement("td");
      + * tracker.pushElement("div");
      + *
      + * Path path = tracker.getPath(); // returns "/table/tr/td[2]/div"
        * 
      - * + * * @see Path * @see PathTrackingReader * @see PathTrackingWriter + * * @author Joe Walnes */ public class PathTracker { private int pointer; private int capacity; private String[] pathStack; - private Map[] indexMapStack; + private Map[] indexMapStack; private Path currentPath; @@ -58,34 +58,32 @@ /** * @param initialCapacity Size of the initial stack of nodes (one level per depth in the tree). Note that this is - * only for optimizations - the stack will resize itself if it exceeds its capacity. If in doubt, use the - * other constructor. + * only for optimizations - the stack will resize itself if it exceeds its capacity. If in doubt, + * use the other constructor. */ - public PathTracker(final int initialCapacity) { - capacity = Math.max(1, initialCapacity); + public PathTracker(int initialCapacity) { + this.capacity = Math.max(1, initialCapacity); pathStack = new String[capacity]; - @SuppressWarnings("unchecked") - final Map[] newIndexMapStack = new Map[capacity]; - indexMapStack = newIndexMapStack; + indexMapStack = new Map[capacity]; } /** * Notify the tracker that the stream has moved into a new element. - * + * * @param name Name of the element */ - public void pushElement(final String name) { + public void pushElement(String name) { if (pointer + 1 >= capacity) { resizeStacks(capacity * 2); } pathStack[pointer] = name; - Map indexMap = indexMapStack[pointer]; + Map indexMap = indexMapStack[pointer]; if (indexMap == null) { - indexMap = new HashMap(); + indexMap = new HashMap(); indexMapStack[pointer] = indexMap; } if (indexMap.containsKey(name)) { - indexMap.put(name, new Integer(indexMap.get(name).intValue() + 1)); + indexMap.put(name, new Integer(((Integer) indexMap.get(name)).intValue() + 1)); } else { indexMap.put(name, new Integer(1)); } @@ -102,7 +100,7 @@ currentPath = null; pointer--; } - + /** * Get the last path element from the stack. * @@ -112,25 +110,25 @@ public String peekElement() { return peekElement(0); } - + /** * Get a path element from the stack. * * @param i path index * @return the name of the path element * @since 1.4.2 - * @throws ArrayIndexOutOfBoundsException if the index is >= 0 or <= -depth() + * @throws ArrayIndexOutOfBoundsException if the index is >= 0 or <= -depth() */ - public String peekElement(final int i) { + public String peekElement(int i) { if (i < -pointer || i > 0) { throw new ArrayIndexOutOfBoundsException(i); } - final int idx = pointer + i - 1; - final String name; - final Integer integer = indexMapStack[idx].get(pathStack[idx]); - final int index = integer.intValue(); + int idx = pointer + i - 1; + final String name; + Integer integer = ((Integer) indexMapStack[idx].get(pathStack[idx])); + int index = integer.intValue(); if (index > 1) { - final StringBuffer chunk = new StringBuffer(pathStack[idx].length() + 6); + StringBuffer chunk = new StringBuffer(pathStack[idx].length() + 6); chunk.append(pathStack[idx]).append('[').append(index).append(']'); name = chunk.toString(); } else { @@ -146,14 +144,13 @@ * @since 1.4.2 */ public int depth() { - return pointer; + return pointer; } - private void resizeStacks(final int newCapacity) { - final String[] newPathStack = new String[newCapacity]; - @SuppressWarnings("unchecked") - final Map[] newIndexMapStack = new Map[newCapacity]; - final int min = Math.min(capacity, newCapacity); + private void resizeStacks(int newCapacity) { + String[] newPathStack = new String[newCapacity]; + Map[] newIndexMapStack = new Map[newCapacity]; + int min = Math.min(capacity, newCapacity); System.arraycopy(pathStack, 0, newPathStack, 0, min); System.arraycopy(indexMapStack, 0, newIndexMapStack, 0, min); pathStack = newPathStack; @@ -166,9 +163,9 @@ */ public Path getPath() { if (currentPath == null) { - final String[] chunks = new String[pointer + 1]; + String[] chunks = new String[pointer + 1]; chunks[0] = ""; - for (int i = -pointer; ++i <= 0;) { + for (int i = -pointer; ++i <= 0; ) { final String name = peekElement(i); chunks[i + pointer] = name; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/PathTrackingReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/PathTrackingReader.java (.../PathTrackingReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/PathTrackingReader.java (.../PathTrackingReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -15,38 +15,35 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.ReaderWrapper; - /** * Wrapper for HierarchicalStreamReader that tracks the path (a subset of XPath) of the current node that is being read. - * + * * @see PathTracker * @see Path + * * @author Joe Walnes */ public class PathTrackingReader extends ReaderWrapper { private final PathTracker pathTracker; - public PathTrackingReader(final HierarchicalStreamReader reader, final PathTracker pathTracker) { + public PathTrackingReader(HierarchicalStreamReader reader, PathTracker pathTracker) { super(reader); this.pathTracker = pathTracker; pathTracker.pushElement(getNodeName()); } - @Override public void moveDown() { super.moveDown(); pathTracker.pushElement(getNodeName()); } - @Override public void moveUp() { super.moveUp(); pathTracker.popElement(); } - @Override - public void appendErrors(final ErrorWriter errorWriter) { + public void appendErrors(ErrorWriter errorWriter) { errorWriter.add("path", pathTracker.getPath().toString()); super.appendErrors(errorWriter); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/PathTrackingWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/PathTrackingWriter.java (.../PathTrackingWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/path/PathTrackingWriter.java (.../PathTrackingWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -15,39 +15,35 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.WriterWrapper; - /** - * Wrapper for HierarchicalStreamWriter that tracks the path (a subset of XPath) of the current node that is being - * written. - * + * Wrapper for HierarchicalStreamWriter that tracks the path (a subset of XPath) of the current node that is being written. + * * @see PathTracker * @see Path + * * @author Joe Walnes */ public class PathTrackingWriter extends WriterWrapper { private final PathTracker pathTracker; private final boolean isNameEncoding; - public PathTrackingWriter(final HierarchicalStreamWriter writer, final PathTracker pathTracker) { + public PathTrackingWriter(HierarchicalStreamWriter writer, PathTracker pathTracker) { super(writer); - isNameEncoding = writer.underlyingWriter() instanceof AbstractWriter; + this.isNameEncoding = writer.underlyingWriter() instanceof AbstractWriter; this.pathTracker = pathTracker; } - @Override - public void startNode(final String name) { + public void startNode(String name) { pathTracker.pushElement(isNameEncoding ? ((AbstractWriter)wrapped.underlyingWriter()).encodeNode(name) : name); - super.startNode(name); + super.startNode(name); } - @Override - public void startNode(final String name, final Class clazz) { + public void startNode(String name, Class clazz) { pathTracker.pushElement(isNameEncoding ? ((AbstractWriter)wrapped.underlyingWriter()).encodeNode(name) : name); super.startNode(name, clazz); } - @Override public void endNode() { super.endNode(); pathTracker.popElement(); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractDocumentReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractDocumentReader.java (.../AbstractDocumentReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractDocumentReader.java (.../AbstractDocumentReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -18,50 +18,44 @@ import com.thoughtworks.xstream.io.AttributeNameIterator; import com.thoughtworks.xstream.io.naming.NameCoder; - public abstract class AbstractDocumentReader extends AbstractXmlReader implements DocumentReader { - private final FastStack pointers = new FastStack(16); + private FastStack pointers = new FastStack(16); private Object current; - protected AbstractDocumentReader(final Object rootElement) { + protected AbstractDocumentReader(Object rootElement) { this(rootElement, new XmlFriendlyNameCoder()); } /** - * @since 1.4 - */ - protected AbstractDocumentReader(final Object rootElement, final NameCoder nameCoder) { + * @since 1.4 + */ + protected AbstractDocumentReader(Object rootElement, NameCoder nameCoder) { super(nameCoder); - current = rootElement; + this.current = rootElement; pointers.push(new Pointer()); reassignCurrentElement(current); } /** - * @since 1.2 - * @deprecated As of 1.4, use {@link AbstractDocumentReader#AbstractDocumentReader(Object, NameCoder)} instead. - */ - @Deprecated - protected AbstractDocumentReader(final Object rootElement, final XmlFriendlyReplacer replacer) { + * @since 1.2 + * @deprecated As of 1.4, use {@link AbstractDocumentReader#AbstractDocumentReader(Object, NameCoder)} instead. + */ + protected AbstractDocumentReader(Object rootElement, XmlFriendlyReplacer replacer) { this(rootElement, (NameCoder)replacer); } - + protected abstract void reassignCurrentElement(Object current); - protected abstract Object getParent(); - protected abstract Object getChild(int index); - protected abstract int getChildCount(); private static class Pointer { public int v; } - @Override public boolean hasMoreChildren() { - final Pointer pointer = pointers.peek(); + Pointer pointer = (Pointer) pointers.peek(); if (pointer.v < getChildCount()) { return true; @@ -70,16 +64,14 @@ } } - @Override public void moveUp() { current = getParent(); pointers.popSilently(); reassignCurrentElement(current); } - @Override public void moveDown() { - final Pointer pointer = pointers.peek(); + Pointer pointer = (Pointer) pointers.peek(); pointers.push(new Pointer()); current = getChild(pointer.v); @@ -88,21 +80,17 @@ reassignCurrentElement(current); } - @Override - public Iterator getAttributeNames() { + public Iterator getAttributeNames() { return new AttributeNameIterator(this); } - @Override - public void appendErrors(final ErrorWriter errorWriter) { + public void appendErrors(ErrorWriter errorWriter) { } - - @Override + public Object getCurrent() { - return current; + return this.current; } - @Override public void close() { // don't need to do anything } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractDocumentWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractDocumentWriter.java (.../AbstractDocumentWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractDocumentWriter.java (.../AbstractDocumentWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,32 +10,34 @@ */ package com.thoughtworks.xstream.io.xml; -import java.util.ArrayList; -import java.util.List; - import com.thoughtworks.xstream.core.util.FastStack; import com.thoughtworks.xstream.io.naming.NameCoder; +import java.util.ArrayList; +import java.util.List; + /** - * A generic {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} for DOM writer implementations. The - * implementation manages a list of top level DOM nodes. Every time the last node is closed on the node stack, the next - * started node is added to the list. This list can be retrieved using the {@link DocumentWriter#getTopLevelNodes()} - * method. + * A generic {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} for DOM writer + * implementations. The implementation manages a list of top level DOM nodes. Every time the + * last node is closed on the node stack, the next started node is added to the list. This list + * can be retrieved using the {@link DocumentWriter#getTopLevelNodes()} method. * * @author Laurent Bihanic * @author Jörg Schaible * @since 1.2.1 */ -public abstract class AbstractDocumentWriter extends AbstractXmlWriter implements DocumentWriter { +public abstract class AbstractDocumentWriter extends AbstractXmlWriter implements + DocumentWriter { - private final List result = new ArrayList(); - private final FastStack nodeStack = new FastStack(16); + private final List result = new ArrayList(); + private final FastStack nodeStack = new FastStack(16); /** * Constructs an AbstractDocumentWriter. * - * @param container the top level container for the nodes to create (may be null) + * @param container the top level container for the nodes to create (may be + * null) * @param nameCoder the object that creates XML-friendly names * @since 1.4 */ @@ -50,33 +52,33 @@ /** * Constructs an AbstractDocumentWriter. * - * @param container the top level container for the nodes to create (may be null) + * @param container the top level container for the nodes to create (may be + * null) * @param replacer the object that creates XML-friendly names * @since 1.2.1 - * @deprecated As of 1.4 use {@link AbstractDocumentWriter#AbstractDocumentWriter(Object, NameCoder)} instead. + * @deprecated As of 1.4 use + * {@link AbstractDocumentWriter#AbstractDocumentWriter(Object, NameCoder)} + * instead. */ - @Deprecated public AbstractDocumentWriter(final Object container, final XmlFriendlyReplacer replacer) { this(container, (NameCoder)replacer); } - @Override public final void startNode(final String name) { final Object node = createNode(name); nodeStack.push(node); } /** - * Create a node. The provided node name is not yet XML friendly. If {@link #getCurrent()} returns null - * the node is a top level node. + * Create a node. The provided node name is not yet XML friendly. If {@link #getCurrent()} + * returns null the node is a top level node. * * @param name the node name * @return the new node * @since 1.2.1 */ protected abstract Object createNode(String name); - @Override public final void endNode() { endNodeInternally(); final Object node = nodeStack.pop(); @@ -100,17 +102,14 @@ return nodeStack.peek(); } - @Override - public List getTopLevelNodes() { + public List getTopLevelNodes() { return result; } - @Override public void flush() { // don't need to do anything } - @Override public void close() { // don't need to do anything } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractPullReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractPullReader.java (.../AbstractPullReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractPullReader.java (.../AbstractPullReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2010, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2010, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -17,11 +17,10 @@ import com.thoughtworks.xstream.io.AttributeNameIterator; import com.thoughtworks.xstream.io.naming.NameCoder; - /** - * Base class that contains common functionality across HierarchicalStreamReader implementations that need to read from - * a pull parser. - * + * Base class that contains common functionality across HierarchicalStreamReader implementations + * that need to read from a pull parser. + * * @author Joe Walnes * @author James Strachan */ @@ -33,11 +32,11 @@ protected static final int COMMENT = 4; protected static final int OTHER = 0; - private final FastStack elementStack = new FastStack(16); - private final FastStack pool = new FastStack(16); + private final FastStack elementStack = new FastStack(16); + private final FastStack pool = new FastStack(16); - private final FastStack lookahead = new FastStack(4); - private final FastStack lookback = new FastStack(4); + private final FastStack lookahead = new FastStack(4); + private final FastStack lookback = new FastStack(4); private boolean marked; private static class Event { @@ -48,29 +47,27 @@ /** * @since 1.4 */ - protected AbstractPullReader(final NameCoder nameCoder) { + protected AbstractPullReader(NameCoder nameCoder) { super(nameCoder); } /** * @since 1.2 * @deprecated As of 1.4 use {@link AbstractPullReader#AbstractPullReader(NameCoder)} instead */ - @Deprecated - protected AbstractPullReader(final XmlFriendlyReplacer replacer) { + protected AbstractPullReader(XmlFriendlyReplacer replacer) { this((NameCoder)replacer); } + /** * Pull the next event from the stream. - *

      - * This MUST return {@link #START_NODE}, {@link #END_NODE}, {@link #TEXT}, {@link #COMMENT}, {@link #OTHER} or throw - * {@link com.thoughtworks.xstream.io.StreamException}. - *

      - *

      - * The underlying pull parser will most likely return its own event types. These must be mapped to the appropriate - * events. - *

      + * + *

      This MUST return {@link #START_NODE}, {@link #END_NODE}, {@link #TEXT}, {@link #COMMENT}, + * {@link #OTHER} or throw {@link com.thoughtworks.xstream.io.StreamException}.

      + * + *

      The underlying pull parser will most likely return its own event types. These must be + * mapped to the appropriate events.

      */ protected abstract int pullNextEvent(); @@ -84,26 +81,24 @@ */ protected abstract String pullText(); - @Override public boolean hasMoreChildren() { mark(); while (true) { switch (readEvent().type) { - case START_NODE: - reset(); - return true; - case END_NODE: - reset(); - return false; - default: - continue; + case START_NODE: + reset(); + return true; + case END_NODE: + reset(); + return false; + default: + continue; } } } - @Override public void moveDown() { - final int currentDepth = elementStack.size(); + int currentDepth = elementStack.size(); while (elementStack.size() <= currentDepth) { move(); if (elementStack.size() < currentDepth) { @@ -112,9 +107,8 @@ } } - @Override public void moveUp() { - final int currentDepth = elementStack.size(); + int currentDepth = elementStack.size(); while (elementStack.size() >= currentDepth) { move(); } @@ -124,33 +118,33 @@ final Event event = readEvent(); pool.push(event); switch (event.type) { - case START_NODE: - elementStack.push(pullElementName()); - break; - case END_NODE: - elementStack.pop(); - break; + case START_NODE: + elementStack.push(pullElementName()); + break; + case END_NODE: + elementStack.pop(); + break; } } private Event readEvent() { if (marked) { if (lookback.hasStuff()) { - return lookahead.push(lookback.pop()); + return (Event) lookahead.push(lookback.pop()); } else { - return lookahead.push(readRealEvent()); + return (Event) lookahead.push(readRealEvent()); } } else { if (lookback.hasStuff()) { - return lookback.pop(); + return (Event) lookback.pop(); } else { return readRealEvent(); } } } private Event readRealEvent() { - final Event event = pool.hasStuff() ? (Event)pool.pop() : new Event(); + Event event = pool.hasStuff() ? (Event)pool.pop() : new Event(); event.type = pullNextEvent(); if (event.type == TEXT) { event.value = pullText(); @@ -167,13 +161,12 @@ } public void reset() { - while (lookahead.hasStuff()) { + while(lookahead.hasStuff()) { lookback.push(lookahead.pop()); } marked = false; } - @Override public String getValue() { // we should collapse together any text which // contains comments @@ -187,7 +180,7 @@ Event event = readEvent(); while (true) { if (event.type == TEXT) { - final String text = event.value; + String text = event.value; if (text != null && text.length() > 0) { if (last == null) { last = text; @@ -207,34 +200,31 @@ if (buffer != null) { return buffer.toString(); } else { - return last == null ? "" : last; + return (last == null) ? "" : last; } } - @Override - public Iterator getAttributeNames() { + public Iterator getAttributeNames() { return new AttributeNameIterator(this); } - @Override public String getNodeName() { - return unescapeXmlName(elementStack.peek()); + return unescapeXmlName((String) elementStack.peek()); } - @Override public String peekNextChild() { mark(); while (true) { - final Event ev = readEvent(); + Event ev = readEvent(); switch (ev.type) { - case START_NODE: - reset(); - return ev.value; - case END_NODE: - reset(); - return null; - default: - continue; + case START_NODE: + reset(); + return ev.value; + case END_NODE: + reset(); + return null; + default: + continue; } } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXmlDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXmlDriver.java (.../AbstractXmlDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXmlDriver.java (.../AbstractXmlDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,34 +16,30 @@ /** - * Base class for HierarchicalStreamDrivers to use XML-based HierarchicalStreamReader and HierarchicalStreamWriter. + * Base class for HierarchicalStreamDrivers to use xml-based HierarchicalStreamReader and + * HierarchicalStreamWriter. * * @author Mauro Talevi * @author Jörg Schaible * @since 1.2 * @deprecated As of 1.4 */ -@Deprecated public abstract class AbstractXmlDriver extends AbstractDriver { /** * Creates a AbstractXmlFriendlyDriver with default XmlFriendlyReplacer * * @deprecated As of 1.4 */ - @Deprecated public AbstractXmlDriver() { this(new XmlFriendlyNameCoder()); } /** * Creates a AbstractXmlFriendlyDriver with default XmlFriendlyReplacer - * * @since 1.4 - * @deprecated As of 1.4 */ - @Deprecated - public AbstractXmlDriver(final NameCoder nameCoder) { + public AbstractXmlDriver(NameCoder nameCoder) { super(nameCoder); } @@ -53,17 +49,15 @@ * @param replacer the XmlFriendlyReplacer * @deprecated As of 1.4 */ - @Deprecated - public AbstractXmlDriver(final XmlFriendlyReplacer replacer) { + public AbstractXmlDriver(XmlFriendlyReplacer replacer) { this((NameCoder)replacer); } /** * @deprecated As of 1.4 */ - @Deprecated protected XmlFriendlyReplacer xmlFriendlyReplacer() { - final NameCoder nameCoder = getNameCoder(); + NameCoder nameCoder = getNameCoder(); return nameCoder instanceof XmlFriendlyReplacer ? (XmlFriendlyReplacer)nameCoder : null; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXmlReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXmlReader.java (.../AbstractXmlReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXmlReader.java (.../AbstractXmlReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,29 +16,28 @@ /** - * Abstract base implementation of HierarchicalStreamReader that provides common functionality to all XML-based readers. + * Abstract base implementation of HierarchicalStreamReader that provides common functionality + * to all XML-based readers. * * @author Mauro Talevi * @author Jörg Schaible * @since 1.2 * @deprecated As of 1.4, use {@link AbstractReader} instead. */ -@Deprecated -public abstract class AbstractXmlReader extends AbstractReader /* implements XmlFriendlyReader */{ +public abstract class AbstractXmlReader extends AbstractReader /* implements XmlFriendlyReader */ { protected AbstractXmlReader() { this(new XmlFriendlyNameCoder()); } /** - * @deprecated As of 1.4, use {@link AbstractReader} instead. - */ - @Deprecated - protected AbstractXmlReader(final XmlFriendlyReplacer replacer) { + * @deprecated As of 1.4, use {@link AbstractReader} instead. + */ + protected AbstractXmlReader(XmlFriendlyReplacer replacer) { this((NameCoder)replacer); } - protected AbstractXmlReader(final NameCoder nameCoder) { + protected AbstractXmlReader(NameCoder nameCoder) { super(nameCoder); } @@ -49,8 +48,7 @@ * @return An unescaped name with original characters * @deprecated As of 1.4, use {@link #decodeNode(String)} or {@link #decodeAttribute(String)} instead. */ - @Deprecated - public String unescapeXmlName(final String name) { + public String unescapeXmlName(String name) { return decodeNode(name); } @@ -61,8 +59,7 @@ * @return An escaped name with original characters * @deprecated As of 1.4, use {@link AbstractReader} instead. */ - @Deprecated - protected String escapeXmlName(final String name) { + protected String escapeXmlName(String name) { return encodeNode(name); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXmlWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXmlWriter.java (.../AbstractXmlWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXmlWriter.java (.../AbstractXmlWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,31 +14,29 @@ import com.thoughtworks.xstream.io.AbstractWriter; import com.thoughtworks.xstream.io.naming.NameCoder; - /** - * Abstract base implementation of HierarchicalStreamWriter that provides common functionality to all XML-based writers. + * Abstract base implementation of HierarchicalStreamWriter that provides common functionality + * to all XML-based writers. * * @author Mauro Talevi * @author Jörg Schaible * @since 1.2 * @deprecated As of 1.4 use {@link AbstractWriter} instead */ -@Deprecated public abstract class AbstractXmlWriter extends AbstractWriter implements XmlFriendlyWriter { - protected AbstractXmlWriter() { + protected AbstractXmlWriter(){ this(new XmlFriendlyNameCoder()); } /** * @deprecated As of 1.4 */ - @Deprecated - protected AbstractXmlWriter(final XmlFriendlyReplacer replacer) { + protected AbstractXmlWriter(XmlFriendlyReplacer replacer) { this((NameCoder)replacer); } - protected AbstractXmlWriter(final NameCoder nameCoder) { + protected AbstractXmlWriter(NameCoder nameCoder) { super(nameCoder); } @@ -49,9 +47,7 @@ * @return An escaped name with original characters replaced * @deprecated As of 1.4 use {@link #encodeNode(String)} or {@link #encodeAttribute(String)} instead */ - @Deprecated - @Override - public String escapeXmlName(final String name) { + public String escapeXmlName(String name) { return super.encodeNode(name); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXppDomDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXppDomDriver.java (.../AbstractXppDomDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXppDomDriver.java (.../AbstractXppDomDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,27 +10,26 @@ */ package com.thoughtworks.xstream.io.xml; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.UnsupportedEncodingException; -import java.io.Writer; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - import com.thoughtworks.xstream.core.util.XmlHeaderAwareReader; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.naming.NameCoder; import com.thoughtworks.xstream.io.xml.xppdom.XppDom; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.UnsupportedEncodingException; +import java.io.Writer; + /** - * An abstract base class for a driver using an XPP DOM implementation. + * An abstract base class for a driver using an XPP DOM implementation. * * @author Joe Walnes * @author Jörg Schaible @@ -44,47 +43,55 @@ * @param nameCoder the replacer for XML friendly names * @since 1.4 */ - public AbstractXppDomDriver(final NameCoder nameCoder) { + public AbstractXppDomDriver(NameCoder nameCoder) { super(nameCoder); } - @Override - public HierarchicalStreamReader createReader(final Reader in) { + /** + * {@inheritDoc} + */ + public HierarchicalStreamReader createReader(Reader in) { try { - final XmlPullParser parser = createParser(); + XmlPullParser parser = createParser(); parser.setInput(in); return new XppDomReader(XppDom.build(parser), getNameCoder()); - } catch (final XmlPullParserException e) { + } catch (XmlPullParserException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final InputStream in) { + /** + * {@inheritDoc} + */ + public HierarchicalStreamReader createReader(InputStream in) { try { return createReader(new XmlHeaderAwareReader(in)); - } catch (final UnsupportedEncodingException e) { + } catch (UnsupportedEncodingException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamWriter createWriter(final Writer out) { + /** + * {@inheritDoc} + */ + public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out, getNameCoder()); } - @Override - public HierarchicalStreamWriter createWriter(final OutputStream out) { + /** + * {@inheritDoc} + */ + public HierarchicalStreamWriter createWriter(OutputStream out) { return createWriter(new OutputStreamWriter(out)); } /** * Create the parser of the XPP implementation. - * + * @throws XmlPullParserException if the parser cannot be created * @since 1.4 */ Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXppDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXppDriver.java (.../AbstractXppDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/AbstractXppDriver.java (.../AbstractXppDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,6 +10,15 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.core.util.XmlHeaderAwareReader; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.io.naming.NameCoder; + +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -18,18 +27,8 @@ import java.io.UnsupportedEncodingException; import java.io.Writer; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - -import com.thoughtworks.xstream.core.util.XmlHeaderAwareReader; -import com.thoughtworks.xstream.io.HierarchicalStreamReader; -import com.thoughtworks.xstream.io.HierarchicalStreamWriter; -import com.thoughtworks.xstream.io.StreamException; -import com.thoughtworks.xstream.io.naming.NameCoder; - - /** - * An abstract base class for a driver using an XPP implementation. + * An abstract base class for a driver using an XPP implementation. * * @author Joe Walnes * @author Jörg Schaible @@ -43,43 +42,51 @@ * @param nameCoder the replacer for XML friendly tag and attribute names * @since 1.4 */ - public AbstractXppDriver(final NameCoder nameCoder) { + public AbstractXppDriver(NameCoder nameCoder) { super(nameCoder); } - @Override - public HierarchicalStreamReader createReader(final Reader in) { + /** + * {@inheritDoc} + */ + public HierarchicalStreamReader createReader(Reader in) { try { return new XppReader(in, createParser(), getNameCoder()); } catch (final XmlPullParserException e) { - throw new StreamException("Cannot create XmlPullParser"); + throw new StreamException("Cannot create XmlPullParser", e); } } - @Override - public HierarchicalStreamReader createReader(final InputStream in) { + /** + * {@inheritDoc} + */ + public HierarchicalStreamReader createReader(InputStream in) { try { return createReader(new XmlHeaderAwareReader(in)); - } catch (final UnsupportedEncodingException e) { + } catch (UnsupportedEncodingException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamWriter createWriter(final Writer out) { + /** + * {@inheritDoc} + */ + public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out, getNameCoder()); } - @Override - public HierarchicalStreamWriter createWriter(final OutputStream out) { + /** + * {@inheritDoc} + */ + public HierarchicalStreamWriter createWriter(OutputStream out) { return createWriter(new OutputStreamWriter(out)); } /** * Create the parser of the XPP implementation. - * + * @throws XmlPullParserException if the parser cannot be created * @since 1.4 */ Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/BEAStaxDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/BEAStaxDriver.java (.../BEAStaxDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/BEAStaxDriver.java (.../BEAStaxDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,26 +1,25 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011, 2014, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 29. April 2009 by Joerg Schaible */ package com.thoughtworks.xstream.io.xml; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; - import com.bea.xml.stream.MXParserFactory; import com.bea.xml.stream.XMLOutputFactoryBase; import com.thoughtworks.xstream.io.naming.NameCoder; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; /** * A driver using the BEA StAX implementation. - * + * * @author Jörg Schaible * @since 1.4 */ @@ -33,43 +32,43 @@ /** * @deprecated As of 1.4.6 use {@link #BEAStaxDriver(QNameMap, NameCoder)} */ - @Deprecated - public BEAStaxDriver(final QNameMap qnameMap, final XmlFriendlyNameCoder nameCoder) { + public BEAStaxDriver(QNameMap qnameMap, XmlFriendlyNameCoder nameCoder) { super(qnameMap, nameCoder); } /** * @since 1.4.6 */ - public BEAStaxDriver(final QNameMap qnameMap, final NameCoder nameCoder) { + public BEAStaxDriver(QNameMap qnameMap, NameCoder nameCoder) { super(qnameMap, nameCoder); } - public BEAStaxDriver(final QNameMap qnameMap) { + public BEAStaxDriver(QNameMap qnameMap) { super(qnameMap); } /** * @deprecated As of 1.4.6 use {@link #BEAStaxDriver(NameCoder)} */ - @Deprecated - public BEAStaxDriver(final XmlFriendlyNameCoder nameCoder) { + public BEAStaxDriver(XmlFriendlyNameCoder nameCoder) { super(nameCoder); } /** * @since 1.4.6 */ - public BEAStaxDriver(final NameCoder nameCoder) { + public BEAStaxDriver(NameCoder nameCoder) { super(nameCoder); } - @Override protected XMLInputFactory createInputFactory() { - return new MXParserFactory(); + final XMLInputFactory instance = new MXParserFactory(); + instance.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); +// if (instance.isPropertySupported(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES)) +// throw new IllegalStateException("Should not support external entities now!"); + return instance; } - @Override protected XMLOutputFactory createOutputFactory() { return new XMLOutputFactoryBase(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/CompactWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/CompactWriter.java (.../CompactWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/CompactWriter.java (.../CompactWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,56 +11,52 @@ */ package com.thoughtworks.xstream.io.xml; -import java.io.Writer; - import com.thoughtworks.xstream.io.naming.NameCoder; +import java.io.Writer; public class CompactWriter extends PrettyPrintWriter { - public CompactWriter(final Writer writer) { + public CompactWriter(Writer writer) { super(writer); } /** * @since 1.3 */ - public CompactWriter(final Writer writer, final int mode) { + public CompactWriter(Writer writer, int mode) { super(writer, mode); } /** * @since 1.4 */ - public CompactWriter(final Writer writer, final NameCoder nameCoder) { + public CompactWriter(Writer writer, NameCoder nameCoder) { super(writer, nameCoder); } /** * @since 1.4 */ - public CompactWriter(final Writer writer, final int mode, final NameCoder nameCoder) { + public CompactWriter(Writer writer, int mode, NameCoder nameCoder) { super(writer, mode, nameCoder); } /** * @deprecated As of 1.4 use {@link CompactWriter#CompactWriter(Writer, NameCoder)} instead. */ - @Deprecated - public CompactWriter(final Writer writer, final XmlFriendlyReplacer replacer) { + public CompactWriter(Writer writer, XmlFriendlyReplacer replacer) { super(writer, replacer); } /** * @since 1.3 * @deprecated As of 1.4 use {@link CompactWriter#CompactWriter(Writer, int, NameCoder)} instead. */ - @Deprecated - public CompactWriter(final Writer writer, final int mode, final XmlFriendlyReplacer replacer) { + public CompactWriter(Writer writer, int mode, XmlFriendlyReplacer replacer) { super(writer, mode, replacer); } - - @Override + protected void endOfLine() { // override parent: don't write anything at end of line } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DocumentWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DocumentWriter.java (.../DocumentWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DocumentWriter.java (.../DocumentWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,24 +16,25 @@ /** - * A generic interface for all {@link HierarchicalStreamWriter} implementations generating a DOM. + * A generic interface for all {@link HierarchicalStreamWriter} implementations generating a + * DOM. * * @author Jörg Schaible * @since 1.2.1 */ public interface DocumentWriter extends HierarchicalStreamWriter { /** - * Retrieve a {@link List} with the top elements. - *

      - * In the standard use case this list will only contain a single element. Additional elements can only occur, if - * {@link HierarchicalStreamWriter#startNode(String)} of the implementing {@link HierarchicalStreamWriter} was - * called multiple times with an empty node stack. Such a situation occurs calling - * {@link com.thoughtworks.xstream.XStream#marshal(Object, HierarchicalStreamWriter)} multiple times directly. - *

      + * Retrieve a {@link List} with the top elements. In the standard use case this list will + * only contain a single element. Additional elements can only occur, if + * {@link HierarchicalStreamWriter#startNode(String)} of the implementing + * {@link HierarchicalStreamWriter} was called multiple times with an empty node stack. Such + * a situation occurs calling + * {@link com.thoughtworks.xstream.XStream#marshal(Object, HierarchicalStreamWriter)} + * multiple times directly. * * @return a {@link List} with top nodes * @since 1.2.1 */ - List getTopLevelNodes(); + List getTopLevelNodes(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JDriver.java (.../Dom4JDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JDriver.java (.../Dom4JDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011, 2014, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -26,13 +26,13 @@ import org.dom4j.io.OutputFormat; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; +import org.xml.sax.SAXException; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.naming.NameCoder; - public class Dom4JDriver extends AbstractXmlDriver { private DocumentFactory documentFactory; @@ -45,19 +45,19 @@ /** * @since 1.4 */ - public Dom4JDriver(final NameCoder nameCoder) { + public Dom4JDriver(NameCoder nameCoder) { this(new DocumentFactory(), OutputFormat.createPrettyPrint(), nameCoder); outputFormat.setTrimText(false); } - public Dom4JDriver(final DocumentFactory documentFactory, final OutputFormat outputFormat) { + public Dom4JDriver(DocumentFactory documentFactory, OutputFormat outputFormat) { this(documentFactory, outputFormat, new XmlFriendlyNameCoder()); } /** * @since 1.4 */ - public Dom4JDriver(final DocumentFactory documentFactory, final OutputFormat outputFormat, final NameCoder nameCoder) { + public Dom4JDriver(DocumentFactory documentFactory, OutputFormat outputFormat, NameCoder nameCoder) { super(nameCoder); this.documentFactory = documentFactory; this.outputFormat = outputFormat; @@ -67,94 +67,99 @@ * @since 1.2 * @deprecated As of 1.4, use {@link Dom4JDriver#Dom4JDriver(DocumentFactory, OutputFormat, NameCoder)} instead. */ - @Deprecated - public Dom4JDriver( - final DocumentFactory documentFactory, final OutputFormat outputFormat, final XmlFriendlyReplacer replacer) { + public Dom4JDriver(DocumentFactory documentFactory, OutputFormat outputFormat, XmlFriendlyReplacer replacer) { this(documentFactory, outputFormat, (NameCoder)replacer); } + public DocumentFactory getDocumentFactory() { return documentFactory; } - public void setDocumentFactory(final DocumentFactory documentFactory) { + public void setDocumentFactory(DocumentFactory documentFactory) { this.documentFactory = documentFactory; } public OutputFormat getOutputFormat() { return outputFormat; } - public void setOutputFormat(final OutputFormat outputFormat) { + public void setOutputFormat(OutputFormat outputFormat) { this.outputFormat = outputFormat; } - @Override - public HierarchicalStreamReader createReader(final Reader text) { + public HierarchicalStreamReader createReader(Reader text) { try { - final SAXReader reader = new SAXReader(); - final Document document = reader.read(text); + final Document document = createReader().read(text); return new Dom4JReader(document, getNameCoder()); - } catch (final DocumentException e) { + } catch (DocumentException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final InputStream in) { + public HierarchicalStreamReader createReader(InputStream in) { try { - final SAXReader reader = new SAXReader(); - final Document document = reader.read(in); + final Document document = createReader().read(in); return new Dom4JReader(document, getNameCoder()); - } catch (final DocumentException e) { + } catch (DocumentException e) { throw new StreamException(e); } } /** * @since 1.4 */ - @Override - public HierarchicalStreamReader createReader(final URL in) { + public HierarchicalStreamReader createReader(URL in) { try { - final SAXReader reader = new SAXReader(); - final Document document = reader.read(in); + final Document document = createReader().read(in); return new Dom4JReader(document, getNameCoder()); - } catch (final DocumentException e) { + } catch (DocumentException e) { throw new StreamException(e); } } /** * @since 1.4 */ - @Override - public HierarchicalStreamReader createReader(final File in) { + public HierarchicalStreamReader createReader(File in) { try { - final SAXReader reader = new SAXReader(); - final Document document = reader.read(in); + final Document document = createReader().read(in); return new Dom4JReader(document, getNameCoder()); - } catch (final DocumentException e) { + } catch (DocumentException e) { throw new StreamException(e); } } - @Override public HierarchicalStreamWriter createWriter(final Writer out) { final HierarchicalStreamWriter[] writer = new HierarchicalStreamWriter[1]; - final FilterWriter filter = new FilterWriter(out) { - @Override + final FilterWriter filter = new FilterWriter(out){ public void close() { writer[0].close(); } }; - writer[0] = new Dom4JXmlWriter(new XMLWriter(filter, outputFormat), getNameCoder()); + writer[0] = new Dom4JXmlWriter(new XMLWriter(filter, outputFormat), getNameCoder()); return writer[0]; } - @Override public HierarchicalStreamWriter createWriter(final OutputStream out) { final Writer writer = new OutputStreamWriter(out); return createWriter(writer); } + + /** + * Create and initialize the SAX reader. + * + * @return the SAX reader instance. + * @throws DocumentException if DOCTYPE processing cannot be disabled + * @since 1.4.9 + */ + protected SAXReader createReader() throws DocumentException { + final SAXReader reader = new SAXReader(); + try { + reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + } catch (SAXException e) { + throw new DocumentException("Cannot disable DOCTYPE processing", e); + } + return reader; + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JReader.java (.../Dom4JReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JReader.java (.../Dom4JReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,121 +11,103 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.converters.ErrorWriter; +import com.thoughtworks.xstream.io.naming.NameCoder; import java.util.List; - import org.dom4j.Document; import org.dom4j.Element; -import com.thoughtworks.xstream.converters.ErrorWriter; -import com.thoughtworks.xstream.io.naming.NameCoder; - - public class Dom4JReader extends AbstractDocumentReader { private Element currentElement; - public Dom4JReader(final Element rootElement) { + public Dom4JReader(Element rootElement) { this(rootElement, new XmlFriendlyNameCoder()); } - public Dom4JReader(final Document document) { + public Dom4JReader(Document document) { this(document.getRootElement()); } /** * @since 1.4 */ - public Dom4JReader(final Element rootElement, final NameCoder nameCoder) { + public Dom4JReader(Element rootElement, NameCoder nameCoder) { super(rootElement, nameCoder); } /** * @since 1.4 */ - public Dom4JReader(final Document document, final NameCoder nameCoder) { + public Dom4JReader(Document document, NameCoder nameCoder) { this(document.getRootElement(), nameCoder); } /** * @since 1.2 * @deprecated As of 1.4, use {@link Dom4JReader#Dom4JReader(Element, NameCoder)} instead */ - @Deprecated - public Dom4JReader(final Element rootElement, final XmlFriendlyReplacer replacer) { + public Dom4JReader(Element rootElement, XmlFriendlyReplacer replacer) { this(rootElement, (NameCoder)replacer); } /** * @since 1.2 * @deprecated As of 1.4, use {@link Dom4JReader#Dom4JReader(Document, NameCoder)} instead */ - @Deprecated - public Dom4JReader(final Document document, final XmlFriendlyReplacer replacer) { + public Dom4JReader(Document document, XmlFriendlyReplacer replacer) { this(document.getRootElement(), (NameCoder)replacer); } - - @Override + public String getNodeName() { return decodeNode(currentElement.getName()); } - @Override public String getValue() { return currentElement.getText(); } - @Override - public String getAttribute(final String name) { + public String getAttribute(String name) { return currentElement.attributeValue(encodeAttribute(name)); } - @Override - public String getAttribute(final int index) { + public String getAttribute(int index) { return currentElement.attribute(index).getValue(); } - @Override public int getAttributeCount() { return currentElement.attributeCount(); } - @Override - public String getAttributeName(final int index) { + public String getAttributeName(int index) { return decodeAttribute(currentElement.attribute(index).getQualifiedName()); } - @Override protected Object getParent() { return currentElement.getParent(); } - @Override - protected Object getChild(final int index) { + protected Object getChild(int index) { return currentElement.elements().get(index); } - @Override protected int getChildCount() { return currentElement.elements().size(); } - @Override - protected void reassignCurrentElement(final Object current) { - currentElement = (Element)current; + protected void reassignCurrentElement(Object current) { + currentElement = (Element) current; } - @Override public String peekNextChild() { - @SuppressWarnings("unchecked") - final List list = currentElement.elements(); + List list = currentElement.elements(); if (null == list || list.isEmpty()) { return null; } - return decodeNode(list.get(0).getName()); + return decodeNode(((Element) list.get(0)).getName()); } - @Override - public void appendErrors(final ErrorWriter errorWriter) { + public void appendErrors(ErrorWriter errorWriter) { errorWriter.add("xpath", currentElement.getPath()); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JWriter.java (.../Dom4JWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JWriter.java (.../Dom4JWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,21 +11,22 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.io.naming.NameCoder; + import org.dom4j.Branch; import org.dom4j.DocumentFactory; import org.dom4j.Element; -import com.thoughtworks.xstream.io.naming.NameCoder; - public class Dom4JWriter extends AbstractDocumentWriter { private final DocumentFactory documentFactory; /** * @since 1.4 */ - public Dom4JWriter(final Branch root, final DocumentFactory factory, final NameCoder nameCoder) { + public Dom4JWriter( + final Branch root, final DocumentFactory factory, final NameCoder nameCoder) { super(root, nameCoder); documentFactory = factory; } @@ -48,16 +49,15 @@ * @since 1.2.1 * @deprecated As of 1.4 use {@link Dom4JWriter#Dom4JWriter(Branch, DocumentFactory, NameCoder)} instead. */ - @Deprecated - public Dom4JWriter(final Branch root, final DocumentFactory factory, final XmlFriendlyReplacer replacer) { + public Dom4JWriter( + final Branch root, final DocumentFactory factory, final XmlFriendlyReplacer replacer) { this(root, factory, (NameCoder)replacer); } /** * @since 1.2.1 * @deprecated As of 1.4 use {@link Dom4JWriter#Dom4JWriter(DocumentFactory, NameCoder)} instead. */ - @Deprecated public Dom4JWriter(final DocumentFactory factory, final XmlFriendlyReplacer replacer) { this(null, factory, (NameCoder)replacer); } @@ -73,7 +73,6 @@ * @since 1.2.1 * @deprecated As of 1.4 use {@link Dom4JWriter#Dom4JWriter(Branch, NameCoder)} instead */ - @Deprecated public Dom4JWriter(final Branch root, final XmlFriendlyReplacer replacer) { this(root, new DocumentFactory(), (NameCoder)replacer); } @@ -89,7 +88,6 @@ this(new DocumentFactory(), new XmlFriendlyNameCoder()); } - @Override protected Object createNode(final String name) { final Element element = documentFactory.createElement(encodeNode(name)); final Branch top = top(); @@ -99,12 +97,10 @@ return element; } - @Override public void setValue(final String text) { top().setText(text); } - @Override public void addAttribute(final String key, final String value) { ((Element)top()).addAttribute(encodeAttribute(key), value); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JXmlWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JXmlWriter.java (.../Dom4JXmlWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Dom4JXmlWriter.java (.../Dom4JXmlWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,52 +1,52 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 07. March 2004 by Joe Walnes */ package com.thoughtworks.xstream.io.xml; -import java.io.IOException; +import com.thoughtworks.xstream.core.util.FastStack; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.io.naming.NameCoder; import org.dom4j.Element; import org.dom4j.io.XMLWriter; import org.dom4j.tree.DefaultElement; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; -import com.thoughtworks.xstream.core.util.FastStack; -import com.thoughtworks.xstream.io.StreamException; -import com.thoughtworks.xstream.io.naming.NameCoder; +import java.io.IOException; public class Dom4JXmlWriter extends AbstractXmlWriter { private final XMLWriter writer; - private final FastStack elementStack; - private final AttributesImpl attributes; + private final FastStack elementStack; + private AttributesImpl attributes; private boolean started; private boolean children; - public Dom4JXmlWriter(final XMLWriter writer) { + public Dom4JXmlWriter(XMLWriter writer) { this(writer, new XmlFriendlyNameCoder()); } /** * @since 1.4 */ - public Dom4JXmlWriter(final XMLWriter writer, final NameCoder nameCoder) { + public Dom4JXmlWriter(XMLWriter writer, NameCoder nameCoder) { super(nameCoder); this.writer = writer; - elementStack = new FastStack(16); - attributes = new AttributesImpl(); + this.elementStack = new FastStack(16); + this.attributes = new AttributesImpl(); try { writer.startDocument(); - } catch (final SAXException e) { + } catch (SAXException e) { throw new StreamException(e); } } @@ -55,17 +55,15 @@ * @since 1.2 * @deprecated As of 1.4 use {@link Dom4JXmlWriter#Dom4JXmlWriter(XMLWriter, NameCoder)} instead. */ - @Deprecated - public Dom4JXmlWriter(final XMLWriter writer, final XmlFriendlyReplacer replacer) { + public Dom4JXmlWriter(XMLWriter writer, XmlFriendlyReplacer replacer) { this(writer, (NameCoder)replacer); } - @Override - public void startNode(final String name) { + public void startNode(String name) { if (elementStack.size() > 0) { try { startElement(); - } catch (final SAXException e) { + } catch (SAXException e) { throw new StreamException(e); } started = false; @@ -74,69 +72,67 @@ children = false; } - @Override - public void setValue(final String text) { - final char[] value = text.toCharArray(); + public void setValue(String text) { + char[] value = text.toCharArray(); if (value.length > 0) { try { startElement(); writer.characters(value, 0, value.length); - } catch (final SAXException e) { + } catch (SAXException e) { throw new StreamException(e); } children = true; } } - @Override - public void addAttribute(final String key, final String value) { + public void addAttribute(String key, String value) { attributes.addAttribute("", "", encodeAttribute(key), "string", value); } - @Override public void endNode() { try { if (!children) { - final Element element = new DefaultElement(elementStack.pop()); + Element element = new DefaultElement((String)elementStack.pop()); for (int i = 0; i < attributes.getLength(); ++i) { element.addAttribute(attributes.getQName(i), attributes.getValue(i)); } writer.write(element); attributes.clear(); - children = true; // node just closed is child of node on top of stack + children = true; // node just closed is child of node on top of stack started = true; } else { startElement(); - writer.endElement("", "", elementStack.pop()); + writer.endElement("", "", (String)elementStack.pop()); } - } catch (final SAXException e) { + } catch (SAXException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override public void flush() { try { writer.flush(); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override public void close() { try { writer.endDocument(); - } catch (final SAXException e) { + writer.flush(); + } catch (SAXException e) { throw new StreamException(e); + } catch (IOException e) { + throw new StreamException(e); } } private void startElement() throws SAXException { if (!started) { - writer.startElement("", "", elementStack.peek(), attributes); + writer.startElement("", "", (String)elementStack.peek(), attributes); attributes.clear(); started = true; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DomDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DomDriver.java (.../DomDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DomDriver.java (.../DomDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,12 +1,12 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 07. March 2004 by Joe Walnes */ package com.thoughtworks.xstream.io.xml; @@ -19,6 +19,8 @@ import java.io.Reader; import java.io.UnsupportedEncodingException; import java.io.Writer; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.URL; import javax.xml.parsers.DocumentBuilder; @@ -30,6 +32,8 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; +import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.StreamException; @@ -39,7 +43,7 @@ public class DomDriver extends AbstractXmlDriver { private final String encoding; - private final DocumentBuilderFactory documentBuilderFactory; + private DocumentBuilderFactory documentBuilderFactory; /** * Construct a DomDriver. @@ -49,81 +53,112 @@ } /** - * Construct a DomDriver with a specified encoding. The created DomReader will ignore any encoding attribute of the - * XML header though. + * Construct a DomDriver with a specified encoding. The created DomReader will ignore any + * encoding attribute of the XML header though. */ - public DomDriver(final String encoding) { + public DomDriver(String encoding) { this(encoding, new XmlFriendlyNameCoder()); } /** * @since 1.4 */ - public DomDriver(final String encoding, final NameCoder nameCoder) { + public DomDriver(String encoding, NameCoder nameCoder) { super(nameCoder); - documentBuilderFactory = DocumentBuilderFactory.newInstance(); this.encoding = encoding; } /** * @since 1.2 * @deprecated As of 1.4, use {@link #DomDriver(String, NameCoder)} instead. */ - @Deprecated - public DomDriver(final String encoding, final XmlFriendlyReplacer replacer) { + public DomDriver(String encoding, XmlFriendlyReplacer replacer) { this(encoding, (NameCoder)replacer); } - @Override - public HierarchicalStreamReader createReader(final Reader in) { + public HierarchicalStreamReader createReader(Reader in) { return createReader(new InputSource(in)); } - @Override - public HierarchicalStreamReader createReader(final InputStream in) { + public HierarchicalStreamReader createReader(InputStream in) { return createReader(new InputSource(in)); } - @Override - public HierarchicalStreamReader createReader(final URL in) { + public HierarchicalStreamReader createReader(URL in) { return createReader(new InputSource(in.toExternalForm())); } - @Override - public HierarchicalStreamReader createReader(final File in) { + public HierarchicalStreamReader createReader(File in) { return createReader(new InputSource(in.toURI().toASCIIString())); } - private HierarchicalStreamReader createReader(final InputSource source) { + private HierarchicalStreamReader createReader(InputSource source) { try { + if (documentBuilderFactory == null) { + synchronized (this) { + if (documentBuilderFactory == null) { + documentBuilderFactory = createDocumentBuilderFactory(); + } + } + } final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); if (encoding != null) { source.setEncoding(encoding); } - final Document document = documentBuilder.parse(source); + Document document = documentBuilder.parse(source); return new DomReader(document, getNameCoder()); - } catch (final FactoryConfigurationError e) { + } catch (FactoryConfigurationError e) { throw new StreamException(e); - } catch (final ParserConfigurationException e) { + } catch (ParserConfigurationException e) { throw new StreamException(e); - } catch (final SAXException e) { + } catch (SAXException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamWriter createWriter(final Writer out) { + public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out, getNameCoder()); } - @Override - public HierarchicalStreamWriter createWriter(final OutputStream out) { + public HierarchicalStreamWriter createWriter(OutputStream out) { try { - return createWriter(encoding != null ? new OutputStreamWriter(out, encoding) : new OutputStreamWriter(out)); - } catch (final UnsupportedEncodingException e) { + return createWriter(encoding != null + ? new OutputStreamWriter(out, encoding) + : new OutputStreamWriter(out)); + } catch (UnsupportedEncodingException e) { throw new StreamException(e); } } + + /** + * Create the DocumentBuilderFactory instance. + * + * @return the new instance + * @since 1.4.9 + */ + protected DocumentBuilderFactory createDocumentBuilderFactory() { + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + if (JVM.is15()) { + try { + Method method = DocumentBuilderFactory.class.getMethod("setFeature", + new Class[]{ String.class, boolean.class }); + method.invoke(factory, new Object[]{ "http://apache.org/xml/features/disallow-doctype-decl", Boolean.TRUE }); + } catch (NoSuchMethodException e) { + // Ignore + } catch (IllegalAccessException e) { + throw new ObjectAccessException("Cannot set feature of DocumentBuilderFactory.", e); + } catch (InvocationTargetException e) { + Throwable cause = e.getCause(); + if (JVM.is16() + || (cause instanceof ParserConfigurationException + && cause.getMessage().indexOf("disallow-doctype-decl") < 0)) { + throw new StreamException(cause); + } + } + } + factory.setExpandEntityReferences(false); + return factory; + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DomReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DomReader.java (.../DomReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DomReader.java (.../DomReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,8 +11,7 @@ */ package com.thoughtworks.xstream.io.xml; -import java.util.ArrayList; -import java.util.List; +import com.thoughtworks.xstream.io.naming.NameCoder; import org.w3c.dom.Attr; import org.w3c.dom.Document; @@ -21,132 +20,119 @@ import org.w3c.dom.NodeList; import org.w3c.dom.Text; -import com.thoughtworks.xstream.io.naming.NameCoder; +import java.util.ArrayList; +import java.util.List; - public class DomReader extends AbstractDocumentReader { private Element currentElement; - private final StringBuilder textBuffer; - private List childElements; + private StringBuffer textBuffer; + private List childElements; - public DomReader(final Element rootElement) { + public DomReader(Element rootElement) { this(rootElement, new XmlFriendlyNameCoder()); } - public DomReader(final Document document) { + public DomReader(Document document) { this(document.getDocumentElement()); } /** * @since 1.4 */ - public DomReader(final Element rootElement, final NameCoder nameCoder) { + public DomReader(Element rootElement, NameCoder nameCoder) { super(rootElement, nameCoder); - textBuffer = new StringBuilder(); + textBuffer = new StringBuffer(); } /** * @since 1.4 */ - public DomReader(final Document document, final NameCoder nameCoder) { + public DomReader(Document document, NameCoder nameCoder) { this(document.getDocumentElement(), nameCoder); } /** * @since 1.2 * @deprecated As of 1.4, use {@link DomReader#DomReader(Element, NameCoder)} instead. */ - @Deprecated - public DomReader(final Element rootElement, final XmlFriendlyReplacer replacer) { + public DomReader(Element rootElement, XmlFriendlyReplacer replacer) { this(rootElement, (NameCoder)replacer); } /** * @since 1.2 * @deprecated As of 1.4, use {@link DomReader#DomReader(Document, NameCoder)} instead. */ - @Deprecated - public DomReader(final Document document, final XmlFriendlyReplacer replacer) { + public DomReader(Document document, XmlFriendlyReplacer replacer) { this(document.getDocumentElement(), (NameCoder)replacer); } - - @Override + public String getNodeName() { return decodeNode(currentElement.getTagName()); } - @Override public String getValue() { - final NodeList childNodes = currentElement.getChildNodes(); + NodeList childNodes = currentElement.getChildNodes(); textBuffer.setLength(0); - final int length = childNodes.getLength(); + int length = childNodes.getLength(); for (int i = 0; i < length; i++) { - final Node childNode = childNodes.item(i); + Node childNode = childNodes.item(i); if (childNode instanceof Text) { - final Text text = (Text)childNode; + Text text = (Text) childNode; textBuffer.append(text.getData()); } } return textBuffer.toString(); } - @Override - public String getAttribute(final String name) { - final Attr attribute = currentElement.getAttributeNode(encodeAttribute(name)); + public String getAttribute(String name) { + Attr attribute = currentElement.getAttributeNode(encodeAttribute(name)); return attribute == null ? null : attribute.getValue(); } - @Override - public String getAttribute(final int index) { - return ((Attr)currentElement.getAttributes().item(index)).getValue(); + public String getAttribute(int index) { + return ((Attr) currentElement.getAttributes().item(index)).getValue(); } - @Override public int getAttributeCount() { return currentElement.getAttributes().getLength(); } - @Override - public String getAttributeName(final int index) { - return decodeAttribute(((Attr)currentElement.getAttributes().item(index)).getName()); + public String getAttributeName(int index) { + return decodeAttribute(((Attr) currentElement.getAttributes().item(index)).getName()); } - @Override protected Object getParent() { return currentElement.getParentNode(); } - @Override - protected Object getChild(final int index) { + protected Object getChild(int index) { return childElements.get(index); } - @Override protected int getChildCount() { return childElements.size(); } - @Override - protected void reassignCurrentElement(final Object current) { - currentElement = (Element)current; - final NodeList childNodes = currentElement.getChildNodes(); - childElements = new ArrayList(); + protected void reassignCurrentElement(Object current) { + currentElement = (Element) current; + NodeList childNodes = currentElement.getChildNodes(); + childElements = new ArrayList(); for (int i = 0; i < childNodes.getLength(); i++) { - final Node node = childNodes.item(i); + Node node = childNodes.item(i); if (node instanceof Element) { - childElements.add((Element)node); + childElements.add(node); } } } - @Override public String peekNextChild() { - final NodeList childNodes = currentElement.getChildNodes(); + NodeList childNodes = currentElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { - final Node node = childNodes.item(i); + Node node = childNodes.item(i); if (node instanceof Element) { - return decodeNode(((Element)node).getTagName()); + return decodeNode(((Element) node).getTagName()); } } return null; Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DomWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DomWriter.java (.../DomWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/DomWriter.java (.../DomWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,12 +11,12 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.io.naming.NameCoder; + import org.w3c.dom.Document; import org.w3c.dom.Element; -import com.thoughtworks.xstream.io.naming.NameCoder; - /** * @author Michael Kopp */ @@ -60,7 +60,6 @@ * @since 1.2 * @deprecated As of 1.4 use {@link DomWriter#DomWriter(Document, NameCoder)} instead. */ - @Deprecated public DomWriter(final Document document, final XmlFriendlyReplacer replacer) { this(document.getDocumentElement(), document, (NameCoder)replacer); } @@ -69,7 +68,6 @@ * @since 1.2.1 * @deprecated As of 1.4 use {@link DomWriter#DomWriter(Element, Document, NameCoder)} instead. */ - @Deprecated public DomWriter(final Element element, final Document document, final XmlFriendlyReplacer replacer) { this(element, document, (NameCoder)replacer); } @@ -78,12 +76,10 @@ * @since 1.2 * @deprecated As of 1.4 use {@link DomWriter#DomWriter(Element, NameCoder)} instead. */ - @Deprecated public DomWriter(final Element rootElement, final XmlFriendlyReplacer replacer) { this(rootElement, rootElement.getOwnerDocument(), (NameCoder)replacer); } - @Override protected Object createNode(final String name) { final Element child = document.createElement(encodeNode(name)); final Element top = top(); @@ -96,12 +92,10 @@ return child; } - @Override public void addAttribute(final String name, final String value) { top().setAttribute(encodeAttribute(name), value); } - @Override public void setValue(final String text) { top().appendChild(document.createTextNode(text)); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDom2Driver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDom2Driver.java (.../JDom2Driver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDom2Driver.java (.../JDom2Driver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,12 +1,12 @@ /* - * Copyright (C) 2013, 2014 XStream Committers. + * Copyright (C) 2013, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. * - * Created on 24. June 2013 by Joerg Schaible + * Created on 24. June 2012 by Joerg Schaible */ package com.thoughtworks.xstream.io.xml; @@ -29,7 +29,6 @@ import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.naming.NameCoder; - /** * @since 1.4.5 */ @@ -42,69 +41,76 @@ /** * @since 1.4.5 */ - public JDom2Driver(final NameCoder nameCoder) { + public JDom2Driver(NameCoder nameCoder) { super(nameCoder); } - @Override - public HierarchicalStreamReader createReader(final Reader reader) { + public HierarchicalStreamReader createReader(Reader reader) { try { - final SAXBuilder builder = new SAXBuilder(); + final SAXBuilder builder = createBuilder(); final Document document = builder.build(reader); return new JDom2Reader(document, getNameCoder()); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); - } catch (final JDOMException e) { + } catch (JDOMException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final InputStream in) { + public HierarchicalStreamReader createReader(InputStream in) { try { - final SAXBuilder builder = new SAXBuilder(); + final SAXBuilder builder = createBuilder(); final Document document = builder.build(in); return new JDom2Reader(document, getNameCoder()); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); - } catch (final JDOMException e) { + } catch (JDOMException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final URL in) { + public HierarchicalStreamReader createReader(URL in) { try { - final SAXBuilder builder = new SAXBuilder(); + final SAXBuilder builder = createBuilder(); final Document document = builder.build(in); return new JDom2Reader(document, getNameCoder()); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); - } catch (final JDOMException e) { + } catch (JDOMException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final File in) { + public HierarchicalStreamReader createReader(File in) { try { - final SAXBuilder builder = new SAXBuilder(); + final SAXBuilder builder = createBuilder(); final Document document = builder.build(in); return new JDom2Reader(document, getNameCoder()); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); - } catch (final JDOMException e) { + } catch (JDOMException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamWriter createWriter(final Writer out) { + public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out, getNameCoder()); } - @Override - public HierarchicalStreamWriter createWriter(final OutputStream out) { + public HierarchicalStreamWriter createWriter(OutputStream out) { return new PrettyPrintWriter(new OutputStreamWriter(out)); } + + /** + * Create and initialize the SAX builder. + * + * @return the SAX builder instance. + * @since 1.4.9 + */ + protected SAXBuilder createBuilder() { + final SAXBuilder builder = new SAXBuilder(); + builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + return builder; + } } + Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDom2Reader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDom2Reader.java (.../JDom2Reader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDom2Reader.java (.../JDom2Reader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,23 +1,20 @@ /* - * Copyright (C) 2013, 2014 XStream Committers. + * Copyright (C) 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. * - * Created on 24. June 2013 by Joerg Schaible + * Created on 24. June 2012 by Joerg Schaible */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.io.naming.NameCoder; import java.util.List; - import org.jdom2.Document; import org.jdom2.Element; -import com.thoughtworks.xstream.io.naming.NameCoder; - - /** * @since 1.4.5 */ @@ -28,87 +25,77 @@ /** * @since 1.4.5 */ - public JDom2Reader(final Element root) { + public JDom2Reader(Element root) { super(root); } /** * @since 1.4.5 */ - public JDom2Reader(final Document document) { + public JDom2Reader(Document document) { super(document.getRootElement()); } /** * @since 1.4.5 */ - public JDom2Reader(final Element root, final NameCoder nameCoder) { + public JDom2Reader(Element root, NameCoder nameCoder) { super(root, nameCoder); } /** * @since 1.4.5 */ - public JDom2Reader(final Document document, final NameCoder nameCoder) { + public JDom2Reader(Document document, NameCoder nameCoder) { super(document.getRootElement(), nameCoder); } - - @Override - protected void reassignCurrentElement(final Object current) { - currentElement = (Element)current; + + protected void reassignCurrentElement(Object current) { + currentElement = (Element) current; } - @Override protected Object getParent() { return currentElement.getParentElement(); } - @Override - protected Object getChild(final int index) { + protected Object getChild(int index) { return currentElement.getChildren().get(index); } - @Override protected int getChildCount() { return currentElement.getChildren().size(); } - @Override public String getNodeName() { return decodeNode(currentElement.getName()); } - @Override public String getValue() { return currentElement.getText(); } - @Override - public String getAttribute(final String name) { + public String getAttribute(String name) { return currentElement.getAttributeValue(encodeAttribute(name)); } - @Override - public String getAttribute(final int index) { + public String getAttribute(int index) { return currentElement.getAttributes().get(index).getValue(); } - @Override public int getAttributeCount() { return currentElement.getAttributes().size(); } - @Override - public String getAttributeName(final int index) { + public String getAttributeName(int index) { return decodeAttribute(currentElement.getAttributes().get(index).getQualifiedName()); } - @Override public String peekNextChild() { - final List list = currentElement.getChildren(); + List list = currentElement.getChildren(); if (null == list || list.isEmpty()) { return null; } - return decodeNode(list.get(0).getName()); + return decodeNode(((Element) list.get(0)).getName()); } } + Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDom2Writer.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDom2Writer.java (.../JDom2Writer.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDom2Writer.java (.../JDom2Writer.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,22 +1,22 @@ /* - * Copyright (C) 2013, 2014 XStream Committers. + * Copyright (C) 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. * - * Created on 24. June 2013 by Joerg Schaible + * Created on 24. June 2012 by Joerg Schaible */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.io.naming.NameCoder; + import org.jdom2.DefaultJDOMFactory; import org.jdom2.Element; import org.jdom2.JDOMFactory; -import com.thoughtworks.xstream.io.naming.NameCoder; - /** * @since 1.4.5 */ @@ -27,7 +27,9 @@ /** * @since 1.4.5 */ - public JDom2Writer(final Element container, final JDOMFactory factory, final NameCoder nameCoder) { + public JDom2Writer( + final Element container, final JDOMFactory factory, + final NameCoder nameCoder) { super(container, nameCoder); documentFactory = factory; } @@ -74,7 +76,6 @@ this(new DefaultJDOMFactory()); } - @Override protected Object createNode(final String name) { final Element element = documentFactory.element(encodeNode(name)); final Element parent = top(); @@ -84,12 +85,10 @@ return element; } - @Override public void setValue(final String text) { top().addContent(documentFactory.text(text)); } - @Override public void addAttribute(final String key, final String value) { top().setAttribute(documentFactory.attribute(encodeAttribute(key), value)); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDomDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDomDriver.java (.../JDomDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDomDriver.java (.../JDomDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -29,7 +29,6 @@ import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.naming.NameCoder; - /** * @author Laurent Bihanic */ @@ -42,79 +41,85 @@ /** * @since 1.4 */ - public JDomDriver(final NameCoder nameCoder) { + public JDomDriver(NameCoder nameCoder) { super(nameCoder); } /** * @since 1.2 * @deprecated As of 1.4, use {@link JDomDriver#JDomDriver(NameCoder)} instead. */ - @Deprecated - public JDomDriver(final XmlFriendlyReplacer replacer) { + public JDomDriver(XmlFriendlyReplacer replacer) { this((NameCoder)replacer); } - @Override - public HierarchicalStreamReader createReader(final Reader reader) { + public HierarchicalStreamReader createReader(Reader reader) { try { - final SAXBuilder builder = new SAXBuilder(); + final SAXBuilder builder = createBuilder(); final Document document = builder.build(reader); return new JDomReader(document, getNameCoder()); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); - } catch (final JDOMException e) { + } catch (JDOMException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final InputStream in) { + public HierarchicalStreamReader createReader(InputStream in) { try { - final SAXBuilder builder = new SAXBuilder(); + final SAXBuilder builder = createBuilder(); final Document document = builder.build(in); return new JDomReader(document, getNameCoder()); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); - } catch (final JDOMException e) { + } catch (JDOMException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final URL in) { + public HierarchicalStreamReader createReader(URL in) { try { - final SAXBuilder builder = new SAXBuilder(); + final SAXBuilder builder = createBuilder(); final Document document = builder.build(in); return new JDomReader(document, getNameCoder()); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); - } catch (final JDOMException e) { + } catch (JDOMException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final File in) { + public HierarchicalStreamReader createReader(File in) { try { - final SAXBuilder builder = new SAXBuilder(); + final SAXBuilder builder = createBuilder(); final Document document = builder.build(in); return new JDomReader(document, getNameCoder()); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); - } catch (final JDOMException e) { + } catch (JDOMException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamWriter createWriter(final Writer out) { + public HierarchicalStreamWriter createWriter(Writer out) { return new PrettyPrintWriter(out, getNameCoder()); } - @Override - public HierarchicalStreamWriter createWriter(final OutputStream out) { + public HierarchicalStreamWriter createWriter(OutputStream out) { return new PrettyPrintWriter(new OutputStreamWriter(out)); } + /** + * Create and initialize the SAX builder. + * + * @return the SAX builder instance. + * @since 1.4.9 + */ + protected SAXBuilder createBuilder() { + final SAXBuilder builder = new SAXBuilder(); + builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + return builder; + } + } + Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDomReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDomReader.java (.../JDomReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDomReader.java (.../JDomReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,68 +11,61 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.io.naming.NameCoder; import java.util.List; - import org.jdom.Attribute; import org.jdom.Document; import org.jdom.Element; -import com.thoughtworks.xstream.io.naming.NameCoder; - - /** * @author Laurent Bihanic */ public class JDomReader extends AbstractDocumentReader { private Element currentElement; - public JDomReader(final Element root) { + public JDomReader(Element root) { super(root); } - public JDomReader(final Document document) { + public JDomReader(Document document) { super(document.getRootElement()); } /** * @since 1.4 */ - public JDomReader(final Element root, final NameCoder nameCoder) { + public JDomReader(Element root, NameCoder nameCoder) { super(root, nameCoder); } /** * @since 1.4 */ - public JDomReader(final Document document, final NameCoder nameCoder) { + public JDomReader(Document document, NameCoder nameCoder) { super(document.getRootElement(), nameCoder); } /** * @since 1.2 * @deprecated As of 1.4, use {@link JDomReader#JDomReader(Element, NameCoder)} instead. */ - @Deprecated - public JDomReader(final Element root, final XmlFriendlyReplacer replacer) { + public JDomReader(Element root, XmlFriendlyReplacer replacer) { this(root, (NameCoder)replacer); } /** * @since 1.2 * @deprecated As of 1.4, use {@link JDomReader#JDomReader(Document, NameCoder)} instead. */ - @Deprecated - public JDomReader(final Document document, final XmlFriendlyReplacer replacer) { + public JDomReader(Document document, XmlFriendlyReplacer replacer) { this(document.getRootElement(), (NameCoder)replacer); } - - @Override - protected void reassignCurrentElement(final Object current) { - currentElement = (Element)current; + + protected void reassignCurrentElement(Object current) { + currentElement = (Element) current; } - @Override protected Object getParent() { // JDOM 1.0: return currentElement.getParentElement(); @@ -85,54 +78,45 @@ // return currentElement.getParent(); } - @Override - protected Object getChild(final int index) { + protected Object getChild(int index) { return currentElement.getChildren().get(index); } - @Override protected int getChildCount() { return currentElement.getChildren().size(); } - @Override public String getNodeName() { return decodeNode(currentElement.getName()); } - @Override public String getValue() { return currentElement.getText(); } - @Override - public String getAttribute(final String name) { + public String getAttribute(String name) { return currentElement.getAttributeValue(encodeAttribute(name)); } - @Override - public String getAttribute(final int index) { - return ((Attribute)currentElement.getAttributes().get(index)).getValue(); + public String getAttribute(int index) { + return ((Attribute) currentElement.getAttributes().get(index)).getValue(); } - @Override public int getAttributeCount() { return currentElement.getAttributes().size(); } - @Override - public String getAttributeName(final int index) { - return decodeAttribute(((Attribute)currentElement.getAttributes().get(index)).getQualifiedName()); + public String getAttributeName(int index) { + return decodeAttribute(((Attribute) currentElement.getAttributes().get(index)).getQualifiedName()); } - @Override public String peekNextChild() { - @SuppressWarnings("unchecked") - final List list = currentElement.getChildren(); + List list = currentElement.getChildren(); if (null == list || list.isEmpty()) { return null; } - return decodeNode(list.get(0).getName()); + return decodeNode(((Element) list.get(0)).getName()); } } + Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDomWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDomWriter.java (.../JDomWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/JDomWriter.java (.../JDomWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,13 +11,13 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.io.naming.NameCoder; + import org.jdom.DefaultJDOMFactory; import org.jdom.Element; import org.jdom.JDOMFactory; -import com.thoughtworks.xstream.io.naming.NameCoder; - /** * @author Laurent Bihanic */ @@ -28,7 +28,9 @@ /** * @since 1.4 */ - public JDomWriter(final Element container, final JDOMFactory factory, final NameCoder nameCoder) { + public JDomWriter( + final Element container, final JDOMFactory factory, + final NameCoder nameCoder) { super(container, nameCoder); documentFactory = factory; } @@ -37,8 +39,9 @@ * @since 1.2 * @deprecated As of 1.4 use {@link JDomWriter#JDomWriter(Element, JDOMFactory, NameCoder)} instead. */ - @Deprecated - public JDomWriter(final Element container, final JDOMFactory factory, final XmlFriendlyReplacer replacer) { + public JDomWriter( + final Element container, final JDOMFactory factory, + final XmlFriendlyReplacer replacer) { this(container, factory, (NameCoder)replacer); } @@ -57,7 +60,6 @@ * @since 1.2.1 * @deprecated As of 1.4 use {@link JDomWriter#JDomWriter(JDOMFactory, NameCoder)} instead. */ - @Deprecated public JDomWriter(final JDOMFactory factory, final XmlFriendlyReplacer replacer) { this(null, factory, (NameCoder)replacer); } @@ -77,7 +79,6 @@ * @since 1.2.1 * @deprecated As of 1.4 use {@link JDomWriter#JDomWriter(Element, NameCoder)} instead. */ - @Deprecated public JDomWriter(final Element container, final XmlFriendlyReplacer replacer) { this(container, new DefaultJDOMFactory(), (NameCoder)replacer); } @@ -90,7 +91,6 @@ this(new DefaultJDOMFactory()); } - @Override protected Object createNode(final String name) { final Element element = documentFactory.element(encodeNode(name)); final Element parent = top(); @@ -100,12 +100,10 @@ return element; } - @Override public void setValue(final String text) { top().addContent(documentFactory.text(text)); } - @Override public void addAttribute(final String key, final String value) { top().setAttribute(documentFactory.attribute(encodeAttribute(key), value)); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/KXml2DomDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/KXml2DomDriver.java (.../KXml2DomDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/KXml2DomDriver.java (.../KXml2DomDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,12 +10,11 @@ */ package com.thoughtworks.xstream.io.xml; -import org.kxml2.io.KXmlParser; -import org.xmlpull.v1.XmlPullParser; - import com.thoughtworks.xstream.io.HierarchicalStreamDriver; import com.thoughtworks.xstream.io.naming.NameCoder; +import org.kxml2.io.KXmlParser; +import org.xmlpull.v1.XmlPullParser; /** * A {@link HierarchicalStreamDriver} for XPP DOM using the kXML2 parser. @@ -40,14 +39,13 @@ * @param nameCoder the replacer for XML friendly names * @since 1.4 */ - public KXml2DomDriver(final NameCoder nameCoder) { + public KXml2DomDriver(NameCoder nameCoder) { super(nameCoder); } /** * {@inheritDoc} */ - @Override protected XmlPullParser createParser() { return new KXmlParser(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/KXml2Driver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/KXml2Driver.java (.../KXml2Driver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/KXml2Driver.java (.../KXml2Driver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,13 +10,14 @@ */ package com.thoughtworks.xstream.io.xml; -import org.kxml2.io.KXmlParser; -import org.xmlpull.v1.XmlPullParser; import com.thoughtworks.xstream.io.HierarchicalStreamDriver; import com.thoughtworks.xstream.io.naming.NameCoder; +import org.kxml2.io.KXmlParser; +import org.xmlpull.v1.XmlPullParser; + /** * A {@link HierarchicalStreamDriver} using the kXML2 parser. * @@ -40,14 +41,13 @@ * @param nameCoder the replacer for XML friendly names * @since 1.4 */ - public KXml2Driver(final NameCoder nameCoder) { + public KXml2Driver(NameCoder nameCoder) { super(nameCoder); } /** * {@inheritDoc} */ - @Override protected XmlPullParser createParser() { return new KXmlParser(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.java (.../PrettyPrintWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.java (.../PrettyPrintWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,37 +11,38 @@ */ package com.thoughtworks.xstream.io.xml; -import java.io.Writer; - import com.thoughtworks.xstream.core.util.FastStack; import com.thoughtworks.xstream.core.util.QuickWriter; import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.naming.NameCoder; +import java.io.Writer; + /** * A simple writer that outputs XML in a pretty-printed indented stream. *

      - * By default, the chars
      - * & < > " ' \r
      - * are escaped and replaced with a suitable XML entity. To alter this behavior, override the - * {@link #writeText(com.thoughtworks.xstream.core.util.QuickWriter, String)} and + * By default, the chars
      & < > " ' \r
      are escaped + * and replaced with a suitable XML entity. To alter this behavior, override + * the {@link #writeText(com.thoughtworks.xstream.core.util.QuickWriter, String)} and * {@link #writeAttributeValue(com.thoughtworks.xstream.core.util.QuickWriter, String)} methods. *

      *

      - * The XML specification requires XML parsers to drop CR characters completely. This implementation will therefore use - * only a LF for line endings, never the platform encoding. You can overwrite the {@link #getNewLine()} method for a - * different behavior. + * The XML specification requires XML parsers to drop CR characters completely. This implementation + * will therefore use only a LF for line endings, never the platform encoding. You can overwrite the + * {@link #getNewLine()} method for a different behavior. *

      *

      - * Note: Depending on the XML version some characters cannot be written. Especially a 0 character is never valid in XML, - * neither directly nor as entity nor within CDATA. However, this writer works by default in a quirks mode, where it - * will write any character at least as character entity (even a null character). You may switch into XML_1_1 mode - * (which supports most characters) or XML_1_0 that does only support a very limited number of control characters. See - * XML specification for version 1.0 or 1.1. If a character is not supported, a - * {@link StreamException} is thrown. Select a proper parser implementation that respects the version in the XML header - * (the Xpp3 parser will also read character entities of normally invalid characters). + * Note: Depending on the XML version some characters cannot be written. Especially a 0 + * character is never valid in XML, neither directly nor as entity nor within CDATA. However, this writer + * works by default in a quirks mode, where it will write any character at least as character entity (even + * a null character). You may switch into XML_1_1 mode (which supports most characters) or XML_1_0 + * that does only support a very limited number of control characters. See XML specification for version + * 1.0 or + * 1.1. If a character is + * not supported, a {@link StreamException} is thrown. Select a proper parser implementation that + * respects the version in the XML header (the Xpp3 parser will also read character entities of normally + * invalid characters). *

      * * @author Joe Walnes @@ -54,14 +55,15 @@ public static int XML_1_1 = 1; private final QuickWriter writer; - private final FastStack elementStack = new FastStack(16); + private final FastStack elementStack = new FastStack(16); private final char[] lineIndenter; private final int mode; private boolean tagInProgress; protected int depth; private boolean readyForNewLine; private boolean tagIsEmpty; + private String newLine; private static final char[] NULL = "�".toCharArray(); private static final char[] AMP = "&".toCharArray(); @@ -72,123 +74,147 @@ private static final char[] APOS = "'".toCharArray(); private static final char[] CLOSE = " XML_1_1) { throw new IllegalArgumentException("Not a valid XML mode"); } } /** + * @since 1.2 + * @deprecated As of 1.3 + */ + public PrettyPrintWriter( + Writer writer, char[] lineIndenter, String newLine, XmlFriendlyReplacer replacer) { + this(writer, XML_QUIRKS, lineIndenter, replacer, newLine); + } + + /** + * @since 1.4 + */ + public PrettyPrintWriter( + Writer writer, int mode, char[] lineIndenter, NameCoder nameCoder) { + this(writer, mode, lineIndenter, nameCoder, "\n"); + } + + /** * @since 1.3 * @deprecated As of 1.4 use {@link PrettyPrintWriter#PrettyPrintWriter(Writer, int, char[], NameCoder)} instead */ - @Deprecated public PrettyPrintWriter( - final Writer writer, final int mode, final char[] lineIndenter, final XmlFriendlyReplacer replacer) { - this(writer, mode, lineIndenter, (NameCoder)replacer); + Writer writer, int mode, char[] lineIndenter, XmlFriendlyReplacer replacer) { + this(writer, mode, lineIndenter, replacer, "\n"); } /** + * @deprecated As of 1.3 + */ + public PrettyPrintWriter(Writer writer, char[] lineIndenter, String newLine) { + this(writer, lineIndenter, newLine, new XmlFriendlyReplacer()); + } + + /** * @since 1.3 */ - public PrettyPrintWriter(final Writer writer, final int mode, final char[] lineIndenter) { + public PrettyPrintWriter(Writer writer, int mode, char[] lineIndenter) { this(writer, mode, lineIndenter, new XmlFriendlyNameCoder()); } - public PrettyPrintWriter(final Writer writer, final char[] lineIndenter) { + public PrettyPrintWriter(Writer writer, char[] lineIndenter) { this(writer, XML_QUIRKS, lineIndenter); } /** + * @deprecated As of 1.3 + */ + public PrettyPrintWriter(Writer writer, String lineIndenter, String newLine) { + this(writer, lineIndenter.toCharArray(), newLine); + } + + /** * @since 1.3 */ - public PrettyPrintWriter(final Writer writer, final int mode, final String lineIndenter) { + public PrettyPrintWriter(Writer writer, int mode, String lineIndenter) { this(writer, mode, lineIndenter.toCharArray()); } - public PrettyPrintWriter(final Writer writer, final String lineIndenter) { + public PrettyPrintWriter(Writer writer, String lineIndenter) { this(writer, lineIndenter.toCharArray()); } /** * @since 1.4 */ - public PrettyPrintWriter(final Writer writer, final int mode, final NameCoder nameCoder) { + public PrettyPrintWriter(Writer writer, int mode, NameCoder nameCoder) { this(writer, mode, new char[]{' ', ' '}, nameCoder); } /** * @since 1.3 * @deprecated As of 1.4 use {@link PrettyPrintWriter#PrettyPrintWriter(Writer, int, NameCoder)} instead */ - @Deprecated - public PrettyPrintWriter(final Writer writer, final int mode, final XmlFriendlyReplacer replacer) { + public PrettyPrintWriter(Writer writer, int mode, XmlFriendlyReplacer replacer) { this(writer, mode, new char[]{' ', ' '}, replacer); } /** * @since 1.4 */ - public PrettyPrintWriter(final Writer writer, final NameCoder nameCoder) { - this(writer, XML_QUIRKS, new char[]{' ', ' '}, nameCoder); + public PrettyPrintWriter(Writer writer, NameCoder nameCoder) { + this(writer, XML_QUIRKS, new char[]{' ', ' '}, nameCoder, "\n"); } /** * @deprecated As of 1.4 use {@link PrettyPrintWriter#PrettyPrintWriter(Writer, NameCoder)} instead. */ - @Deprecated - public PrettyPrintWriter(final Writer writer, final XmlFriendlyReplacer replacer) { - this(writer, XML_QUIRKS, new char[]{' ', ' '}, replacer); + public PrettyPrintWriter(Writer writer, XmlFriendlyReplacer replacer) { + this(writer, new char[]{' ', ' '}, "\n", replacer); } /** * @since 1.3 */ - public PrettyPrintWriter(final Writer writer, final int mode) { + public PrettyPrintWriter(Writer writer, int mode) { this(writer, mode, new char[]{' ', ' '}); } - public PrettyPrintWriter(final Writer writer) { + public PrettyPrintWriter(Writer writer) { this(writer, new char[]{' ', ' '}); } - @Override - public void startNode(final String name) { - final String escapedName = encodeNode(name); + public void startNode(String name) { + String escapedName = encodeNode(name); tagIsEmpty = false; finishTag(); writer.write('<'); writer.write(escapedName); elementStack.push(escapedName); tagInProgress = true; - depth++; + depth++ ; readyForNewLine = true; tagIsEmpty = true; } - @Override - public void startNode(final String name, final Class clazz) { + public void startNode(String name, Class clazz) { startNode(name); } - @Override - public void setValue(final String text) { + public void setValue(String text) { readyForNewLine = false; tagIsEmpty = false; finishTag(); writeText(writer, text); } - @Override - public void addAttribute(final String key, final String value) { + public void addAttribute(String key, String value) { writer.write(' '); writer.write(encodeAttribute(key)); writer.write('='); @@ -197,51 +223,50 @@ writer.write('\"'); } - protected void writeAttributeValue(final QuickWriter writer, final String text) { + protected void writeAttributeValue(QuickWriter writer, String text) { writeText(text, true); } - protected void writeText(final QuickWriter writer, final String text) { + protected void writeText(QuickWriter writer, String text) { writeText(text, false); } - private void writeText(final String text, final boolean isAttribute) { - final int length = text.length(); - for (int i = 0; i < length; i++) { - final char c = text.charAt(i); + private void writeText(String text, boolean isAttribute) { + int length = text.length(); + for (int i = 0; i < length; i++ ) { + char c = text.charAt(i); switch (c) { case '\0': if (mode == XML_QUIRKS) { - writer.write(NULL); + this.writer.write(NULL); } else { throw new StreamException("Invalid character 0x0 in XML stream"); } break; case '&': - writer.write(AMP); + this.writer.write(AMP); break; case '<': - writer.write(LT); + this.writer.write(LT); break; case '>': - writer.write(GT); + this.writer.write(GT); break; case '"': - writer.write(QUOT); + this.writer.write(QUOT); break; case '\'': - writer.write(APOS); + this.writer.write(APOS); break; case '\r': - writer.write(CR); + this.writer.write(CR); break; case '\t': case '\n': if (!isAttribute) { - writer.write(c); + this.writer.write(c); break; } - //$FALL-THROUGH$ default: if (Character.isDefined(c) && !Character.isISOControl(c)) { if (mode != XML_QUIRKS) { @@ -251,10 +276,14 @@ + " in XML stream"); } } - writer.write(c); + this.writer.write(c); } else { if (mode == XML_1_0) { - if (c < 9 || c == '\u000b' || c == '\u000c' || c == '\u000e' || c >= '\u000f' && c <= '\u001f') { + if (c < 9 + || c == '\u000b' + || c == '\u000c' + || c == '\u000e' + || (c >= '\u000f' && c <= '\u001f')) { throw new StreamException("Invalid character 0x" + Integer.toHexString(c) + " in XML 1.0 stream"); @@ -267,17 +296,16 @@ + " in XML stream"); } } - writer.write("&#x"); - writer.write(Integer.toHexString(c)); - writer.write(';'); + this.writer.write("&#x"); + this.writer.write(Integer.toHexString(c)); + this.writer.write(';'); } } } } - @Override public void endNode() { - depth--; + depth-- ; if (tagIsEmpty) { writer.write('/'); readyForNewLine = false; @@ -286,7 +314,7 @@ } else { finishTag(); writer.write(CLOSE); - writer.write(elementStack.pop()); + writer.write((String)elementStack.pop()); writer.write('>'); } readyForNewLine = true; @@ -309,29 +337,29 @@ protected void endOfLine() { writer.write(getNewLine()); - for (int i = 0; i < depth; i++) { + for (int i = 0; i < depth; i++ ) { writer.write(lineIndenter); } } - @Override public void flush() { writer.flush(); } - @Override public void close() { writer.close(); } /** - * Retrieve the line terminator. This method returns always a line feed, since according the XML specification any - * parser must ignore a carriage return. Overload this method, if you need different behavior. + * Retrieve the line terminator. * + * This method returns always a line feed, since according the XML specification any parser + * must ignore a carriage return. Overload this method, if you need different behavior. + * * @return the line terminator * @since 1.3 */ protected String getNewLine() { - return "\n"; + return newLine; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/QNameMap.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/QNameMap.java (.../QNameMap.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/QNameMap.java (.../QNameMap.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2014 XStream Committers. + * Copyright (C) 2006, 2007 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,35 +11,35 @@ */ package com.thoughtworks.xstream.io.xml; +import javax.xml.namespace.QName; + import java.util.Collections; import java.util.HashMap; import java.util.Map; -import javax.xml.namespace.QName; - - /** - * Represents a mapping of {@link QName} instances to Java class names allowing class aliases and namespace aware - * mappings of QNames to class names. - * + * Represents a mapping of {@link QName} instances to Java class names + * allowing class aliases and namespace aware mappings of QNames to class names. + * * @author James Strachan * @version $Revision$ */ public class QNameMap { // lets make the mapping a no-op unless we specify some mapping - private Map qnameToJava; - private Map javaToQName; + private Map qnameToJava; + private Map javaToQName; private String defaultPrefix = ""; private String defaultNamespace = ""; /** - * Returns the Java class name that should be used for the given QName. If no explicit mapping has been made then - * the localPart of the QName is used which is the normal default in XStream. + * Returns the Java class name that should be used for the given QName. + * If no explicit mapping has been made then the localPart of the QName is used + * which is the normal default in XStream. */ - public String getJavaClassName(final QName qname) { + public String getJavaClassName(QName qname) { if (qnameToJava != null) { - final String answer = qnameToJava.get(qname); + String answer = (String) qnameToJava.get(qname); if (answer != null) { return answer; } @@ -48,12 +48,13 @@ } /** - * Returns the Java class name that should be used for the given QName. If no explicit mapping has been made then - * the localPart of the QName is used which is the normal default in XStream. + * Returns the Java class name that should be used for the given QName. + * If no explicit mapping has been made then the localPart of the QName is used + * which is the normal default in XStream. */ - public QName getQName(final String javaClassName) { + public QName getQName(String javaClassName) { if (javaToQName != null) { - final QName answer = javaToQName.get(javaClassName); + QName answer = (QName) javaToQName.get(javaClassName); if (answer != null) { return answer; } @@ -64,12 +65,12 @@ /** * Registers the mapping of the Java class name to the QName */ - public synchronized void registerMapping(final QName qname, final String javaClassName) { + public synchronized void registerMapping(QName qname, String javaClassName) { if (javaToQName == null) { - javaToQName = Collections.synchronizedMap(new HashMap()); + javaToQName = Collections.synchronizedMap(new HashMap()); } if (qnameToJava == null) { - qnameToJava = Collections.synchronizedMap(new HashMap()); + qnameToJava = Collections.synchronizedMap(new HashMap()); } javaToQName.put(javaClassName, qname); qnameToJava.put(qname, javaClassName); @@ -78,23 +79,23 @@ /** * Registers the mapping of the type to the QName */ - public synchronized void registerMapping(final QName qname, final Class type) { + public synchronized void registerMapping(QName qname, Class type) { registerMapping(qname, type.getName()); } public String getDefaultNamespace() { return defaultNamespace; } - public void setDefaultNamespace(final String defaultNamespace) { + public void setDefaultNamespace(String defaultNamespace) { this.defaultNamespace = defaultNamespace; } public String getDefaultPrefix() { return defaultPrefix; } - public void setDefaultPrefix(final String defaultPrefix) { + public void setDefaultPrefix(String defaultPrefix) { this.defaultPrefix = defaultPrefix; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/SaxWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/SaxWriter.java (.../SaxWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/SaxWriter.java (.../SaxWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,12 +11,9 @@ */ package com.thoughtworks.xstream.io.xml; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.io.naming.NameCoder; import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; @@ -29,51 +26,63 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.AttributesImpl; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.StreamException; -import com.thoughtworks.xstream.io.naming.NameCoder; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; - /** * A SAX {@link org.xml.sax.XMLReader parser} that acts as an XStream - * {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} to enable direct generation of a SAX event flow from the - * XStream serialization of a list of list of Java objects. + * {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} to enable direct generation of a + * SAX event flow from the XStream serialization of a list of list of Java objects. *

      - * As a custom SAX parser, this class ignores the arguments of the two standard parse methods ( - * {@link #parse(java.lang.String)} and {@link #parse(org.xml.sax.InputSource)}) but relies on a proprietary SAX - * property {@link #SOURCE_OBJECT_LIST_PROPERTY} to define the list of objects to serialize. + * As a + * custom SAX parser, this class ignores the arguments of the two standard parse methods ({@link #parse(java.lang.String)} + * and {@link #parse(org.xml.sax.InputSource)}) but relies on a proprietary SAX property + * {@link #SOURCE_OBJECT_LIST_PROPERTY} to define the list of objects to serialize. *

      *

      - * Configuration of this SAX parser is achieved through the standard {@link #setProperty SAX property mechanism}. While - * specific setter methods require direct access to the parser instance, SAX properties support configuration settings - * to be propagated through a chain of {@link org.xml.sax.XMLFilter filters} down to the underlying parser object. + * Configuration of this SAX parser is achieved through the standard + * {@link #setProperty SAX property mechanism}. While specific setter methods require direct + * access to the parser instance, SAX properties support configuration settings to be propagated + * through a chain of {@link org.xml.sax.XMLFilter filters} down to the underlying parser + * object. *

      *

      - * This mechanism shall be used to configure the {@link #SOURCE_OBJECT_LIST_PROPERTY objects to be serialized} as well - * as the {@link #CONFIGURED_XSTREAM_PROPERTY XStream facade}. + * This mechanism shall be used to configure the + * {@link #SOURCE_OBJECT_LIST_PROPERTY objects to be serialized} as well as the + * {@link #CONFIGURED_XSTREAM_PROPERTY XStream facade}. *

      * * @author Laurent Bihanic */ public final class SaxWriter extends AbstractXmlWriter implements XMLReader { /** - * The {@link #setProperty SAX property} to configure the XStream facade to be used for object serialization. If the - * property is not set, a new XStream facade will be allocated for each parse. + * The {@link #setProperty SAX property} to configure the XStream + * facade to be used for object serialization. If the property + * is not set, a new XStream facade will be allocated for each + * parse. */ - public final static String CONFIGURED_XSTREAM_PROPERTY = "http://com.thoughtworks.xstream/sax/property/configured-xstream"; + public final static String CONFIGURED_XSTREAM_PROPERTY = + "http://com.thoughtworks.xstream/sax/property/configured-xstream"; /** - * The {@link #setProperty SAX property} to configure the list of Java objects to serialize. Setting this property - * prior invoking one of the parse() methods is mandatory. - * + * The {@link #setProperty SAX property} to configure the list of + * Java objects to serialize. Setting this property prior + * invoking one of the parse() methods is mandatory. + * * @see #parse(java.lang.String) * @see #parse(org.xml.sax.InputSource) */ - public final static String SOURCE_OBJECT_LIST_PROPERTY = "http://com.thoughtworks.xstream/sax/property/source-object-list"; + public final static String SOURCE_OBJECT_LIST_PROPERTY = + "http://com.thoughtworks.xstream/sax/property/source-object-list"; - // ========================================================================= + //========================================================================= // SAX XMLReader interface support - // ========================================================================= + //========================================================================= /** * The SAX EntityResolver associated to this XMLReader. @@ -98,89 +107,94 @@ /** * The SAX features defined for this XMLReader. *

      - * This class does not define any feature (yet) and ignores the SAX mandatory feature. Thus, this member is present - * only to support the mandatory feature setting and retrieval logic defined by SAX. - *

      + * This class does not define any feature (yet) and ignores + * the SAX mandatory feature. Thus, this member is present + * only to support the mandatory feature setting and retrieval + * logic defined by SAX.

      */ - private final Map features = new HashMap(); + private Map features = new HashMap(); /** * The SAX properties defined for this XMLReader. */ - private final Map properties = new HashMap(); + private final Map properties = new HashMap(); private final boolean includeEnclosingDocument; /** * @since 1.4 */ - public SaxWriter(final NameCoder nameCoder) { + public SaxWriter(NameCoder nameCoder) + { this(true, nameCoder); } - + /** * @since 1.4 */ - public SaxWriter(final boolean includeEnclosingDocument, final NameCoder nameCoder) { + public SaxWriter(boolean includeEnclosingDocument, NameCoder nameCoder) + { super(nameCoder); this.includeEnclosingDocument = includeEnclosingDocument; } /** * @deprecated As of 1.4 use {@link SaxWriter#SaxWriter(NameCoder)} instead. */ - @Deprecated - public SaxWriter(final XmlFriendlyReplacer replacer) { - this(true, replacer); + public SaxWriter(XmlFriendlyReplacer replacer) + { + this(true, replacer); } - + /** * @deprecated As of 1.4 use {@link SaxWriter#SaxWriter(boolean, NameCoder)} instead. */ - @Deprecated - public SaxWriter(final boolean includeEnclosingDocument, final XmlFriendlyReplacer replacer) { - this(includeEnclosingDocument, (NameCoder)replacer); + public SaxWriter(boolean includeEnclosingDocument, XmlFriendlyReplacer replacer) + { + this(includeEnclosingDocument, (NameCoder)replacer); } - - public SaxWriter(final boolean includeEnclosingDocument) { + + public SaxWriter(boolean includeEnclosingDocument) { this(includeEnclosingDocument, new XmlFriendlyNameCoder()); } public SaxWriter() { this(true); } - // ------------------------------------------------------------------------- + //------------------------------------------------------------------------- // Configuration - // ------------------------------------------------------------------------- + //------------------------------------------------------------------------- /** * Sets the state of a feature. *

      - * The feature name is any fully-qualified URI. - *

      + * The feature name is any fully-qualified URI.

      *

      - * All XMLReaders are required to support setting http://xml.org/sax/features/namespaces to - * true and http://xml.org/sax/features/namespace-prefixes to false. - *

      + * All XMLReaders are required to support setting + * http://xml.org/sax/features/namespaces to + * true and + * http://xml.org/sax/features/namespace-prefixes to + * false.

      *

      - * Some feature values may be immutable or mutable only in specific contexts, such as before, during, or after a - * parse. - *

      + * Some feature values may be immutable or mutable only + * in specific contexts, such as before, during, or after + * a parse.

      *

      - * Note: This implementation only supports the two mandatory SAX features. - *

      - * - * @param name the feature name, which is a fully-qualified URI. + * Note: This implementation only supports the two + * mandatory SAX features.

      + * + * @param name the feature name, which is a fully-qualified URI. * @param value the requested state of the feature (true or false). - * @throws SAXNotRecognizedException when the XMLReader does not recognize the feature name. + * @throws SAXNotRecognizedException when the XMLReader does not + * recognize the feature name. * @see #getFeature */ - @Override - public void setFeature(final String name, final boolean value) throws SAXNotRecognizedException { - if (name.equals("http://xml.org/sax/features/namespaces") - || name.equals("http://xml.org/sax/features/namespace-prefixes")) { - features.put(name, value ? Boolean.TRUE : Boolean.FALSE); // JDK 1.3 friendly + public void setFeature(String name, boolean value) + throws SAXNotRecognizedException { + if ((name.equals("http://xml.org/sax/features/namespaces")) || + (name.equals("http://xml.org/sax/features/namespace-prefixes"))) { + this.features.put(name, value ? Boolean.TRUE : Boolean.FALSE); // JDK 1.3 friendly } else { throw new SAXNotRecognizedException(name); } @@ -189,31 +203,35 @@ /** * Looks up the value of a feature. *

      - * The feature name is any fully-qualified URI. It is possible for an XMLReader to recognize a feature name but to - * be unable to return its value; this is especially true in the case of an adapter for a SAX1 Parser, which has no - * way of knowing whether the underlying parser is performing validation or expanding external entities. - *

      + * The feature name is any fully-qualified URI. It is + * possible for an XMLReader to recognize a feature name but + * to be unable to return its value; this is especially true + * in the case of an adapter for a SAX1 Parser, which has + * no way of knowing whether the underlying parser is + * performing validation or expanding external entities.

      *

      - * All XMLReaders are required to recognize the http://xml.org/sax/features/namespaces and the - * http://xml.org/sax/features/namespace-prefixes feature names. - *

      + * All XMLReaders are required to recognize the + * http://xml.org/sax/features/namespaces and the + * http://xml.org/sax/features/namespace-prefixes feature + * names.

      *

      - * Some feature values may be available only in specific contexts, such as before, during, or after a parse. - *

      + * Some feature values may be available only in specific + * contexts, such as before, during, or after a parse.

      *

      - * Implementors are free (and encouraged) to invent their own features, using names built on their own URIs. - *

      - * + * Implementors are free (and encouraged) to invent their own + * features, using names built on their own URIs.

      + * * @param name the feature name, which is a fully-qualified URI. * @return the current state of the feature (true or false). - * @throws SAXNotRecognizedException when the XMLReader does not recognize the feature name. + * @throws SAXNotRecognizedException when the XMLReader does not + * recognize the feature name. * @see #setFeature */ - @Override - public boolean getFeature(final String name) throws SAXNotRecognizedException { - if (name.equals("http://xml.org/sax/features/namespaces") - || name.equals("http://xml.org/sax/features/namespace-prefixes")) { - Boolean value = features.get(name); + public boolean getFeature(String name) + throws SAXNotRecognizedException { + if ((name.equals("http://xml.org/sax/features/namespaces")) || + (name.equals("http://xml.org/sax/features/namespace-prefixes"))) { + Boolean value = (Boolean) (this.features.get(name)); if (value == null) { value = Boolean.FALSE; @@ -227,473 +245,484 @@ /** * Sets the value of a property. *

      - * The property name is any fully-qualified URI. It is possible for an XMLReader to recognize a property name but to - * be unable to set its value. - *

      + * The property name is any fully-qualified URI. It is + * possible for an XMLReader to recognize a property name but + * to be unable to set its value.

      *

      - * XMLReaders are not required to recognize setting any specific property names, though a core set is provided with - * SAX2. - *

      + * XMLReaders are not required to recognize setting any + * specific property names, though a core set is provided with + * SAX2.

      *

      - * Some property values may be immutable or mutable only in specific contexts, such as before, during, or after a - * parse. - *

      + * Some property values may be immutable or mutable only + * in specific contexts, such as before, during, or after + * a parse.

      *

      - * This method is also the standard mechanism for setting extended handlers. - *

      + * This method is also the standard mechanism for setting + * extended handlers.

      *

      - * Note: This implementation only supports two (proprietary) properties: - * {@link #CONFIGURED_XSTREAM_PROPERTY} and {@link #SOURCE_OBJECT_LIST_PROPERTY}. - *

      - * - * @param name the property name, which is a fully-qualified URI. + * Note: This implementation only supports two + * (proprietary) properties: {@link #CONFIGURED_XSTREAM_PROPERTY} + * and {@link #SOURCE_OBJECT_LIST_PROPERTY}.

      + * + * @param name the property name, which is a fully-qualified URI. * @param value the requested value for the property. - * @throws SAXNotRecognizedException when the XMLReader does not recognize the property name. - * @throws SAXNotSupportedException when the XMLReader recognizes the property name but cannot set the requested - * value. + * @throws SAXNotRecognizedException when the XMLReader does not + * recognize the property name. + * @throws SAXNotSupportedException when the XMLReader recognizes + * the property name but cannot set + * the requested value. * @see #getProperty */ - @Override - public void setProperty(final String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { + public void setProperty(String name, Object value) + throws SAXNotRecognizedException, + SAXNotSupportedException { if (name.equals(CONFIGURED_XSTREAM_PROPERTY)) { if (!(value instanceof XStream)) { - throw new SAXNotSupportedException("Value for property \"" - + CONFIGURED_XSTREAM_PROPERTY - + "\" must be a non-null XStream object"); + throw new SAXNotSupportedException("Value for property \"" + + CONFIGURED_XSTREAM_PROPERTY + + "\" must be a non-null XStream object"); } } else if (name.equals(SOURCE_OBJECT_LIST_PROPERTY)) { if (value instanceof List) { - final List list = (List)value; + List list = (List) value; if (list.isEmpty()) { - throw new SAXNotSupportedException("Value for property \"" - + SOURCE_OBJECT_LIST_PROPERTY - + "\" shall not be an empty list"); + throw new SAXNotSupportedException("Value for property \"" + + SOURCE_OBJECT_LIST_PROPERTY + + "\" shall not be an empty list"); } else { // Perform a copy of the list to prevent the application to // modify its content while the parse is being performed. - value = Collections.unmodifiableList(new ArrayList(list)); + value = Collections.unmodifiableList(new ArrayList(list)); } } else { - throw new SAXNotSupportedException("Value for property \"" - + SOURCE_OBJECT_LIST_PROPERTY - + "\" must be a non-null List object"); + throw new SAXNotSupportedException("Value for property \"" + + SOURCE_OBJECT_LIST_PROPERTY + + "\" must be a non-null List object"); } } else { throw new SAXNotRecognizedException(name); } - properties.put(name, value); + this.properties.put(name, value); } /** * Looks up the value of a property. *

      - * The property name is any fully-qualified URI. It is possible for an XMLReader to recognize a property name but to - * be unable to return its state. - *

      + * The property name is any fully-qualified URI. It is + * possible for an XMLReader to recognize a property name but + * to be unable to return its state.

      *

      - * XMLReaders are not required to recognize any specific property names, though an initial core set is documented - * for SAX2. - *

      + * XMLReaders are not required to recognize any specific + * property names, though an initial core set is documented for + * SAX2.

      *

      - * Some property values may be available only in specific contexts, such as before, during, or after a parse. - *

      + * Some property values may be available only in specific + * contexts, such as before, during, or after a parse.

      *

      - * Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs. - *

      - * + * Implementors are free (and encouraged) to invent their own properties, + * using names built on their own URIs.

      + * * @param name the property name, which is a fully-qualified URI. * @return the current value of the property. - * @throws SAXNotRecognizedException when the XMLReader does not recognize the property name. + * @throws SAXNotRecognizedException when the XMLReader does not + * recognize the property name. * @see #getProperty */ - @Override - public Object getProperty(final String name) throws SAXNotRecognizedException { - if (name.equals(CONFIGURED_XSTREAM_PROPERTY) || name.equals(SOURCE_OBJECT_LIST_PROPERTY)) { - return properties.get(name); + public Object getProperty(String name) + throws SAXNotRecognizedException { + if ((name.equals(CONFIGURED_XSTREAM_PROPERTY)) || + (name.equals(SOURCE_OBJECT_LIST_PROPERTY))) { + return this.properties.get(name); } else { throw new SAXNotRecognizedException(name); } } - // --------------------------------------------------------------------- + //--------------------------------------------------------------------- // Event handlers - // --------------------------------------------------------------------- + //--------------------------------------------------------------------- /** * Allows an application to register an entity resolver. *

      - * If the application does not register an entity resolver, the XMLReader will perform its own default resolution. - *

      + * If the application does not register an entity resolver, + * the XMLReader will perform its own default resolution.

      *

      - * Applications may register a new or different resolver in the middle of a parse, and the SAX parser must begin - * using the new resolver immediately. - *

      - * + * Applications may register a new or different resolver in the + * middle of a parse, and the SAX parser must begin using the new + * resolver immediately.

      + * * @param resolver the entity resolver. - * @throws NullPointerException if the resolver argument is null. + * @throws NullPointerException if the resolver argument is + * null. * @see #getEntityResolver */ - @Override - public void setEntityResolver(final EntityResolver resolver) { + public void setEntityResolver(EntityResolver resolver) { if (resolver == null) { throw new NullPointerException("resolver"); } - entityResolver = resolver; + this.entityResolver = resolver; return; } /** * Returns the current entity resolver. - * - * @return the current entity resolver, or null if none has been registered. + * + * @return the current entity resolver, or null if none + * has been registered. * @see #setEntityResolver */ - @Override public EntityResolver getEntityResolver() { - return entityResolver; + return this.entityResolver; } /** * Allows an application to register a DTD event handler. *

      - * If the application does not register a DTD handler, all DTD events reported by the SAX parser will be silently - * ignored. - *

      + * If the application does not register a DTD handler, all DTD + * events reported by the SAX parser will be silently ignored.

      *

      - * Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin - * using the new handler immediately. - *

      - * + * Applications may register a new or different handler in the + * middle of a parse, and the SAX parser must begin using the new + * handler immediately.

      + * * @param handler the DTD handler. - * @throws NullPointerException if the handler argument is null. + * @throws NullPointerException if the handler argument is + * null. * @see #getDTDHandler */ - @Override - public void setDTDHandler(final DTDHandler handler) { + public void setDTDHandler(DTDHandler handler) { if (handler == null) { throw new NullPointerException("handler"); } - dtdHandler = handler; + this.dtdHandler = handler; return; } /** * Returns the current DTD handler. - * - * @return the current DTD handler, or null if none has been registered. + * + * @return the current DTD handler, or null if none + * has been registered. * @see #setDTDHandler */ - @Override public DTDHandler getDTDHandler() { - return dtdHandler; + return this.dtdHandler; } /** * Allows an application to register a content event handler. *

      - * If the application does not register a content handler, all content events reported by the SAX parser will be - * silently ignored. - *

      + * If the application does not register a content handler, all + * content events reported by the SAX parser will be silently + * ignored.

      *

      - * Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin - * using the new handler immediately. - *

      - * + * Applications may register a new or different handler in the + * middle of a parse, and the SAX parser must begin using the new + * handler immediately.

      + * * @param handler the content handler. - * @throws NullPointerException if the handler argument is null. + * @throws NullPointerException if the handler argument is + * null. * @see #getContentHandler */ - @Override - public void setContentHandler(final ContentHandler handler) { + public void setContentHandler(ContentHandler handler) { if (handler == null) { throw new NullPointerException("handler"); } - contentHandler = handler; + this.contentHandler = handler; return; } /** * Returns the current content handler. - * - * @return the current content handler, or null if none has been registered. + * + * @return the current content handler, or null if none + * has been registered. * @see #setContentHandler */ - @Override public ContentHandler getContentHandler() { - return contentHandler; + return this.contentHandler; } /** * Allows an application to register an error event handler. *

      - * If the application does not register an error handler, all error events reported by the SAX parser will be - * silently ignored; however, normal processing may not continue. It is highly recommended that all SAX applications - * implement an error handler to avoid unexpected bugs. - *

      + * If the application does not register an error handler, all + * error events reported by the SAX parser will be silently + * ignored; however, normal processing may not continue. It is + * highly recommended that all SAX applications implement an + * error handler to avoid unexpected bugs.

      *

      - * Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin - * using the new handler immediately. - *

      - * + * Applications may register a new or different handler in the + * middle of a parse, and the SAX parser must begin using the new + * handler immediately.

      + * * @param handler the error handler. - * @throws NullPointerException if the handler argument is null. + * @throws NullPointerException if the handler argument is + * null. * @see #getErrorHandler */ - @Override - public void setErrorHandler(final ErrorHandler handler) { + public void setErrorHandler(ErrorHandler handler) { if (handler == null) { throw new NullPointerException("handler"); } - errorHandler = handler; + this.errorHandler = handler; return; } /** * Returns the current error handler. - * - * @return the current error handler, or null if none has been registered. + * + * @return the current error handler, or null if none + * has been registered. * @see #setErrorHandler */ - @Override public ErrorHandler getErrorHandler() { - return errorHandler; + return this.errorHandler; } - // --------------------------------------------------------------------- + //--------------------------------------------------------------------- // Parsing - // --------------------------------------------------------------------- + //--------------------------------------------------------------------- /** * Parses an XML document from a system identifier (URI). *

      - * This method is a shortcut for the common case of reading a document from a system identifier. It is the exact - * equivalent of the following: - *

      + * This method is a shortcut for the common case of reading a + * document from a system identifier. It is the exact + * equivalent of the following:

      *
      - * *
      -     * parse(new InputSource(systemId));
      -     * 
      - * + * parse(new InputSource(systemId)); + * *
      *

      - * If the system identifier is a URL, it must be fully resolved by the application before it is passed to the - * parser. - *

      + * If the system identifier is a URL, it must be fully resolved + * by the application before it is passed to the parser.

      *

      - * Note: As a custom SAX parser, this class ignores the systemId argument of this - * method and relies on the proprietary SAX property {@link #SOURCE_OBJECT_LIST_PROPERTY}) to define the list of - * objects to serialize. - *

      - * + * Note: As a custom SAX parser, this class + * ignores the systemId argument of this method + * and relies on the proprietary SAX property + * {@link #SOURCE_OBJECT_LIST_PROPERTY}) to define the list of + * objects to serialize.

      + * * @param systemId the system identifier (URI). - * @throws SAXException Any SAX exception, possibly wrapping another exception. + * @throws SAXException Any SAX exception, possibly wrapping + * another exception. * @see #parse(org.xml.sax.InputSource) */ - @Override - public void parse(final String systemId) throws SAXException { + public void parse(String systemId) throws SAXException { this.parse(); } /** * Parse an XML document. *

      - * The application can use this method to instruct the XML reader to begin parsing an XML document from any valid - * input source (a character stream, a byte stream, or a URI). - *

      + * The application can use this method to instruct the XML + * reader to begin parsing an XML document from any valid input + * source (a character stream, a byte stream, or a URI).

      *

      - * Applications may not invoke this method while a parse is in progress (they should create a new XMLReader instead - * for each nested XML document). Once a parse is complete, an application may reuse the same XMLReader object, - * possibly with a different input source. - *

      + * Applications may not invoke this method while a parse is in + * progress (they should create a new XMLReader instead for each + * nested XML document). Once a parse is complete, an + * application may reuse the same XMLReader object, possibly + * with a different input source.

      *

      - * During the parse, the XMLReader will provide information about the XML document through the registered event - * handlers. - *

      + * During the parse, the XMLReader will provide information + * about the XML document through the registered event + * handlers.

      *

      - * This method is synchronous: it will not return until parsing has ended. If a client application wants to - * terminate parsing early, it should throw an exception. - *

      + * This method is synchronous: it will not return until parsing + * has ended. If a client application wants to terminate + * parsing early, it should throw an exception.

      *

      - * Note: As a custom SAX parser, this class ignores the source argument of this method - * and relies on the proprietary SAX property {@link #SOURCE_OBJECT_LIST_PROPERTY}) to define the list of objects to - * serialize. - *

      - * - * @param input The input source for the top-level of the XML document. - * @throws SAXException Any SAX exception, possibly wrapping another exception. + * Note: As a custom SAX parser, this class + * ignores the source argument of this method + * and relies on the proprietary SAX property + * {@link #SOURCE_OBJECT_LIST_PROPERTY}) to define the list of + * objects to serialize.

      + * + * @param input The input source for the top-level of the + * XML document. + * @throws SAXException Any SAX exception, possibly wrapping + * another exception. * @see org.xml.sax.InputSource * @see #parse(java.lang.String) * @see #setEntityResolver * @see #setDTDHandler * @see #setContentHandler * @see #setErrorHandler */ - @Override - public void parse(final InputSource input) throws SAXException { + public void parse(InputSource input) throws SAXException { this.parse(); } /** - * Serializes the Java objects of the configured list into a flow of SAX events. - * - * @throws SAXException if the configured object list is invalid or object serialization failed. + * Serializes the Java objects of the configured list into a flow + * of SAX events. + * + * @throws SAXException if the configured object list is invalid + * or object serialization failed. */ private void parse() throws SAXException { - XStream xstream = (XStream)properties.get(CONFIGURED_XSTREAM_PROPERTY); + XStream xstream = (XStream) (this.properties.get(CONFIGURED_XSTREAM_PROPERTY)); if (xstream == null) { xstream = new XStream(); } - final List source = (List)properties.get(SOURCE_OBJECT_LIST_PROPERTY); - if (source == null || source.isEmpty()) { - throw new SAXException("Missing or empty source object list. Setting property \"" - + SOURCE_OBJECT_LIST_PROPERTY - + "\" is mandatory"); + List source = (List) (this.properties.get(SOURCE_OBJECT_LIST_PROPERTY)); + if ((source == null) || (source.isEmpty())) { + throw new SAXException("Missing or empty source object list. Setting property \"" + + SOURCE_OBJECT_LIST_PROPERTY + "\" is mandatory"); } try { - startDocument(true); - for (final Object name : source) { - xstream.marshal(name, this); + this.startDocument(true); + for (Iterator i = source.iterator(); i.hasNext();) { + xstream.marshal(i.next(), this); } - endDocument(true); - } catch (final StreamException e) { + this.endDocument(true); + } catch (StreamException e) { if (e.getCause() instanceof SAXException) { - throw (SAXException)e.getCause(); + throw (SAXException) (e.getCause()); } else { throw new SAXException(e); } } } - // ========================================================================= + + //========================================================================= // XStream HierarchicalStreamWriter interface support - // ========================================================================= + //========================================================================= private int depth = 0; - private final List elementStack = new LinkedList(); + private List elementStack = new LinkedList(); private char[] buffer = new char[128]; private boolean startTagInProgress = false; private final AttributesImpl attributeList = new AttributesImpl(); - @Override - public void startNode(final String name) { + public void startNode(String name) { try { - if (depth != 0) { - flushStartTag(); + if (this.depth != 0) { + this.flushStartTag(); } else if (includeEnclosingDocument) { - startDocument(false); + this.startDocument(false); } - elementStack.add(0, escapeXmlName(name)); + this.elementStack.add(0, escapeXmlName(name)); - startTagInProgress = true; - depth++; - } catch (final SAXException e) { + this.startTagInProgress = true; + this.depth++; + } catch (SAXException e) { throw new StreamException(e); } } - @Override - public void addAttribute(final String name, final String value) { - if (startTagInProgress) { - final String escapedName = escapeXmlName(name); - attributeList.addAttribute("", escapedName, escapedName, "CDATA", value); + public void addAttribute(String name, String value) { + if (this.startTagInProgress) { + String escapedName = escapeXmlName(name); + this.attributeList.addAttribute("", escapedName, escapedName, "CDATA", value); } else { throw new StreamException(new IllegalStateException("No startElement being processed")); } } - @Override - public void setValue(final String text) { + public void setValue(String text) { try { - flushStartTag(); + this.flushStartTag(); - final int lg = text.length(); + int lg = text.length(); if (lg > buffer.length) { buffer = new char[lg]; } text.getChars(0, lg, buffer, 0); - contentHandler.characters(buffer, 0, lg); - } catch (final SAXException e) { + this.contentHandler.characters(buffer, 0, lg); + } catch (SAXException e) { throw new StreamException(e); } } - @Override public void endNode() { try { - flushStartTag(); + this.flushStartTag(); - final String tagName = elementStack.remove(0); + String tagName = (String) (this.elementStack.remove(0)); - contentHandler.endElement("", tagName, tagName); + this.contentHandler.endElement("", tagName, tagName); - depth--; - if (depth == 0 && includeEnclosingDocument) { - endDocument(false); + this.depth--; + if (this.depth == 0 && includeEnclosingDocument) { + this.endDocument(false); } - } catch (final SAXException e) { + } catch (SAXException e) { throw new StreamException(e); } } /** - * Fires the SAX startDocument event towards the configured ContentHandler. - * - * @param multiObjectMode whether serialization of several object will be merge into a single SAX document. + * Fires the SAX startDocument event towards the configured + * ContentHandler. + * + * @param multiObjectMode whether serialization of several + * object will be merge into a single + * SAX document. * @throws SAXException if thrown by the ContentHandler. */ - private void startDocument(final boolean multiObjectMode) throws SAXException { - if (depth == 0) { + private void startDocument(boolean multiObjectMode) throws SAXException { + if (this.depth == 0) { // Notify contentHandler of document start. - contentHandler.startDocument(); + this.contentHandler.startDocument(); if (multiObjectMode) { // Prevent marshalling of each object to fire its own // start/endDocument events. - depth++; + this.depth++; } } } /** - * Fires the SAX endDocument event towards the configured ContentHandler. - * - * @param multiObjectMode whether serialization of several object will be merge into a single SAX document. + * Fires the SAX endDocument event towards the configured + * ContentHandler. + * + * @param multiObjectMode whether serialization of several + * object will be merge into a single + * SAX document. * @throws SAXException if thrown by the ContentHandler. */ - private void endDocument(final boolean multiObjectMode) throws SAXException { - if (depth == 0 || depth == 1 && multiObjectMode) { - contentHandler.endDocument(); - depth = 0; + private void endDocument(boolean multiObjectMode) throws SAXException { + if ((this.depth == 0) || ((this.depth == 1) && (multiObjectMode))) { + this.contentHandler.endDocument(); + this.depth = 0; } } /** - * Fires any pending SAX startElement event towards the configured ContentHandler. - * + * Fires any pending SAX startElement event towards the + * configured ContentHandler. + * * @throws SAXException if thrown by the ContentHandler. */ private void flushStartTag() throws SAXException { - if (startTagInProgress) { - final String tagName = elementStack.get(0); + if (this.startTagInProgress) { + String tagName = (String) (this.elementStack.get(0)); - contentHandler.startElement("", tagName, tagName, attributeList); - attributeList.clear(); - startTagInProgress = false; + this.contentHandler.startElement("", tagName, + tagName, this.attributeList); + this.attributeList.clear(); + this.startTagInProgress = false; } } - @Override public void flush() { // don't need to do anything } - @Override public void close() { // don't need to do anything } } + Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/SjsxpDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/SjsxpDriver.java (.../SjsxpDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/SjsxpDriver.java (.../SjsxpDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2009, 2011, 2013, 2014, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,68 +10,62 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.io.StreamException; + import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLOutputFactory; -import com.thoughtworks.xstream.io.StreamException; - - /** * A driver using the JDK 6 StAX implementation of Sun. * * @author Jörg Schaible * @since 1.4 * @deprecated As of 1.4.5 use {@link StandardStaxDriver} */ -@Deprecated public class SjsxpDriver extends StaxDriver { /** * @deprecated As of 1.4.5 use {@link StandardStaxDriver#StandardStaxDriver()} */ - @Deprecated public SjsxpDriver() { super(); } /** * @deprecated As of 1.4.5 use {@link StandardStaxDriver#StandardStaxDriver(QNameMap, XmlFriendlyNameCoder)} */ - @Deprecated - public SjsxpDriver(final QNameMap qnameMap, final XmlFriendlyNameCoder nameCoder) { + public SjsxpDriver(QNameMap qnameMap, XmlFriendlyNameCoder nameCoder) { super(qnameMap, nameCoder); } /** * @deprecated As of 1.4.5 use {@link StandardStaxDriver#StandardStaxDriver(QNameMap)} */ - @Deprecated - public SjsxpDriver(final QNameMap qnameMap) { + public SjsxpDriver(QNameMap qnameMap) { super(qnameMap); } /** * @deprecated As of 1.4.5 use {@link StandardStaxDriver#StandardStaxDriver(XmlFriendlyNameCoder)} */ - @Deprecated - public SjsxpDriver(final XmlFriendlyNameCoder nameCoder) { + public SjsxpDriver(XmlFriendlyNameCoder nameCoder) { super(nameCoder); } /** * @deprecated As of 1.4.5 use {@link StandardStaxDriver#createInputFactory()} */ - @Deprecated - @Override protected XMLInputFactory createInputFactory() { Exception exception = null; try { - return (XMLInputFactory)Class.forName("com.sun.xml.internal.stream.XMLInputFactoryImpl").newInstance(); + final XMLInputFactory instance = (XMLInputFactory)Class.forName("com.sun.xml.internal.stream.XMLInputFactoryImpl").newInstance(); + instance.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); + return instance; } catch (final InstantiationException e) { exception = e; - } catch (final IllegalAccessException e) { + } catch (IllegalAccessException e) { exception = e; - } catch (final ClassNotFoundException e) { + } catch (ClassNotFoundException e) { exception = e; } throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLInputFaqctory instance.", exception); @@ -80,17 +74,15 @@ /** * @deprecated As of 1.4.5 use {@link StandardStaxDriver#createOutputFactory()} */ - @Deprecated - @Override protected XMLOutputFactory createOutputFactory() { Exception exception = null; try { return (XMLOutputFactory)Class.forName("com.sun.xml.internal.stream.XMLOutputFactoryImpl").newInstance(); - } catch (final InstantiationException e) { + } catch (InstantiationException e) { exception = e; - } catch (final IllegalAccessException e) { + } catch (IllegalAccessException e) { exception = e; - } catch (final ClassNotFoundException e) { + } catch (ClassNotFoundException e) { exception = e; } throw new StreamException("Cannot create SJSXP (Sun JDK 6 StAX) XMLOutputFaqctory instance.", exception); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StandardStaxDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StandardStaxDriver.java (.../StandardStaxDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StandardStaxDriver.java (.../StandardStaxDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,32 +1,34 @@ /* - * Copyright (C) 2013, 2014 XStream Committers. + * Copyright (C) 2013, 2014, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 27. July 2013 by Joerg Schaible */ package com.thoughtworks.xstream.io.xml; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; - import com.thoughtworks.xstream.core.JVM; import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.naming.NameCoder; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + /** - * A driver using the standard JDK StAX implementation provided by the Java runtime. + * A driver using the standard JDK StAX implementation provided by the Java runtime (since Java + * 6). *

      - * In contrast to XMLInputFactory.newFactory() or XMLOutputFactory.newFactory() this implementation will ignore any - * implementations provided with the system properties javax.xml.stream.XMLInputFactory and - * javax.xml.stream.XMLOutputFactory, all implementations configured in lib/stax.properties or - * registered with the Service API. + * In contrast to XMLInputFactory.newFactory() or XMLOutputFactory.newFactory() this + * implementation will ignore any implementations provided with the system properties + * javax.xml.stream.XMLInputFactory and javax.xml.stream.XMLOutputFactory, all + * implementations configured in lib/stax.properties or registered with the Service + * API. *

      - * + * * @author Jörg Schaible * @since 1.4.5 */ @@ -39,72 +41,70 @@ /** * @deprecated As of 1.4.6 use {@link #StandardStaxDriver(QNameMap, NameCoder)} */ - @Deprecated - public StandardStaxDriver(final QNameMap qnameMap, final XmlFriendlyNameCoder nameCoder) { + public StandardStaxDriver(QNameMap qnameMap, XmlFriendlyNameCoder nameCoder) { super(qnameMap, nameCoder); } /** * @since 1.4.6 */ - public StandardStaxDriver(final QNameMap qnameMap, final NameCoder nameCoder) { + public StandardStaxDriver(QNameMap qnameMap, NameCoder nameCoder) { super(qnameMap, nameCoder); } - public StandardStaxDriver(final QNameMap qnameMap) { + public StandardStaxDriver(QNameMap qnameMap) { super(qnameMap); } /** * @deprecated As of 1.4.6 use {@link #StandardStaxDriver(NameCoder)} */ - @Deprecated - public StandardStaxDriver(final XmlFriendlyNameCoder nameCoder) { + public StandardStaxDriver(XmlFriendlyNameCoder nameCoder) { super(nameCoder); } /** * @since 1.4.6 */ - public StandardStaxDriver(final NameCoder nameCoder) { + public StandardStaxDriver(NameCoder nameCoder) { super(nameCoder); } - @Override protected XMLInputFactory createInputFactory() { Exception exception = null; try { - final Class staxInputFactory = JVM.getStaxInputFactory(); + Class staxInputFactory = JVM.getStaxInputFactory(); if (staxInputFactory != null) { - return staxInputFactory.newInstance(); + final XMLInputFactory instance = (XMLInputFactory)staxInputFactory.newInstance(); + instance.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); + return instance; } else { throw new StreamException("Java runtime has no standard XMLInputFactory implementation.", exception); } - } catch (final InstantiationException e) { + } catch (InstantiationException e) { exception = e; - } catch (final IllegalAccessException e) { + } catch (IllegalAccessException e) { exception = e; - } catch (final ClassNotFoundException e) { + } catch (ClassNotFoundException e) { exception = e; } throw new StreamException("Cannot create standard XMLInputFactory instance of Java runtime.", exception); } - @Override protected XMLOutputFactory createOutputFactory() { Exception exception = null; try { - final Class staxOutputFactory = JVM.getStaxOutputFactory(); + Class staxOutputFactory = JVM.getStaxOutputFactory(); if (staxOutputFactory != null) { - return staxOutputFactory.newInstance(); + return (XMLOutputFactory)staxOutputFactory.newInstance(); } else { throw new StreamException("Java runtime has no standard XMLOutputFactory implementation.", exception); } - } catch (final InstantiationException e) { + } catch (InstantiationException e) { exception = e; - } catch (final IllegalAccessException e) { + } catch (IllegalAccessException e) { exception = e; - } catch (final ClassNotFoundException e) { + } catch (ClassNotFoundException e) { exception = e; } throw new StreamException("Cannot create standard XMLOutputFactory instance of Java runtime.", exception); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StaxDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StaxDriver.java (.../StaxDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StaxDriver.java (.../StaxDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011, 2013, 2014, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -35,10 +35,9 @@ import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.naming.NameCoder; - /** * A driver using the StAX API to create XML reader and writer. - * + * * @author James Strachan * @author Jörg Schaible * @version $Revision$ @@ -53,154 +52,143 @@ this(new QNameMap()); } - public StaxDriver(final QNameMap qnameMap) { + public StaxDriver(QNameMap qnameMap) { this(qnameMap, new XmlFriendlyNameCoder()); } /** * @since 1.4 */ - public StaxDriver(final QNameMap qnameMap, final NameCoder nameCoder) { + public StaxDriver(QNameMap qnameMap, NameCoder nameCoder) { super(nameCoder); this.qnameMap = qnameMap; } - + /** * @since 1.4 */ - public StaxDriver(final NameCoder nameCoder) { + public StaxDriver(NameCoder nameCoder) { this(new QNameMap(), nameCoder); } /** * @since 1.2 * @deprecated As of 1.4, use {@link StaxDriver#StaxDriver(QNameMap, NameCoder)} instead. */ - @Deprecated - public StaxDriver(final QNameMap qnameMap, final XmlFriendlyReplacer replacer) { + public StaxDriver(QNameMap qnameMap, XmlFriendlyReplacer replacer) { this(qnameMap, (NameCoder)replacer); } - + /** * @since 1.2 * @deprecated As of 1.4, use {@link StaxDriver#StaxDriver(NameCoder)} instead. */ - @Deprecated - public StaxDriver(final XmlFriendlyReplacer replacer) { + public StaxDriver(XmlFriendlyReplacer replacer) { this(new QNameMap(), (NameCoder)replacer); } - @Override - public HierarchicalStreamReader createReader(final Reader xml) { + public HierarchicalStreamReader createReader(Reader xml) { try { return createStaxReader(createParser(xml)); - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final InputStream in) { + public HierarchicalStreamReader createReader(InputStream in) { try { return createStaxReader(createParser(in)); - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); } } - @SuppressWarnings("resource") - @Override - public HierarchicalStreamReader createReader(final URL in) { + public HierarchicalStreamReader createReader(URL in) { final InputStream stream; try { stream = in.openStream(); - final HierarchicalStreamReader reader = createStaxReader(createParser(new StreamSource(stream, in - .toExternalForm()))); + HierarchicalStreamReader reader = createStaxReader(createParser(new StreamSource( + stream, in.toExternalForm()))); return new ReaderWrapper(reader) { - @Override public void close() { super.close(); try { stream.close(); - } catch (final IOException e) { + } catch (IOException e) { // ignore } } }; - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @SuppressWarnings("resource") - @Override - public HierarchicalStreamReader createReader(final File in) { + public HierarchicalStreamReader createReader(File in) { final InputStream stream; try { stream = new FileInputStream(in); - final HierarchicalStreamReader reader = createStaxReader(createParser(new StreamSource(stream, in - .toURI() - .toASCIIString()))); + HierarchicalStreamReader reader = createStaxReader(createParser(new StreamSource( + stream, in.toURI().toASCIIString()))); return new ReaderWrapper(reader) { - @Override public void close() { super.close(); try { stream.close(); - } catch (final IOException e) { + } catch (IOException e) { // ignore } } }; - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); - } catch (final FileNotFoundException e) { + } catch (FileNotFoundException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamWriter createWriter(final Writer out) { + public HierarchicalStreamWriter createWriter(Writer out) { try { return createStaxWriter(getOutputFactory().createXMLStreamWriter(out)); - } catch (final XMLStreamException e) { + } + catch (XMLStreamException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamWriter createWriter(final OutputStream out) { + public HierarchicalStreamWriter createWriter(OutputStream out) { try { return createStaxWriter(getOutputFactory().createXMLStreamWriter(out)); - } catch (final XMLStreamException e) { + } + catch (XMLStreamException e) { throw new StreamException(e); } } - public AbstractPullReader createStaxReader(final XMLStreamReader in) { + public AbstractPullReader createStaxReader(XMLStreamReader in) { return new StaxReader(qnameMap, in, getNameCoder()); } - public StaxWriter createStaxWriter(final XMLStreamWriter out, final boolean writeStartEndDocument) - throws XMLStreamException { + public StaxWriter createStaxWriter(XMLStreamWriter out, boolean writeStartEndDocument) throws XMLStreamException { return new StaxWriter(qnameMap, out, writeStartEndDocument, isRepairingNamespace(), getNameCoder()); } - public StaxWriter createStaxWriter(final XMLStreamWriter out) throws XMLStreamException { + public StaxWriter createStaxWriter(XMLStreamWriter out) throws XMLStreamException { return createStaxWriter(out, true); } + // Properties - // ------------------------------------------------------------------------- + //------------------------------------------------------------------------- public QNameMap getQnameMap() { return qnameMap; } - public void setQnameMap(final QNameMap qnameMap) { + public void setQnameMap(QNameMap qnameMap) { this.qnameMap = qnameMap; } @@ -219,36 +207,40 @@ } public boolean isRepairingNamespace() { - return Boolean.TRUE.equals(getOutputFactory().getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES)); + return Boolean.TRUE.equals(getOutputFactory().getProperty( + XMLOutputFactory.IS_REPAIRING_NAMESPACES)); } /** * @since 1.2 */ - public void setRepairingNamespace(final boolean repairing) { + public void setRepairingNamespace(boolean repairing) { getOutputFactory().setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, - repairing ? Boolean.TRUE : Boolean.FALSE); + repairing ? Boolean.TRUE : Boolean.FALSE); } + // Implementation methods - // ------------------------------------------------------------------------- - protected XMLStreamReader createParser(final Reader xml) throws XMLStreamException { + //------------------------------------------------------------------------- + protected XMLStreamReader createParser(Reader xml) throws XMLStreamException { return getInputFactory().createXMLStreamReader(xml); } - protected XMLStreamReader createParser(final InputStream xml) throws XMLStreamException { + protected XMLStreamReader createParser(InputStream xml) throws XMLStreamException { return getInputFactory().createXMLStreamReader(xml); } - protected XMLStreamReader createParser(final Source source) throws XMLStreamException { + protected XMLStreamReader createParser(Source source) throws XMLStreamException { return getInputFactory().createXMLStreamReader(source); } /** * @since 1.4 */ protected XMLInputFactory createInputFactory() { - return XMLInputFactory.newInstance(); + final XMLInputFactory instance = XMLInputFactory.newInstance(); + instance.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); + return instance; } /** Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StaxReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StaxReader.java (.../StaxReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StaxReader.java (.../StaxReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,19 +11,18 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.converters.ErrorWriter; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.io.naming.NameCoder; + import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; -import com.thoughtworks.xstream.converters.ErrorWriter; -import com.thoughtworks.xstream.io.StreamException; -import com.thoughtworks.xstream.io.naming.NameCoder; - - /** * A reader using the StAX API. - * + * * @author James Strachan * @version $Revision$ */ @@ -32,14 +31,14 @@ private final QNameMap qnameMap; private final XMLStreamReader in; - public StaxReader(final QNameMap qnameMap, final XMLStreamReader in) { + public StaxReader(QNameMap qnameMap, XMLStreamReader in) { this(qnameMap, in, new XmlFriendlyNameCoder()); } /** * @since 1.4 */ - public StaxReader(final QNameMap qnameMap, final XMLStreamReader in, final NameCoder replacer) { + public StaxReader(QNameMap qnameMap, XMLStreamReader in, NameCoder replacer) { super(replacer); this.qnameMap = qnameMap; this.in = in; @@ -50,77 +49,67 @@ * @since 1.2 * @deprecated As of 1.4 use {@link StaxReader#StaxReader(QNameMap, XMLStreamReader, NameCoder)} instead. */ - @Deprecated - public StaxReader(final QNameMap qnameMap, final XMLStreamReader in, final XmlFriendlyReplacer replacer) { + public StaxReader(QNameMap qnameMap, XMLStreamReader in, XmlFriendlyReplacer replacer) { this(qnameMap, in, (NameCoder)replacer); } - - @Override + protected int pullNextEvent() { try { - switch (in.next()) { - case XMLStreamConstants.START_DOCUMENT: - case XMLStreamConstants.START_ELEMENT: - return START_NODE; - case XMLStreamConstants.END_DOCUMENT: - case XMLStreamConstants.END_ELEMENT: - return END_NODE; - case XMLStreamConstants.CHARACTERS: - return TEXT; - case XMLStreamConstants.COMMENT: - return COMMENT; - default: - return OTHER; + switch(in.next()) { + case XMLStreamConstants.START_DOCUMENT: + case XMLStreamConstants.START_ELEMENT: + return START_NODE; + case XMLStreamConstants.END_DOCUMENT: + case XMLStreamConstants.END_ELEMENT: + return END_NODE; + case XMLStreamConstants.CHARACTERS: + return TEXT; + case XMLStreamConstants.COMMENT: + return COMMENT; + default: + return OTHER; } - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); } } - @Override protected String pullElementName() { // let the QNameMap handle any mapping of QNames to Java class names - final QName qname = in.getName(); + QName qname = in.getName(); return qnameMap.getJavaClassName(qname); } - @Override protected String pullText() { return in.getText(); } - @Override - public String getAttribute(final String name) { + public String getAttribute(String name) { return in.getAttributeValue(null, encodeAttribute(name)); } - @Override - public String getAttribute(final int index) { + public String getAttribute(int index) { return in.getAttributeValue(index); } - @Override public int getAttributeCount() { return in.getAttributeCount(); } - @Override - public String getAttributeName(final int index) { + public String getAttributeName(int index) { return decodeAttribute(in.getAttributeLocalName(index)); } - @Override - public void appendErrors(final ErrorWriter errorWriter) { + public void appendErrors(ErrorWriter errorWriter) { errorWriter.add("line number", String.valueOf(in.getLocation().getLineNumber())); } - @Override public void close() { try { in.close(); - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); } } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StaxWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StaxWriter.java (.../StaxWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/StaxWriter.java (.../StaxWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,14 +11,14 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.io.naming.NameCoder; + import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import com.thoughtworks.xstream.io.StreamException; -import com.thoughtworks.xstream.io.naming.NameCoder; - /** * A stream writing that outputs to a StAX stream writer * @@ -30,11 +30,11 @@ private final QNameMap qnameMap; private final XMLStreamWriter out; private final boolean writeEnclosingDocument; - private final boolean namespaceRepairingMode; + private boolean namespaceRepairingMode; private int tagDepth; - public StaxWriter(final QNameMap qnameMap, final XMLStreamWriter out) throws XMLStreamException { + public StaxWriter(QNameMap qnameMap, XMLStreamWriter out) throws XMLStreamException { this(qnameMap, out, true, true); } @@ -47,8 +47,8 @@ * @throws XMLStreamException if the events could not be written to the output * @since 1.4 */ - public StaxWriter(final QNameMap qnameMap, final XMLStreamWriter out, final NameCoder nameCoder) - throws XMLStreamException { + public StaxWriter(QNameMap qnameMap, XMLStreamWriter out, NameCoder nameCoder) + throws XMLStreamException { this(qnameMap, out, true, true, nameCoder); } @@ -57,15 +57,16 @@ * * @param qnameMap is the mapper of Java class names to QNames * @param out the stream to output to - * @param writeEnclosingDocument a flag to indicate whether or not the start/end document events should be written + * @param writeEnclosingDocument a flag to indicate whether or not the start/end document + * events should be written * @param namespaceRepairingMode a flag to enable StAX' namespace repairing mode * @param nameCoder the xml-friendly replacer to escape Java names * @throws XMLStreamException if the events could not be written to the output * @since 1.4 */ public StaxWriter( - final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument, - final boolean namespaceRepairingMode, final NameCoder nameCoder) throws XMLStreamException { + QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument, + boolean namespaceRepairingMode, NameCoder nameCoder) throws XMLStreamException { super(nameCoder); this.qnameMap = qnameMap; this.out = out; @@ -81,108 +82,106 @@ * * @param qnameMap is the mapper of Java class names to QNames * @param out the stream to output to - * @param writeEnclosingDocument a flag to indicate whether or not the start/end document events should be written + * @param writeEnclosingDocument a flag to indicate whether or not the start/end document + * events should be written * @throws XMLStreamException if the events could not be written to the output */ public StaxWriter( - final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument, - final boolean namespaceRepairingMode) throws XMLStreamException { - this(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, new XmlFriendlyNameCoder()); + QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument, + boolean namespaceRepairingMode) throws XMLStreamException { + this( + qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, + new XmlFriendlyNameCoder()); } /** * Allows a StaxWriter to be created for partial XML output * * @param qnameMap is the mapper of Java class names to QNames * @param out the stream to output to - * @param writeEnclosingDocument a flag to indicate whether or not the start/end document events should be written + * @param writeEnclosingDocument a flag to indicate whether or not the start/end document + * events should be written * @param replacer the xml-friendly replacer to escape Java names * @throws XMLStreamException if the events could not be written to the output * @since 1.2 - * @deprecated As of 1.4 use {@link StaxWriter#StaxWriter(QNameMap, XMLStreamWriter, boolean, boolean, NameCoder)} + * @deprecated As of 1.4 use + * {@link StaxWriter#StaxWriter(QNameMap, XMLStreamWriter, boolean, boolean, NameCoder)} * instead */ - @Deprecated public StaxWriter( - final QNameMap qnameMap, final XMLStreamWriter out, final boolean writeEnclosingDocument, - final boolean namespaceRepairingMode, final XmlFriendlyReplacer replacer) throws XMLStreamException { + QNameMap qnameMap, XMLStreamWriter out, boolean writeEnclosingDocument, + boolean namespaceRepairingMode, XmlFriendlyReplacer replacer) throws XMLStreamException { this(qnameMap, out, writeEnclosingDocument, namespaceRepairingMode, (NameCoder)replacer); } - @Override public void flush() { try { out.flush(); - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); } } /** * Call this method when you're finished with me */ - @Override public void close() { try { out.close(); - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); } } - @Override - public void addAttribute(final String name, final String value) { + public void addAttribute(String name, String value) { try { out.writeAttribute(encodeAttribute(name), value); - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); } } - @Override public void endNode() { try { - tagDepth--; + tagDepth-- ; out.writeEndElement(); if (tagDepth == 0 && writeEnclosingDocument) { out.writeEndDocument(); } - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); } } - @Override - public void setValue(final String text) { + public void setValue(String text) { try { out.writeCharacters(text); - } catch (final XMLStreamException e) { + } catch (XMLStreamException e) { throw new StreamException(e); } } - @Override - public void startNode(final String name) { + public void startNode(String name) { try { - final QName qname = qnameMap.getQName(encodeNode(name)); - final String prefix = qname.getPrefix(); - final String uri = qname.getNamespaceURI(); + QName qname = qnameMap.getQName(encodeNode(name)); + String prefix = qname.getPrefix(); + String uri = qname.getNamespaceURI(); // before you ask - yes it really is this complicated to output QNames to StAX // handling both repair namespace modes :) - final boolean hasPrefix = prefix != null && prefix.length() > 0; - final boolean hasURI = uri != null && uri.length() > 0; + boolean hasPrefix = prefix != null && prefix.length() > 0; + boolean hasURI = uri != null && uri.length() > 0; boolean writeNamespace = false; if (hasURI) { if (hasPrefix) { - final String currentNamespace = out.getNamespaceContext().getNamespaceURI(prefix); + String currentNamespace = out.getNamespaceContext().getNamespaceURI(prefix); if (currentNamespace == null || !currentNamespace.equals(uri)) { writeNamespace = true; } } else { - final String defaultNamespace = out.getNamespaceContext().getNamespaceURI(""); + String defaultNamespace = out.getNamespaceContext().getNamespaceURI(""); if (defaultNamespace == null || !defaultNamespace.equals(uri)) { writeNamespace = true; } @@ -204,8 +203,8 @@ out.writeDefaultNamespace(uri); } } - tagDepth++; - } catch (final XMLStreamException e) { + tagDepth++ ; + } catch (XMLStreamException e) { throw new StreamException(e); } } @@ -218,11 +217,11 @@ } protected QNameMap getQNameMap() { - return qnameMap; + return this.qnameMap; } protected XMLStreamWriter getXMLStreamWriter() { - return out; + return this.out; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/TraxSource.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/TraxSource.java (.../TraxSource.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/TraxSource.java (.../TraxSource.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,29 +11,29 @@ */ package com.thoughtworks.xstream.io.xml; -import java.util.ArrayList; -import java.util.List; +import com.thoughtworks.xstream.XStream; -import javax.xml.transform.sax.SAXSource; - import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLFilter; import org.xml.sax.XMLReader; -import com.thoughtworks.xstream.XStream; +import javax.xml.transform.sax.SAXSource; +import java.util.ArrayList; +import java.util.List; + /** - * A {@link SAXSource JAXP TrAX Source} that enables using XStream object serialization as direct input for XSLT - * processors without resorting to an intermediate representation such as text XML, DOM or DOM4J. + * A {@link SAXSource JAXP TrAX Source} that enables using XStream object serialization as + * direct input for XSLT processors without resorting to an intermediate representation such as + * text XML, DOM or DOM4J. *

      - * The following example shows how to apply an XSL Transformation to a set of Java objects gathered into a List ( - * source): + * The following example shows how to apply an XSL Transformation + * to a set of Java objects gathered into a List (source): *

      * - *
      - * 
      + * 
      
        * public static String transform(List source, String stylesheet) {
        *     try {
        *         Transformer transformer = TransformerFactory.newInstance().newTransformer(
      @@ -46,26 +46,26 @@
        *         throw new RuntimeException("XSLT Transformation failed", e);
        *     }
        * }
      - * 
      - * 
      + *
      * * @author Laurent Bihanic */ public class TraxSource extends SAXSource { /** - * If {@link javax.xml.transform.TransformerFactory#getFeature} returns true when passed this value as - * an argument, the Transformer natively supports XStream. + * If {@link javax.xml.transform.TransformerFactory#getFeature} returns true + * when passed this value as an argument, the Transformer natively supports XStream. *

      - * Note: This implementation does not override the {@link SAXSource#FEATURE} value defined by its - * superclass to be considered as a SAXSource by Transformer implementations not natively supporting this - * XStream-specific source + * Note: This implementation does not override the + * {@link SAXSource#FEATURE} value defined by its superclass to be considered as a SAXSource + * by Transformer implementations not natively supporting this XStream-specific source *

      */ public final static String XSTREAM_FEATURE = "http://com.thoughtworks.xstream/XStreamSource/feature"; /** - * The XMLReader object associated to this source or null if no XMLReader has yet been requested. + * The XMLReader object associated to this source or null if no XMLReader has + * yet been requested. * * @see #getXMLReader */ @@ -79,7 +79,7 @@ /** * The list of Java objects to be serialized. */ - private List source = null; + private List source = null; // ------------------------------------------------------------------------- // Constructors @@ -99,56 +99,60 @@ * @throws IllegalArgumentException if source is null. * @see #setSource(java.lang.Object) */ - public TraxSource(final Object source) { + public TraxSource(Object source) { super(new InputSource()); - setSource(source); + this.setSource(source); } /** - * Creates a XStream TrAX source, specifying the object to marshal and a configured (with aliases) XStream facade. + * Creates a XStream TrAX source, specifying the object to marshal and a configured (with + * aliases) XStream facade. * * @param source the object to marshal. * @param xstream a configured XStream facade. - * @throws IllegalArgumentException if source or xstream is null. + * @throws IllegalArgumentException if source or xstream is + * null. * @see #setSource(java.lang.Object) * @see #setXStream(com.thoughtworks.xstream.XStream) */ - public TraxSource(final Object source, final XStream xstream) { + public TraxSource(Object source, XStream xstream) { super(new InputSource()); - setSource(source); - setXStream(xstream); + this.setSource(source); + this.setXStream(xstream); } /** * Creates a XStream TrAX source, setting the objects to marshal. * * @param source the list of objects to marshal. - * @throws IllegalArgumentException if source is null or empty. + * @throws IllegalArgumentException if source is null or + * empty. * @see #setSourceAsList(java.util.List) */ - public TraxSource(final List source) { + public TraxSource(List source) { super(new InputSource()); - setSourceAsList(source); + this.setSourceAsList(source); } /** - * Creates a XStream TrAX source, setting the objects to marshal and a configured (with aliases) XStream facade. + * Creates a XStream TrAX source, setting the objects to marshal and a configured (with + * aliases) XStream facade. * * @param source the list of objects to marshal. * @param xstream a configured XStream facade. - * @throws IllegalArgumentException if source or xstream is null or - * source is empty. + * @throws IllegalArgumentException if source or xstream is + * null or source is empty. * @see #setSourceAsList(java.util.List) * @see #setXStream(com.thoughtworks.xstream.XStream) */ - public TraxSource(final List source, final XStream xstream) { + public TraxSource(List source, XStream xstream) { super(new InputSource()); - setSourceAsList(source); - setXStream(xstream); + this.setSourceAsList(source); + this.setXStream(xstream); } // ------------------------------------------------------------------------- @@ -158,50 +162,50 @@ /** * Sets the SAX InputSource to be used for the Source. *

      - * As this implementation only supports object lists as data source, this method always throws an + * As this implementation only + * supports object lists as data source, this method always throws an * {@link UnsupportedOperationException}. *

      * * @param inputSource a valid InputSource reference. * @throws UnsupportedOperationException always! */ - @Override - public void setInputSource(final InputSource inputSource) { + public void setInputSource(InputSource inputSource) { throw new UnsupportedOperationException(); } /** * Set the XMLReader to be used for the Source. *

      - * As this implementation only supports object lists as data source, this method throws an - * {@link UnsupportedOperationException} if the provided reader object does not implement the SAX {@link XMLFilter} - * interface. Otherwise, a {@link SaxWriter} instance will be attached as parent of the filter chain. + * As this implementation only supports + * object lists as data source, this method throws an {@link UnsupportedOperationException} + * if the provided reader object does not implement the SAX {@link XMLFilter} interface. + * Otherwise, a {@link SaxWriter} instance will be attached as parent of the filter chain. *

      * * @param reader a valid XMLReader or XMLFilter reference. - * @throws UnsupportedOperationException if reader is not a SAX {@link XMLFilter}. + * @throws UnsupportedOperationException if reader is not a SAX + * {@link XMLFilter}. * @see #getXMLReader */ - @Override - public void setXMLReader(final XMLReader reader) { - createXMLReader(reader); + public void setXMLReader(XMLReader reader) { + this.createXMLReader(reader); } /** * Returns the XMLReader to be used for the Source. *

      - * This implementation returns a specific XMLReader ({@link SaxWriter}) generating the XML from a list of input - * objects. + * This implementation returns a + * specific XMLReader ({@link SaxWriter}) generating the XML from a list of input objects. *

      * * @return an XMLReader generating the XML from a list of input objects. */ - @Override public XMLReader getXMLReader() { - if (xmlReader == null) { - createXMLReader(null); + if (this.xmlReader == null) { + this.createXMLReader(null); } - return xmlReader; + return this.xmlReader; } // ------------------------------------------------------------------------- @@ -214,13 +218,13 @@ * @param xstream a configured XStream facade. * @throws IllegalArgumentException if xstream is null. */ - public void setXStream(final XStream xstream) { + public void setXStream(XStream xstream) { if (xstream == null) { throw new IllegalArgumentException("xstream"); } this.xstream = xstream; - configureXMLReader(); + this.configureXMLReader(); } /** @@ -229,71 +233,74 @@ * @param obj the object to marshal. * @throws IllegalArgumentException if source is null. */ - public void setSource(final Object obj) { + public void setSource(Object obj) { if (obj == null) { throw new IllegalArgumentException("obj"); } - final List list = new ArrayList(1); + List list = new ArrayList(1); list.add(obj); - setSourceAsList(list); + this.setSourceAsList(list); } /** * Sets the list of objects to marshal. *

      - * When dealing with non-text input (such as SAX or DOM), XSLT processors support multiple root node children for - * the source tree (see section 3.1 of the "XSL - * Transformations (XSLT) Version 1.0" specification. Using a list of objects as source makes use of this - * feature and allows creating XML documents merging the XML serialization of several Java objects. + * When dealing with non-text input (such as SAX + * or DOM), XSLT processors support multiple root node children for the source tree (see section 3.1 of the "XSL + * Transformations (XSLT) Version 1.0" specification. Using a list of objects as source + * makes use of this feature and allows creating XML documents merging the XML serialization + * of several Java objects. * * @param list the list of objects to marshal. - * @throws IllegalArgumentException if source is null or empty. + * @throws IllegalArgumentException if source is null or + * empty. */ - public void setSourceAsList(final List list) { - if (list == null || list.isEmpty()) { + public void setSourceAsList(List list) { + if ((list == null) || (list.isEmpty())) { throw new IllegalArgumentException("list"); } - source = list; + this.source = list; - configureXMLReader(); + this.configureXMLReader(); } - private void createXMLReader(final XMLReader filterChain) { + private void createXMLReader(XMLReader filterChain) { if (filterChain == null) { - xmlReader = new SaxWriter(); + this.xmlReader = new SaxWriter(); } else { if (filterChain instanceof XMLFilter) { // Connect the filter chain to a document reader. XMLFilter filter = (XMLFilter)filterChain; while (filter.getParent() instanceof XMLFilter) { - filter = (XMLFilter)filter.getParent(); + filter = (XMLFilter)(filter.getParent()); } if (!(filter.getParent() instanceof SaxWriter)) { - @SuppressWarnings("resource") - final SaxWriter saxWriter = new SaxWriter(); - filter.setParent(saxWriter); + filter.setParent(new SaxWriter()); } // Read XML data from filter chain. - xmlReader = filterChain; + this.xmlReader = filterChain; } else { throw new UnsupportedOperationException(); } } - configureXMLReader(); + this.configureXMLReader(); } private void configureXMLReader() { - if (xmlReader != null) { + if (this.xmlReader != null) { try { - if (xstream != null) { - xmlReader.setProperty(SaxWriter.CONFIGURED_XSTREAM_PROPERTY, xstream); + if (this.xstream != null) { + this.xmlReader.setProperty( + SaxWriter.CONFIGURED_XSTREAM_PROPERTY, this.xstream); } - if (source != null) { - xmlReader.setProperty(SaxWriter.SOURCE_OBJECT_LIST_PROPERTY, source); + if (this.source != null) { + this.xmlReader.setProperty( + SaxWriter.SOURCE_OBJECT_LIST_PROPERTY, this.source); } - } catch (final SAXException e) { + } catch (SAXException e) { throw new IllegalArgumentException(e.getMessage()); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/WstxDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/WstxDriver.java (.../WstxDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/WstxDriver.java (.../WstxDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011, 2014, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,13 +10,12 @@ */ package com.thoughtworks.xstream.io.xml; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; - import com.ctc.wstx.stax.WstxInputFactory; import com.ctc.wstx.stax.WstxOutputFactory; import com.thoughtworks.xstream.io.naming.NameCoder; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; /** * A driver using the Woodstox StAX implementation. @@ -33,43 +32,41 @@ /** * @deprecated As of 1.4.6 use {@link #WstxDriver(QNameMap, NameCoder)} */ - @Deprecated - public WstxDriver(final QNameMap qnameMap, final XmlFriendlyNameCoder nameCoder) { + public WstxDriver(QNameMap qnameMap, XmlFriendlyNameCoder nameCoder) { super(qnameMap, nameCoder); } /** * @since 1.4.6 */ - public WstxDriver(final QNameMap qnameMap, final NameCoder nameCoder) { + public WstxDriver(QNameMap qnameMap, NameCoder nameCoder) { super(qnameMap, nameCoder); } - public WstxDriver(final QNameMap qnameMap) { + public WstxDriver(QNameMap qnameMap) { super(qnameMap); } /** * @deprecated As of 1.4.6 use {@link #WstxDriver(NameCoder)} */ - @Deprecated - public WstxDriver(final XmlFriendlyNameCoder nameCoder) { + public WstxDriver(XmlFriendlyNameCoder nameCoder) { super(nameCoder); } /** * @since 1.4.6 */ - public WstxDriver(final NameCoder nameCoder) { + public WstxDriver(NameCoder nameCoder) { super(nameCoder); } - @Override protected XMLInputFactory createInputFactory() { - return new WstxInputFactory(); + final XMLInputFactory instance = new WstxInputFactory(); + instance.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); + return instance; } - @Override protected XMLOutputFactory createOutputFactory() { return new WstxOutputFactory(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XStream11NameCoder.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XStream11NameCoder.java (.../XStream11NameCoder.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XStream11NameCoder.java (.../XStream11NameCoder.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,6 +10,7 @@ */ package com.thoughtworks.xstream.io.xml; + /** * A XmlFriendlyNameCoder to support backward compatibility with XStream 1.1. * @@ -19,18 +20,18 @@ public class XStream11NameCoder extends XmlFriendlyNameCoder { /** - * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1 compatibility. + * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1 + * compatibility. */ - @Override - public String decodeAttribute(final String attributeName) { + public String decodeAttribute(String attributeName) { return attributeName; } /** - * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1 compatibility. + * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1 + * compatibility. */ - @Override - public String decodeNode(final String elementName) { + public String decodeNode(String elementName) { return elementName; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XStream11XmlFriendlyReplacer.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XStream11XmlFriendlyReplacer.java (.../XStream11XmlFriendlyReplacer.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XStream11XmlFriendlyReplacer.java (.../XStream11XmlFriendlyReplacer.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,37 +12,36 @@ package com.thoughtworks.xstream.io.xml; /** - * Allows replacement of Strings in xml-friendly drivers to provide compatibility with XStream 1.1 format + * Allows replacement of Strings in xml-friendly drivers to provide compatibility with XStream + * 1.1 format * * @author Mauro Talevi * @since 1.2 * @deprecated As of 1.4, use {@link XStream11NameCoder} instead */ -@Deprecated public class XStream11XmlFriendlyReplacer extends XmlFriendlyReplacer { /** * Default constructor. * * @deprecated As of 1.4, use {@link XStream11NameCoder} instead */ - @Deprecated public XStream11XmlFriendlyReplacer() { } /** - * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1 compatibility. + * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1 + * compatibility. */ - @Override - public String decodeAttribute(final String attributeName) { + public String decodeAttribute(String attributeName) { return attributeName; } /** - * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1 compatibility. + * {@inheritDoc} Noop implementation that does not decode. Used for XStream 1.1 + * compatibility. */ - @Override - public String decodeNode(final String elementName) { + public String decodeNode(String elementName) { return elementName; } @@ -52,8 +51,7 @@ * @param name the name of attribute or node * @return The String with unescaped name */ - @Override - public String unescapeName(final String name) { + public String unescapeName(String name) { return name; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyNameCoder.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyNameCoder.java (.../XmlFriendlyNameCoder.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyNameCoder.java (.../XmlFriendlyNameCoder.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,28 +11,28 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; +import com.thoughtworks.xstream.io.naming.NameCoder; + import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import com.thoughtworks.xstream.converters.reflection.ObjectAccessException; -import com.thoughtworks.xstream.io.naming.NameCoder; - /** * Encode and decode tag and attribute names in XML drivers. *

      - * This NameCoder is designed to ensure the correct encoding and decoding of names used for Java types and fields to XML - * tags and attribute names. + * This NameCoder is designed to ensure the correct encoding and decoding of names used for Java + * types and fields to XML tags and attribute names. *

      *

      * The default replacements are: *

      *
        *
      • $ (dollar) chars are replaced with _- (underscore dash) string.
      • *
      • _ (underscore) chars are replaced with __ (double underscore) string.
      • - *
      • other characters that are invalid in XML names are encoded with _.XXXX (underscore dot followed by hex - * representation of character).
      • + *
      • other characters that are invalid in XML names are encoded with _.XXXX (underscore + * dot followed by hex representation of character).
      • *
      * * @author Jörg Schaible @@ -41,27 +41,28 @@ * @author Michael Schnell * @see XML 1.0 name definition * @see XML 1.1 name definition - * @see Java identifier definition + * @see Java + * identifier definition * @since 1.4 */ public class XmlFriendlyNameCoder implements NameCoder, Cloneable { private static final IntPair[] XML_NAME_START_CHAR_BOUNDS; private static final IntPair[] XML_NAME_CHAR_EXTRA_BOUNDS; static { - class IntPairList extends ArrayList { - void add(final int min, final int max) { + class IntPairList extends ArrayList { + void add(int min, int max) { super.add(new IntPair(min, max)); } - void add(final char cp) { + void add(char cp) { super.add(new IntPair(cp, cp)); } } // legal characters in XML names according to // http://www.w3.org/TR/REC-xml/#NT-Name and // http://www.w3.org/TR/xml11/#NT-Name - final IntPairList list = new IntPairList(); + IntPairList list = new IntPairList(); list.add(':'); list.add('A', 'Z'); @@ -80,7 +81,7 @@ list.add(0xF900, 0xFDCF); list.add(0xFDF0, 0xFFFD); list.add(0x10000, 0xEFFFF); - XML_NAME_START_CHAR_BOUNDS = list.toArray(new IntPair[list.size()]); + XML_NAME_START_CHAR_BOUNDS = (IntPair[])list.toArray(new IntPair[list.size()]); list.clear(); list.add('-'); @@ -89,13 +90,13 @@ list.add('\u00b7'); list.add(0x0300, 0x036F); list.add(0x203F, 0x2040); - XML_NAME_CHAR_EXTRA_BOUNDS = list.toArray(new IntPair[list.size()]); + XML_NAME_CHAR_EXTRA_BOUNDS = (IntPair[])list.toArray(new IntPair[list.size()]); } private final String dollarReplacement; private final String escapeCharReplacement; - private transient Map escapeCache; - private transient Map unescapeCache; + private transient Map escapeCache; + private transient Map unescapeCache; private final String hexPrefix; /** @@ -108,62 +109,72 @@ } /** - * Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the escape character. + * Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar and the + * escape character. * * @param dollarReplacement * @param escapeCharReplacement * @since 1.4 */ - public XmlFriendlyNameCoder(final String dollarReplacement, final String escapeCharReplacement) { + public XmlFriendlyNameCoder(String dollarReplacement, String escapeCharReplacement) { this(dollarReplacement, escapeCharReplacement, "_."); } /** - * Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar, the escape character and the - * prefix for hexadecimal encoding of invalid characters in XML names. + * Construct a new XmlFriendlyNameCoder with custom replacement strings for dollar, the + * escape character and the prefix for hexadecimal encoding of invalid characters in XML + * names. * * @param dollarReplacement * @param escapeCharReplacement * @since 1.4 */ public XmlFriendlyNameCoder( - final String dollarReplacement, final String escapeCharReplacement, final String hexPrefix) { + String dollarReplacement, String escapeCharReplacement, String hexPrefix) { this.dollarReplacement = dollarReplacement; this.escapeCharReplacement = escapeCharReplacement; this.hexPrefix = hexPrefix; readResolve(); } - @Override - public String decodeAttribute(final String attributeName) { + /** + * {@inheritDoc} + */ + public String decodeAttribute(String attributeName) { return decodeName(attributeName); } - @Override - public String decodeNode(final String elementName) { + /** + * {@inheritDoc} + */ + public String decodeNode(String elementName) { return decodeName(elementName); } - @Override - public String encodeAttribute(final String name) { + /** + * {@inheritDoc} + */ + public String encodeAttribute(String name) { return encodeName(name); } - @Override - public String encodeNode(final String name) { + /** + * {@inheritDoc} + */ + public String encodeNode(String name) { return encodeName(name); } - private String encodeName(final String name) { - String s = escapeCache.get(name); + private String encodeName(String name) { + String s = (String)escapeCache.get(name); if (s == null) { final int length = name.length(); // First, fast (common) case: nothing to escape int i = 0; - for (; i < length; i++) { - final char c = name.charAt(i); + for (; i < length; i++ ) { + char c = name.charAt(i); if (c == '$' || c == '_' || c <= 27 || c >= 127) { break; } @@ -181,21 +192,17 @@ result.append(name.substring(0, i)); } - for (; i < length; i++) { - final char c = name.charAt(i); + for (; i < length; i++ ) { + char c = name.charAt(i); if (c == '$') { result.append(dollarReplacement); } else if (c == '_') { result.append(escapeCharReplacement); - } else if (i == 0 && !isXmlNameStartChar(c) || i > 0 && !isXmlNameChar(c)) { + } else if ((i == 0 && !isXmlNameStartChar(c)) || (i > 0 && !isXmlNameChar(c))) { result.append(hexPrefix); - if (c < 16) { - result.append("000"); - } else if (c < 256) { - result.append("00"); - } else if (c < 4096) { - result.append("0"); - } + if (c < 16) result.append("000"); + else if (c < 256) result.append("00"); + else if (c < 4096) result.append("0"); result.append(Integer.toHexString(c)); } else { result.append(c); @@ -207,8 +214,8 @@ return s; } - private String decodeName(final String name) { - String s = unescapeCache.get(name); + private String decodeName(String name) { + String s = (String)unescapeCache.get(name); if (s == null) { final char dollarReplacementFirstChar = dollarReplacement.charAt(0); final char escapeReplacementFirstChar = escapeCharReplacement.charAt(0); @@ -218,10 +225,12 @@ // First, fast (common) case: nothing to decode int i = 0; - for (; i < length; i++) { - final char c = name.charAt(i); + for (; i < length; i++ ) { + char c = name.charAt(i); // We'll do a quick check for potential match - if (c == dollarReplacementFirstChar || c == escapeReplacementFirstChar || c == hexPrefixFirstChar) { + if (c == dollarReplacementFirstChar + || c == escapeReplacementFirstChar + || c == hexPrefixFirstChar) { // and if it might be a match, just quit, will check later on break; } @@ -239,7 +248,7 @@ result.append(name.substring(0, i)); } - for (; i < length; i++) { + for (; i < length; i++ ) { char c = name.charAt(i); if (c == dollarReplacementFirstChar && name.startsWith(dollarReplacement, i)) { i += dollarReplacement.length() - 1; @@ -249,7 +258,8 @@ c = (char)Integer.parseInt(name.substring(i, i + 4), 16); i += 3; result.append(c); - } else if (c == escapeReplacementFirstChar && name.startsWith(escapeCharReplacement, i)) { + } else if (c == escapeReplacementFirstChar + && name.startsWith(escapeCharReplacement, i)) { i += escapeCharReplacement.length() - 1; result.append('_'); } else { @@ -263,14 +273,13 @@ return s; } - @Override public Object clone() { try { - final XmlFriendlyNameCoder coder = (XmlFriendlyNameCoder)super.clone(); + XmlFriendlyNameCoder coder = (XmlFriendlyNameCoder)super.clone(); coder.readResolve(); return coder; - } catch (final CloneNotSupportedException e) { + } catch (CloneNotSupportedException e) { throw new ObjectAccessException("Cannot clone XmlFriendlyNameCoder", e); } } @@ -281,33 +290,34 @@ return this; } - protected Map createCacheMap() { - return new HashMap(); + protected Map createCacheMap() { + return new HashMap(); } private static class IntPair { int min; int max; - public IntPair(final int min, final int max) { + public IntPair(int min, int max) { this.min = min; this.max = max; } } - private static boolean isXmlNameStartChar(final int cp) { + private static boolean isXmlNameStartChar(int cp) { return isInNameCharBounds(cp, XML_NAME_START_CHAR_BOUNDS); } - private static boolean isXmlNameChar(final int cp) { + private static boolean isXmlNameChar(int cp) { if (isXmlNameStartChar(cp)) { return true; } return isInNameCharBounds(cp, XML_NAME_CHAR_EXTRA_BOUNDS); } - private static boolean isInNameCharBounds(final int cp, final IntPair[] nameCharBounds) { - for (final IntPair p : nameCharBounds) { + private static boolean isInNameCharBounds(int cp, IntPair[] nameCharBounds) { + for (int i = 0; i < nameCharBounds.length; ++i) { + IntPair p = nameCharBounds[i]; if (cp >= p.min && cp <= p.max) { return true; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyReader.java (.../XmlFriendlyReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyReader.java (.../XmlFriendlyReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2007, 2008, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,14 +11,14 @@ package com.thoughtworks.xstream.io.xml; /** - * An interface for a {@link com.thoughtworks.xstream.io.HierarchicalStreamReader} supporting XML-friendly names. + * An interface for a {@link com.thoughtworks.xstream.io.HierarchicalStreamReader} supporting + * XML-friendly names. * * @author Jörg Schaible * @author Mauro Talevi * @since 1.3 * @deprecated As of 1.4 */ -@Deprecated public interface XmlFriendlyReader { /** @@ -28,7 +28,6 @@ * @return An unescaped name with original characters * @deprecated As of 1.4 */ - @Deprecated String unescapeXmlName(String name); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyReplacer.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyReplacer.java (.../XmlFriendlyReplacer.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyReplacer.java (.../XmlFriendlyReplacer.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -26,15 +26,13 @@ * @since 1.2 * @deprecated As of 1.4, use {@link XmlFriendlyNameCoder} instead */ -@Deprecated public class XmlFriendlyReplacer extends XmlFriendlyNameCoder { /** * Default constructor. * * @deprecated As of 1.4, use {@link XmlFriendlyNameCoder} instead */ - @Deprecated public XmlFriendlyReplacer() { this("_-", "__"); } @@ -46,8 +44,7 @@ * @param underscoreReplacement the replacement for '_' * @deprecated As of 1.4, use {@link XmlFriendlyNameCoder} instead */ - @Deprecated - public XmlFriendlyReplacer(final String dollarReplacement, final String underscoreReplacement) { + public XmlFriendlyReplacer(String dollarReplacement, String underscoreReplacement) { super(dollarReplacement, underscoreReplacement); } @@ -58,8 +55,7 @@ * @return The String with the escaped name * @deprecated As of 1.4, use {@link XmlFriendlyNameCoder} instead */ - @Deprecated - public String escapeName(final String name) { + public String escapeName(String name) { return super.encodeNode(name); } @@ -70,8 +66,7 @@ * @return The String with unescaped name * @deprecated As of 1.4, use {@link XmlFriendlyNameCoder} instead */ - @Deprecated - public String unescapeName(final String name) { + public String unescapeName(String name) { return super.decodeNode(name); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyWriter.java (.../XmlFriendlyWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XmlFriendlyWriter.java (.../XmlFriendlyWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2007, 2008, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,14 +11,14 @@ package com.thoughtworks.xstream.io.xml; /** - * An interface for a {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} supporting XML-friendly names. + * An interface for a {@link com.thoughtworks.xstream.io.HierarchicalStreamWriter} supporting + * XML-friendly names. * * @author Jörg Schaible * @author Mauro Talevi * @since 1.3 * @deprecated As of 1.4 */ -@Deprecated public interface XmlFriendlyWriter { /** @@ -28,6 +28,5 @@ * @return An escaped name with original characters replaced * @deprecated As of 1.4 */ - @Deprecated String escapeXmlName(String name); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XomDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XomDriver.java (.../XomDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XomDriver.java (.../XomDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -20,128 +20,145 @@ import java.io.Writer; import java.net.URL; -import com.thoughtworks.xstream.io.HierarchicalStreamReader; -import com.thoughtworks.xstream.io.HierarchicalStreamWriter; -import com.thoughtworks.xstream.io.StreamException; -import com.thoughtworks.xstream.io.naming.NameCoder; - import nu.xom.Builder; import nu.xom.Document; import nu.xom.ParsingException; import nu.xom.ValidityException; +import com.thoughtworks.xstream.io.HierarchicalStreamReader; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.io.naming.NameCoder; public class XomDriver extends AbstractXmlDriver { private final Builder builder; public XomDriver() { - this(new Builder()); + this(new XmlFriendlyNameCoder()); } - public XomDriver(final Builder builder) { + /** + * @deprecated As of 1.4.9, use {@link #XomDriver()} and overload {@link #createBuilder()} instead + */ + public XomDriver(Builder builder) { this(builder, new XmlFriendlyNameCoder()); } - + /** * @since 1.4 */ - public XomDriver(final NameCoder nameCoder) { - this(new Builder(), nameCoder); + public XomDriver(NameCoder nameCoder) { + super(nameCoder); + this.builder = null; } - + /** * @since 1.4 + * @deprecated As of 1.4.9, use {@link #XomDriver(NameCoder)} and overload {@link #createBuilder()} instead */ - public XomDriver(final Builder builder, final NameCoder nameCoder) { + public XomDriver(Builder builder, NameCoder nameCoder) { super(nameCoder); this.builder = builder; } /** * @since 1.2 - * @deprecated As of 1.4, use {@link #XomDriver(Builder, NameCoder)} instead + * @deprecated As of 1.4, use {@link #XomDriver(NameCoder)} instead */ - @Deprecated - public XomDriver(final XmlFriendlyReplacer replacer) { - this(new Builder(), replacer); + public XomDriver(XmlFriendlyReplacer replacer) { + this((NameCoder)replacer); } - + /** * @since 1.2 - * @deprecated As of 1.4, use {@link #XomDriver(Builder, NameCoder)} instead + * @deprecated As of 1.4, use {@link #XomDriver(NameCoder)} and overload {@link #createBuilder()} instead */ - @Deprecated - public XomDriver(final Builder builder, final XmlFriendlyReplacer replacer) { - this((NameCoder)replacer); + public XomDriver(Builder builder, XmlFriendlyReplacer replacer) { + this(builder, (NameCoder)replacer); } + /** + * @deprecated As of 1.4.9, overload {@link #createBuilder()} instead + */ protected Builder getBuilder() { - return builder; + return this.builder; } - @Override - public HierarchicalStreamReader createReader(final Reader text) { + /** + * Create the Builder instance. + * + * A XOM builder is a wrapper around a {@link org.xml.sax.XMLReader} + * instance which is not thread-safe by definition. Therefore each reader + * should use its own builder instance to avoid concurrency problems. + * + * Overload this method to configure the generated builder instances e.g. + * to activate validation. + * + * @return the new builder + * @since 1.4.9 + */ + protected Builder createBuilder() { + final Builder builder = getBuilder(); + return builder != null ? builder : new Builder(); + } + + public HierarchicalStreamReader createReader(Reader text) { try { - final Document document = builder.build(text); + final Document document = createBuilder().build(text); return new XomReader(document, getNameCoder()); - } catch (final ValidityException e) { + } catch (ValidityException e) { throw new StreamException(e); - } catch (final ParsingException e) { + } catch (ParsingException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final InputStream in) { + public HierarchicalStreamReader createReader(InputStream in) { try { - final Document document = builder.build(in); + final Document document = createBuilder().build(in); return new XomReader(document, getNameCoder()); - } catch (final ValidityException e) { + } catch (ValidityException e) { throw new StreamException(e); - } catch (final ParsingException e) { + } catch (ParsingException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final URL in) { + public HierarchicalStreamReader createReader(URL in) { try { - final Document document = builder.build(in.toExternalForm()); + final Document document = createBuilder().build(in.toExternalForm()); return new XomReader(document, getNameCoder()); - } catch (final ValidityException e) { + } catch (ValidityException e) { throw new StreamException(e); - } catch (final ParsingException e) { + } catch (ParsingException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override - public HierarchicalStreamReader createReader(final File in) { + public HierarchicalStreamReader createReader(File in) { try { - final Document document = builder.build(in); + final Document document = createBuilder().build(in); return new XomReader(document, getNameCoder()); - } catch (final ValidityException e) { + } catch (ValidityException e) { throw new StreamException(e); - } catch (final ParsingException e) { + } catch (ParsingException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override public HierarchicalStreamWriter createWriter(final Writer out) { return new PrettyPrintWriter(out, getNameCoder()); } - @Override public HierarchicalStreamWriter createWriter(final OutputStream out) { return new PrettyPrintWriter(new OutputStreamWriter(out), getNameCoder()); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XomReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XomReader.java (.../XomReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XomReader.java (.../XomReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,121 +12,106 @@ package com.thoughtworks.xstream.io.xml; import com.thoughtworks.xstream.io.naming.NameCoder; - import nu.xom.Document; import nu.xom.Element; import nu.xom.Elements; import nu.xom.Node; import nu.xom.Text; - public class XomReader extends AbstractDocumentReader { private Element currentElement; - public XomReader(final Element rootElement) { + public XomReader(Element rootElement) { super(rootElement); } - public XomReader(final Document document) { + public XomReader(Document document) { super(document.getRootElement()); } /** * @since 1.4 */ - public XomReader(final Element rootElement, final NameCoder nameCoder) { + public XomReader(Element rootElement, NameCoder nameCoder) { super(rootElement, nameCoder); } /** * @since 1.4 */ - public XomReader(final Document document, final NameCoder nameCoder) { + public XomReader(Document document, NameCoder nameCoder) { super(document.getRootElement(), nameCoder); } /** * @since 1.2 * @deprecated As of 1.4 use {@link XomReader#XomReader(Element, NameCoder)} instead. */ - @Deprecated - public XomReader(final Element rootElement, final XmlFriendlyReplacer replacer) { + public XomReader(Element rootElement, XmlFriendlyReplacer replacer) { this(rootElement, (NameCoder)replacer); } /** * @since 1.2 * @deprecated As of 1.4 use {@link XomReader#XomReader(Element, NameCoder)} instead. */ - @Deprecated - public XomReader(final Document document, final XmlFriendlyReplacer replacer) { - this(document.getRootElement(), (NameCoder)replacer); + public XomReader(Document document, XmlFriendlyReplacer replacer) { + this(document.getRootElement(), (NameCoder)replacer); } - - @Override + public String getNodeName() { return decodeNode(currentElement.getLocalName()); } - @Override public String getValue() { // currentElement.getValue() not used as this includes text of child elements, which we don't want. - final StringBuffer result = new StringBuffer(); - final int childCount = currentElement.getChildCount(); - for (int i = 0; i < childCount; i++) { - final Node child = currentElement.getChild(i); + StringBuffer result = new StringBuffer(); + int childCount = currentElement.getChildCount(); + for(int i = 0; i < childCount; i++) { + Node child = currentElement.getChild(i); if (child instanceof Text) { - final Text text = (Text)child; + Text text = (Text) child; result.append(text.getValue()); } } return result.toString(); } - @Override - public String getAttribute(final String name) { + public String getAttribute(String name) { return currentElement.getAttributeValue(encodeAttribute(name)); } - @Override - public String getAttribute(final int index) { + public String getAttribute(int index) { return currentElement.getAttribute(index).getValue(); } - @Override public int getAttributeCount() { return currentElement.getAttributeCount(); } - @Override - public String getAttributeName(final int index) { + public String getAttributeName(int index) { return decodeAttribute(currentElement.getAttribute(index).getQualifiedName()); } - @Override protected int getChildCount() { return currentElement.getChildElements().size(); } - @Override protected Object getParent() { return currentElement.getParent(); } - @Override - protected Object getChild(final int index) { + protected Object getChild(int index) { return currentElement.getChildElements().get(index); } - @Override - protected void reassignCurrentElement(final Object current) { - currentElement = (Element)current; + protected void reassignCurrentElement(Object current) { + currentElement = (Element) current; } - @Override public String peekNextChild() { - final Elements children = currentElement.getChildElements(); + Elements children = currentElement.getChildElements(); if (null == children || children.size() == 0) { return null; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XomWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XomWriter.java (.../XomWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XomWriter.java (.../XomWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -41,27 +41,23 @@ * @since 1.2 * @deprecated As of 1.4 use {@link XomWriter#XomWriter(Element, NameCoder)} instead */ - @Deprecated public XomWriter(final Element parentElement, final XmlFriendlyReplacer replacer) { this(parentElement, (NameCoder)replacer); } - @Override protected Object createNode(final String name) { final Element newNode = new Element(encodeNode(name)); final Element top = top(); - if (top != null) { + if (top != null){ top().appendChild(newNode); } return newNode; } - @Override public void addAttribute(final String name, final String value) { top().addAttribute(new Attribute(encodeAttribute(name), value)); } - @Override public void setValue(final String text) { top().appendChild(text); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Xpp3DomDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Xpp3DomDriver.java (.../Xpp3DomDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Xpp3DomDriver.java (.../Xpp3DomDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,12 +10,11 @@ */ package com.thoughtworks.xstream.io.xml; -import org.xmlpull.mxp1.MXParser; -import org.xmlpull.v1.XmlPullParser; - import com.thoughtworks.xstream.io.HierarchicalStreamDriver; import com.thoughtworks.xstream.io.naming.NameCoder; +import org.xmlpull.mxp1.MXParser; +import org.xmlpull.v1.XmlPullParser; /** * A {@link HierarchicalStreamDriver} for XPP DOM using the Xpp3 parser. @@ -40,11 +39,13 @@ * @param nameCoder the replacer for XML friendly names * @since 1.4 */ - public Xpp3DomDriver(final NameCoder nameCoder) { + public Xpp3DomDriver(NameCoder nameCoder) { super(nameCoder); } - @Override + /** + * {@inheritDoc} + */ protected XmlPullParser createParser() { return new MXParser(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Xpp3Driver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Xpp3Driver.java (.../Xpp3Driver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/Xpp3Driver.java (.../Xpp3Driver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,13 +10,14 @@ */ package com.thoughtworks.xstream.io.xml; -import org.xmlpull.mxp1.MXParser; -import org.xmlpull.v1.XmlPullParser; import com.thoughtworks.xstream.io.HierarchicalStreamDriver; import com.thoughtworks.xstream.io.naming.NameCoder; +import org.xmlpull.mxp1.MXParser; +import org.xmlpull.v1.XmlPullParser; + /** * A {@link HierarchicalStreamDriver} using the Xpp3 parser. * @@ -40,11 +41,13 @@ * @param nameCoder the replacer for XML friendly names * @since 1.4 */ - public Xpp3Driver(final NameCoder nameCoder) { + public Xpp3Driver(NameCoder nameCoder) { super(nameCoder); } - @Override + /** + * {@inheritDoc} + */ protected XmlPullParser createParser() { return new MXParser(); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDomDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDomDriver.java (.../XppDomDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDomDriver.java (.../XppDomDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,45 +11,45 @@ */ package com.thoughtworks.xstream.io.xml; +import com.thoughtworks.xstream.io.HierarchicalStreamDriver; +import com.thoughtworks.xstream.io.naming.NameCoder; + import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; -import com.thoughtworks.xstream.io.HierarchicalStreamDriver; -import com.thoughtworks.xstream.io.naming.NameCoder; - - /** * A {@link HierarchicalStreamDriver} for XPP DOM using the XmlPullParserFactory to locate an parser. - * + * * @author Joe Walnes * @author Jörg Schaible */ public class XppDomDriver extends AbstractXppDomDriver { private static XmlPullParserFactory factory; - + public XppDomDriver() { super(new XmlFriendlyNameCoder()); } /** * @since 1.4 */ - public XppDomDriver(final NameCoder nameCoder) { + public XppDomDriver(NameCoder nameCoder) { super(nameCoder); } /** * @since 1.2 * @deprecated As of 1.4, use {@link XppDomDriver#XppDomDriver(NameCoder)} instead. */ - @Deprecated - public XppDomDriver(final XmlFriendlyReplacer replacer) { + public XppDomDriver(XmlFriendlyReplacer replacer) { super(replacer); } - @Override + /** + * {@inheritDoc} + */ protected synchronized XmlPullParser createParser() throws XmlPullParserException { if (factory == null) { factory = XmlPullParserFactory.newInstance(null, XppDomDriver.class); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDomReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDomReader.java (.../XppDomReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDomReader.java (.../XppDomReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,93 +14,80 @@ import com.thoughtworks.xstream.io.naming.NameCoder; import com.thoughtworks.xstream.io.xml.xppdom.XppDom; - /** * @author Jason van Zyl */ public class XppDomReader extends AbstractDocumentReader { private XppDom currentElement; - public XppDomReader(final XppDom xppDom) { + public XppDomReader(XppDom xppDom) { super(xppDom); } /** * @since 1.4 */ - public XppDomReader(final XppDom xppDom, final NameCoder nameCoder) { + public XppDomReader(XppDom xppDom, NameCoder nameCoder) { super(xppDom, nameCoder); } /** * @since 1.2 * @deprecated As of 1.4 use {@link XppDomReader#XppDomReader(XppDom, NameCoder)} instead. */ - @Deprecated - public XppDomReader(final XppDom xppDom, final XmlFriendlyReplacer replacer) { + public XppDomReader(XppDom xppDom, XmlFriendlyReplacer replacer) { this(xppDom, (NameCoder)replacer); } - - @Override + public String getNodeName() { return decodeNode(currentElement.getName()); } - @Override public String getValue() { String text = null; try { text = currentElement.getValue(); - } catch (final Exception e) { + } catch (Exception e) { // do nothing. } return text == null ? "" : text; } - @Override - public String getAttribute(final String attributeName) { + public String getAttribute(String attributeName) { return currentElement.getAttribute(encodeAttribute(attributeName)); } - @Override - public String getAttribute(final int index) { + public String getAttribute(int index) { return currentElement.getAttribute(currentElement.getAttributeNames()[index]); } - @Override public int getAttributeCount() { return currentElement.getAttributeNames().length; } - @Override - public String getAttributeName(final int index) { + public String getAttributeName(int index) { return decodeAttribute(currentElement.getAttributeNames()[index]); } - @Override protected Object getParent() { return currentElement.getParent(); } - @Override - protected Object getChild(final int index) { + protected Object getChild(int index) { return currentElement.getChild(index); } - @Override protected int getChildCount() { return currentElement.getChildCount(); } - @Override - protected void reassignCurrentElement(final Object current) { - currentElement = (XppDom)current; + protected void reassignCurrentElement(Object current) { + this.currentElement = (XppDom) current; } - @Override public String peekNextChild() { if (currentElement.getChildCount() == 0) { return null; Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDomWriter.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDomWriter.java (.../XppDomWriter.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDomWriter.java (.../XppDomWriter.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -45,7 +45,6 @@ * @since 1.2 * @deprecated As of 1.4 use {@link XppDomWriter#XppDomWriter(NameCoder)} instead */ - @Deprecated public XppDomWriter(final XmlFriendlyReplacer replacer) { this(null, replacer); } @@ -54,7 +53,6 @@ * @since 1.2.1 * @deprecated As of 1.4 use {@link XppDomWriter#XppDomWriter(XppDom, NameCoder)} instead. */ - @Deprecated public XppDomWriter(final XppDom parent, final XmlFriendlyReplacer replacer) { this(parent, (NameCoder)replacer); } @@ -63,7 +61,6 @@ return (XppDom)getTopLevelNodes().get(0); } - @Override protected Object createNode(final String name) { final XppDom newNode = new XppDom(encodeNode(name)); final XppDom top = top(); @@ -73,12 +70,10 @@ return newNode; } - @Override public void setValue(final String text) { top().setValue(text); } - @Override public void addAttribute(final String key, final String value) { top().setAttribute(encodeAttribute(key), value); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDriver.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDriver.java (.../XppDriver.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppDriver.java (.../XppDriver.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,17 +11,18 @@ */ package com.thoughtworks.xstream.io.xml; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlPullParserFactory; import com.thoughtworks.xstream.io.HierarchicalStreamDriver; import com.thoughtworks.xstream.io.naming.NameCoder; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlPullParserFactory; + /** * A {@link HierarchicalStreamDriver} using the XmlPullParserFactory to locate an XML Pull Parser. - * + * * @author Joe Walnes * @author Jörg Schaible */ @@ -36,20 +37,21 @@ /** * @since 1.4 */ - public XppDriver(final NameCoder nameCoder) { + public XppDriver(NameCoder nameCoder) { super(nameCoder); } /** * @since 1.2 * @deprecated As of 1.4, use {@link XppDriver#XppDriver(NameCoder)} instead. */ - @Deprecated - public XppDriver(final XmlFriendlyReplacer replacer) { + public XppDriver(XmlFriendlyReplacer replacer) { this((NameCoder)replacer); } - @Override + /** + * {@inheritDoc} + */ protected synchronized XmlPullParser createParser() throws XmlPullParserException { if (factory == null) { factory = XmlPullParserFactory.newInstance(); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppReader.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppReader.java (.../XppReader.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/XppReader.java (.../XppReader.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -21,10 +21,9 @@ import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.naming.NameCoder; - /** * XStream reader that pulls directly from the stream using the XmlPullParser API. - * + * * @author Joe Walnes * @author Jörg Schaible */ @@ -40,7 +39,7 @@ * @param parser the XPP parser to use * @since 1.4 */ - public XppReader(final Reader reader, final XmlPullParser parser) { + public XppReader(Reader reader, XmlPullParser parser) { this(reader, parser, new XmlFriendlyNameCoder()); } @@ -52,131 +51,116 @@ * @param nameCoder the coder for XML friendly tag and attribute names * @since 1.4 */ - public XppReader(final Reader reader, final XmlPullParser parser, final NameCoder nameCoder) { + public XppReader(Reader reader, XmlPullParser parser, NameCoder nameCoder) { super(nameCoder); this.parser = parser; this.reader = reader; try { parser.setInput(this.reader); - } catch (final XmlPullParserException e) { + } catch (XmlPullParserException e) { throw new StreamException(e); } moveDown(); } /** - * @deprecated As of 1.4, use {@link #XppReader(Reader, XmlPullParser)} instead + * @deprecated As of 1.4, use {@link #XppReader(Reader, XmlPullParser)} instead */ - @Deprecated - public XppReader(final Reader reader) { + public XppReader(Reader reader) { this(reader, new XmlFriendlyReplacer()); } /** * @since 1.2 - * @deprecated As of 1.4, use {@link #XppReader(Reader, XmlPullParser, NameCoder)} instead + * @deprecated As of 1.4, use {@link #XppReader(Reader, XmlPullParser, NameCoder)} instead */ - @Deprecated - public XppReader(final Reader reader, final XmlFriendlyReplacer replacer) { + public XppReader(Reader reader, XmlFriendlyReplacer replacer) { super(replacer); try { parser = createParser(); this.reader = reader; parser.setInput(this.reader); moveDown(); - } catch (final XmlPullParserException e) { + } catch (XmlPullParserException e) { throw new StreamException(e); } } - + /** * To use another implementation of org.xmlpull.v1.XmlPullParser, override this method. - * - * @deprecated As of 1.4, use {@link #XppReader(Reader, XmlPullParser)} instead + * @deprecated As of 1.4, use {@link #XppReader(Reader, XmlPullParser)} instead */ - @Deprecated protected XmlPullParser createParser() { Exception exception = null; try { - return (XmlPullParser)Class - .forName("org.xmlpull.mxp1.MXParser", true, XmlPullParser.class.getClassLoader()) - .newInstance(); - } catch (final InstantiationException e) { + return (XmlPullParser)Class.forName("org.xmlpull.mxp1.MXParser", true, XmlPullParser.class.getClassLoader()).newInstance(); + } catch (InstantiationException e) { exception = e; - } catch (final IllegalAccessException e) { + } catch (IllegalAccessException e) { exception = e; - } catch (final ClassNotFoundException e) { + } catch (ClassNotFoundException e) { exception = e; } throw new StreamException("Cannot create Xpp3 parser instance.", exception); } - @Override protected int pullNextEvent() { try { - switch (parser.next()) { - case XmlPullParser.START_DOCUMENT: - case XmlPullParser.START_TAG: - return START_NODE; - case XmlPullParser.END_DOCUMENT: - case XmlPullParser.END_TAG: - return END_NODE; - case XmlPullParser.TEXT: - return TEXT; - case XmlPullParser.COMMENT: - return COMMENT; - default: - return OTHER; + switch(parser.next()) { + case XmlPullParser.START_DOCUMENT: + case XmlPullParser.START_TAG: + return START_NODE; + case XmlPullParser.END_DOCUMENT: + case XmlPullParser.END_TAG: + return END_NODE; + case XmlPullParser.TEXT: + return TEXT; + case XmlPullParser.COMMENT: + return COMMENT; + default: + return OTHER; } - } catch (final XmlPullParserException e) { + } catch (XmlPullParserException e) { throw new StreamException(e); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } - @Override protected String pullElementName() { return parser.getName(); } - @Override protected String pullText() { return parser.getText(); } - @Override - public String getAttribute(final String name) { + public String getAttribute(String name) { return parser.getAttributeValue(null, encodeAttribute(name)); } - @Override - public String getAttribute(final int index) { + public String getAttribute(int index) { return parser.getAttributeValue(index); } - @Override public int getAttributeCount() { return parser.getAttributeCount(); } - @Override - public String getAttributeName(final int index) { + public String getAttributeName(int index) { return decodeAttribute(parser.getAttributeName(index)); } - @Override - public void appendErrors(final ErrorWriter errorWriter) { + public void appendErrors(ErrorWriter errorWriter) { errorWriter.add("line number", String.valueOf(parser.getLineNumber())); } - @Override public void close() { try { reader.close(); - } catch (final IOException e) { + } catch (IOException e) { throw new StreamException(e); } } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/Xpp3Dom.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/Xpp3Dom.java (.../Xpp3Dom.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/Xpp3Dom.java (.../Xpp3Dom.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -19,14 +19,12 @@ * @author Jörg Schaible * @deprecated As of 1.4, use {@link XppDom} instead */ -@Deprecated public class Xpp3Dom extends XppDom { - + /** * @deprecated As of 1.4, use {@link XppDom} instead */ - @Deprecated - public Xpp3Dom(final String name) { + public Xpp3Dom(String name) { super(name); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/Xpp3DomBuilder.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/Xpp3DomBuilder.java (.../Xpp3DomBuilder.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/Xpp3DomBuilder.java (.../Xpp3DomBuilder.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,26 +11,24 @@ */ package com.thoughtworks.xstream.io.xml.xppdom; -import java.io.Reader; - import org.xmlpull.mxp1.MXParser; import org.xmlpull.v1.XmlPullParser; +import java.io.Reader; + /** * @author Jason van Zyl * @author Joe Walnes * @author Jörg Schaible * @deprecated As of 1.4, use {@link XppDom#build(XmlPullParser)} instead */ -@Deprecated public class Xpp3DomBuilder { /** * @deprecated As of 1.4, use {@link XppDom#build(XmlPullParser)} instead */ - @Deprecated - public static Xpp3Dom build(final Reader reader) throws Exception { - final XmlPullParser parser = new MXParser(); + public static Xpp3Dom build(Reader reader) throws Exception { + XmlPullParser parser = new MXParser(); parser.setInput(reader); try { return (Xpp3Dom)XppDom.build(parser); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/XppDom.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/XppDom.java (.../XppDom.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/XppDom.java (.../XppDom.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,17 +10,18 @@ */ package com.thoughtworks.xstream.io.xml.xppdom; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - /** * Simple Document Object Model for XmlPullParser implementations. * @@ -31,18 +32,18 @@ */ public class XppDom implements Serializable { private static final long serialVersionUID = 1L; - - private final String name; + + private String name; private String value; - private Map attributes; - private final List childList; - transient private Map childMap; + private Map attributes; + private List childList; + transient private Map childMap; private XppDom parent; - public XppDom(final String name) { + public XppDom(String name) { this.name = name; - childList = new ArrayList(); - childMap = new HashMap(); + childList = new ArrayList(); + childMap = new HashMap(); } // ---------------------------------------------------------------------- @@ -61,7 +62,7 @@ return value; } - public void setValue(final String value) { + public void setValue(String value) { this.value = value; } @@ -73,17 +74,17 @@ if (null == attributes) { return new String[0]; } else { - return attributes.keySet().toArray(new String[0]); + return (String[])attributes.keySet().toArray(new String[0]); } } - public String getAttribute(final String name) { - return null != attributes ? (String)attributes.get(name) : null; + public String getAttribute(String name) { + return (null != attributes) ? (String)attributes.get(name) : null; } - public void setAttribute(final String name, final String value) { + public void setAttribute(String name, String value) { if (null == attributes) { - attributes = new HashMap(); + attributes = new HashMap(); } attributes.put(name, value); @@ -93,15 +94,15 @@ // Child handling // ---------------------------------------------------------------------- - public XppDom getChild(final int i) { - return childList.get(i); + public XppDom getChild(int i) { + return (XppDom)childList.get(i); } - public XppDom getChild(final String name) { - return childMap.get(name); + public XppDom getChild(String name) { + return (XppDom)childMap.get(name); } - public void addChild(final XppDom xpp3Dom) { + public void addChild(XppDom xpp3Dom) { xpp3Dom.setParent(this); childList.add(xpp3Dom); childMap.put(xpp3Dom.getName(), xpp3Dom); @@ -111,25 +112,25 @@ if (null == childList) { return new XppDom[0]; } else { - return childList.toArray(new XppDom[0]); + return (XppDom[])childList.toArray(new XppDom[0]); } } - public XppDom[] getChildren(final String name) { + public XppDom[] getChildren(String name) { if (null == childList) { return new XppDom[0]; } else { - final ArrayList children = new ArrayList(); - final int size = childList.size(); + ArrayList children = new ArrayList(); + int size = this.childList.size(); - for (int i = 0; i < size; i++) { - final XppDom configuration = childList.get(i); + for (int i = 0; i < size; i++ ) { + XppDom configuration = (XppDom)this.childList.get(i); if (name.equals(configuration.getName())) { children.add(configuration); } } - return children.toArray(new XppDom[0]); + return (XppDom[])children.toArray(new XppDom[0]); } } @@ -149,7 +150,7 @@ return parent; } - public void setParent(final XppDom parent) { + public void setParent(XppDom parent) { this.parent = parent; } @@ -158,8 +159,9 @@ // ---------------------------------------------------------------------- Object readResolve() { - childMap = new HashMap(); - for (final XppDom element : childList) { + childMap = new HashMap(); + for (final Iterator iter = childList.iterator(); iter.hasNext();) { + final XppDom element = (XppDom)iter.next(); childMap.put(element.getName(), element); } return this; @@ -170,49 +172,51 @@ // ---------------------------------------------------------------------- /** - * Build an XPP DOM hierarchy. The {@link java.io.InputStream} or {@link java.io.Reader} used by the parser must - * have already been set. The method does not close it after reading the document's end. + * Build an XPP DOM hierarchy. The {@link java.io.InputStream} or {@link java.io.Reader} + * used by the parser must have already been set. The method does not close it after reading + * the document's end. * * @param parser the XPP instance - * @throws XmlPullParserException if the parser turns into an invalid state or reads invalid XML + * @throws XmlPullParserException if the parser turns into an invalid state or reads invalid + * XML * @throws IOException if the data cannot be read */ - public static XppDom build(final XmlPullParser parser) throws XmlPullParserException, IOException { - final List elements = new ArrayList(); - final List values = new ArrayList(); + public static XppDom build(XmlPullParser parser) throws XmlPullParserException, IOException { + List elements = new ArrayList(); + List values = new ArrayList(); XppDom node = null; int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { - final String rawName = parser.getName(); + String rawName = parser.getName(); // Use XppDom when deprecated Xpp3Dom is removed - final XppDom child = new Xpp3Dom(rawName); + XppDom child = new Xpp3Dom(rawName); - final int depth = elements.size(); + int depth = elements.size(); if (depth > 0) { - final XppDom parent = elements.get(depth - 1); + XppDom parent = (XppDom)elements.get(depth - 1); parent.addChild(child); } elements.add(child); - values.add(new StringBuilder()); + values.add(new StringBuffer()); - final int attributesSize = parser.getAttributeCount(); - for (int i = 0; i < attributesSize; i++) { - final String name = parser.getAttributeName(i); - final String value = parser.getAttributeValue(i); + int attributesSize = parser.getAttributeCount(); + for (int i = 0; i < attributesSize; i++ ) { + String name = parser.getAttributeName(i); + String value = parser.getAttributeValue(i); child.setAttribute(name, value); } } else if (eventType == XmlPullParser.TEXT) { - final int depth = values.size() - 1; - final StringBuilder valueBuffer = values.get(depth); + int depth = values.size() - 1; + StringBuffer valueBuffer = (StringBuffer)values.get(depth); valueBuffer.append(parser.getText()); } else if (eventType == XmlPullParser.END_TAG) { - final int depth = elements.size() - 1; - final XppDom finalNode = elements.remove(depth); - final String accumulatedValue = values.remove(depth).toString(); + int depth = elements.size() - 1; + XppDom finalNode = (XppDom)elements.remove(depth); + String accumulatedValue = (values.remove(depth)).toString(); String finishedValue; if (0 == accumulatedValue.length()) { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/XppDomComparator.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/XppDomComparator.java (.../XppDomComparator.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/io/xml/xppdom/XppDomComparator.java (.../XppDomComparator.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, 2014 XStream Committers. + * Copyright (C) 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -22,8 +22,8 @@ * @author Jörg Schaible * @since 1.4.1 */ -public class XppDomComparator implements Comparator { - private final ThreadLocal xpath; +public class XppDomComparator implements Comparator { + private final ThreadLocal xpath; /** * Creates a new Xpp3DomComparator object. @@ -40,15 +40,14 @@ * @param xpath the reference for the XPath * @since 1.4.1 */ - public XppDomComparator(final ThreadLocal xpath) { + public XppDomComparator(final ThreadLocal xpath) { this.xpath = xpath; } - @Override - public int compare(final XppDom dom1, final XppDom dom2) { + public int compare(final Object dom1, final Object dom2) { - final StringBuilder xpath = new StringBuilder("/"); - final int s = compareInternal(dom1, dom2, xpath, -1); + final StringBuffer xpath = new StringBuffer("/"); + final int s = compareInternal((XppDom)dom1, (XppDom)dom2, xpath, -1); if (this.xpath != null) { if (s != 0) { this.xpath.set(xpath.toString()); @@ -60,7 +59,8 @@ return s; } - private int compareInternal(final XppDom dom1, final XppDom dom2, final StringBuilder xpath, final int count) { + private int compareInternal(final XppDom dom1, final XppDom dom2, + final StringBuffer xpath, final int count) { final int pathlen = xpath.length(); final String name = dom1.getName(); int s = name.compareTo(dom2.getName()); @@ -114,12 +114,14 @@ if (children > 0) { if (dom1.getValue() != null || dom2.getValue() != null) { - throw new IllegalArgumentException("XppDom cannot handle mixed mode at " + xpath + "::text()"); + throw new IllegalArgumentException("XppDom cannot handle mixed mode at " + + xpath + + "::text()"); } xpath.append('/'); - final Map names = new HashMap(); + final Map names = new HashMap(); for (int i = 0; i < children; ++i) { final XppDom child1 = dom1.getChild(i); final XppDom child2 = dom2.getChild(i); @@ -128,7 +130,7 @@ names.put(child, new int[1]); } - s = compareInternal(child1, child2, xpath, names.get(child)[0]++); + s = compareInternal(child1, child2, xpath, ((int[])names.get(child))[0]++); if (s != 0) { return s; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AbstractAttributeAliasingMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AbstractAttributeAliasingMapper.java (.../AbstractAttributeAliasingMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AbstractAttributeAliasingMapper.java (.../AbstractAttributeAliasingMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2014 XStream Committers. + * Copyright (C) 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,9 +11,9 @@ package com.thoughtworks.xstream.mapper; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; - /** * Abstract base class for AttributeAliassingMapper and its system version. * @@ -22,10 +22,10 @@ */ public abstract class AbstractAttributeAliasingMapper extends MapperWrapper { - protected final Map aliasToName = new HashMap(); - protected transient Map nameToAlias = new HashMap(); + protected final Map aliasToName = new HashMap(); + protected transient Map nameToAlias = new HashMap(); - public AbstractAttributeAliasingMapper(final Mapper wrapped) { + public AbstractAttributeAliasingMapper(Mapper wrapped) { super(wrapped); } @@ -34,10 +34,11 @@ nameToAlias.put(attributeName, alias); } - private Object readResolve() { - nameToAlias = new HashMap(); - for (final Map.Entry entry : aliasToName.entrySet()) { - nameToAlias.put(entry.getValue(), entry.getKey()); + Object readResolve() { + nameToAlias = new HashMap(); + for (final Iterator iter = aliasToName.keySet().iterator(); iter.hasNext();) { + final Object alias = iter.next(); + nameToAlias.put(aliasToName.get(alias), alias); } return this; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AbstractXmlFriendlyMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AbstractXmlFriendlyMapper.java (.../AbstractXmlFriendlyMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AbstractXmlFriendlyMapper.java (.../AbstractXmlFriendlyMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,37 +11,35 @@ */ package com.thoughtworks.xstream.mapper; + /** - * Mapper that ensures that all names in the serialization stream are XML friendly. The replacement chars and strings - * are: + * Mapper that ensures that all names in the serialization stream are XML friendly. + * The replacement chars and strings are: *
        - *
      • $ (dollar) chars appearing in class names are replaced with _ (underscore) chars.
        - *
      • - *
      • $ (dollar) chars appearing in field names are replaced with _DOLLAR_ string.
        - *
      • - *
      • _ (underscore) chars appearing in field names are replaced with __ (double underscore) string.
        - *
      • + *
      • $ (dollar) chars appearing in class names are replaced with _ (underscore) chars.
      • + *
      • $ (dollar) chars appearing in field names are replaced with _DOLLAR_ string.
      • + *
      • _ (underscore) chars appearing in field names are replaced with __ (double underscore) string.
      • *
      • default as the prefix for class names with no package.
      • *
      - * Note, this class is no longer in regular use for current XStream versions. It exists to provide backward - * compatibility to existing XML data written with older XStream versions. * + * Note, this class is no longer in regular use for current XStream versions. It exists to provide backward compatibility + * to existing XML data written with older XStream versions. + * * @author Joe Walnes * @author Mauro Talevi * @deprecated As of 1.4 use {@link com.thoughtworks.xstream.io.xml.XmlFriendlyReader} */ -@Deprecated public class AbstractXmlFriendlyMapper extends MapperWrapper { - private final char dollarReplacementInClass = '-'; - private final String dollarReplacementInField = "_DOLLAR_"; - private final String underscoreReplacementInField = "__"; - private final String noPackagePrefix = "default"; - - protected AbstractXmlFriendlyMapper(final Mapper wrapped) { + private char dollarReplacementInClass = '-'; + private String dollarReplacementInField = "_DOLLAR_"; + private String underscoreReplacementInField = "__"; + private String noPackagePrefix = "default"; + + protected AbstractXmlFriendlyMapper(Mapper wrapped) { super(wrapped); } - + protected String escapeClassName(String className) { // the $ used in inner class names is illegal as an xml element getNodeName className = className.replace('$', dollarReplacementInClass); @@ -56,7 +54,7 @@ protected String unescapeClassName(String className) { // special case for classes named $Blah with no package; <-Blah> is illegal XML - if (className.startsWith(noPackagePrefix + dollarReplacementInClass)) { + if (className.startsWith(noPackagePrefix+dollarReplacementInClass)) { className = className.substring(noPackagePrefix.length()); } @@ -66,12 +64,12 @@ return className; } - protected String escapeFieldName(final String fieldName) { - final StringBuilder result = new StringBuilder(); - final int length = fieldName.length(); - for (int i = 0; i < length; i++) { - final char c = fieldName.charAt(i); - if (c == '$') { + protected String escapeFieldName(String fieldName) { + StringBuffer result = new StringBuffer(); + int length = fieldName.length(); + for(int i = 0; i < length; i++) { + char c = fieldName.charAt(i); + if (c == '$' ) { result.append(dollarReplacementInField); } else if (c == '_') { result.append(underscoreReplacementInField); @@ -80,18 +78,18 @@ } } return result.toString(); - } - - protected String unescapeFieldName(final String xmlName) { - final StringBuilder result = new StringBuilder(); - final int length = xmlName.length(); - for (int i = 0; i < length; i++) { - final char c = xmlName.charAt(i); - if (stringFoundAt(xmlName, i, underscoreReplacementInField)) { - i += underscoreReplacementInField.length() - 1; + } + + protected String unescapeFieldName(String xmlName) { + StringBuffer result = new StringBuffer(); + int length = xmlName.length(); + for(int i = 0; i < length; i++) { + char c = xmlName.charAt(i); + if ( stringFoundAt(xmlName, i,underscoreReplacementInField)) { + i +=underscoreReplacementInField.length() - 1; result.append('_'); - } else if (stringFoundAt(xmlName, i, dollarReplacementInField)) { - i += dollarReplacementInField.length() - 1; + } else if ( stringFoundAt(xmlName, i,dollarReplacementInField)) { + i +=dollarReplacementInField.length() - 1; result.append('$'); } else { result.append(c); @@ -100,12 +98,12 @@ return result.toString(); } - private boolean stringFoundAt(final String name, final int i, final String replacement) { - if (name.length() >= i + replacement.length() - && name.substring(i, i + replacement.length()).equals(replacement)) { + private boolean stringFoundAt(String name, int i, String replacement) { + if ( name.length() >= i + replacement.length() + && name.substring(i, i + replacement.length()).equals(replacement) ){ return true; } return false; } - + } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AnnotationConfiguration.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AnnotationConfiguration.java (.../AnnotationConfiguration.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AnnotationConfiguration.java (.../AnnotationConfiguration.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2013, 2014 XStream Committers. + * Copyright (C) 2007, 2008, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,18 +11,16 @@ package com.thoughtworks.xstream.mapper; /** - * A helper interface for the configuration part of the AnnotationMapper. + * An interface for the configuration part of the AnnotationMapper. * * @author Jörg Schaible * @since 1.3 - * @deprecated As of 1.4.5, minimal JDK version will be 1.6 for next major release and AnnotationMapper can be used - * directly + * @deprecated As of 1.4.5, minimal JDK version will be 1.6 for next major release */ -@Deprecated public interface AnnotationConfiguration { void autodetectAnnotations(boolean mode); - void processAnnotations(Class... types); + void processAnnotations(Class[] types); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AnnotationMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AnnotationMapper.java (.../AnnotationMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AnnotationMapper.java (.../AnnotationMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2009, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2007, 2008, 2009, 2011, 2012, 2013, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -38,6 +38,7 @@ import com.thoughtworks.xstream.annotations.XStreamConverter; import com.thoughtworks.xstream.annotations.XStreamConverters; import com.thoughtworks.xstream.annotations.XStreamImplicit; +import com.thoughtworks.xstream.annotations.XStreamImplicitCollection; import com.thoughtworks.xstream.annotations.XStreamInclude; import com.thoughtworks.xstream.annotations.XStreamOmitField; import com.thoughtworks.xstream.converters.Converter; @@ -68,10 +69,13 @@ private transient DefaultImplementationsMapper defaultImplementationsMapper; private transient ImplicitCollectionMapper implicitCollectionMapper; private transient FieldAliasingMapper fieldAliasingMapper; + private transient ElementIgnoringMapper elementIgnoringMapper; private transient AttributeMapper attributeMapper; private transient LocalConversionMapper localConversionMapper; - private final Map, Map, Converter>> converterCache = new HashMap, Map, Converter>>(); - private final Set> annotatedTypes = Collections.synchronizedSet(new HashSet>()); + private final Map, Map, Converter>> converterCache = + new HashMap, Map, Converter>>(); + private final Set> annotatedTypes = + Collections.synchronizedSet(new HashSet>()); /** * Construct an AnnotationMapper. @@ -80,95 +84,92 @@ * @since 1.4.5 */ public AnnotationMapper( - final Mapper wrapped, final ConverterRegistry converterRegistry, final ConverterLookup converterLookup, - final ClassLoaderReference classLoaderReference, final ReflectionProvider reflectionProvider) { + final Mapper wrapped, final ConverterRegistry converterRegistry, final ConverterLookup converterLookup, + final ClassLoaderReference classLoaderReference, final ReflectionProvider reflectionProvider) { super(wrapped); this.converterRegistry = converterRegistry; annotatedTypes.add(Object.class); setupMappers(); locked = true; - + final ClassLoader classLoader = classLoaderReference.getReference(); arguments = new Object[]{ this, classLoaderReference, reflectionProvider, converterLookup, new JVM(), - classLoader != null ? classLoader : new TypedNull(ClassLoader.class)}; + classLoader != null ? classLoader : new TypedNull(ClassLoader.class)}; } /** * Construct an AnnotationMapper. * * @param wrapped the next {@link Mapper} in the chain * @since 1.3 - * @deprecated As of 1.4.5 use - * {@link #AnnotationMapper(Mapper, ConverterRegistry, ConverterLookup, ClassLoaderReference, ReflectionProvider)} + * @deprecated As of 1.4.5 use {@link #AnnotationMapper(Mapper, ConverterRegistry, ConverterLookup, ClassLoaderReference, ReflectionProvider)} */ - @Deprecated public AnnotationMapper( - final Mapper wrapped, final ConverterRegistry converterRegistry, final ConverterLookup converterLookup, - final ClassLoader classLoader, final ReflectionProvider reflectionProvider, final JVM jvm) { + final Mapper wrapped, final ConverterRegistry converterRegistry, final ConverterLookup converterLookup, + final ClassLoader classLoader, final ReflectionProvider reflectionProvider, + final JVM jvm) { this(wrapped, converterRegistry, converterLookup, new ClassLoaderReference(classLoader), reflectionProvider); } @Override - public String realMember(final Class type, final String serialized) { + public String realMember(final Class type, final String serialized) { if (!locked) { - processAnnotation(type); + processAnnotations(type); } return super.realMember(type, serialized); } @Override - public String serializedClass(final Class type) { + public String serializedClass(final Class type) { if (!locked) { - processAnnotation(type); + processAnnotations(type); } return super.serializedClass(type); } @Override - public Class defaultImplementationOf(final Class type) { + public Class defaultImplementationOf(final Class type) { if (!locked) { - processAnnotation(type); + processAnnotations(type); } - final Class defaultImplementation = super.defaultImplementationOf(type); + final Class defaultImplementation = super.defaultImplementationOf(type); if (!locked) { - processAnnotation(defaultImplementation); + processAnnotations(defaultImplementation); } return defaultImplementation; } @Override - public Converter getLocalConverter(final Class definedIn, final String fieldName) { + public Converter getLocalConverter(final Class definedIn, final String fieldName) { if (!locked) { - processAnnotation(definedIn); + processAnnotations(definedIn); } return super.getLocalConverter(definedIn, fieldName); } - @Override public void autodetectAnnotations(final boolean mode) { locked = !mode; } - @Override - public void processAnnotations(final Class... initialTypes) { + public void processAnnotations(final Class[] initialTypes) { if (initialTypes == null || initialTypes.length == 0) { return; } locked = true; - + final Set> types = new UnprocessedTypesSet(); - for (final Class initialType : initialTypes) { + for (final Class initialType : initialTypes) { types.add(initialType); } processTypes(types); } - private void processAnnotation(final Class initialType) { + private void processAnnotations(final Class initialType) { if (initialType == null) { return; } - + final Set> types = new UnprocessedTypesSet(); types.add(initialType); processTypes(types); @@ -180,38 +181,41 @@ final Class type = iter.next(); iter.remove(); - synchronized (type) { + synchronized(type) { if (annotatedTypes.contains(type)) { continue; } try { if (type.isPrimitive()) { continue; } - + addParametrizedTypes(type, types); - + processConverterAnnotations(type); processAliasAnnotation(type, types); processAliasTypeAnnotation(type); - + if (type.isInterface()) { continue; } - + + processImplicitCollectionAnnotation(type); + final Field[] fields = type.getDeclaredFields(); - for (final Field field : fields) { + for (int i = 0; i < fields.length; i++ ) { + final Field field = fields[i]; if (field.isEnumConstant() || (field.getModifiers() & (Modifier.STATIC | Modifier.TRANSIENT)) > 0) { continue; } - + addParametrizedTypes(field.getGenericType(), types); - + if (field.isSynthetic()) { continue; } - + processFieldAliasAnnotation(field); processAsAttributeAnnotation(field); processImplicitAnnotation(field); @@ -283,15 +287,19 @@ private void processConverterAnnotations(final Class type) { if (converterRegistry != null) { - final XStreamConverters convertersAnnotation = type.getAnnotation(XStreamConverters.class); - final XStreamConverter converterAnnotation = type.getAnnotation(XStreamConverter.class); - final List annotations = convertersAnnotation != null ? new ArrayList( - Arrays.asList(convertersAnnotation.value())) : new ArrayList(); + final XStreamConverters convertersAnnotation = type + .getAnnotation(XStreamConverters.class); + final XStreamConverter converterAnnotation = type + .getAnnotation(XStreamConverter.class); + final List annotations = convertersAnnotation != null + ? new ArrayList(Arrays.asList(convertersAnnotation.value())) + : new ArrayList(); if (converterAnnotation != null) { annotations.add(converterAnnotation); } for (final XStreamConverter annotation : annotations) { - final Converter converter = cacheConverter(annotation, converterAnnotation != null ? type : null); + final Converter converter = cacheConverter( + annotation, converterAnnotation != null ? type : null); if (converter != null) { if (converterAnnotation != null || converter.canConvert(type)) { converterRegistry.registerConverter(converter, annotation.priority()); @@ -310,12 +318,15 @@ final XStreamAlias aliasAnnotation = type.getAnnotation(XStreamAlias.class); if (aliasAnnotation != null) { if (classAliasingMapper == null) { - throw new InitializationException("No " + ClassAliasingMapper.class.getName() + " available"); + throw new InitializationException("No " + + ClassAliasingMapper.class.getName() + + " available"); } classAliasingMapper.addClassAlias(aliasAnnotation.value(), type); if (aliasAnnotation.impl() != Void.class) { // Alias for Interface/Class with an impl - defaultImplementationsMapper.addDefaultImplementation(aliasAnnotation.impl(), type); + defaultImplementationsMapper.addDefaultImplementation( + aliasAnnotation.impl(), type); if (type.isInterface()) { types.add(aliasAnnotation.impl()); // alias Interface's impl } @@ -327,27 +338,76 @@ final XStreamAliasType aliasAnnotation = type.getAnnotation(XStreamAliasType.class); if (aliasAnnotation != null) { if (classAliasingMapper == null) { - throw new InitializationException("No " + ClassAliasingMapper.class.getName() + " available"); + throw new InitializationException("No " + + ClassAliasingMapper.class.getName() + + " available"); } classAliasingMapper.addTypeAlias(aliasAnnotation.value(), type); } } + @Deprecated + private void processImplicitCollectionAnnotation(final Class type) { + final XStreamImplicitCollection implicitColAnnotation = type + .getAnnotation(XStreamImplicitCollection.class); + if (implicitColAnnotation != null) { + if (implicitCollectionMapper == null) { + throw new InitializationException("No " + + ImplicitCollectionMapper.class.getName() + + " available"); + } + final String fieldName = implicitColAnnotation.value(); + final String itemFieldName = implicitColAnnotation.item(); + final Field field; + try { + field = type.getDeclaredField(fieldName); + } catch (final NoSuchFieldException e) { + throw new InitializationException(type.getName() + + " does not have a field named '" + + fieldName + + "' as required by " + + XStreamImplicitCollection.class.getName()); + } + Class itemType = null; + final Type genericType = field.getGenericType(); + if (genericType instanceof ParameterizedType) { + final Type typeArgument = ((ParameterizedType)genericType) + .getActualTypeArguments()[0]; + itemType = getClass(typeArgument); + } + if (itemType == null) { + implicitCollectionMapper.add(type, fieldName, null, Object.class); + } else { + if (itemFieldName.equals("")) { + implicitCollectionMapper.add(type, fieldName, null, itemType); + } else { + implicitCollectionMapper.add(type, fieldName, itemFieldName, itemType); + } + } + } + } + private void processFieldAliasAnnotation(final Field field) { final XStreamAlias aliasAnnotation = field.getAnnotation(XStreamAlias.class); if (aliasAnnotation != null) { if (fieldAliasingMapper == null) { - throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available"); + throw new InitializationException("No " + + FieldAliasingMapper.class.getName() + + " available"); } - fieldAliasingMapper.addFieldAlias(aliasAnnotation.value(), field.getDeclaringClass(), field.getName()); + fieldAliasingMapper.addFieldAlias( + aliasAnnotation.value(), field.getDeclaringClass(), field.getName()); } } private void processAsAttributeAnnotation(final Field field) { - final XStreamAsAttribute asAttributeAnnotation = field.getAnnotation(XStreamAsAttribute.class); + final XStreamAsAttribute asAttributeAnnotation = field + .getAnnotation(XStreamAsAttribute.class); if (asAttributeAnnotation != null) { if (attributeMapper == null) { - throw new InitializationException("No " + AttributeMapper.class.getName() + " available"); + throw new InitializationException("No " + + AttributeMapper.class.getName() + + " available"); } attributeMapper.addAttributeFor(field); } @@ -357,42 +417,53 @@ final XStreamImplicit implicitAnnotation = field.getAnnotation(XStreamImplicit.class); if (implicitAnnotation != null) { if (implicitCollectionMapper == null) { - throw new InitializationException("No " + ImplicitCollectionMapper.class.getName() + " available"); + throw new InitializationException("No " + + ImplicitCollectionMapper.class.getName() + + " available"); } final String fieldName = field.getName(); final String itemFieldName = implicitAnnotation.itemFieldName(); final String keyFieldName = implicitAnnotation.keyFieldName(); - final boolean isMap = Map.class.isAssignableFrom(field.getType()); - Class itemType = null; + boolean isMap = Map.class.isAssignableFrom(field.getType()); + Class itemType = null; if (!field.getType().isArray()) { final Type genericType = field.getGenericType(); if (genericType instanceof ParameterizedType) { - final Type[] actualTypeArguments = ((ParameterizedType)genericType).getActualTypeArguments(); + final Type[] actualTypeArguments = ((ParameterizedType)genericType) + .getActualTypeArguments(); final Type typeArgument = actualTypeArguments[isMap ? 1 : 0]; itemType = getClass(typeArgument); } } if (isMap) { - implicitCollectionMapper.add(field.getDeclaringClass(), fieldName, itemFieldName != null - && !"".equals(itemFieldName) ? itemFieldName : null, itemType, keyFieldName != null - && !"".equals(keyFieldName) ? keyFieldName : null); + implicitCollectionMapper.add( + field.getDeclaringClass(), fieldName, + itemFieldName != null && !"".equals(itemFieldName) ? itemFieldName : null, + itemType, keyFieldName != null && !"".equals(keyFieldName) + ? keyFieldName + : null); } else { if (itemFieldName != null && !"".equals(itemFieldName)) { - implicitCollectionMapper.add(field.getDeclaringClass(), fieldName, itemFieldName, itemType); + implicitCollectionMapper.add( + field.getDeclaringClass(), fieldName, itemFieldName, itemType); } else { - implicitCollectionMapper.add(field.getDeclaringClass(), fieldName, itemType); + implicitCollectionMapper + .add(field.getDeclaringClass(), fieldName, itemType); } } } } private void processOmitFieldAnnotation(final Field field) { - final XStreamOmitField omitFieldAnnotation = field.getAnnotation(XStreamOmitField.class); + final XStreamOmitField omitFieldAnnotation = field + .getAnnotation(XStreamOmitField.class); if (omitFieldAnnotation != null) { - if (fieldAliasingMapper == null) { - throw new InitializationException("No " + FieldAliasingMapper.class.getName() + " available"); + if (elementIgnoringMapper == null) { + throw new InitializationException("No " + + ElementIgnoringMapper.class.getName() + + " available"); } - fieldAliasingMapper.omitField(field.getDeclaringClass(), field.getName()); + elementIgnoringMapper.omitField(field.getDeclaringClass(), field.getName()); } } @@ -402,14 +473,18 @@ final Converter converter = cacheConverter(annotation, field.getType()); if (converter != null) { if (localConversionMapper == null) { - throw new InitializationException("No " + LocalConversionMapper.class.getName() + " available"); + throw new InitializationException("No " + + LocalConversionMapper.class.getName() + + " available"); } - localConversionMapper.registerLocalConverter(field.getDeclaringClass(), field.getName(), converter); + localConversionMapper.registerLocalConverter( + field.getDeclaringClass(), field.getName(), converter); } } } - private Converter cacheConverter(final XStreamConverter annotation, final Class targetType) { + private Converter cacheConverter(final XStreamConverter annotation, + final Class targetType) { Converter result = null; final Object[] args; final List parameter = new ArrayList(); @@ -427,24 +502,25 @@ arrays.add(annotation.shorts()); arrays.add(annotation.strings()); arrays.add(annotation.types()); - for (final Object array : arrays) { + for(Object array : arrays) { if (array != null) { - final int length = Array.getLength(array); - for (int i = 0; i < length; i++) { - final Object object = Array.get(array, i); - if (!parameter.contains(object)) { - parameter.add(object); - } + int length = Array.getLength(array); + for (int i = 0; i < length; i++ ) { + parameter.add(Array.get(array, i)); } } } + for (final Class type : annotation.nulls()) { + final TypedNull nullType = new TypedNull(type); + parameter.add(nullType); + } final Class converterType = annotation.value(); Map, Converter> converterMapping = converterCache.get(converterType); if (converterMapping != null) { result = converterMapping.get(parameter); } if (result == null) { - final int size = parameter.size(); + int size = parameter.size(); if (size > 0) { args = new Object[arguments.length + size]; System.arraycopy(arguments, 0, args, size, arguments.length); @@ -457,11 +533,12 @@ try { if (SingleValueConverter.class.isAssignableFrom(converterType) && !Converter.class.isAssignableFrom(converterType)) { - final SingleValueConverter svc = (SingleValueConverter)DependencyInjectionFactory.newInstance( - converterType, args); + final SingleValueConverter svc = (SingleValueConverter)DependencyInjectionFactory + .newInstance(converterType, args); converter = new SingleValueConverterWrapper(svc); } else { - converter = (Converter)DependencyInjectionFactory.newInstance(converterType, args); + converter = (Converter)DependencyInjectionFactory.newInstance( + converterType, args); } } catch (final Exception e) { throw new InitializationException("Cannot instantiate converter " @@ -487,39 +564,40 @@ } return type; } - + private void setupMappers() { - classAliasingMapper = lookupMapperOfType(ClassAliasingMapper.class); - defaultImplementationsMapper = lookupMapperOfType(DefaultImplementationsMapper.class); - implicitCollectionMapper = lookupMapperOfType(ImplicitCollectionMapper.class); - fieldAliasingMapper = lookupMapperOfType(FieldAliasingMapper.class); - attributeMapper = lookupMapperOfType(AttributeMapper.class); - localConversionMapper = lookupMapperOfType(LocalConversionMapper.class); + classAliasingMapper = (ClassAliasingMapper)lookupMapperOfType(ClassAliasingMapper.class); + defaultImplementationsMapper = (DefaultImplementationsMapper)lookupMapperOfType(DefaultImplementationsMapper.class); + implicitCollectionMapper = (ImplicitCollectionMapper)lookupMapperOfType(ImplicitCollectionMapper.class); + fieldAliasingMapper = (FieldAliasingMapper)lookupMapperOfType(FieldAliasingMapper.class); + elementIgnoringMapper = (ElementIgnoringMapper)lookupMapperOfType(ElementIgnoringMapper.class); + attributeMapper = (AttributeMapper)lookupMapperOfType(AttributeMapper.class); + localConversionMapper = (LocalConversionMapper)lookupMapperOfType(LocalConversionMapper.class); } private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); - final int max = arguments.length - 2; + int max = arguments.length - 2; out.writeInt(max); - for (int i = 0; i < max; i++) { + for (int i = 0; i < max; i++ ) { out.writeObject(arguments[i]); } } - + private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); setupMappers(); - final int max = in.readInt(); - arguments = new Object[max + 2]; - for (int i = 0; i < max; i++) { + int max = in.readInt(); + arguments = new Object[max+2]; + for (int i = 0; i < max; i++ ) { arguments[i] = in.readObject(); if (arguments[i] instanceof ClassLoaderReference) { - arguments[max + 1] = ((ClassLoaderReference)arguments[i]).getReference(); + arguments[max+1] = ((ClassLoaderReference)arguments[i]).getReference(); } } arguments[max] = new JVM(); } - + private final class UnprocessedTypesSet extends LinkedHashSet> { @Override public boolean add(Class type) { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ArrayMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ArrayMapper.java (.../ArrayMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ArrayMapper.java (.../ArrayMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,22 +13,20 @@ import com.thoughtworks.xstream.core.util.Primitives; - /** - * Mapper that detects arrays and changes the name so it can identified as an array (for example Foo[] gets serialized - * as foo-array). Supports multi-dimensional arrays. - * - * @author Joe Walnes + * Mapper that detects arrays and changes the name so it can identified as an array + * (for example Foo[] gets serialized as foo-array). Supports multi-dimensional arrays. + * + * @author Joe Walnes */ public class ArrayMapper extends MapperWrapper { - public ArrayMapper(final Mapper wrapped) { + public ArrayMapper(Mapper wrapped) { super(wrapped); } - @Override - public String serializedClass(Class type) { - final StringBuilder arraySuffix = new StringBuilder(); + public String serializedClass(Class type) { + StringBuffer arraySuffix = new StringBuffer(); String name = null; while (type.isArray()) { name = super.serializedClass(type); @@ -53,8 +51,7 @@ } } - @Override - public Class realClass(String elementName) { + public Class realClass(String elementName) { int dimensions = 0; // strip off "-array" suffix @@ -64,7 +61,7 @@ } if (dimensions > 0) { - Class componentType = Primitives.primitiveType(elementName); + Class componentType = Primitives.primitiveType(elementName); if (componentType == null) { componentType = super.realClass(elementName); } @@ -78,8 +75,8 @@ } } - private String arrayType(final int dimensions, final Class componentType) { - final StringBuilder className = new StringBuilder(); + private String arrayType(int dimensions, Class componentType) { + StringBuffer className = new StringBuffer(); for (int i = 0; i < dimensions; i++) { className.append('['); } @@ -91,8 +88,8 @@ return className.toString(); } } - - private String boxedTypeName(final Class type) { + + private String boxedTypeName(Class type) { return Primitives.isBoxed(type) ? type.getName() : null; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AttributeAliasingMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AttributeAliasingMapper.java (.../AttributeAliasingMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AttributeAliasingMapper.java (.../AttributeAliasingMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,6 +11,8 @@ */ package com.thoughtworks.xstream.mapper; + + /** * Mapper that allows aliasing of attribute names. * @@ -20,19 +22,17 @@ */ public class AttributeAliasingMapper extends AbstractAttributeAliasingMapper { - public AttributeAliasingMapper(final Mapper wrapped) { + public AttributeAliasingMapper(Mapper wrapped) { super(wrapped); } - @Override - public String aliasForAttribute(final String attribute) { - final String alias = nameToAlias.get(attribute); + public String aliasForAttribute(String attribute) { + String alias = (String)nameToAlias.get(attribute); return alias == null ? super.aliasForAttribute(attribute) : alias; } - @Override - public String attributeForAlias(final String alias) { - final String name = aliasToName.get(alias); + public String attributeForAlias(String alias) { + String name = (String)aliasToName.get(alias); return name == null ? super.attributeForAlias(alias) : name; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AttributeMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AttributeMapper.java (.../AttributeMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/AttributeMapper.java (.../AttributeMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2013 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -22,12 +22,12 @@ import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; - /** - * Mapper that allows the usage of attributes for fields and corresponding types or specified arbitrary types. It is - * responsible for the lookup of the {@link SingleValueConverter} for item types and attribute names. - * - * @author Paul Hammant + * Mapper that allows the usage of attributes for fields and corresponding + * types or specified arbitrary types. It is responsible for the lookup of the + * {@link SingleValueConverter} for item types and attribute names. + * + * @author Paul Hammant * @author Ian Cartwright * @author Jörg Schaible * @author Mauro Talevi @@ -36,76 +36,117 @@ */ public class AttributeMapper extends MapperWrapper { - private final Map> fieldNameToTypeMap = new HashMap>(); - private final Set> typeSet = new HashSet>(); - private final ConverterLookup converterLookup; - private final ReflectionProvider reflectionProvider; - private final Set fieldToUseAsAttribute = new HashSet(); + private final Map fieldNameToTypeMap = new HashMap(); + private final Set typeSet = new HashSet(); + private ConverterLookup converterLookup; + private ReflectionProvider reflectionProvider; + private final Set fieldToUseAsAttribute = new HashSet(); - public AttributeMapper( - final Mapper wrapped, final ConverterLookup converterLookup, final ReflectionProvider refProvider) { + /** + * @deprecated As of 1.3 + */ + public AttributeMapper(Mapper wrapped) { + this(wrapped, null, null); + } + + public AttributeMapper(Mapper wrapped, ConverterLookup converterLookup, ReflectionProvider refProvider) { super(wrapped); this.converterLookup = converterLookup; - reflectionProvider = refProvider; + this.reflectionProvider = refProvider; } + + /** + * @deprecated As of 1.3 + */ + public void setConverterLookup(ConverterLookup converterLookup) { + this.converterLookup = converterLookup; + } - public void addAttributeFor(final String fieldName, final Class type) { + public void addAttributeFor(final String fieldName, final Class type) { fieldNameToTypeMap.put(fieldName, type); } - public void addAttributeFor(final Class type) { + public void addAttributeFor(final Class type) { typeSet.add(type); } - private SingleValueConverter getLocalConverterFromItemType(final Class type) { - final Converter converter = converterLookup.lookupConverterForType(type); + private SingleValueConverter getLocalConverterFromItemType(Class type) { + Converter converter = converterLookup.lookupConverterForType(type); if (converter != null && converter instanceof SingleValueConverter) { return (SingleValueConverter)converter; } else { return null; } } - @Override - public SingleValueConverter getConverterFromItemType(final String fieldName, final Class type, - final Class definedIn) { + /** + * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)} + */ + public SingleValueConverter getConverterFromItemType(String fieldName, Class type) { + if (fieldNameToTypeMap.get(fieldName) == type) { + return getLocalConverterFromItemType(type); + } else { + return null; + } + } + + public SingleValueConverter getConverterFromItemType(String fieldName, Class type, + Class definedIn) { if (shouldLookForSingleValueConverter(fieldName, type, definedIn)) { - final SingleValueConverter converter = getLocalConverterFromItemType(type); + SingleValueConverter converter = getLocalConverterFromItemType(type); if (converter != null) { return converter; } } return super.getConverterFromItemType(fieldName, type, definedIn); } - public boolean shouldLookForSingleValueConverter(final String fieldName, final Class type, - final Class definedIn) { + public boolean shouldLookForSingleValueConverter(String fieldName, Class type, Class definedIn) { if (typeSet.contains(type)) { return true; } else if (fieldNameToTypeMap.get(fieldName) == type) { return true; } else if (fieldName != null && definedIn != null) { - final Field field = reflectionProvider.getField(definedIn, fieldName); + Field field = reflectionProvider.getField(definedIn, fieldName); return fieldToUseAsAttribute.contains(field); } return false; } /** + * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)} + */ + public SingleValueConverter getConverterFromItemType(Class type) { + if (typeSet.contains(type)) { + return getLocalConverterFromItemType(type); + } else { + return null; + } + } + + /** + * @deprecated As of 1.3, use {@link #getConverterFromAttribute(Class, String, Class)} + */ + public SingleValueConverter getConverterFromAttribute(String attributeName) { + SingleValueConverter converter = null; + Class type = (Class)fieldNameToTypeMap.get(attributeName); + if (type != null) { + converter = getLocalConverterFromItemType(type); + } + return converter; + } + + /** * @deprecated As of 1.3.1, use {@link #getConverterFromAttribute(Class, String, Class)} */ - @Deprecated - @Override - public SingleValueConverter getConverterFromAttribute(final Class definedIn, final String attribute) { - final Field field = reflectionProvider.getField(definedIn, attribute); + public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute) { + Field field = reflectionProvider.getField(definedIn, attribute); return getConverterFromAttribute(definedIn, attribute, field.getType()); } - @Override - public SingleValueConverter getConverterFromAttribute(final Class definedIn, final String attribute, - final Class type) { + public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, Class type) { if (shouldLookForSingleValueConverter(attribute, type, definedIn)) { - final SingleValueConverter converter = getLocalConverterFromItemType(type); + SingleValueConverter converter = getLocalConverterFromItemType(type); if (converter != null) { return converter; } @@ -119,7 +160,7 @@ * @param field the field itself * @since 1.2.2 */ - public void addAttributeFor(final Field field) { + public void addAttributeFor(Field field) { fieldToUseAsAttribute.add(field); } @@ -131,7 +172,7 @@ * @throws IllegalArgumentException if the field does not exist * @since 1.3 */ - public void addAttributeFor(final Class definedIn, final String fieldName) { + public void addAttributeFor(Class definedIn, String fieldName) { fieldToUseAsAttribute.add(reflectionProvider.getField(definedIn, fieldName)); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/CGLIBMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/CGLIBMapper.java (.../CGLIBMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/CGLIBMapper.java (.../CGLIBMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2007, 2008, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,47 +12,46 @@ import net.sf.cglib.proxy.Enhancer; - /** - * Mapper that detects proxies generated by the CGLIB enhancer. The implementation modifies the name, so that it can - * identify these types. Note, that this mapper relies on the CGLIB converters: + * Mapper that detects proxies generated by the CGLIB enhancer. The implementation modifies + * the name, so that it can identify these types. Note, that this mapper relies on the CGLIB + * converters: *
        *
      • CGLIBEnhancedConverter
      • *
      - * + * * @author Jörg Schaible * @since 1.2 */ public class CGLIBMapper extends MapperWrapper { - + private static String DEFAULT_NAMING_MARKER = "$$EnhancerByCGLIB$$"; private final String alias; + + public interface Marker { + } - public interface Marker {} - - public CGLIBMapper(final Mapper wrapped) { + public CGLIBMapper(Mapper wrapped) { this(wrapped, "CGLIB-enhanced-proxy"); } - public CGLIBMapper(final Mapper wrapped, final String alias) { + public CGLIBMapper(Mapper wrapped, String alias) { super(wrapped); this.alias = alias; } - @Override - public String serializedClass(final Class type) { - final String serializedName = super.serializedClass(type); + public String serializedClass(Class type) { + String serializedName = super.serializedClass(type); if (type == null) { return serializedName; } - final String typeName = type.getName(); + String typeName = type.getName(); return typeName.equals(serializedName) && typeName.indexOf(DEFAULT_NAMING_MARKER) > 0 && Enhancer.isEnhanced(type) ? alias : serializedName; } - @Override - public Class realClass(final String elementName) { + public Class realClass(String elementName) { return elementName.equals(alias) ? Marker.class : super.realClass(elementName); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/CachingMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/CachingMapper.java (.../CachingMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/CachingMapper.java (.../CachingMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -19,52 +19,49 @@ import com.thoughtworks.xstream.core.Caching; import com.thoughtworks.xstream.security.ForbiddenClassException; - /** * Mapper that caches which names map to which classes. Prevents repetitive searching and class loading. - * + * * @author Joe Walnes * @author Jörg Schaible */ public class CachingMapper extends MapperWrapper implements Caching { - private transient Map realClassCache; + private transient Map realClassCache; - public CachingMapper(final Mapper wrapped) { + public CachingMapper(Mapper wrapped) { super(wrapped); readResolve(); } - @Override - public Class realClass(final String elementName) { - final Object cached = realClassCache.get(elementName); + public Class realClass(String elementName) { + Object cached = realClassCache.get(elementName); if (cached != null) { if (cached instanceof Class) { - return (Class)cached; + return (Class)cached; } throw (XStreamException)cached; } try { - final Class result = super.realClass(elementName); + Class result = super.realClass(elementName); realClassCache.put(elementName, result); return result; - } catch (final ForbiddenClassException e) { + } catch (ForbiddenClassException e) { realClassCache.put(elementName, e); throw e; - } catch (final CannotResolveClassException e) { + } catch (CannotResolveClassException e) { realClassCache.put(elementName, e); throw e; } } - @Override public void flushCache() { realClassCache.clear(); } private Object readResolve() { - realClassCache = Collections.synchronizedMap(new HashMap(128)); + realClassCache = Collections.synchronizedMap(new HashMap(128)); return this; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ClassAliasingMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ClassAliasingMapper.java (.../ClassAliasingMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ClassAliasingMapper.java (.../ClassAliasingMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -12,58 +12,64 @@ package com.thoughtworks.xstream.mapper; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import com.thoughtworks.xstream.core.util.Primitives; - /** * Mapper that allows a fully qualified class name to be replaced with an alias. - * + * * @author Joe Walnes * @author Jörg Schaible */ public class ClassAliasingMapper extends MapperWrapper { - private final Map, String> typeToName = new HashMap, String>(); - private final Map classToName = new HashMap(); - private transient Map nameToType = new HashMap(); + private final Map typeToName = new HashMap(); + private final Map classToName = new HashMap(); + private transient Map nameToType = new HashMap(); - public ClassAliasingMapper(final Mapper wrapped) { + public ClassAliasingMapper(Mapper wrapped) { super(wrapped); } - public void addClassAlias(final String name, final Class type) { + public void addClassAlias(String name, Class type) { nameToType.put(name, type.getName()); classToName.put(type.getName(), name); } - public void addTypeAlias(final String name, final Class type) { + /** + * @deprecated As of 1.3, method was a leftover of an old implementation + */ + public void addClassAttributeAlias(String name, Class type) { + addClassAlias(name, type); + } + + public void addTypeAlias(String name, Class type) { nameToType.put(name, type.getName()); typeToName.put(type, name); } - @Override - public String serializedClass(final Class type) { - final String alias = classToName.get(type.getName()); + public String serializedClass(Class type) { + String alias = (String) classToName.get(type.getName()); if (alias != null) { return alias; } else { - for (final Class compatibleType : typeToName.keySet()) { + for (final Iterator iter = typeToName.keySet().iterator(); iter.hasNext();) { + final Class compatibleType = (Class)iter.next(); if (compatibleType.isAssignableFrom(type)) { - return typeToName.get(compatibleType); + return (String)typeToName.get(compatibleType); } } return super.serializedClass(type); } } - @Override - public Class realClass(String elementName) { - final String mappedName = nameToType.get(elementName); + public Class realClass(String elementName) { + String mappedName = (String) nameToType.get(elementName); if (mappedName != null) { - final Class type = Primitives.primitiveType(mappedName); + Class type = Primitives.primitiveType(mappedName); if (type != null) { return type; } @@ -73,20 +79,28 @@ return super.realClass(elementName); } - public boolean itemTypeAsAttribute(final Class clazz) { - return classToName.containsKey(clazz); + /** + * @deprecated As of 1.4.9 + */ + public boolean itemTypeAsAttribute(Class clazz) { + return classToName.containsKey(clazz.getName()); } - public boolean aliasIsAttribute(final String name) { + /** + * @deprecated As of 1.4.9 + */ + public boolean aliasIsAttribute(String name) { return nameToType.containsKey(name); } - + private Object readResolve() { - nameToType = new HashMap(); - for (final String type : classToName.keySet()) { + nameToType = new HashMap(); + for (final Iterator iter = classToName.keySet().iterator(); iter.hasNext();) { + final Object type = iter.next(); nameToType.put(classToName.get(type), type); } - for (final Class type : typeToName.keySet()) { + for (final Iterator iter = typeToName.keySet().iterator(); iter.hasNext();) { + final Class type = (Class)iter.next(); nameToType.put(typeToName.get(type), type.getName()); } return this; Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/DefaultImplementationsMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/DefaultImplementationsMapper.java (.../DefaultImplementationsMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/DefaultImplementationsMapper.java (.../DefaultImplementationsMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,24 +11,26 @@ */ package com.thoughtworks.xstream.mapper; +import com.thoughtworks.xstream.InitializationException; + import java.util.HashMap; +import java.util.Iterator; import java.util.Map; -import com.thoughtworks.xstream.InitializationException; - /** - * Mapper that resolves default implementations of classes. For example, mapper.serializedClass(ArrayList.class) will - * return java.util.List. Calling mapper.defaultImplementationOf(List.class) will return ArrayList. + * Mapper that resolves default implementations of classes. For example, + * mapper.serializedClass(ArrayList.class) will return java.util.List. Calling + * mapper.defaultImplementationOf(List.class) will return ArrayList. * * @author Joe Walnes */ public class DefaultImplementationsMapper extends MapperWrapper { - private final Map, Class> typeToImpl = new HashMap, Class>(); - private transient Map, Class> implToType = new HashMap, Class>(); + private final Map typeToImpl = new HashMap(); + private transient Map implToType = new HashMap(); - public DefaultImplementationsMapper(final Mapper wrapped) { + public DefaultImplementationsMapper(Mapper wrapped) { super(wrapped); addDefaults(); } @@ -47,33 +49,33 @@ addDefaultImplementation(Long.class, long.class); } - public void addDefaultImplementation(final Class defaultImplementation, final Class ofType) { + public void addDefaultImplementation(Class defaultImplementation, Class ofType) { if (defaultImplementation != null && defaultImplementation.isInterface()) { - throw new InitializationException("Default implementation is not a concrete class: " - + defaultImplementation.getName()); + throw new InitializationException( + "Default implementation is not a concrete class: " + + defaultImplementation.getName()); } typeToImpl.put(ofType, defaultImplementation); implToType.put(defaultImplementation, ofType); } - @Override - public String serializedClass(final Class type) { - final Class baseType = implToType.get(type); + public String serializedClass(Class type) { + Class baseType = (Class)implToType.get(type); return baseType == null ? super.serializedClass(type) : super.serializedClass(baseType); } - @Override - public Class defaultImplementationOf(final Class type) { + public Class defaultImplementationOf(Class type) { if (typeToImpl.containsKey(type)) { - return typeToImpl.get(type); + return (Class)typeToImpl.get(type); } else { return super.defaultImplementationOf(type); } } private Object readResolve() { - implToType = new HashMap, Class>(); - for (final Class type : typeToImpl.keySet()) { + implToType = new HashMap(); + for (final Iterator iter = typeToImpl.keySet().iterator(); iter.hasNext();) { + final Object type = iter.next(); implToType.put(typeToImpl.get(type), type); } return this; Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/DefaultMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/DefaultMapper.java (.../DefaultMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/DefaultMapper.java (.../DefaultMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,12 +1,12 @@ /* * Copyright (C) 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 3014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2015, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 22. January 2005 by Joe Walnes */ package com.thoughtworks.xstream.mapper; @@ -22,51 +22,49 @@ *

      * To build up the functionality required, wrap this mapper with other mapper implementations. *

      - * + * * @author Joe Walnes * @author Jörg Schaible */ public class DefaultMapper implements Mapper { private static String XSTREAM_PACKAGE_ROOT; static { - final String packageName = DefaultMapper.class.getName(); - final int idx = packageName.indexOf(".xstream."); - XSTREAM_PACKAGE_ROOT = idx > 0 ? packageName.substring(0, idx + 9) : ".N/A"; + String packageName = DefaultMapper.class.getName(); + int idx = packageName.indexOf(".xstream."); + XSTREAM_PACKAGE_ROOT = idx > 0 ? packageName.substring(0, idx+9) : ".N/A"; } - + private final ClassLoaderReference classLoaderReference; + /** * Construct a DefaultMapper. - * + * * @param classLoaderReference the reference to the classloader used by the XStream instance. * @since 1.4.5 */ - public DefaultMapper(final ClassLoaderReference classLoaderReference) { + public DefaultMapper(ClassLoaderReference classLoaderReference) { this.classLoaderReference = classLoaderReference; } /** * Construct a DefaultMapper. - * + * * @param classLoader the ClassLoader used by the XStream instance. * @deprecated As of 1.4.5 use {@link #DefaultMapper(ClassLoaderReference)} */ - @Deprecated - public DefaultMapper(final ClassLoader classLoader) { + public DefaultMapper(ClassLoader classLoader) { this(new ClassLoaderReference(classLoader)); } - @Override - public String serializedClass(final Class type) { + public String serializedClass(Class type) { return type.getName(); } - @Override - public Class realClass(final String elementName) { - final Class resultingClass = Primitives.primitiveType(elementName); - if (resultingClass != null) { + public Class realClass(String elementName) { + Class resultingClass = Primitives.primitiveType(elementName); + if( resultingClass != null ){ return resultingClass; } try { @@ -79,148 +77,127 @@ initialize = elementName.charAt(0) == '['; } return Class.forName(elementName, initialize, classLoader); - } catch (final ClassNotFoundException e) { + } catch (ClassNotFoundException e) { throw new CannotResolveClassException(elementName); } } - @Override - public Class defaultImplementationOf(final Class type) { + public Class defaultImplementationOf(Class type) { return type; } - @Override - public String aliasForAttribute(final String attribute) { + public String aliasForAttribute(String attribute) { return attribute; } - @Override - public String attributeForAlias(final String alias) { + public String attributeForAlias(String alias) { return alias; } - @Override - public String aliasForSystemAttribute(final String attribute) { + public String aliasForSystemAttribute(String attribute) { return attribute; } - @Override - public boolean isImmutableValueType(final Class type) { + public boolean isImmutableValueType(Class type) { return false; } - @Override - public String getFieldNameForItemTypeAndName(final Class definedIn, final Class itemType, - final String itemFieldName) { + public boolean isReferenceable(final Class type) { + return true; + } + + public String getFieldNameForItemTypeAndName(Class definedIn, Class itemType, String itemFieldName) { return null; } - @Override - public Class getItemTypeForItemFieldName(final Class definedIn, final String itemFieldName) { + public Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName) { return null; } - @Override - public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(final Class itemType, - final String fieldName) { + public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType, String fieldName) { return null; } - @Override - public boolean shouldSerializeMember(final Class definedIn, final String fieldName) { + public boolean shouldSerializeMember(Class definedIn, String fieldName) { return true; } + + public boolean isIgnoredElement(String name) { + return false; + } - public String lookupName(final Class type) { + public String lookupName(Class type) { return serializedClass(type); } - public Class lookupType(final String elementName) { + public Class lookupType(String elementName) { return realClass(elementName); } - @Override - public String serializedMember(final Class type, final String memberName) { + public String serializedMember(Class type, String memberName) { return memberName; } - @Override - public String realMember(final Class type, final String serialized) { + public String realMember(Class type, String serialized) { return serialized; } /** * @deprecated As of 1.3, use {@link #getConverterFromAttribute(Class, String, Class)} */ - @Deprecated - public SingleValueConverter getConverterFromAttribute(final String name) { - throw new UnsupportedOperationException(); + public SingleValueConverter getConverterFromAttribute(String name) { + return null; } /** * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)} */ - @Deprecated - public SingleValueConverter getConverterFromItemType(final String fieldName, final Class type) { - throw new UnsupportedOperationException(); + public SingleValueConverter getConverterFromItemType(String fieldName, Class type) { + return null; } /** * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)} */ - @Deprecated - public SingleValueConverter getConverterFromItemType(final Class type) { - throw new UnsupportedOperationException(); + public SingleValueConverter getConverterFromItemType(Class type) { + return null; } - @Override - public SingleValueConverter getConverterFromItemType(final String fieldName, final Class type, - final Class definedIn) { + public SingleValueConverter getConverterFromItemType(String fieldName, Class type, + Class definedIn) { return null; } - @Override - public Converter getLocalConverter(final Class definedIn, final String fieldName) { + public Converter getLocalConverter(Class definedIn, String fieldName) { return null; } - @Override - public T lookupMapperOfType(final Class type) { - @SuppressWarnings("unchecked") - final T t = type.isAssignableFrom(getClass()) ? (T)this : null; - return t; + public Mapper lookupMapperOfType(Class type) { + return null; } /** - * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and - * {@link #getConverterFromItemType(String, Class, Class)} + * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)} */ - @Deprecated - public String aliasForAttribute(final Class definedIn, final String fieldName) { - throw new UnsupportedOperationException(); + public String aliasForAttribute(Class definedIn, String fieldName) { + return fieldName; } /** - * @deprecated As of 1.3, use combination of {@link #realMember(Class, String)} and - * {@link #getConverterFromItemType(String, Class, Class)} + * @deprecated As of 1.3, use combination of {@link #realMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)} */ - @Deprecated - public String attributeForAlias(final Class definedIn, final String alias) { - throw new UnsupportedOperationException(); + public String attributeForAlias(Class definedIn, String alias) { + return alias; } /** - * @deprecated As of 1.3.1, use {@link #getConverterFromAttribute(Class, String, Class)} + * @deprecated As of 1.3.1, use {@link #getConverterFromAttribute(Class, String, Class)} */ - @Deprecated - @Override - public SingleValueConverter getConverterFromAttribute(final Class definedIn, final String attribute) { + public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute) { return null; } - @Override - public SingleValueConverter getConverterFromAttribute(final Class definedIn, final String attribute, - final Class type) { + public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, Class type) { return null; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/DynamicProxyMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/DynamicProxyMapper.java (.../DynamicProxyMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/DynamicProxyMapper.java (.../DynamicProxyMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,24 +13,21 @@ import java.lang.reflect.Proxy; - /** - * Mapper for handling special cases of aliasing dynamic proxies. - *

      - * The alias property specifies the name an instance of a dynamic proxy should be serialized with. - *

      - * + * Mapper for handling special cases of aliasing dynamic proxies. The alias property specifies the name an instance + * of a dynamic proxy should be serialized with. + * * @author Joe Walnes */ public class DynamicProxyMapper extends MapperWrapper { private String alias; - public DynamicProxyMapper(final Mapper wrapped) { + public DynamicProxyMapper(Mapper wrapped) { this(wrapped, "dynamic-proxy"); } - public DynamicProxyMapper(final Mapper wrapped, final String alias) { + public DynamicProxyMapper(Mapper wrapped, String alias) { super(wrapped); this.alias = alias; } @@ -39,21 +36,19 @@ return alias; } - public void setAlias(final String alias) { + public void setAlias(String alias) { this.alias = alias; } - @Override - public String serializedClass(final Class type) { + public String serializedClass(Class type) { if (Proxy.isProxyClass(type)) { return alias; } else { return super.serializedClass(type); } } - @Override - public Class realClass(final String elementName) { + public Class realClass(String elementName) { if (elementName.equals(alias)) { return DynamicProxy.class; } else { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ElementIgnoringMapper.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ElementIgnoringMapper.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ElementIgnoringMapper.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2013, 2016 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 08. January 2016 by Joerg Schaible, factored out from FieldAliasingMapper. + */ +package com.thoughtworks.xstream.mapper; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.regex.Pattern; + +import com.thoughtworks.xstream.core.util.FastField; + +/** + * Mapper that allows an field of a specific class to be omitted entirely. + * + * @author Joerg Schaible + */ +public class ElementIgnoringMapper extends MapperWrapper { + + protected final Set fieldsToOmit = new HashSet(); + protected final Set unknownElementsToIgnore = new LinkedHashSet(); + + public ElementIgnoringMapper(Mapper wrapped) { + super(wrapped); + } + + public void addElementsToIgnore(final Pattern pattern) { + unknownElementsToIgnore.add(pattern); + } + + public void omitField(Class definedIn, String fieldName) { + fieldsToOmit.add(key(definedIn, fieldName)); + } + + public boolean shouldSerializeMember(Class definedIn, String fieldName) { + if (fieldsToOmit.contains(key(definedIn, fieldName))) { + return false; + } else if (definedIn == Object.class && isIgnoredElement(fieldName)) { + return false; + } + return super.shouldSerializeMember(definedIn, fieldName); + } + + public boolean isIgnoredElement(String name) { + if (!unknownElementsToIgnore.isEmpty()) { + for(Iterator iter = unknownElementsToIgnore.iterator(); iter.hasNext();) { + Pattern pattern = (Pattern)iter.next(); + if (pattern.matcher(name).matches()) { + return true; + } + } + } + return super.isIgnoredElement(name); + } + + private Object key(Class type, String name) { + return new FastField(type, name); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/EnumMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/EnumMapper.java (.../EnumMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/EnumMapper.java (.../EnumMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,45 +1,55 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 20. March 2005 by Joe Walnes */ package com.thoughtworks.xstream.mapper; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - +import com.thoughtworks.xstream.converters.ConverterLookup; import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.converters.enums.EnumSingleValueConverter; import com.thoughtworks.xstream.core.Caching; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + /** * Mapper that handles the special case of polymorphic enums in Java 1.5. This renames MyEnum$1 to MyEnum making it less * bloaty in the XML and avoiding the need for an alias per enum value to be specified. Additionally every enum is - * treated automatically as immutable type and can be written as attribute. - * + * treated automatically as immutable and non-refrenceable type that can be written as attribute. + * * @author Joe Walnes * @author Jörg Schaible */ public class EnumMapper extends MapperWrapper implements Caching { private transient AttributeMapper attributeMapper; - private transient Map, SingleValueConverter> enumConverterMap; + private transient Map enumConverterMap; - public EnumMapper(final Mapper wrapped) { + /** + * @deprecated As of 1.3.1, use {@link #EnumMapper(Mapper)} + */ + @Deprecated + public EnumMapper(Mapper wrapped, ConverterLookup lookup) { super(wrapped); readResolve(); } + public EnumMapper(Mapper wrapped) { + super(wrapped); + readResolve(); + } + @Override - public String serializedClass(final Class type) { + public String serializedClass(Class type) { if (type == null) { return super.serializedClass(type); } @@ -53,38 +63,49 @@ } @Override - public boolean isImmutableValueType(final Class type) { - return Enum.class.isAssignableFrom(type) || super.isImmutableValueType(type); + public boolean isImmutableValueType(Class type) { + return (Enum.class.isAssignableFrom(type)) || super.isImmutableValueType(type); } @Override - public SingleValueConverter getConverterFromItemType(final String fieldName, final Class type, - final Class definedIn) { - final SingleValueConverter converter = getLocalConverter(fieldName, type, definedIn); - return converter == null ? super.getConverterFromItemType(fieldName, type, definedIn) : converter; + public boolean isReferenceable(final Class type) { + if (type != null && Enum.class.isAssignableFrom(type)) { + return false; + } else { + return super.isReferenceable(type); + } } @Override - public SingleValueConverter getConverterFromAttribute(final Class definedIn, final String attribute, - final Class type) { - final SingleValueConverter converter = getLocalConverter(attribute, type, definedIn); - return converter == null ? super.getConverterFromAttribute(definedIn, attribute, type) : converter; + public SingleValueConverter getConverterFromItemType(String fieldName, Class type, + Class definedIn) { + SingleValueConverter converter = getLocalConverter(fieldName, type, definedIn); + return converter == null + ? super.getConverterFromItemType(fieldName, type, definedIn) + : converter; } - private SingleValueConverter getLocalConverter(final String fieldName, final Class type, final Class definedIn) { + @Override + public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, + Class type) { + SingleValueConverter converter = getLocalConverter(attribute, type, definedIn); + return converter == null + ? super.getConverterFromAttribute(definedIn, attribute, type) + : converter; + } + + private SingleValueConverter getLocalConverter(String fieldName, Class type, Class definedIn) { if (attributeMapper != null - && Enum.class.isAssignableFrom(type) - && attributeMapper.shouldLookForSingleValueConverter(fieldName, type, definedIn)) { + && Enum.class.isAssignableFrom(type) + && attributeMapper.shouldLookForSingleValueConverter(fieldName, type, definedIn)) { synchronized (enumConverterMap) { SingleValueConverter singleValueConverter = enumConverterMap.get(type); if (singleValueConverter == null) { singleValueConverter = super.getConverterFromItemType(fieldName, type, definedIn); if (singleValueConverter == null) { @SuppressWarnings("unchecked") - final Class> enumType = (Class>)type; - @SuppressWarnings({"rawtypes", "unchecked"}) - final EnumSingleValueConverter enumConverter = new EnumSingleValueConverter(enumType); - singleValueConverter = enumConverter; + Class enumType = type; + singleValueConverter = new EnumSingleValueConverter(enumType); } enumConverterMap.put(type, singleValueConverter); } @@ -94,7 +115,6 @@ return null; } - @Override public void flushCache() { if (enumConverterMap.size() > 0) { synchronized (enumConverterMap) { @@ -104,8 +124,8 @@ } private Object readResolve() { - enumConverterMap = new HashMap, SingleValueConverter>(); - attributeMapper = lookupMapperOfType(AttributeMapper.class); + this.enumConverterMap = new HashMap(); + this.attributeMapper = (AttributeMapper)lookupMapperOfType(AttributeMapper.class); return this; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/FieldAliasingMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/FieldAliasingMapper.java (.../FieldAliasingMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/FieldAliasingMapper.java (.../FieldAliasingMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2014, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,89 +11,81 @@ */ package com.thoughtworks.xstream.mapper; +import com.thoughtworks.xstream.core.util.FastField; + import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.Map; -import java.util.Set; import java.util.regex.Pattern; -import com.thoughtworks.xstream.core.util.FastField; - - /** - * Mapper that allows a field of a specific class to be replaced with a shorter alias, or omitted entirely. - * + * Mapper that allows a field of a specific class to be replaced with a shorter alias. + * * @author Joe Walnes */ public class FieldAliasingMapper extends MapperWrapper { - protected final Map fieldToAliasMap = new HashMap(); - protected final Map aliasToFieldMap = new HashMap(); - protected final Set fieldsToOmit = new HashSet(); - protected final Set unknownFieldsToIgnore = new LinkedHashSet(); + protected final Map fieldToAliasMap = new HashMap(); + protected final Map aliasToFieldMap = new HashMap(); + private final ElementIgnoringMapper elementIgnoringMapper; - public FieldAliasingMapper(final Mapper wrapped) { + public FieldAliasingMapper(Mapper wrapped) { super(wrapped); + elementIgnoringMapper = + (ElementIgnoringMapper)lookupMapperOfType(ElementIgnoringMapper.class); } - public void addFieldAlias(final String alias, final Class type, final String fieldName) { + public void addFieldAlias(String alias, Class type, String fieldName) { fieldToAliasMap.put(key(type, fieldName), alias); aliasToFieldMap.put(key(type, alias), fieldName); } - + + /** + * @deprecated As of 1.4.9 use {@link ElementIgnoringMapper#addElementsToIgnore(Pattern)}. + */ public void addFieldsToIgnore(final Pattern pattern) { - unknownFieldsToIgnore.add(pattern); + if (elementIgnoringMapper != null) { + elementIgnoringMapper.addElementsToIgnore(pattern); + } } - private FastField key(final Class type, final String name) { + /** + * @deprecated As of 1.4.9 use {@link ElementIgnoringMapper#omitField(Class, String)}. + */ + public void omitField(Class definedIn, String fieldName) { + if (elementIgnoringMapper != null) { + elementIgnoringMapper.omitField(definedIn, fieldName); + } + } + + private Object key(Class type, String name) { return new FastField(type, name); } - @Override - public String serializedMember(final Class type, final String memberName) { - final String alias = getMember(type, memberName, fieldToAliasMap); + public String serializedMember(Class type, String memberName) { + String alias = getMember(type, memberName, fieldToAliasMap); if (alias == null) { return super.serializedMember(type, memberName); } else { return alias; } } - @Override - public String realMember(final Class type, final String serialized) { - final String real = getMember(type, serialized, aliasToFieldMap); + public String realMember(Class type, String serialized) { + String real = getMember(type, serialized, aliasToFieldMap); if (real == null) { return super.realMember(type, serialized); } else { return real; } } - private String getMember(final Class type, final String name, final Map map) { + private String getMember(Class type, String name, Map map) { String member = null; - for (Class declaringType = type; member == null && declaringType != Object.class && declaringType != null; declaringType = declaringType - .getSuperclass()) { - member = map.get(key(declaringType, name)); + for (Class declaringType = type; + member == null && declaringType != Object.class && declaringType != null; + declaringType = declaringType.getSuperclass()) { + member = (String) map.get(key(declaringType, name)); } return member; } - - @Override - public boolean shouldSerializeMember(final Class definedIn, final String fieldName) { - if (fieldsToOmit.contains(key(definedIn, fieldName))) { - return false; - } else if (definedIn == Object.class && !unknownFieldsToIgnore.isEmpty()) { - for (final Pattern pattern : unknownFieldsToIgnore) { - if (pattern.matcher(fieldName).matches()) { - return false; - } - } - } - return true; - } - - public void omitField(final Class definedIn, final String fieldName) { - fieldsToOmit.add(key(definedIn, fieldName)); - } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ImmutableTypesMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ImmutableTypesMapper.java (.../ImmutableTypesMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ImmutableTypesMapper.java (.../ImmutableTypesMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,45 +1,75 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 22. January 2005 by Joe Walnes */ package com.thoughtworks.xstream.mapper; import java.util.HashSet; import java.util.Set; - /** * Mapper that specifies which types are basic immutable types. Types that are marked as immutable will be written * multiple times in the serialization stream without using references. - * + *

      + * Note, that an already persisted stream might still contain references for immutable types. They can be dereferenced + * at deserialization time, unless the type is explicitly declared as unreferenceable. However, this is only possible at + * the expense of memory book-keeping all instances. + *

      + * * @author Joe Walnes */ public class ImmutableTypesMapper extends MapperWrapper { - private final Set> immutableTypes = new HashSet>(); + private final Set unreferenceableTypes = new HashSet(); + private final Set immutableTypes = new HashSet(); - public ImmutableTypesMapper(final Mapper wrapped) { + public ImmutableTypesMapper(Mapper wrapped) { super(wrapped); } - public void addImmutableType(final Class type) { + /** + * @deprecated As of 1.4.9 use {@link #addImmutableType(Class, boolean)} + */ + public void addImmutableType(Class type) { + addImmutableType(type, true); + } + + /** + * Declare a type as immutable. + * + * @param type the immutable type + * @param isReferenceable flag for possible references + * @since 1.4.9 + */ + public void addImmutableType(final Class type, final boolean isReferenceable) { immutableTypes.add(type); + if (!isReferenceable) { + unreferenceableTypes.add(type); + } else { + unreferenceableTypes.remove(type); + } } - @Override - public boolean isImmutableValueType(final Class type) { + public boolean isImmutableValueType(Class type) { if (immutableTypes.contains(type)) { return true; } else { return super.isImmutableValueType(type); } } + public boolean isReferenceable(final Class type) { + if (unreferenceableTypes.contains(type)) { + return false; + } else { + return super.isReferenceable(type); + } + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ImplicitCollectionMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ImplicitCollectionMapper.java (.../ImplicitCollectionMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/ImplicitCollectionMapper.java (.../ImplicitCollectionMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,153 +1,176 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2012, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011, 2012, 2013, 2014, 2015, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 16. February 2005 by Joe Walnes */ package com.thoughtworks.xstream.mapper; +import com.thoughtworks.xstream.InitializationException; +import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; +import com.thoughtworks.xstream.core.util.Primitives; + import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; -import com.thoughtworks.xstream.InitializationException; -import com.thoughtworks.xstream.core.util.Primitives; - public class ImplicitCollectionMapper extends MapperWrapper { - public ImplicitCollectionMapper(final Mapper wrapped) { + private ReflectionProvider reflectionProvider; + + public ImplicitCollectionMapper(Mapper wrapped, ReflectionProvider reflectionProvider) { super(wrapped); + this.reflectionProvider = reflectionProvider; } - private final Map, ImplicitCollectionMapperForClass> classNameToMapper = new HashMap, ImplicitCollectionMapperForClass>(); + // { definedIn (Class) -> (ImplicitCollectionMapperForClass) } + private final Map classNameToMapper = new HashMap(); - private ImplicitCollectionMapperForClass getMapper(Class definedIn) { + private ImplicitCollectionMapperForClass getMapper(final Class declaredFor, final String fieldName) { + Class definedIn = declaredFor; + Field field = fieldName != null ? reflectionProvider.getFieldOrNull(definedIn, fieldName) : null; + Class inheritanceStop = field != null ? field.getDeclaringClass() : null; while (definedIn != null) { - final ImplicitCollectionMapperForClass mapper = classNameToMapper.get(definedIn); + ImplicitCollectionMapperForClass mapper = (ImplicitCollectionMapperForClass)classNameToMapper + .get(definedIn); if (mapper != null) { return mapper; } + if (definedIn == inheritanceStop) { + break; + } definedIn = definedIn.getSuperclass(); } return null; } - private ImplicitCollectionMapperForClass getOrCreateMapper(final Class definedIn) { - ImplicitCollectionMapperForClass mapper = classNameToMapper.get(definedIn); + private ImplicitCollectionMapperForClass getOrCreateMapper(Class definedIn) { + ImplicitCollectionMapperForClass mapper = (ImplicitCollectionMapperForClass)classNameToMapper + .get(definedIn); if (mapper == null) { mapper = new ImplicitCollectionMapperForClass(definedIn); classNameToMapper.put(definedIn, mapper); } return mapper; } - @Override - public String getFieldNameForItemTypeAndName(final Class definedIn, final Class itemType, - final String itemFieldName) { - final ImplicitCollectionMapperForClass mapper = getMapper(definedIn); + public String getFieldNameForItemTypeAndName(Class definedIn, Class itemType, + String itemFieldName) { + ImplicitCollectionMapperForClass mapper = getMapper(definedIn, null); if (mapper != null) { return mapper.getFieldNameForItemTypeAndName(itemType, itemFieldName); } else { return null; } } - @Override - public Class getItemTypeForItemFieldName(final Class definedIn, final String itemFieldName) { - final ImplicitCollectionMapperForClass mapper = getMapper(definedIn); + public Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName) { + ImplicitCollectionMapperForClass mapper = getMapper(definedIn, null); if (mapper != null) { return mapper.getItemTypeForItemFieldName(itemFieldName); } else { return null; } } - @Override - public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(final Class itemType, - final String fieldName) { - final ImplicitCollectionMapperForClass mapper = getMapper(itemType); + public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType, + String fieldName) { + ImplicitCollectionMapperForClass mapper = getMapper(itemType, fieldName); if (mapper != null) { return mapper.getImplicitCollectionDefForFieldName(fieldName); } else { return null; } } - public void add(final Class definedIn, final String fieldName, final Class itemType) { + public void add(Class definedIn, String fieldName, Class itemType) { add(definedIn, fieldName, null, itemType); } - public void add(final Class definedIn, final String fieldName, final String itemFieldName, - final Class itemType) { + public void add(Class definedIn, String fieldName, String itemFieldName, Class itemType) { add(definedIn, fieldName, itemFieldName, itemType, null); } - public void add(final Class definedIn, final String fieldName, final String itemFieldName, Class itemType, - final String keyFieldName) { + public void add(Class definedIn, String fieldName, String itemFieldName, Class itemType, String keyFieldName) { Field field = null; - Class declaredIn = definedIn; - while (declaredIn != Object.class && definedIn != null) { - try { - field = declaredIn.getDeclaredField(fieldName); - break; - } catch (final SecurityException e) { - throw new InitializationException("Access denied for field with implicit collection", e); - } catch (final NoSuchFieldException e) { - declaredIn = declaredIn.getSuperclass(); + if (definedIn != null) { + Class declaredIn = definedIn; + while (declaredIn != Object.class) { + try { + field = declaredIn.getDeclaredField(fieldName); + if (!Modifier.isStatic(field.getModifiers())) { + break; + } + field = null; + } catch (final SecurityException e) { + throw new InitializationException("Access denied for field with implicit collection", e); + } catch (final NoSuchFieldException e) { + declaredIn = declaredIn.getSuperclass(); + } } } if (field == null) { - throw new InitializationException("No field \"" + fieldName + "\" for implicit collection"); + throw new InitializationException("No field \"" + + fieldName + + "\" for implicit collection"); } else if (Map.class.isAssignableFrom(field.getType())) { if (itemFieldName == null && keyFieldName == null) { itemType = Map.Entry.class; } } else if (!Collection.class.isAssignableFrom(field.getType())) { - final Class fieldType = field.getType(); + Class fieldType = field.getType(); if (!fieldType.isArray()) { - throw new InitializationException("Field \"" + fieldName + "\" declares no collection or array"); + throw new InitializationException("Field \"" + + fieldName + + "\" declares no collection or array"); } else { - Class componentType = fieldType.getComponentType(); + Class componentType = fieldType.getComponentType(); componentType = componentType.isPrimitive() ? Primitives.box(componentType) : componentType; if (itemType == null) { itemType = componentType; } else { itemType = itemType.isPrimitive() ? Primitives.box(itemType) : itemType; if (!componentType.isAssignableFrom(itemType)) { throw new InitializationException("Field \"" - + fieldName - + "\" declares an array, but the array type is not compatible with " - + itemType.getName()); - + + fieldName + + "\" declares an array, but the array type is not compatible with " + itemType.getName()); + } } } } - final ImplicitCollectionMapperForClass mapper = getOrCreateMapper(definedIn); + ImplicitCollectionMapperForClass mapper = getOrCreateMapper(definedIn); mapper.add(new ImplicitCollectionMappingImpl(fieldName, itemType, itemFieldName, keyFieldName)); } private class ImplicitCollectionMapperForClass { - private final Class definedIn; - private final Map namedItemTypeToDef = new HashMap(); - private final Map itemFieldNameToDef = new HashMap(); - private final Map fieldNameToDef = new HashMap(); + private Class definedIn; + // { (NamedItemType) -> (ImplicitCollectionDefImpl) } + private Map namedItemTypeToDef = new HashMap(); + // { itemFieldName (String) -> (ImplicitCollectionDefImpl) } + private Map itemFieldNameToDef = new HashMap(); + // { fieldName (String) -> (ImplicitCollectionDefImpl) } + private Map fieldNameToDef = new HashMap(); - ImplicitCollectionMapperForClass(final Class definedIn) { + ImplicitCollectionMapperForClass(Class definedIn) { this.definedIn = definedIn; } - public String getFieldNameForItemTypeAndName(final Class itemType, final String itemFieldName) { + public String getFieldNameForItemTypeAndName(Class itemType, String itemFieldName) { ImplicitCollectionMappingImpl unnamed = null; - for (final NamedItemType itemTypeForFieldName : namedItemTypeToDef.keySet()) { - final ImplicitCollectionMappingImpl def = namedItemTypeToDef.get(itemTypeForFieldName); + for (Iterator iterator = namedItemTypeToDef.keySet().iterator(); iterator.hasNext();) { + NamedItemType itemTypeForFieldName = (NamedItemType)iterator.next(); + ImplicitCollectionMappingImpl def = (ImplicitCollectionMappingImpl)namedItemTypeToDef + .get(itemTypeForFieldName); if (itemType == Mapper.Null.class) { unnamed = def; break; @@ -159,8 +182,8 @@ } else { if (unnamed == null || unnamed.getItemType() == null - || def.getItemType() != null - && unnamed.getItemType().isAssignableFrom(def.getItemType())) { + || (def.getItemType() != null + && unnamed.getItemType().isAssignableFrom(def.getItemType()))) { unnamed = def; } } @@ -169,46 +192,47 @@ if (unnamed != null) { return unnamed.getFieldName(); } else { - final ImplicitCollectionMapperForClass mapper = getMapper(definedIn.getSuperclass()); + ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass(), null); return mapper != null ? mapper.getFieldNameForItemTypeAndName(itemType, itemFieldName) : null; } } - public Class getItemTypeForItemFieldName(final String itemFieldName) { - final ImplicitCollectionMappingImpl def = getImplicitCollectionDefByItemFieldName(itemFieldName); + public Class getItemTypeForItemFieldName(String itemFieldName) { + ImplicitCollectionMappingImpl def = getImplicitCollectionDefByItemFieldName(itemFieldName); if (def != null) { return def.getItemType(); } else { - final ImplicitCollectionMapperForClass mapper = getMapper(definedIn.getSuperclass()); + ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass(), null); return mapper != null ? mapper.getItemTypeForItemFieldName(itemFieldName) : null; } } - private ImplicitCollectionMappingImpl getImplicitCollectionDefByItemFieldName(final String itemFieldName) { + private ImplicitCollectionMappingImpl getImplicitCollectionDefByItemFieldName( + String itemFieldName) { if (itemFieldName == null) { return null; } else { - final ImplicitCollectionMappingImpl mapping = itemFieldNameToDef.get(itemFieldName); + ImplicitCollectionMappingImpl mapping = (ImplicitCollectionMappingImpl)itemFieldNameToDef.get(itemFieldName); if (mapping != null) { return mapping; } else { - final ImplicitCollectionMapperForClass mapper = getMapper(definedIn.getSuperclass()); + ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass(), null); return mapper != null ? mapper.getImplicitCollectionDefByItemFieldName(itemFieldName) : null; } } } - public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(final String fieldName) { - final ImplicitCollectionMapping mapping = fieldNameToDef.get(fieldName); + public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(String fieldName) { + ImplicitCollectionMapping mapping = (ImplicitCollectionMapping)fieldNameToDef.get(fieldName); if (mapping != null) { return mapping; } else { - final ImplicitCollectionMapperForClass mapper = getMapper(definedIn.getSuperclass()); + ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass(), null); return mapper != null ? mapper.getImplicitCollectionDefForFieldName(fieldName) : null; } } - public void add(final ImplicitCollectionMappingImpl def) { + public void add(ImplicitCollectionMappingImpl def) { fieldNameToDef.put(def.getFieldName(), def); namedItemTypeToDef.put(def.createNamedItemType(), def); if (def.getItemFieldName() != null) { @@ -221,11 +245,10 @@ private static class ImplicitCollectionMappingImpl implements ImplicitCollectionMapping { private final String fieldName; private final String itemFieldName; - private final Class itemType; + private final Class itemType; private final String keyFieldName; - ImplicitCollectionMappingImpl( - final String fieldName, final Class itemType, final String itemFieldName, final String keyFieldName) { + ImplicitCollectionMappingImpl(String fieldName, Class itemType, String itemFieldName, String keyFieldName) { this.fieldName = fieldName; this.itemFieldName = itemFieldName; this.itemType = itemType; @@ -236,55 +259,49 @@ return new NamedItemType(itemType, itemFieldName); } - @Override public String getFieldName() { return fieldName; } - @Override public String getItemFieldName() { return itemFieldName; } - @Override - public Class getItemType() { + public Class getItemType() { return itemType; } - @Override public String getKeyFieldName() { return keyFieldName; } } private static class NamedItemType { - Class itemType; + Class itemType; String itemFieldName; - NamedItemType(final Class itemType, final String itemFieldName) { - this.itemType = itemType == null ? Object.class : itemType; + NamedItemType(Class itemType, String itemFieldName) { + this.itemType = itemType == null ? Object.class : itemType; this.itemFieldName = itemFieldName; } - @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (obj instanceof NamedItemType) { - final NamedItemType b = (NamedItemType)obj; + NamedItemType b = (NamedItemType)obj; return itemType.equals(b.itemType) && isEquals(itemFieldName, b.itemFieldName); } else { return false; } } - private static boolean isEquals(final Object a, final Object b) { + private static boolean isEquals(Object a, Object b) { if (a == null) { return b == null; } else { return a.equals(b); } } - @Override public int hashCode() { int hash = itemType.hashCode() << 7; if (itemFieldName != null) { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/LambdaMapper.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/LambdaMapper.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/LambdaMapper.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2015 XStream Committers. + * All rights reserved. + * + * Created on 15. January 2015 by Joerg Schaible + */ +package com.thoughtworks.xstream.mapper; + +import java.io.Serializable; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import com.thoughtworks.xstream.core.util.Types; + + +/** + * Mapper to map serializable lambda types to the name of their functional interface and non-serializable ones to + * Mapper.Null. + * + * @author Jörg Schaible + * @since 1.4.8 + */ +public class LambdaMapper extends MapperWrapper { + + /** + * Constructs a LambdaMapper. + * + * @param wrapped mapper + * @since 1.4.8 + */ + public LambdaMapper(final Mapper wrapped) { + super(wrapped); + } + + @Override + public String serializedClass(final Class type) { + Class replacement = null; + if (Types.isLambdaType(type)) { + if (Serializable.class.isAssignableFrom(type)) { + final Class[] interfaces = type.getInterfaces(); + if (interfaces.length > 1) { + for (int i = 0; replacement == null && i < interfaces.length; i++) { + final Class iface = interfaces[i]; + for (final Method method : iface.getMethods()) { + if (!method.isDefault() && !Modifier.isStatic(method.getModifiers())) { + replacement = iface; + break; + } + } + } + } else { + replacement = interfaces[0]; + } + } else { + replacement = Null.class; + } + } + return super.serializedClass(replacement == null ? type : replacement); + } +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/LocalConversionMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/LocalConversionMapper.java (.../LocalConversionMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/LocalConversionMapper.java (.../LocalConversionMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008, 2014 XStream Committers. + * Copyright (C) 2007, 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,14 +10,14 @@ */ package com.thoughtworks.xstream.mapper; -import java.util.HashMap; -import java.util.Map; - import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.core.util.FastField; +import java.util.HashMap; +import java.util.Map; + /** * A Mapper for locally defined converters for a member field. * @@ -26,7 +26,7 @@ */ public class LocalConversionMapper extends MapperWrapper { - private final Map localConverters = new HashMap(); + private final Map localConverters = new HashMap(); private transient AttributeMapper attributeMapper; /** @@ -35,38 +35,42 @@ * @param wrapped * @since 1.3 */ - public LocalConversionMapper(final Mapper wrapped) { + public LocalConversionMapper(Mapper wrapped) { super(wrapped); readResolve(); } - public void registerLocalConverter(final Class definedIn, final String fieldName, final Converter converter) { + public void registerLocalConverter(Class definedIn, String fieldName, Converter converter) { localConverters.put(new FastField(definedIn, fieldName), converter); } - @Override - public Converter getLocalConverter(final Class definedIn, final String fieldName) { - return localConverters.get(new FastField(definedIn, fieldName)); + public Converter getLocalConverter(Class definedIn, String fieldName) { + return (Converter)localConverters.get(new FastField(definedIn, fieldName)); } - @Override - public SingleValueConverter getConverterFromAttribute(final Class definedIn, final String attribute, - final Class type) { - final SingleValueConverter converter = getLocalSingleValueConverter(definedIn, attribute, type); - return converter == null ? super.getConverterFromAttribute(definedIn, attribute, type) : converter; + public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, + Class type) { + SingleValueConverter converter = getLocalSingleValueConverter( + definedIn, attribute, type); + return converter == null + ? super.getConverterFromAttribute(definedIn, attribute, type) + : converter; } - @Override - public SingleValueConverter getConverterFromItemType(final String fieldName, final Class type, - final Class definedIn) { - final SingleValueConverter converter = getLocalSingleValueConverter(definedIn, fieldName, type); - return converter == null ? super.getConverterFromItemType(fieldName, type, definedIn) : converter; + public SingleValueConverter getConverterFromItemType(String fieldName, Class type, + Class definedIn) { + SingleValueConverter converter = getLocalSingleValueConverter( + definedIn, fieldName, type); + return converter == null + ? super.getConverterFromItemType(fieldName, type, definedIn) + : converter; } - private SingleValueConverter getLocalSingleValueConverter(final Class definedIn, final String fieldName, - final Class type) { - if (attributeMapper != null && attributeMapper.shouldLookForSingleValueConverter(fieldName, type, definedIn)) { - final Converter converter = getLocalConverter(definedIn, fieldName); + private SingleValueConverter getLocalSingleValueConverter(Class definedIn, + String fieldName, Class type) { + if (attributeMapper != null + && attributeMapper.shouldLookForSingleValueConverter(fieldName, type, definedIn)) { + Converter converter = getLocalConverter(definedIn, fieldName); if (converter != null && converter instanceof SingleValueConverter) { return (SingleValueConverter)converter; } @@ -75,7 +79,7 @@ } private Object readResolve() { - attributeMapper = lookupMapperOfType(AttributeMapper.class); + this.attributeMapper = (AttributeMapper)lookupMapperOfType(AttributeMapper.class); return this; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/Mapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/Mapper.java (.../Mapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/Mapper.java (.../Mapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,20 +1,19 @@ /* * Copyright (C) 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2103, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2015, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 22. January 2005 by Joe Walnes */ package com.thoughtworks.xstream.mapper; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.SingleValueConverter; - public interface Mapper { /** * Place holder type used for null values. @@ -24,34 +23,41 @@ /** * How a class name should be represented in its serialized form. */ - String serializedClass(Class type); + String serializedClass(Class type); /** * How a serialized class representation should be mapped back to a real class. */ - Class realClass(String elementName); + Class realClass(String elementName); /** * How a class member should be represented in its serialized form. */ - String serializedMember(Class type, String memberName); + String serializedMember(Class type, String memberName); /** * How a serialized member representation should be mapped back to a real member. */ - String realMember(Class type, String serialized); + String realMember(Class type, String serialized); /** - * Whether this type is a simple immutable value (int, boolean, String, URL, etc. Immutable types will be repeatedly - * written in the serialized stream, instead of using object references. + * Whether this type is a simple immutable value (int, boolean, String, URL, etc). Immutable types will be + * repeatedly written in the serialized stream, instead of using object references. */ - boolean isImmutableValueType(Class type); + boolean isImmutableValueType(Class type); - Class defaultImplementationOf(Class type); + /** + * Whether this type is referenceable in a stream. + * + * @since 1.4.9 + */ + boolean isReferenceable(Class type); + Class defaultImplementationOf(Class type); + /** * Get the alias for an attribute's name. - * + * * @param attribute the attribute * @return the alias * @since 1.2 @@ -60,7 +66,7 @@ /** * Get the attribute's name for an alias. - * + * * @param alias the alias * @return the attribute's name * @since 1.2 @@ -69,7 +75,7 @@ /** * Get the alias for a system attribute's name. - * + * * @param attribute the system attribute * @return the alias * @since 1.3.1 @@ -78,66 +84,107 @@ /** * Get the name of the field that acts as the default collection for an object, or return null if there is none. - * + * * @param definedIn owning type * @param itemType item type * @param itemFieldName optional item element name */ - String getFieldNameForItemTypeAndName(Class definedIn, Class itemType, String itemFieldName); + String getFieldNameForItemTypeAndName(Class definedIn, Class itemType, String itemFieldName); - Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName); + Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName); - ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType, String fieldName); + ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType, String fieldName); /** * Determine whether a specific member should be serialized. - * + * * @since 1.1.3 */ - boolean shouldSerializeMember(Class definedIn, String fieldName); + boolean shouldSerializeMember(Class definedIn, String fieldName); + /** + * Whether this name can be ignored. + * + * @since 1.4.9 + */ + boolean isIgnoredElement(String name); + interface ImplicitCollectionMapping { String getFieldName(); - String getItemFieldName(); - - Class getItemType(); - + Class getItemType(); String getKeyFieldName(); } - Converter getLocalConverter(Class definedIn, String fieldName); + /** + * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)} + */ + SingleValueConverter getConverterFromItemType(String fieldName, Class type); - T lookupMapperOfType(final Class type); + /** + * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)} + */ + SingleValueConverter getConverterFromItemType(Class type); /** + * @deprecated As of 1.3, use {@link #getConverterFromAttribute(Class, String, Class)} + */ + SingleValueConverter getConverterFromAttribute(String name); + + Converter getLocalConverter(Class definedIn, String fieldName); + + Mapper lookupMapperOfType(Class type); + + /** * Returns a single value converter to be used in a specific field. - * + * * @param fieldName the field name * @param type the field type * @param definedIn the type which defines this field - * @return a SingleValueConverter or null if there no such converter should be used for this field. + * @return a SingleValueConverter or null if there no such converter should be used for this + * field. * @since 1.2.2 */ - SingleValueConverter getConverterFromItemType(String fieldName, Class type, Class definedIn); + SingleValueConverter getConverterFromItemType(String fieldName, Class type, Class definedIn); /** - * Returns which converter to use for an specific attribute in a type. + * Returns an alias for a single field defined in an specific type. * + * @param definedIn the type where the field was defined + * @param fieldName the field name + * @return the alias for this field or its own name if no alias was defined + * @since 1.2.2 + * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)} + */ + String aliasForAttribute(Class definedIn, String fieldName); + + /** + * Returns the field name for an aliased attribute. + * + * @param definedIn the type where the field was defined + * @param alias the alias + * @return the original attribute name + * @since 1.2.2 + * @deprecated As of 1.3, use combination of {@link #realMember(Class, String)} and {@link #getConverterFromItemType(String, Class, Class)} + */ + String attributeForAlias(Class definedIn, String alias); + + /** + * Returns which converter to use for an specific attribute in a type. + * * @param definedIn the field's parent * @param attribute the attribute name - * @deprecated As of 1.3.1, use {@link #getConverterFromAttribute(Class, String, Class)} + * @deprecated As of 1.3.1, use {@link #getConverterFromAttribute(Class, String, Class)} */ - @Deprecated - SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute); + SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute); /** * Returns which converter to use for an specific attribute in a type. - * + * * @param definedIn the field's parent * @param attribute the attribute name * @param type the type the converter should create * @since 1.3.1 */ - SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, Class type); + SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, Class type); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/MapperWrapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/MapperWrapper.java (.../MapperWrapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/MapperWrapper.java (.../MapperWrapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2005, 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2008, 2009, 2013, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2008, 2009, 2015, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,116 +11,230 @@ */ package com.thoughtworks.xstream.mapper; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.SingleValueConverter; public abstract class MapperWrapper implements Mapper { - private final Mapper wrapped; + private final Mapper aliasForAttributeMapper; + private final Mapper aliasForSystemAttributeMapper; + private final Mapper attributeForAliasMapper; + private final Mapper defaultImplementationOfMapper; + private final Mapper getConverterFromAttributeMapper; + private final Mapper getConverterFromItemTypeMapper; + private final Mapper getFieldNameForItemTypeAndNameMapper; + private final Mapper getImplicitCollectionDefForFieldNameMapper; + private final Mapper getItemTypeForItemFieldNameMapper; + private final Mapper getLocalConverterMapper; + private final Mapper isIgnoredElementMapper; + private final Mapper isImmutableValueTypeMapper; + private final Mapper isReferenceableMapper; + private final Mapper realClassMapper; + private final Mapper realMemberMapper; + private final Mapper serializedClassMapper; + private final Mapper serializedMemberMapper; + private final Mapper shouldSerializeMemberMapper; - public MapperWrapper(final Mapper wrapped) { + public MapperWrapper(Mapper wrapped) { this.wrapped = wrapped; + + if (wrapped instanceof MapperWrapper) { + final MapperWrapper wrapper = (MapperWrapper)wrapped; + final Map wrapperMap = new HashMap(); + wrapperMap.put("aliasForAttribute", wrapper.aliasForAttributeMapper); + wrapperMap.put("aliasForSystemAttribute", wrapper.aliasForSystemAttributeMapper); + wrapperMap.put("attributeForAlias", wrapper.attributeForAliasMapper); + wrapperMap.put("defaultImplementationOf", wrapper.defaultImplementationOfMapper); + wrapperMap.put("getConverterFromAttribute", wrapper.getConverterFromAttributeMapper); + wrapperMap.put("getConverterFromItemType", wrapper.getConverterFromItemTypeMapper); + wrapperMap.put("getFieldNameForItemTypeAndName", wrapper.getFieldNameForItemTypeAndNameMapper); + wrapperMap.put("getImplicitCollectionDefForFieldName", wrapper.getImplicitCollectionDefForFieldNameMapper); + wrapperMap.put("getItemTypeForItemFieldName", wrapper.getItemTypeForItemFieldNameMapper); + wrapperMap.put("getLocalConverter", wrapper.getLocalConverterMapper); + wrapperMap.put("isIgnoredElement", wrapper.isIgnoredElementMapper); + wrapperMap.put("isImmutableValueType", wrapper.isImmutableValueTypeMapper); + wrapperMap.put("isReferenceable", wrapper.isReferenceableMapper); + wrapperMap.put("realClass", wrapper.realClassMapper); + wrapperMap.put("realMember", wrapper.realMemberMapper); + wrapperMap.put("serializedClass", wrapper.serializedClassMapper); + wrapperMap.put("serializedMember", wrapper.serializedMemberMapper); + wrapperMap.put("shouldSerializeMember", wrapper.shouldSerializeMemberMapper); + + final Method[] methods = wrapped.getClass().getMethods(); + for (int i = 0; i < methods.length; ++i) { + final Method method = methods[i]; + if (method.getDeclaringClass() != MapperWrapper.class) { + final String name = method.getName(); + if (wrapperMap.containsKey(name)) { + wrapperMap.put(name, wrapped); + } + } + } + + aliasForAttributeMapper = (Mapper)wrapperMap.get("aliasForAttribute"); + aliasForSystemAttributeMapper = (Mapper)wrapperMap.get("aliasForSystemAttribute"); + attributeForAliasMapper = (Mapper)wrapperMap.get("attributeForAlias"); + defaultImplementationOfMapper = (Mapper)wrapperMap.get("defaultImplementationOf"); + getConverterFromAttributeMapper = (Mapper)wrapperMap.get("getConverterFromAttribute"); + getConverterFromItemTypeMapper = (Mapper)wrapperMap.get("getConverterFromItemType"); + getFieldNameForItemTypeAndNameMapper = (Mapper)wrapperMap.get("getFieldNameForItemTypeAndName"); + getImplicitCollectionDefForFieldNameMapper = (Mapper)wrapperMap.get("getImplicitCollectionDefForFieldName"); + getItemTypeForItemFieldNameMapper = (Mapper)wrapperMap.get("getItemTypeForItemFieldName"); + getLocalConverterMapper = (Mapper)wrapperMap.get("getLocalConverter"); + isIgnoredElementMapper = (Mapper)wrapperMap.get("isIgnoredElement"); + isImmutableValueTypeMapper = (Mapper)wrapperMap.get("isImmutableValueType"); + isReferenceableMapper = (Mapper)wrapperMap.get("isReferenceable"); + realClassMapper = (Mapper)wrapperMap.get("realClass"); + realMemberMapper = (Mapper)wrapperMap.get("realMember"); + serializedClassMapper = (Mapper)wrapperMap.get("serializedClass"); + serializedMemberMapper = (Mapper)wrapperMap.get("serializedMember"); + shouldSerializeMemberMapper = (Mapper)wrapperMap.get("shouldSerializeMember"); + } else { + aliasForAttributeMapper = wrapped; + aliasForSystemAttributeMapper = wrapped; + attributeForAliasMapper = wrapped; + defaultImplementationOfMapper = wrapped; + getConverterFromAttributeMapper = wrapped; + getConverterFromItemTypeMapper = wrapped; + getFieldNameForItemTypeAndNameMapper = wrapped; + getImplicitCollectionDefForFieldNameMapper = wrapped; + getItemTypeForItemFieldNameMapper = wrapped; + getLocalConverterMapper = wrapped; + isIgnoredElementMapper = wrapped; + isImmutableValueTypeMapper = wrapped; + isReferenceableMapper = wrapped; + realClassMapper = wrapped; + realMemberMapper = wrapped; + serializedClassMapper = wrapped; + serializedMemberMapper = wrapped; + shouldSerializeMemberMapper = wrapped; + } + } - @Override - public String serializedClass(final Class type) { - return wrapped.serializedClass(type); + public String serializedClass(Class type) { + return serializedClassMapper.serializedClass(type); } - @Override - public Class realClass(final String elementName) { - return wrapped.realClass(elementName); + public Class realClass(String elementName) { + return realClassMapper.realClass(elementName); } - @Override - public String serializedMember(final Class type, final String memberName) { - return wrapped.serializedMember(type, memberName); + public String serializedMember(Class type, String memberName) { + return serializedMemberMapper.serializedMember(type, memberName); } - @Override - public String realMember(final Class type, final String serialized) { - return wrapped.realMember(type, serialized); + public String realMember(Class type, String serialized) { + return realMemberMapper.realMember(type, serialized); } - @Override - public boolean isImmutableValueType(final Class type) { - return wrapped.isImmutableValueType(type); + public boolean isImmutableValueType(Class type) { + return isImmutableValueTypeMapper.isImmutableValueType(type); } - @Override - public Class defaultImplementationOf(final Class type) { - return wrapped.defaultImplementationOf(type); + public boolean isReferenceable(Class type) { + return isReferenceableMapper.isReferenceable(type); } - @Override - public String aliasForAttribute(final String attribute) { - return wrapped.aliasForAttribute(attribute); + public Class defaultImplementationOf(Class type) { + return defaultImplementationOfMapper.defaultImplementationOf(type); } - @Override - public String attributeForAlias(final String alias) { - return wrapped.attributeForAlias(alias); + public String aliasForAttribute(String attribute) { + return aliasForAttributeMapper.aliasForAttribute(attribute); } - @Override - public String aliasForSystemAttribute(final String attribute) { - return wrapped.aliasForSystemAttribute(attribute); + public String attributeForAlias(String alias) { + return attributeForAliasMapper.attributeForAlias(alias); } - @Override - public String getFieldNameForItemTypeAndName(final Class definedIn, final Class itemType, - final String itemFieldName) { - return wrapped.getFieldNameForItemTypeAndName(definedIn, itemType, itemFieldName); + public String aliasForSystemAttribute(String attribute) { + return aliasForSystemAttributeMapper.aliasForSystemAttribute(attribute); } - @Override - public Class getItemTypeForItemFieldName(final Class definedIn, final String itemFieldName) { - return wrapped.getItemTypeForItemFieldName(definedIn, itemFieldName); + public String getFieldNameForItemTypeAndName(Class definedIn, Class itemType, String itemFieldName) { + return getFieldNameForItemTypeAndNameMapper.getFieldNameForItemTypeAndName(definedIn, itemType, itemFieldName); } - @Override - public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(final Class itemType, - final String fieldName) { - return wrapped.getImplicitCollectionDefForFieldName(itemType, fieldName); + public Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName) { + return getItemTypeForItemFieldNameMapper.getItemTypeForItemFieldName(definedIn, itemFieldName); } - @Override - public boolean shouldSerializeMember(final Class definedIn, final String fieldName) { - return wrapped.shouldSerializeMember(definedIn, fieldName); + public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(Class itemType, String fieldName) { + return getImplicitCollectionDefForFieldNameMapper.getImplicitCollectionDefForFieldName(itemType, fieldName); } - @Override - public Converter getLocalConverter(final Class definedIn, final String fieldName) { - return wrapped.getLocalConverter(definedIn, fieldName); + public boolean shouldSerializeMember(Class definedIn, String fieldName) { + return shouldSerializeMemberMapper.shouldSerializeMember(definedIn, fieldName); } + + public boolean isIgnoredElement(String name) { + return isIgnoredElementMapper.isIgnoredElement(name); + } - @Override - public T lookupMapperOfType(final Class type) { - @SuppressWarnings("unchecked") - final T t = type.isAssignableFrom(getClass()) ? (T)this : wrapped.lookupMapperOfType(type); - return t; + /** + * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)} + */ + public SingleValueConverter getConverterFromItemType(String fieldName, Class type) { + return getConverterFromItemTypeMapper.getConverterFromItemType(fieldName, type); } - @Override - public SingleValueConverter getConverterFromItemType(final String fieldName, final Class type, - final Class definedIn) { - return wrapped.getConverterFromItemType(fieldName, type, definedIn); + /** + * @deprecated As of 1.3, use {@link #getConverterFromItemType(String, Class, Class)} + */ + public SingleValueConverter getConverterFromItemType(Class type) { + return getConverterFromItemTypeMapper.getConverterFromItemType(type); } /** + * @deprecated As of 1.3, use {@link #getConverterFromAttribute(Class, String, Class)} + */ + public SingleValueConverter getConverterFromAttribute(String name) { + return getConverterFromAttributeMapper.getConverterFromAttribute(name); + } + + public Converter getLocalConverter(Class definedIn, String fieldName) { + return getLocalConverterMapper.getLocalConverter(definedIn, fieldName); + } + + public Mapper lookupMapperOfType(Class type) { + return type.isAssignableFrom(getClass()) ? this : wrapped.lookupMapperOfType(type); + } + + public SingleValueConverter getConverterFromItemType(String fieldName, Class type, Class definedIn) { + return getConverterFromItemTypeMapper.getConverterFromItemType(fieldName, type, definedIn); + } + + /** + * @deprecated As of 1.3, use combination of {@link #serializedMember(Class, String)} and + * {@link #getConverterFromItemType(String, Class, Class)} + */ + public String aliasForAttribute(Class definedIn, String fieldName) { + return aliasForAttributeMapper.aliasForAttribute(definedIn, fieldName); + } + + /** + * @deprecated As of 1.3, use combination of {@link #realMember(Class, String)} and + * {@link #getConverterFromItemType(String, Class, Class)} + */ + public String attributeForAlias(Class definedIn, String alias) { + return attributeForAliasMapper.attributeForAlias(definedIn, alias); + } + + /** * @deprecated As of 1.3.1, use {@link #getConverterFromAttribute(Class, String, Class)} */ - @Deprecated - @Override - public SingleValueConverter getConverterFromAttribute(final Class type, final String attribute) { - return wrapped.getConverterFromAttribute(type, attribute); + public SingleValueConverter getConverterFromAttribute(Class type, String attribute) { + return getConverterFromAttributeMapper.getConverterFromAttribute(type, attribute); } - @Override - public SingleValueConverter getConverterFromAttribute(final Class definedIn, final String attribute, - final Class type) { - return wrapped.getConverterFromAttribute(definedIn, attribute, type); + public SingleValueConverter getConverterFromAttribute(Class definedIn, String attribute, Class type) { + return getConverterFromAttributeMapper.getConverterFromAttribute(definedIn, attribute, type); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/OuterClassMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/OuterClassMapper.java (.../OuterClassMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/OuterClassMapper.java (.../OuterClassMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,49 +1,97 @@ /* * Copyright (C) 2005 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2015 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 31. January 2005 by Joe Walnes */ package com.thoughtworks.xstream.mapper; +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.thoughtworks.xstream.core.Caching; + + /** * Mapper that uses a more meaningful alias for the field in an inner class (this$0) that refers to the outer class. - * + * * @author Joe Walnes */ -public class OuterClassMapper extends MapperWrapper { +public class OuterClassMapper extends MapperWrapper implements Caching { + private static final String[] EMPTY_NAMES = new String[0]; private final String alias; + private final Map innerFields; - public OuterClassMapper(final Mapper wrapped) { + public OuterClassMapper(Mapper wrapped) { this(wrapped, "outer-class"); } - public OuterClassMapper(final Mapper wrapped, final String alias) { + public OuterClassMapper(Mapper wrapped, String alias) { super(wrapped); this.alias = alias; + innerFields = Collections.synchronizedMap(new HashMap()); + innerFields.put(Object.class.getName(), EMPTY_NAMES); } - @Override - public String serializedMember(final Class type, final String memberName) { - if (memberName.equals("this$0")) { - return alias; - } else { - return super.serializedMember(type, memberName); + public String serializedMember(Class type, String memberName) { + if (memberName.startsWith("this$")) { + final String[] innerFieldNames = getInnerFieldNames(type); + for (int i = 0; i < innerFieldNames.length; ++i) { + if (innerFieldNames[i].equals(memberName)) { + return i == 0 ? alias : alias + '-' + i; + } + } } + return super.serializedMember(type, memberName); } - @Override - public String realMember(final Class type, final String serialized) { - if (serialized.equals(alias)) { - return "this$0"; - } else { - return super.realMember(type, serialized); + public String realMember(Class type, String serialized) { + if (serialized.startsWith(alias)) { + int idx = -1; + final int len = alias.length(); + if (len == serialized.length()) { + idx = 0; + } else if (serialized.length() > len + 1 && serialized.charAt(len) == '-') { + idx = Integer.valueOf(serialized.substring(len + 1)).intValue(); + } + if (idx >= 0) { + final String[] innerFieldNames = getInnerFieldNames(type); + if (idx < innerFieldNames.length) { + return innerFieldNames[idx]; + } + } } + return super.realMember(type, serialized); } + + private String[] getInnerFieldNames(final Class type) { + String[] innerFieldNames = (String[])innerFields.get(type.getName()); + if (innerFieldNames == null) { + innerFieldNames = getInnerFieldNames(type.getSuperclass()); + Field[] declaredFields = type.getDeclaredFields(); + for (int i = 0; i < declaredFields.length; i++) { + final Field field = declaredFields[i]; + if (field.getName().startsWith("this$")) { + String[] temp = new String[innerFieldNames.length+1]; + System.arraycopy(innerFieldNames, 0, temp, 0, innerFieldNames.length); + innerFieldNames = temp; + innerFieldNames[innerFieldNames.length - 1] = field.getName(); + } + } + innerFields.put(type.getName(), innerFieldNames); + } + return innerFieldNames; + } + + public void flushCache() { + innerFields.keySet().retainAll(Collections.singletonList(Object.class.getName())); + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/PackageAliasingMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/PackageAliasingMapper.java (.../PackageAliasingMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/PackageAliasingMapper.java (.../PackageAliasingMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2014 XStream Committers. + * Copyright (C) 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -16,6 +16,7 @@ import java.io.Serializable; import java.util.Comparator; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import java.util.TreeMap; @@ -27,16 +28,15 @@ */ public class PackageAliasingMapper extends MapperWrapper implements Serializable { - private static final Comparator REVERSE = new Comparator() { + private static final Comparator REVERSE = new Comparator() { - @Override - public int compare(final String o1, final String o2) { - return o2.compareTo(o1); + public int compare(final Object o1, final Object o2) { + return ((String)o2).compareTo((String)o1); } }; - private Map packageToName = new TreeMap(REVERSE); - protected transient Map nameToPackage = new HashMap(); + private Map packageToName = new TreeMap(REVERSE); + protected transient Map nameToPackage = new HashMap(); public PackageAliasingMapper(final Mapper wrapped) { super(wrapped); @@ -53,15 +53,14 @@ packageToName.put(pkg, name); } - @Override - public String serializedClass(final Class type) { + public String serializedClass(final Class type) { final String className = type.getName(); int length = className.length(); int dot = -1; do { dot = className.lastIndexOf('.', length); final String pkg = dot < 0 ? "" : className.substring(0, dot + 1); - final String alias = packageToName.get(pkg); + final String alias = (String)packageToName.get(pkg); if (alias != null) { return alias + (dot < 0 ? className : className.substring(dot + 1)); } @@ -70,17 +69,17 @@ return super.serializedClass(type); } - @Override - public Class realClass(String elementName) { + public Class realClass(String elementName) { int length = elementName.length(); int dot = -1; do { dot = elementName.lastIndexOf('.', length); final String name = dot < 0 ? "" : elementName.substring(0, dot) + '.'; - final String packageName = nameToPackage.get(name); + final String packageName = (String)nameToPackage.get(name); if (packageName != null) { - elementName = packageName + (dot < 0 ? elementName : elementName.substring(dot + 1)); + elementName = packageName + + (dot < 0 ? elementName : elementName.substring(dot + 1)); break; } length = dot - 1; @@ -90,17 +89,17 @@ } private void writeObject(final ObjectOutputStream out) throws IOException { - out.writeObject(new HashMap(packageToName)); + out.writeObject(new HashMap(packageToName)); } - private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { - packageToName = new TreeMap(REVERSE); - @SuppressWarnings("unchecked") - final Map map = (Map)in.readObject(); - packageToName.putAll(map); - nameToPackage = new HashMap(); - for (final Map.Entry entry : packageToName.entrySet()) { - nameToPackage.put(entry.getValue(), entry.getKey()); + private void readObject(final ObjectInputStream in) + throws IOException, ClassNotFoundException { + packageToName = new TreeMap(REVERSE); + packageToName.putAll((Map)in.readObject()); + nameToPackage = new HashMap(); + for (final Iterator iter = packageToName.keySet().iterator(); iter.hasNext();) { + final Object type = iter.next(); + nameToPackage.put(packageToName.get(type), type); } } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/SecurityMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/SecurityMapper.java (.../SecurityMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/SecurityMapper.java (.../SecurityMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -25,7 +25,7 @@ */ public class SecurityMapper extends MapperWrapper { - private final List permissions; + private final List permissions; /** * Construct a SecurityMapper. @@ -44,11 +44,11 @@ * @param permissions the predefined permissions * @since 1.4.7 */ - public SecurityMapper(final Mapper wrapped, final TypePermission... permissions) { + public SecurityMapper(final Mapper wrapped, final TypePermission[] permissions) { super(wrapped); this.permissions = permissions == null // - ? new ArrayList() - : new ArrayList(Arrays.asList(permissions)); + ? new ArrayList() + : new ArrayList(Arrays.asList(permissions)); } /** @@ -62,19 +62,17 @@ * @since 1.4.7 */ public void addPermission(final TypePermission permission) { - if (permission.equals(NoTypePermission.NONE) || permission.equals(AnyTypePermission.ANY)) { + if (permission.equals(NoTypePermission.NONE) || permission.equals(AnyTypePermission.ANY)) permissions.clear(); - } permissions.add(0, permission); } - @Override - public Class realClass(final String elementName) { - final Class type = super.realClass(elementName); - for (final TypePermission permission : permissions) { - if (permission.allows(type)) { + public Class realClass(final String elementName) { + final Class type = super.realClass(elementName); + for (int i = 0; i < permissions.size(); ++i) { + final TypePermission permission = (TypePermission)permissions.get(i); + if (permission.allows(type)) return type; - } } throw new ForbiddenClassException(type); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/SystemAttributeAliasingMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/SystemAttributeAliasingMapper.java (.../SystemAttributeAliasingMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/SystemAttributeAliasingMapper.java (.../SystemAttributeAliasingMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2014 XStream Committers. + * Copyright (C) 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,6 +10,7 @@ */ package com.thoughtworks.xstream.mapper; + /** * Mapper that allows aliasing of system attribute names. * @@ -18,13 +19,12 @@ */ public class SystemAttributeAliasingMapper extends AbstractAttributeAliasingMapper { - public SystemAttributeAliasingMapper(final Mapper wrapped) { + public SystemAttributeAliasingMapper(Mapper wrapped) { super(wrapped); } - @Override - public String aliasForSystemAttribute(final String attribute) { - String alias = nameToAlias.get(attribute); + public String aliasForSystemAttribute(String attribute) { + String alias = (String)nameToAlias.get(attribute); if (alias == null && !nameToAlias.containsKey(attribute)) { alias = super.aliasForSystemAttribute(attribute); if (alias == attribute) { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/XStream11XmlFriendlyMapper.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/XStream11XmlFriendlyMapper.java (.../XStream11XmlFriendlyMapper.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/XStream11XmlFriendlyMapper.java (.../XStream11XmlFriendlyMapper.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2006, 2007, 2009, 2011, 2014 XStream Committers. + * Copyright (C) 2006, 2007, 2009, 2011 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,6 +11,7 @@ */ package com.thoughtworks.xstream.mapper; + /** * Mapper that ensures that all names in the serialization stream are read in an XML friendly way. *
        @@ -19,31 +20,29 @@ *
      • __ string appearing in field names are replaced with _ (underscore)
      • *
      • default is the prefix for class names with no package.
      • *
      - * Note, this class is no longer in regular use for current XStream versions. It exists to provide backward - * compatibility to existing XML data written with older XStream versions (<= 1.1). * + * Note, this class is no longer in regular use for current XStream versions. It exists to provide backward compatibility + * to existing XML data written with older XStream versions (<= 1.1). + * * @author Joe Walnes * @author Mauro Talevi * @deprecated As of 1.4 use {@link com.thoughtworks.xstream.io.xml.XmlFriendlyReader} */ -@Deprecated public class XStream11XmlFriendlyMapper extends AbstractXmlFriendlyMapper { - public XStream11XmlFriendlyMapper(final Mapper wrapped) { + public XStream11XmlFriendlyMapper(Mapper wrapped) { super(wrapped); } - @Override - public Class realClass(final String elementName) { + public Class realClass(String elementName) { return super.realClass(unescapeClassName(elementName)); } - @Override - public String realMember(final Class type, final String serialized) { + public String realMember(Class type, String serialized) { return unescapeFieldName(super.realMember(type, serialized)); } - public String mapNameFromXML(final String xmlName) { + public String mapNameFromXML(String xmlName) { return unescapeFieldName(xmlName); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/XmlFriendlyMapper.java =================================================================== diff -u --- 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/XmlFriendlyMapper.java (revision 0) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/mapper/XmlFriendlyMapper.java (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005, 2006 Joe Walnes. + * Copyright (C) 2006, 2007, 2008, 2009, 2011 XStream Committers. + * All rights reserved. + * + * The software in this package is published under the terms of the BSD + * style license a copy of which has been included with this distribution in + * the LICENSE.txt file. + * + * Created on 22. January 2005 by Joe Walnes + */ +package com.thoughtworks.xstream.mapper; + +/** + * Mapper that ensures that all names in the serialization stream are XML friendly. + * The replacement chars and strings are: + *
        + *
      • $ (dollar) chars appearing in class names are replaced with _ (underscore) chars.
      • + *
      • $ (dollar) chars appearing in field names are replaced with _DOLLAR_ string.
      • + *
      • _ (underscore) chars appearing in field names are replaced with __ (double underscore) string.
      • + *
      • default as the prefix for class names with no package.
      • + *
      + * + * @author Joe Walnes + * @author Mauro Talevi + * @deprecated As of 1.3 use {@link com.thoughtworks.xstream.io.xml.XmlFriendlyReader} + */ +public class XmlFriendlyMapper extends AbstractXmlFriendlyMapper { + + /** + * @deprecated As of 1.3 use {@link com.thoughtworks.xstream.io.xml.XmlFriendlyReader} + */ + public XmlFriendlyMapper(Mapper wrapped) { + super(wrapped); + } + + public String serializedClass(Class type) { + return escapeClassName(super.serializedClass(type)); + } + + public Class realClass(String elementName) { + return super.realClass(unescapeClassName(elementName)); + } + + public String serializedMember(Class type, String memberName) { + return escapeFieldName(super.serializedMember(type, memberName)); + } + + public String realMember(Class type, String serialized) { + return unescapeFieldName(super.realMember(type, serialized)); + } + + public String mapNameToXML(String javaName) { + return escapeFieldName(javaName); + } + + public String mapNameFromXML(String xmlName) { + return unescapeFieldName(xmlName); + } + +} Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/AbstractFilePersistenceStrategy.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/AbstractFilePersistenceStrategy.java (.../AbstractFilePersistenceStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/AbstractFilePersistenceStrategy.java (.../AbstractFilePersistenceStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2014 XStream Committers. + * Copyright (C) 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -10,6 +10,11 @@ */ package com.thoughtworks.xstream.persistence; +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.converters.ConverterLookup; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.mapper.Mapper; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -22,28 +27,25 @@ import java.io.Writer; import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.converters.ConverterLookup; -import com.thoughtworks.xstream.io.StreamException; -import com.thoughtworks.xstream.mapper.Mapper; - /** * Abstract base class for file based persistence strategies. * * @author Guilherme Silveira * @author Joerg Schaible * @since 1.3.1 */ -public abstract class AbstractFilePersistenceStrategy implements PersistenceStrategy { +public abstract class AbstractFilePersistenceStrategy implements PersistenceStrategy { private final FilenameFilter filter; private final File baseDirectory; private final String encoding; private final transient XStream xstream; - public AbstractFilePersistenceStrategy(final File baseDirectory, final XStream xstream, final String encoding) { + public AbstractFilePersistenceStrategy( + final File baseDirectory, final XStream xstream, final String encoding) { this.baseDirectory = baseDirectory; this.xstream = xstream; this.encoding = encoding; @@ -68,7 +70,7 @@ * @param name the filename * @return the original key */ - protected abstract K extractKey(String name); + protected abstract Object extractKey(String name); /** * Given a key, the escape method returns the filename which shall be used. @@ -79,26 +81,23 @@ protected abstract String getName(Object key); protected class ValidFilenameFilter implements FilenameFilter { - @Override public boolean accept(final File dir, final String name) { return new File(dir, name).isFile() && isValid(dir, name); } } - protected class XmlMapEntriesIterator implements Iterator> { + protected class XmlMapEntriesIterator implements Iterator { private final File[] files = baseDirectory.listFiles(filter); private int position = -1; private File current = null; - @Override public boolean hasNext() { return position + 1 < files.length; } - @Override public void remove() { if (current == null) { throw new IllegalStateException(); @@ -107,53 +106,38 @@ current.delete(); } - @Override - public Map.Entry next() { - return new Map.Entry() { - private final File file = current = files[++position]; - private final K key = extractKey(file.getName()); + public Object next() { + return new Map.Entry() { + private final File file = current = files[ ++position]; + private final Object key = extractKey(file.getName()); - @Override - public K getKey() { + public Object getKey() { return key; } - @Override - public V getValue() { + public Object getValue() { return readFile(file); } - @Override - public V setValue(final V value) { + public Object setValue(final Object value) { return put(key, value); } - @Override - public int hashCode() { - final V value = getValue(); - return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode()); - } - - @Override public boolean equals(final Object obj) { - if (!(obj instanceof Map.Entry)) { + if (!(obj instanceof Entry)) { return false; } - @SuppressWarnings("unchecked") - final Map.Entry e2 = (Map.Entry)obj; - final K key2 = e2.getKey(); - if (key == null ? key2 == null : key.equals(key2)) { - final V value = getValue(); - final V value2 = e2.getValue(); - return value == null ? value2 == null : value.equals(value2); - } - return false; + Object value = getValue(); + final Entry e2 = (Entry)obj; + Object key2 = e2.getKey(); + Object value2 = e2.getValue(); + return (key == null ? key2 == null : key.equals(key2)) + && (value == null ? value2 == null : getValue().equals(e2.getValue())); } }; } } - @SuppressWarnings("resource") private void writeFile(final File file, final Object value) { try { final FileOutputStream out = new FileOutputStream(file); @@ -174,15 +158,14 @@ return new File(baseDirectory, filename); } - @SuppressWarnings("resource") - private V readFile(final File file) { + private Object readFile(final File file) { try { final FileInputStream in = new FileInputStream(file); - final Reader reader = encoding != null ? new InputStreamReader(in, encoding) : new InputStreamReader(in); + final Reader reader = encoding != null + ? new InputStreamReader(in, encoding) + : new InputStreamReader(in); try { - @SuppressWarnings("unchecked") - final V value = (V)xstream.fromXML(reader); - return value; + return xstream.fromXML(reader); } finally { reader.close(); } @@ -194,40 +177,35 @@ } } - @Override - public V put(final K key, final V value) { - final V oldValue = get(key); + public Object put(final Object key, final Object value) { + final Object oldValue = get(key); final String filename = getName(key); writeFile(new File(baseDirectory, filename), value); return oldValue; } - @Override - public Iterator> iterator() { + public Iterator iterator() { return new XmlMapEntriesIterator(); } - @Override public int size() { return baseDirectory.list(filter).length; } - public boolean containsKey(final K key) { + public boolean containsKey(final Object key) { // faster lookup final File file = getFile(getName(key)); return file.isFile(); } - @Override - public V get(final Object key) { + public Object get(final Object key) { return readFile(getFile(getName(key))); } - @Override - public V remove(final Object key) { + public Object remove(final Object key) { // faster lookup final File file = getFile(getName(key)); - V value = null; + Object value = null; if (file.isFile()) { value = readFile(file); file.delete(); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/FilePersistenceStrategy.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/FilePersistenceStrategy.java (.../FilePersistenceStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/FilePersistenceStrategy.java (.../FilePersistenceStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,44 +1,42 @@ /* - * Copyright (C) 2008, 2014 XStream Committers. + * Copyright (C) 2008, 2016 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 20. November 2008 by Joerg Schaible */ package com.thoughtworks.xstream.persistence; import java.io.File; import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.converters.ConversionException; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.SingleValueConverter; -import com.thoughtworks.xstream.io.StreamException; import com.thoughtworks.xstream.io.xml.DomDriver; /** - * PersistenceStrategy to assign keys with single value to objects persisted in files. - *

      - * The default naming strategy is based on the key's type and its {@link SingleValueConverter}. It escapes all - * characters that are normally illegal in the most common file systems. Such a character is escaped with percent - * escaping as it is done by URL encoding. The XStream used to marshal the values is also requested for the key's - * SingleValueConverter. A {@link StreamException} is thrown if no such converter is registered. - *

      - * + * PersistenceStrategy to assign keys with single value to objects persisted in files. The default naming strategy is + * based on the key's type and its {@link SingleValueConverter}. It escapes all characters that are normally illegal in + * the most common file systems. Such a character is escaped with percent escaping as it is done by URL encoding. The + * XStream used to marshal the values is also requested for the key's SingleValueConverter. A + * {@link ConversionException} is thrown if no such converter is registered. + * * @author Jörg Schaible * @author Guilherme Silveira * @since 1.3.1 */ -public class FilePersistenceStrategy extends AbstractFilePersistenceStrategy { +public class FilePersistenceStrategy extends AbstractFilePersistenceStrategy { private final String illegalChars; /** * Create a new FilePersistenceStrategy. Use a standard XStream instance with a {@link DomDriver}. - * + * * @param baseDirectory the directory for the serialized values * @since 1.3.1 */ @@ -48,7 +46,7 @@ /** * Create a new FilePersistenceStrategy with a provided XStream instance. - * + * * @param baseDirectory the directory for the serialized values * @param xstream the XStream instance to use for (de)serialization * @since 1.3.1 @@ -59,7 +57,7 @@ /** * Create a new FilePersistenceStrategy with a provided XStream instance and the characters to encode. - * + * * @param baseDirectory the directory for the serialized values * @param xstream the XStream instance to use for (de)serialization * @param encoding encoding used to write the files @@ -73,41 +71,42 @@ this.illegalChars = illegalChars; } - @Override protected boolean isValid(final File dir, final String name) { return super.isValid(dir, name) && name.indexOf('@') > 0; } /** * Given a filename, the unescape method returns the key which originated it. - * + * * @param name the filename * @return the original key */ - @Override - protected K extractKey(final String name) { + protected Object extractKey(final String name) { final String key = unescape(name.substring(0, name.length() - 4)); if ("null@null".equals(key)) { return null; } final int idx = key.indexOf('@'); if (idx < 0) { - throw new StreamException("Not a valid key: " + key); + final ConversionException exception = new ConversionException("No valid key"); + exception.add("key", key); + throw exception; } - final Class type = getMapper().realClass(key.substring(0, idx)); + final Class type = getMapper().realClass(key.substring(0, idx)); final Converter converter = getConverterLookup().lookupConverterForType(type); if (converter instanceof SingleValueConverter) { final SingleValueConverter svConverter = (SingleValueConverter)converter; - @SuppressWarnings("unchecked") - final K k = (K)svConverter.fromString(key.substring(idx + 1)); - return k; + return svConverter.fromString(key.substring(idx + 1)); } else { - throw new StreamException("No SingleValueConverter for type " + type.getName() + " available"); + final ConversionException exception = new ConversionException( + "No SingleValueConverter available for key type"); + exception.add("key-type", type.getName()); + throw exception; } } protected String unescape(String name) { - final StringBuilder buffer = new StringBuilder(); + final StringBuffer buffer = new StringBuffer(); for (int idx = name.indexOf('%'); idx >= 0; idx = name.indexOf('%')) { buffer.append(name.substring(0, idx)); final int c = Integer.parseInt(name.substring(idx + 1, idx + 3), 16); @@ -120,29 +119,32 @@ /** * Given a key, the escape method returns the filename which shall be used. - * + * * @param key the key * @return the desired and escaped filename */ - @Override protected String getName(final Object key) { if (key == null) { return "null@null.xml"; } - final Class type = key.getClass(); + final Class type = key.getClass(); final Converter converter = getConverterLookup().lookupConverterForType(type); if (converter instanceof SingleValueConverter) { final SingleValueConverter svConverter = (SingleValueConverter)converter; return getMapper().serializedClass(type) + '@' + escape(svConverter.toString(key)) + ".xml"; } else { - throw new StreamException("No SingleValueConverter for type " + type.getName() + " available"); + final ConversionException exception = new ConversionException( + "No SingleValueConverter available for key type"); + exception.add("key-type", type.getName()); + throw exception; } } protected String escape(final String key) { - final StringBuilder buffer = new StringBuilder(); + final StringBuffer buffer = new StringBuffer(); final char[] array = key.toCharArray(); - for (final char c : array) { + for (int i = 0; i < array.length; i++ ) { + final char c = array[i]; if (c >= ' ' && illegalChars.indexOf(c) < 0) { buffer.append(c); } else { Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/FileStreamStrategy.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/FileStreamStrategy.java (.../FileStreamStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/FileStreamStrategy.java (.../FileStreamStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,26 +11,24 @@ */ package com.thoughtworks.xstream.persistence; -import java.io.File; - import com.thoughtworks.xstream.XStream; +import java.io.File; + /** - * PersistenceStrategy to assign string based keys to objects persisted in files. - *

      - * The file naming strategy is based on the key's type name and its toString method. It escapes non digit, non a-z and - * A-Z characters. In order to change the escaping/unescaping algorithm, simply extend this class and rewrite its - * getName/extractKey methods. Note, this implementation silently implies that the keys actually are Strings, since the - * keys will be turned into string keys at deserialization time. - *

      + * PersistenceStrategy to assign string based keys to objects persisted in files. The file + * naming strategy is based on the key's type name and its toString method. It escapes non + * digit, non a-z and A-Z characters. In order to change the escaping/unescaping algorithm, + * simply extend this class and rewrite its getName/extractKey methods. Note, this + * implementation silently implies that the keys actually are Strings, since the keys will be + * turned into string keys at deserialization time. * * @author Guilherme Silveira * @deprecated As of 1.3.1, use FilePersistenceStrategy */ -@Deprecated -public class FileStreamStrategy extends AbstractFilePersistenceStrategy implements - StreamStrategy { +public class FileStreamStrategy extends AbstractFilePersistenceStrategy implements + StreamStrategy { public FileStreamStrategy(final File baseDirectory) { this(baseDirectory, new XStream()); } @@ -45,19 +43,19 @@ * @param name the filename * @return the original key */ - @Override - protected String extractKey(final String name) { + protected Object extractKey(final String name) { final String key = unescape(name.substring(0, name.length() - 4)); return key.equals("\0") ? null : key; } protected String unescape(final String name) { - final StringBuilder buffer = new StringBuilder(); + final StringBuffer buffer = new StringBuffer(); char lastC = '\uffff'; int currentValue = -1; // do we have a regex master to do it? final char[] array = name.toCharArray(); - for (final char c : array) { + for (int i = 0; i < array.length; i++ ) { + final char c = array[i]; if (c == '_' && currentValue != -1) { if (lastC == '_') { buffer.append('_'); @@ -83,21 +81,22 @@ * @param key the key * @return the desired and escaped filename */ - @Override protected String getName(final Object key) { return escape(key == null ? "\0" : key.toString()) + ".xml"; } protected String escape(final String key) { - final StringBuilder buffer = new StringBuilder(); + // do we have a regex master to do it? + final StringBuffer buffer = new StringBuffer(); final char[] array = key.toCharArray(); - for (final char c : array) { - if (Character.isDigit(c) || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') { + for (int i = 0; i < array.length; i++ ) { + final char c = array[i]; + if (Character.isDigit(c) || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { buffer.append(c); } else if (c == '_') { buffer.append("__"); } else { - buffer.append("_" + Integer.toHexString(c) + "_"); + buffer.append("_" + (Integer.toHexString(c)) + "_"); } } return buffer.toString(); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/PersistenceStrategy.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/PersistenceStrategy.java (.../PersistenceStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/PersistenceStrategy.java (.../PersistenceStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2014 XStream Committers. + * Copyright (C) 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -11,7 +11,6 @@ package com.thoughtworks.xstream.persistence; import java.util.Iterator; -import java.util.Map; /** @@ -20,16 +19,16 @@ * @author Guilherme Silveira * @since 1.3.1 */ -public interface PersistenceStrategy { +public interface PersistenceStrategy { - Iterator> iterator(); + Iterator iterator(); int size(); - V get(Object key); + Object get(Object key); - V put(K key, V value); + Object put(Object key, Object value); - V remove(Object key); + Object remove(Object key); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/StreamStrategy.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/StreamStrategy.java (.../StreamStrategy.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/StreamStrategy.java (.../StreamStrategy.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2007, 2008, 2009, 2014 XStream Committers. + * Copyright (C) 2007, 2008, 2009 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -17,5 +17,5 @@ * @author Guilherme Silveira * @deprecated As of 1.3.1, use {@link PersistenceStrategy} instead */ -@Deprecated -public interface StreamStrategy extends PersistenceStrategy {} +public interface StreamStrategy extends PersistenceStrategy { +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/XmlArrayList.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/XmlArrayList.java (.../XmlArrayList.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/XmlArrayList.java (.../XmlArrayList.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2007, 2008, 2014 XStream Committers. + * Copyright (C) 2007, 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -13,69 +13,65 @@ import java.util.AbstractList; - /** * A persistent list implementation backed on a XmlMap. * * @author Guilherme Silveira */ -public class XmlArrayList extends AbstractList { +public class XmlArrayList extends AbstractList { - private final XmlMap map; + private final XmlMap map; - public XmlArrayList(final PersistenceStrategy persistenceStrategy) { - this.map = new XmlMap(persistenceStrategy); - } + public XmlArrayList(PersistenceStrategy persistenceStrategy) { + this.map = new XmlMap(persistenceStrategy); + } - @Override - public int size() { - return map.size(); - } + public int size() { + return map.size(); + } - @Override - public V set(final int index, final V element) { - rangeCheck(index); - final V value = get(index); - map.put(Integer.valueOf(index), element); - return value; - } + public Object set(int index, Object element) { + rangeCheck(index); + Object value = get(index); + map.put(new Integer(index), element); + return value; + } - @Override - public void add(final int index, final V element) { - final int size = size(); - if (index >= size + 1 || index < 0) { - throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); - } - final int to = index != size ? index - 1 : index; - for (int i = size; i > to; i--) { - map.put(Integer.valueOf(i + 1), map.get(Integer.valueOf(i))); - } - map.put(new Integer(index), element); - } + public void add(int index, Object element) { + int size = size(); + if (index >= (size + 1) || index < 0) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + + size); + } + int to = index != size ? index - 1 : index; + for (int i = size; i > to; i--) { + map.put(new Integer(i + 1), map.get(new Integer(i))); + } + map.put(new Integer(index), element); + } - private void rangeCheck(final int index) { - final int size = size(); - if (index >= size || index < 0) { - throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); - } - } + private void rangeCheck(int index) { + int size = size(); + if (index >= size || index < 0) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + + size); + } + } - @Override - public V get(final int index) { - rangeCheck(index); - return map.get(Integer.valueOf(index)); - } + public Object get(int index) { + rangeCheck(index); + return map.get(new Integer(index)); + } - @Override - public V remove(final int index) { - final int size = size(); - rangeCheck(index); - final V value = map.get(Integer.valueOf(index)); - for (int i = index; i < size - 1; i++) { - map.put(Integer.valueOf(i), map.get(Integer.valueOf(i + 1))); - } - map.remove(Integer.valueOf(size - 1)); - return value; - } + public Object remove(int index) { + int size = size(); + rangeCheck(index); + Object value = map.get(new Integer(index)); + for (int i = index; i < size - 1; i++) { + map.put(new Integer(i), map.get(new Integer(i + 1))); + } + map.remove(new Integer(size - 1)); + return value; + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/XmlMap.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/XmlMap.java (.../XmlMap.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/XmlMap.java (.../XmlMap.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2007, 2008, 2014 XStream Committers. + * Copyright (C) 2007, 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,69 +14,58 @@ import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Iterator; -import java.util.Map; import java.util.Set; - /** - * A persistent map. Its values are actually serialized as xml files. - *

      - * If you need an application-wide synchronized version of this map, try the respective Collections methods. - *

      + * A persistent map. Its values are actually serialized as xml files. If you + * need an application-wide synchronized version of this map, try the respective + * Collections methods. * * @author Guilherme Silveira */ -public class XmlMap extends AbstractMap { +public class XmlMap extends AbstractMap { - private final PersistenceStrategy persistenceStrategy; + private final PersistenceStrategy persistenceStrategy; - public XmlMap(final PersistenceStrategy streamStrategy) { - this.persistenceStrategy = streamStrategy; - } + public XmlMap(PersistenceStrategy streamStrategy) { + this.persistenceStrategy = streamStrategy; + } - @Override - public int size() { - return persistenceStrategy.size(); - } + public int size() { + return persistenceStrategy.size(); + } - @Override - public V get(final Object key) { - // faster lookup - return persistenceStrategy.get(key); - } + public Object get(Object key) { + // faster lookup + return persistenceStrategy.get(key); + } - @Override - public V put(final K key, final V value) { - return persistenceStrategy.put(key, value); - } + public Object put(Object key, Object value) { + return persistenceStrategy.put(key,value); + } - @Override - public V remove(final Object key) { - return persistenceStrategy.remove(key); - } + public Object remove(Object key) { + return persistenceStrategy.remove(key); + } - @Override - public Set> entrySet() { - return new XmlMapEntries(); - } + public Set entrySet() { + return new XmlMapEntries(); + } - class XmlMapEntries extends AbstractSet> { + class XmlMapEntries extends AbstractSet { - @Override - public int size() { - return XmlMap.this.size(); - } + public int size() { + return XmlMap.this.size(); + } - @Override - public boolean isEmpty() { - return XmlMap.this.isEmpty(); - } + public boolean isEmpty() { + return XmlMap.this.isEmpty(); + } - @Override - public Iterator> iterator() { - return persistenceStrategy.iterator(); - } + public Iterator iterator() { + return persistenceStrategy.iterator(); + } - } + } -} +} \ No newline at end of file Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/XmlSet.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/XmlSet.java (.../XmlSet.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/persistence/XmlSet.java (.../XmlSet.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Joe Walnes. - * Copyright (C) 2007, 2008, 2014 XStream Committers. + * Copyright (C) 2007, 2008 XStream Committers. * All rights reserved. * * The software in this package is published under the terms of the BSD @@ -14,47 +14,43 @@ import java.util.AbstractSet; import java.util.Iterator; - /** * A persistent set implementation. * * @author Guilherme Silveira */ -public class XmlSet extends AbstractSet { +public class XmlSet extends AbstractSet { - private final XmlMap map; + private final XmlMap map; - public XmlSet(final PersistenceStrategy persistenceStrategy) { - this.map = new XmlMap(persistenceStrategy); - } + public XmlSet(PersistenceStrategy persistenceStrategy) { + this.map = new XmlMap(persistenceStrategy); + } - @Override - public Iterator iterator() { - return map.values().iterator(); - } + public Iterator iterator() { + return map.values().iterator(); + } - @Override - public int size() { - return map.size(); - } + public int size() { + return map.size(); + } - @Override - public boolean add(final V o) { - if (map.containsValue(o)) { - return false; - } else { - // not-synchronized! - map.put(findEmptyKey(), o); - return true; - } - } + public boolean add(Object o) { + if (map.containsValue(o)) { + return false; + } else { + // not-synchronized! + map.put(findEmptyKey(), o); + return true; + } + } - private Long findEmptyKey() { - long i = System.currentTimeMillis(); - while (map.containsKey(Long.valueOf(i))) { - i++; - } - return Long.valueOf(i); - } + private Long findEmptyKey() { + long i = System.currentTimeMillis(); + while (map.containsKey(new Long(i))) { + i++; + } + return new Long(i); + } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/AnyTypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/AnyTypePermission.java (.../AnyTypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/AnyTypePermission.java (.../AnyTypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -18,17 +18,14 @@ */ public static final TypePermission ANY = new AnyTypePermission(); - @Override - public boolean allows(Class type) { + public boolean allows(Class type) { return true; } - @Override public int hashCode() { return 3; } - @Override public boolean equals(Object obj) { return obj != null && obj.getClass() == AnyTypePermission.class; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ArrayTypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ArrayTypePermission.java (.../ArrayTypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ArrayTypePermission.java (.../ArrayTypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -18,17 +18,14 @@ */ public static final TypePermission ARRAYS = new ArrayTypePermission(); - @Override - public boolean allows(Class type) { + public boolean allows(Class type) { return type != null && type.isArray(); } - @Override public int hashCode() { return 13; } - @Override public boolean equals(Object obj) { return obj != null && obj.getClass() == ArrayTypePermission.class; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/CGLIBProxyTypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/CGLIBProxyTypePermission.java (.../CGLIBProxyTypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/CGLIBProxyTypePermission.java (.../CGLIBProxyTypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -21,18 +21,15 @@ */ public static final TypePermission PROXIES = new CGLIBProxyTypePermission(); - @Override - public boolean allows(final Class type) { + public boolean allows(final Class type) { return type != null && type != Object.class && !type.isInterface() && (Proxy.isProxyClass(type) || type.getName().startsWith(Proxy.class.getPackage().getName() + ".")); } - @Override public int hashCode() { return 19; } - @Override public boolean equals(final Object obj) { return obj != null && obj.getClass() == CGLIBProxyTypePermission.class; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ExplicitTypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ExplicitTypePermission.java (.../ExplicitTypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ExplicitTypePermission.java (.../ExplicitTypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -20,12 +20,12 @@ */ public class ExplicitTypePermission implements TypePermission { - final Set names; + final Set names; /** * @since 1.4.7 */ - public ExplicitTypePermission(final Class... types) { + public ExplicitTypePermission(final Class[] types) { this(new Object() { public String[] getNames() { if (types == null) @@ -41,12 +41,11 @@ /** * @since 1.4.7 */ - public ExplicitTypePermission(String... names) { - this.names = names == null ? Collections.emptySet() : new HashSet(Arrays.asList(names)); + public ExplicitTypePermission(String[] names) { + this.names = names == null ? Collections.EMPTY_SET : new HashSet(Arrays.asList(names)); } - @Override - public boolean allows(Class type) { + public boolean allows(Class type) { if (type == null) return false; return names.contains(type.getName()); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ForbiddenClassException.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ForbiddenClassException.java (.../ForbiddenClassException.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ForbiddenClassException.java (.../ForbiddenClassException.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -21,7 +21,7 @@ * @param type the forbidden class * @since 1.4.7 */ - public ForbiddenClassException(Class type) { + public ForbiddenClassException(Class type) { super(type == null ? "null" : type.getName()); } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/InterfaceTypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/InterfaceTypePermission.java (.../InterfaceTypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/InterfaceTypePermission.java (.../InterfaceTypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -18,17 +18,14 @@ */ public static final TypePermission INTERFACES = new InterfaceTypePermission(); - @Override - public boolean allows(Class type) { + public boolean allows(Class type) { return type != null && type.isInterface(); } - @Override public int hashCode() { return 31; } - @Override public boolean equals(Object obj) { return obj != null && obj.getClass() == InterfaceTypePermission.class; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/NoPermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/NoPermission.java (.../NoPermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/NoPermission.java (.../NoPermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -30,8 +30,7 @@ this.permission = permission; } - @Override - public boolean allows(final Class type) { + public boolean allows(final Class type) { if (permission == null || permission.allows(type)) { throw new ForbiddenClassException(type); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/NoTypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/NoTypePermission.java (.../NoTypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/NoTypePermission.java (.../NoTypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -22,17 +22,14 @@ */ public static final TypePermission NONE = new NoTypePermission(); - @Override - public boolean allows(Class type) { + public boolean allows(Class type) { throw new ForbiddenClassException(type); } - @Override public int hashCode() { return 1; } - @Override public boolean equals(Object obj) { return obj != null && obj.getClass() == NoTypePermission.class; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/NullPermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/NullPermission.java (.../NullPermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/NullPermission.java (.../NullPermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -20,8 +20,7 @@ */ public static final TypePermission NULL = new NullPermission(); - @Override - public boolean allows(Class type) { + public boolean allows(Class type) { return type == null || type == Mapper.Null.class; } } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/PrimitiveTypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/PrimitiveTypePermission.java (.../PrimitiveTypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/PrimitiveTypePermission.java (.../PrimitiveTypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 XStream Committers. + * Copyright (C) 2014, 2017 XStream Committers. * All rights reserved. * * Created on 09. January 2014 by Joerg Schaible @@ -8,8 +8,9 @@ import com.thoughtworks.xstream.core.util.Primitives; + /** - * Permission for any primitive type and its boxed counterpart (incl. void). + * Permission for any primitive type and its boxed counterpart (excl. void). * * @author Jörg Schaible * @since 1.4.7 @@ -20,17 +21,15 @@ */ public static final TypePermission PRIMITIVES = new PrimitiveTypePermission(); - @Override - public boolean allows(Class type) { - return type != null && type.isPrimitive() || Primitives.isBoxed(type); + public boolean allows(Class type) { + return type != null && type != void.class && type != Void.class && type.isPrimitive() + || Primitives.isBoxed(type); } - @Override public int hashCode() { return 7; } - @Override public boolean equals(Object obj) { return obj != null && obj.getClass() == PrimitiveTypePermission.class; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ProxyTypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ProxyTypePermission.java (.../ProxyTypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/ProxyTypePermission.java (.../ProxyTypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -23,17 +23,14 @@ */ public static final TypePermission PROXIES = new ProxyTypePermission(); - @Override - public boolean allows(final Class type) { + public boolean allows(final Class type) { return type != null && (Proxy.isProxyClass(type) || type == DynamicProxyMapper.DynamicProxy.class); } - @Override public int hashCode() { return 17; } - @Override public boolean equals(final Object obj) { return obj != null && obj.getClass() == ProxyTypePermission.class; } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/RegExpTypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/RegExpTypePermission.java (.../RegExpTypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/RegExpTypePermission.java (.../RegExpTypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -19,26 +19,25 @@ private final Pattern[] patterns; - public RegExpTypePermission(final String... patterns) { + public RegExpTypePermission(final String[] patterns) { this(getPatterns(patterns)); } - public RegExpTypePermission(final Pattern... patterns) { + public RegExpTypePermission(final Pattern[] patterns) { this.patterns = patterns == null ? new Pattern[0] : patterns; } - @Override - public boolean allows(final Class type) { + public boolean allows(final Class type) { if (type != null) { final String name = type.getName(); - for (final Pattern pattern : patterns) - if (pattern.matcher(name).matches()) + for (int i = 0; i < patterns.length; ++i) + if (patterns[i].matcher(name).matches()) return true; } return false; } - private static Pattern[] getPatterns(final String... patterns) { + private static Pattern[] getPatterns(final String[] patterns) { if (patterns == null) return null; final Pattern[] array = new Pattern[patterns.length]; Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/TypeHierarchyPermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/TypeHierarchyPermission.java (.../TypeHierarchyPermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/TypeHierarchyPermission.java (.../TypeHierarchyPermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -14,17 +14,16 @@ */ public class TypeHierarchyPermission implements TypePermission { - private Class type; + private Class type; /** * @since 1.4.7 */ - public TypeHierarchyPermission(Class type) { + public TypeHierarchyPermission(Class type) { this.type = type; } - @Override - public boolean allows(Class type) { + public boolean allows(Class type) { if (type == null) return false; return this.type.isAssignableFrom(type); Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/TypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/TypePermission.java (.../TypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/TypePermission.java (.../TypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -21,5 +21,5 @@ * @throws ForbiddenClassException if provided type is explicitly forbidden * @since 1.4.7 */ - boolean allows(Class type); + boolean allows(Class type); } Index: 3rdParty_sources/xstream/com/thoughtworks/xstream/security/WildcardTypePermission.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re22799e3f19d9b43efda2fcad687abb2e111fa81 --- 3rdParty_sources/xstream/com/thoughtworks/xstream/security/WildcardTypePermission.java (.../WildcardTypePermission.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ 3rdParty_sources/xstream/com/thoughtworks/xstream/security/WildcardTypePermission.java (.../WildcardTypePermission.java) (revision e22799e3f19d9b43efda2fcad687abb2e111fa81) @@ -29,17 +29,17 @@ /** * @since 1.4.7 */ - public WildcardTypePermission(final String... patterns) { + public WildcardTypePermission(final String[] patterns) { super(getRegExpPatterns(patterns)); } - private static String[] getRegExpPatterns(final String... wildcards) { + private static String[] getRegExpPatterns(final String[] wildcards) { if (wildcards == null) return null; final String[] regexps = new String[wildcards.length]; for (int i = 0; i < wildcards.length; ++i) { final String wildcardExpression = wildcards[i]; - final StringBuilder result = new StringBuilder(wildcardExpression.length() * 2); + final StringBuffer result = new StringBuffer(wildcardExpression.length() * 2); result.append("(?u)"); final int length = wildcardExpression.length(); for (int j = 0; j < length; j++) { Index: lams_build/lib/xstream/xstream-1.4.10.jar =================================================================== diff -u Binary files differ