Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Feb 12, 2020
1 parent f536819 commit ebd2ec5
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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 @@ -748,8 +748,7 @@ private class DeferredImportSelectorHandler {
* @param importSelector the selector to handle
*/
public void handle(ConfigurationClass configClass, DeferredImportSelector importSelector) {
DeferredImportSelectorHolder holder = new DeferredImportSelectorHolder(
configClass, importSelector);
DeferredImportSelectorHolder holder = new DeferredImportSelectorHolder(configClass, importSelector);
if (this.deferredImportSelectors == null) {
DeferredImportSelectorGroupingHandler handler = new DeferredImportSelectorGroupingHandler();
handler.register(holder);
Expand All @@ -775,7 +774,6 @@ public void process() {
this.deferredImportSelectors = new ArrayList<>();
}
}

}


Expand All @@ -786,8 +784,7 @@ private class DeferredImportSelectorGroupingHandler {
private final Map<AnnotationMetadata, ConfigurationClass> configurationClasses = new HashMap<>();

public void register(DeferredImportSelectorHolder deferredImport) {
Class<? extends Group> group = deferredImport.getImportSelector()
.getImportGroup();
Class<? extends Group> group = deferredImport.getImportSelector().getImportGroup();
DeferredImportSelectorGrouping grouping = this.groupings.computeIfAbsent(
(group != null ? group : deferredImport),
key -> new DeferredImportSelectorGrouping(createGroup(group)));
Expand All @@ -799,8 +796,7 @@ public void register(DeferredImportSelectorHolder deferredImport) {
public void processGroupImports() {
for (DeferredImportSelectorGrouping grouping : this.groupings.values()) {
grouping.getImports().forEach(entry -> {
ConfigurationClass configurationClass = this.configurationClasses.get(
entry.getMetadata());
ConfigurationClass configurationClass = this.configurationClasses.get(entry.getMetadata());
try {
processImports(configurationClass, asSourceClass(configurationClass),
asSourceClasses(entry.getImportClassName()), false);
Expand All @@ -818,16 +814,14 @@ public void processGroupImports() {
}

private Group createGroup(@Nullable Class<? extends Group> type) {
Class<? extends Group> effectiveType = (type != null ? type
: DefaultDeferredImportSelectorGroup.class);
Class<? extends Group> effectiveType = (type != null ? type : DefaultDeferredImportSelectorGroup.class);
Group group = BeanUtils.instantiateClass(effectiveType);
ParserStrategyUtils.invokeAwareMethods(group,
ConfigurationClassParser.this.environment,
ConfigurationClassParser.this.resourceLoader,
ConfigurationClassParser.this.registry);
return group;
}

}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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 @@ -51,6 +51,7 @@ default Class<? extends Group> getImportGroup() {

/**
* Interface used to group results from different import selectors.
* @since 5.0
*/
interface Group {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2020 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 @@ -50,6 +50,7 @@ public interface ImportSelector {
/**
* Select and return the names of which class(es) should be imported based on
* the {@link AnnotationMetadata} of the importing @{@link Configuration} class.
* @return the class names, or an empty array if none
*/
String[] selectImports(AnnotationMetadata importingClassMetadata);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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 @@ -530,9 +530,10 @@ static void cleanup() {
static Map<String, List<String>> allImports() {
return TestImportGroup.imports.entrySet()
.stream()
.collect(Collectors.toMap((entry) -> entry.getKey().getClassName(),
.collect(Collectors.toMap(entry -> entry.getKey().getClassName(),
Map.Entry::getValue));
}

private final List<Entry> instanceImports = new ArrayList<>();

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2020 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 @@ -52,10 +52,10 @@ public static void execute(DatabasePopulator populator, DataSource dataSource) t
DataSourceUtils.releaseConnection(connection, dataSource);
}
}
catch (ScriptException ex) {
throw ex;
}
catch (Throwable ex) {
if (ex instanceof ScriptException) {
throw (ScriptException) ex;
}
throw new UncategorizedScriptException("Failed to execute database script", ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementTy
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

boolean forceUseOfBigDecimal = getObjectMapper().isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
if (elementType != null && BigDecimal.class.equals(elementType.getType())) {
if (BigDecimal.class.equals(elementType.getType())) {
forceUseOfBigDecimal = true;
}

Expand All @@ -130,9 +130,10 @@ public Mono<Object> decodeToMono(Publisher<DataBuffer> input, ResolvableType ele
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

boolean forceUseOfBigDecimal = getObjectMapper().isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
if (elementType != null && BigDecimal.class.equals(elementType.getType())) {
if (BigDecimal.class.equals(elementType.getType())) {
forceUseOfBigDecimal = true;
}

Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(Flux.from(input), this.jsonFactory, getObjectMapper(),
false, forceUseOfBigDecimal, getMaxInMemorySize());
return decodeInternal(tokens, elementType, mimeType, hints).singleOrEmpty();
Expand Down Expand Up @@ -177,7 +178,7 @@ private Flux<Object> decodeInternal(Flux<TokenBuffer> tokens, ResolvableType ele
}


// HttpMessageDecoder...
// HttpMessageDecoder

@Override
public Map<String, Object> getDecodeHints(ResolvableType actualType, ResolvableType elementType,
Expand All @@ -191,7 +192,8 @@ public List<MimeType> getDecodableMimeTypes() {
return getMimeTypes();
}

// Jackson2CodecSupport ...

// Jackson2CodecSupport

@Override
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory,
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
}
catch (IOException ex) {
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder",
ex);
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder", ex);
}

byte[] bytes = byteBuilder.toByteArray();
Expand All @@ -197,8 +196,7 @@ private DataBuffer encodeStreamingValue(Object value, DataBufferFactory bufferFa
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
}
catch (IOException ex) {
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder",
ex);
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder", ex);
}

byte[] bytes = byteArrayBuilder.toByteArray();
Expand Down Expand Up @@ -233,6 +231,7 @@ private void logValue(@Nullable Map<String, Object> hints, Object value) {

private ObjectWriter createObjectWriter(ResolvableType valueType, @Nullable MimeType mimeType,
@Nullable Map<String, Object> hints) {

JavaType javaType = getJavaType(valueType.getType(), null);
Class<?> jsonView = (hints != null ? (Class<?>) hints.get(Jackson2CodecSupport.JSON_VIEW_HINT) : null);
ObjectWriter writer = (jsonView != null ?
Expand Down Expand Up @@ -280,7 +279,7 @@ protected JsonEncoding getJsonEncoding(@Nullable MimeType mimeType) {
}


// HttpMessageEncoder...
// HttpMessageEncoder

@Override
public List<MimeType> getEncodableMimeTypes() {
Expand All @@ -299,7 +298,8 @@ public Map<String, Object> getEncodeHints(@Nullable ResolvableType actualType, R
return (actualType != null ? getHints(actualType) : Hints.none());
}

// Jackson2CodecSupport ...

// Jackson2CodecSupport

@Override
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferLimitException;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;

/**
* {@link Function} to transform a JSON stream of arbitrary size, byte array
Expand Down Expand Up @@ -66,7 +65,6 @@ final class Jackson2Tokenizer {

private int byteCount;

@Nullable // yet initialized by calling createToken() in the constructor
private TokenBuffer tokenBuffer;


Expand All @@ -84,7 +82,7 @@ private Jackson2Tokenizer(JsonParser parser, DeserializationContext deserializat
this.forceUseOfBigDecimal = forceUseOfBigDecimal;
this.inputFeeder = (ByteArrayFeeder) this.parser.getNonBlockingInputFeeder();
this.maxInMemorySize = maxInMemorySize;
createToken();
this.tokenBuffer = createToken();
}


Expand Down Expand Up @@ -174,9 +172,8 @@ private void processTokenNormal(JsonToken token, List<TokenBuffer> result) throw

if ((token.isStructEnd() || token.isScalarValue()) && this.objectDepth == 0 && this.arrayDepth == 0) {
result.add(this.tokenBuffer);
createToken();
this.tokenBuffer = createToken();
}

}

private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws IOException {
Expand All @@ -187,13 +184,14 @@ private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws
if (this.objectDepth == 0 && (this.arrayDepth == 0 || this.arrayDepth == 1) &&
(token == JsonToken.END_OBJECT || token.isScalarValue())) {
result.add(this.tokenBuffer);
createToken();
this.tokenBuffer = createToken();
}
}

private void createToken() {
this.tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
this.tokenBuffer.forceUseOfBigDecimal(this.forceUseOfBigDecimal);
private TokenBuffer createToken() {
TokenBuffer tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
tokenBuffer.forceUseOfBigDecimal(this.forceUseOfBigDecimal);
return tokenBuffer;
}

private boolean isTopLevelArrayToken(JsonToken token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
*/
public class RestTemplate extends InterceptingHttpAccessor implements RestOperations {

private static boolean romePresent;
private static final boolean romePresent;

private static final boolean jaxb2Present;

Expand Down Expand Up @@ -200,6 +200,7 @@ public RestTemplate(List<HttpMessageConverter<?>> messageConverters) {
this.uriTemplateHandler = initUriTemplateHandler();
}


private static DefaultUriBuilderFactory initUriTemplateHandler() {
DefaultUriBuilderFactory uriFactory = new DefaultUriBuilderFactory();
uriFactory.setEncodingMode(EncodingMode.URI_COMPONENT); // for backwards compatibility..
Expand Down

0 comments on commit ebd2ec5

Please sign in to comment.