Polishing

This commit is contained in:
Juergen Hoeller
2018-02-13 14:20:07 +01:00
parent f93ca28884
commit 0030ff8711
12 changed files with 83 additions and 62 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -24,14 +24,14 @@ import org.springframework.util.Assert;
/**
* The purpose of this class is to enable capturing and passing a generic
* {@link Type}. In order to capture the generic type and retain it at runtime,
* you need to create a subclass as follows:
* you need to create a subclass (ideally as anonymous inline class) as follows:
*
* <pre class="code">
* ParameterizedTypeReference&lt;List&lt;String&gt;&gt; typeRef = new ParameterizedTypeReference&lt;List&lt;String&gt;&gt;() {};
* </pre>
*
* <p>The resulting {@code typeReference} instance can then be used to obtain a
* {@link Type} instance that carries parameterized type information.
* <p>The resulting {@code typeRef} instance can then be used to obtain a {@link Type}
* instance that carries the captured parameterized type information at runtime.
* For more information on "super type tokens" see the link to Neal Gafter's blog post.
*
* @author Arjen Poutsma
@@ -49,8 +49,9 @@ public abstract class ParameterizedTypeReference<T> {
Type type = parameterizedTypeReferenceSubclass.getGenericSuperclass();
Assert.isInstanceOf(ParameterizedType.class, type, "Type must be a parameterized type");
ParameterizedType parameterizedType = (ParameterizedType) type;
Assert.isTrue(parameterizedType.getActualTypeArguments().length == 1, "Number of type arguments must be 1");
this.type = parameterizedType.getActualTypeArguments()[0];
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
Assert.isTrue(actualTypeArguments.length == 1, "Number of type arguments must be 1");
this.type = actualTypeArguments[0];
}
private ParameterizedTypeReference(Type type) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 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.
@@ -22,8 +22,8 @@ import javax.xml.transform.Transformer;
import org.springframework.util.Assert;
/**
* Contains common behavior relating to {@link javax.xml.transform.Transformer Transformers}, and the
* {@code javax.xml.transform} package in general.
* Contains common behavior relating to {@link javax.xml.transform.Transformer Transformers}
* and the {@code javax.xml.transform} package in general.
*
* @author Rick Evans
* @author Juergen Hoeller
@@ -32,16 +32,16 @@ import org.springframework.util.Assert;
public abstract class TransformerUtils {
/**
* The indent amount of characters if {@link #enableIndenting(javax.xml.transform.Transformer) indenting is enabled}.
* The indent amount of characters if {@link #enableIndenting indenting is enabled}.
* <p>Defaults to "2".
*/
public static final int DEFAULT_INDENT_AMOUNT = 2;
/**
* Enable indenting for the supplied {@link javax.xml.transform.Transformer}. <p>If the underlying XSLT engine is
* Xalan, then the special output key {@code indent-amount} will be also be set to a value of {@link
* #DEFAULT_INDENT_AMOUNT} characters.
*
* Enable indenting for the supplied {@link javax.xml.transform.Transformer}.
* <p>If the underlying XSLT engine is Xalan, then the special output key {@code indent-amount}
* will be also be set to a value of {@link #DEFAULT_INDENT_AMOUNT} characters.
* @param transformer the target transformer
* @see javax.xml.transform.Transformer#setOutputProperty(String, String)
* @see javax.xml.transform.OutputKeys#INDENT
@@ -51,10 +51,9 @@ public abstract class TransformerUtils {
}
/**
* Enable indenting for the supplied {@link javax.xml.transform.Transformer}. <p>If the underlying XSLT engine is
* Xalan, then the special output key {@code indent-amount} will be also be set to a value of {@link
* #DEFAULT_INDENT_AMOUNT} characters.
*
* Enable indenting for the supplied {@link javax.xml.transform.Transformer}.
* <p>If the underlying XSLT engine is Xalan, then the special output key {@code indent-amount}
* will be also be set to a value of {@link #DEFAULT_INDENT_AMOUNT} characters.
* @param transformer the target transformer
* @param indentAmount the size of the indent (2 characters, 3 characters, etc.)
* @see javax.xml.transform.Transformer#setOutputProperty(String, String)
@@ -62,7 +61,9 @@ public abstract class TransformerUtils {
*/
public static void enableIndenting(Transformer transformer, int indentAmount) {
Assert.notNull(transformer, "Transformer must not be null");
Assert.isTrue(indentAmount > -1, "The indent amount cannot be less than zero : got " + indentAmount);
if (indentAmount < 0) {
throw new IllegalArgumentException("The indent amount cannot be less than zero : got " + indentAmount);
}
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
try {
// Xalan-specific, but this is the most common XSLT engine in any case
@@ -74,7 +75,6 @@ public abstract class TransformerUtils {
/**
* Disable indenting for the supplied {@link javax.xml.transform.Transformer}.
*
* @param transformer the target transformer
* @see javax.xml.transform.OutputKeys#INDENT
*/