Skip to content

Commit

Permalink
Removed unused XStreamUtils class; direct access to the xstream field…
Browse files Browse the repository at this point in the history
… in XStreamMarshaller
  • Loading branch information
jhoeller committed Feb 10, 2013
1 parent 6a2ace7 commit 9e9cdf5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -114,7 +114,7 @@ public class XStreamMarshaller extends AbstractMarshaller implements Initializin
/**
* Returns the XStream instance used by this marshaller.
*/
public XStream getXStream() {
public final XStream getXStream() {
return this.xstream;
}

Expand All @@ -125,7 +125,7 @@ public XStream getXStream() {
* @see XStream#NO_REFERENCES
*/
public void setMode(int mode) {
this.getXStream().setMode(mode);
this.xstream.setMode(mode);
}

/**
Expand All @@ -137,10 +137,10 @@ public void setMode(int mode) {
public void setConverters(ConverterMatcher[] converters) {
for (int i = 0; i < converters.length; i++) {
if (converters[i] instanceof Converter) {
this.getXStream().registerConverter((Converter) converters[i], i);
this.xstream.registerConverter((Converter) converters[i], i);
}
else if (converters[i] instanceof SingleValueConverter) {
this.getXStream().registerConverter((SingleValueConverter) converters[i], i);
this.xstream.registerConverter((SingleValueConverter) converters[i], i);
}
else {
throw new IllegalArgumentException("Invalid ConverterMatcher [" + converters[i] + "]");
Expand All @@ -155,9 +155,8 @@ else if (converters[i] instanceof SingleValueConverter) {
*/
public void setAliases(Map<String, ?> aliases) throws ClassNotFoundException {
Map<String, Class<?>> classMap = toClassMap(aliases);

for (Map.Entry<String, Class<?>> entry : classMap.entrySet()) {
this.getXStream().alias(entry.getKey(), entry.getValue());
this.xstream.alias(entry.getKey(), entry.getValue());
}
}

Expand All @@ -169,15 +168,13 @@ public void setAliases(Map<String, ?> aliases) throws ClassNotFoundException {
*/
public void setAliasesByType(Map<String, ?> aliases) throws ClassNotFoundException {
Map<String, Class<?>> classMap = toClassMap(aliases);

for (Map.Entry<String, Class<?>> entry : classMap.entrySet()) {
this.getXStream().aliasType(entry.getKey(), entry.getValue());
this.xstream.aliasType(entry.getKey(), entry.getValue());
}
}

private Map<String, Class<?>> toClassMap(Map<String, ?> map) throws ClassNotFoundException {
Map<String, Class<?>> result = new LinkedHashMap<String, Class<?>>(map.size());

for (Map.Entry<String, ?> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
Expand All @@ -198,10 +195,7 @@ else if (value instanceof String) {
}

/**
* Sets a field alias/type map, consiting of field names
* @param aliases
* @throws ClassNotFoundException
* @throws NoSuchFieldException
* Set a field alias/type map, consiting of field names.
* @see XStream#aliasField(String, Class, String)
*/
public void setFieldAliases(Map<String, String> aliases) throws ClassNotFoundException, NoSuchFieldException {
Expand All @@ -213,8 +207,9 @@ public void setFieldAliases(Map<String, String> aliases) throws ClassNotFoundExc
String className = field.substring(0, idx);
Class clazz = ClassUtils.forName(className, classLoader);
String fieldName = field.substring(idx + 1);
this.getXStream().aliasField(alias, clazz, fieldName);
} else {
this.xstream.aliasField(alias, clazz, fieldName);
}
else {
throw new IllegalArgumentException("Field name [" + field + "] does not contain '.'");
}
}
Expand All @@ -226,7 +221,7 @@ public void setFieldAliases(Map<String, String> aliases) throws ClassNotFoundExc
*/
public void setUseAttributeForTypes(Class[] types) {
for (Class type : types) {
this.getXStream().useAttributeFor(type);
this.xstream.useAttributeFor(type);
}
}

Expand All @@ -242,7 +237,7 @@ public void setUseAttributeFor(Map<?, ?> attributes) {
for (Map.Entry<?, ?> entry : attributes.entrySet()) {
if (entry.getKey() instanceof String) {
if (entry.getValue() instanceof Class) {
this.getXStream().useAttributeFor((String) entry.getKey(), (Class) entry.getValue());
this.xstream.useAttributeFor((String) entry.getKey(), (Class) entry.getValue());
}
else {
throw new IllegalArgumentException(
Expand All @@ -253,14 +248,14 @@ public void setUseAttributeFor(Map<?, ?> attributes) {
else if (entry.getKey() instanceof Class) {
Class<?> key = (Class<?>) entry.getKey();
if (entry.getValue() instanceof String) {
this.getXStream().useAttributeFor(key, (String) entry.getValue());
this.xstream.useAttributeFor(key, (String) entry.getValue());
}
else if (entry.getValue() instanceof List) {
List list = (List) entry.getValue();

for (Object o : list) {
if (o instanceof String) {
this.getXStream().useAttributeFor(key, (String) o);
this.xstream.useAttributeFor(key, (String) o);
}
}
}
Expand All @@ -286,7 +281,7 @@ public void setImplicitCollections(Map<Class<?>, String> implicitCollections) {
for (Map.Entry<Class<?>, String> entry : implicitCollections.entrySet()) {
String[] collectionFields = StringUtils.commaDelimitedListToStringArray(entry.getValue());
for (String collectionField : collectionFields) {
this.getXStream().addImplicitCollection(entry.getKey(), collectionField);
this.xstream.addImplicitCollection(entry.getKey(), collectionField);
}
}
}
Expand All @@ -300,7 +295,7 @@ public void setOmittedFields(Map<Class<?>, String> omittedFields) {
for (Map.Entry<Class<?>, String> entry : omittedFields.entrySet()) {
String[] fields = StringUtils.commaDelimitedListToStringArray(entry.getValue());
for (String field : fields) {
this.getXStream().omitField(entry.getKey(), field);
this.xstream.omitField(entry.getKey(), field);
}
}
}
Expand All @@ -311,7 +306,7 @@ public void setOmittedFields(Map<Class<?>, String> omittedFields) {
*/
public void setAnnotatedClass(Class<?> annotatedClass) {
Assert.notNull(annotatedClass, "'annotatedClass' must not be null");
this.getXStream().processAnnotations(annotatedClass);
this.xstream.processAnnotations(annotatedClass);
}

/**
Expand All @@ -320,7 +315,7 @@ public void setAnnotatedClass(Class<?> annotatedClass) {
*/
public void setAnnotatedClasses(Class<?>[] annotatedClasses) {
Assert.notEmpty(annotatedClasses, "'annotatedClasses' must not be empty");
this.getXStream().processAnnotations(annotatedClasses);
this.xstream.processAnnotations(annotatedClasses);
}

/**
Expand All @@ -330,7 +325,7 @@ public void setAnnotatedClasses(Class<?>[] annotatedClasses) {
* @see XStream#autodetectAnnotations(boolean)
*/
public void setAutodetectAnnotations(boolean autodetectAnnotations) {
this.getXStream().autodetectAnnotations(autodetectAnnotations);
this.xstream.autodetectAnnotations(autodetectAnnotations);
}

/**
Expand Down Expand Up @@ -363,7 +358,7 @@ public void setBeanClassLoader(ClassLoader classLoader) {


public final void afterPropertiesSet() throws Exception {
customizeXStream(getXStream());
customizeXStream(this.xstream);
}

/**
Expand Down Expand Up @@ -458,7 +453,7 @@ protected void marshalWriter(Object graph, Writer writer) throws XmlMappingExcep
*/
private void marshal(Object graph, HierarchicalStreamWriter streamWriter) {
try {
getXStream().marshal(graph, streamWriter);
this.xstream.marshal(graph, streamWriter);
}
catch (Exception ex) {
throw convertXStreamException(ex, true);
Expand Down Expand Up @@ -541,7 +536,7 @@ protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource
*/
private Object unmarshal(HierarchicalStreamReader streamReader) {
try {
return getXStream().unmarshal(streamReader);
return this.xstream.unmarshal(streamReader);
}
catch (Exception ex) {
throw convertXStreamException(ex, false);
Expand Down Expand Up @@ -574,4 +569,5 @@ protected XmlMappingException convertXStreamException(Exception ex, boolean mars
return new UncategorizedMappingException("Unknown XStream exception", ex);
}
}

}

This file was deleted.

0 comments on commit 9e9cdf5

Please sign in to comment.