Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jun 8, 2020
1 parent 7281d44 commit 4f81ab7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 76 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-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 @@ -61,12 +61,12 @@ public class AopNamespaceHandler extends NamespaceHandlerSupport {
*/
@Override
public void init() {
// In 2.0 XSD as well as in 2.1 XSD.
// In 2.0 XSD as well as in 2.5+ XSDs
registerBeanDefinitionParser("config", new ConfigBeanDefinitionParser());
registerBeanDefinitionParser("aspectj-autoproxy", new AspectJAutoProxyBeanDefinitionParser());
registerBeanDefinitionDecorator("scoped-proxy", new ScopedProxyBeanDefinitionDecorator());

// Only in 2.0 XSD: moved to context namespace as of 2.1
// Only in 2.0 XSD: moved to context namespace in 2.5+
registerBeanDefinitionParser("spring-configured", new SpringConfiguredBeanDefinitionParser());
}

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 @@ -39,55 +39,6 @@
*/
public class DefaultUriBuilderFactory implements UriBuilderFactory {

/**
* Enum to represent multiple URI encoding strategies.
* @see #setEncodingMode
*/
public enum EncodingMode {

/**
* Pre-encode the URI template first, then strictly encode URI variables
* when expanded, with the following rules:
* <ul>
* <li>For the URI template replace <em>only</em> non-ASCII and illegal
* (within a given URI component type) characters with escaped octets.
* <li>For URI variables do the same and also replace characters with
* reserved meaning.
* </ul>
* <p>For most cases, this mode is most likely to give the expected
* result because in treats URI variables as opaque data to be fully
* encoded, while {@link #URI_COMPONENT} by comparison is useful only
* if intentionally expanding URI variables with reserved characters.
* @since 5.0.8
* @see UriComponentsBuilder#encode()
*/
TEMPLATE_AND_VALUES,

/**
* Does not encode the URI template and instead applies strict encoding
* to URI variables via {@link UriUtils#encodeUriVariables} prior to
* expanding them into the template.
* @see UriUtils#encodeUriVariables(Object...)
* @see UriUtils#encodeUriVariables(Map)
*/
VALUES_ONLY,

/**
* Expand URI variables first, and then encode the resulting URI
* component values, replacing <em>only</em> non-ASCII and illegal
* (within a given URI component type) characters, but not characters
* with reserved meaning.
* @see UriComponents#encode()
*/
URI_COMPONENT,

/**
* No encoding should be applied.
*/
NONE
}


@Nullable
private final UriComponentsBuilder baseUri;

Expand Down Expand Up @@ -194,16 +145,19 @@ public boolean shouldParsePath() {

// UriTemplateHandler

@Override
public URI expand(String uriTemplate, Map<String, ?> uriVars) {
return uriString(uriTemplate).build(uriVars);
}

@Override
public URI expand(String uriTemplate, Object... uriVars) {
return uriString(uriTemplate).build(uriVars);
}

// UriBuilderFactory

@Override
public UriBuilder uriString(String uriTemplate) {
return new DefaultUriBuilder(uriTemplate);
}
Expand All @@ -214,6 +168,62 @@ public UriBuilder builder() {
}


/**
* Enum to represent multiple URI encoding strategies. The following are
* available:
* <ul>
* <li>{@link #TEMPLATE_AND_VALUES}
* <li>{@link #VALUES_ONLY}
* <li>{@link #URI_COMPONENT}
* <li>{@link #NONE}
* </ul>
* @see #setEncodingMode
*/
public enum EncodingMode {

/**
* Pre-encode the URI template first, then strictly encode URI variables
* when expanded, with the following rules:
* <ul>
* <li>For the URI template replace <em>only</em> non-ASCII and illegal
* (within a given URI component type) characters with escaped octets.
* <li>For URI variables do the same and also replace characters with
* reserved meaning.
* </ul>
* <p>For most cases, this mode is most likely to give the expected
* result because in treats URI variables as opaque data to be fully
* encoded, while {@link #URI_COMPONENT} by comparison is useful only
* if intentionally expanding URI variables with reserved characters.
* @since 5.0.8
* @see UriComponentsBuilder#encode()
*/
TEMPLATE_AND_VALUES,

/**
* Does not encode the URI template and instead applies strict encoding
* to URI variables via {@link UriUtils#encodeUriVariables} prior to
* expanding them into the template.
* @see UriUtils#encodeUriVariables(Object...)
* @see UriUtils#encodeUriVariables(Map)
*/
VALUES_ONLY,

/**
* Expand URI variables first, and then encode the resulting URI
* component values, replacing <em>only</em> non-ASCII and illegal
* (within a given URI component type) characters, but not characters
* with reserved meaning.
* @see UriComponents#encode()
*/
URI_COMPONENT,

/**
* No encoding should be applied.
*/
NONE
}


/**
* {@link DefaultUriBuilderFactory} specific implementation of UriBuilder.
*/
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 All @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.web.util;

/**
Expand All @@ -22,13 +23,14 @@
*
* @author Rossen Stoyanchev
* @since 5.0
* @see DefaultUriBuilderFactory
*/
public interface UriBuilderFactory extends UriTemplateHandler {

/**
* Initialize a builder with the given URI template.
* @param uriTemplate the URI template to use
* @return the URI builder instance
* @return the builder instance
*/
UriBuilder uriString(String uriTemplate);

Expand Down
44 changes: 23 additions & 21 deletions src/docs/asciidoc/core/core-aop.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1403,16 +1403,16 @@ In many cases, you do this binding anyway (as in the preceding example).

What happens when multiple pieces of advice all want to run at the same join point?
Spring AOP follows the same precedence rules as AspectJ to determine the order of advice
execution. The highest precedence advice runs first "`on the way in`" (so, given two pieces
of before advice, the one with highest precedence runs first). "`On the way out`" from a
execution. The highest precedence advice runs first "on the way in" (so, given two pieces
of before advice, the one with highest precedence runs first). "On the way out" from a
join point, the highest precedence advice runs last (so, given two pieces of after
advice, the one with the highest precedence will run second).

When two pieces of advice defined in different aspects both need to run at the same
join point, unless you specify otherwise, the order of execution is undefined. You can
control the order of execution by specifying precedence. This is done in the normal
Spring way by either implementing the `org.springframework.core.Ordered` interface in
the aspect class or annotating it with the `Order` annotation. Given two aspects, the
the aspect class or annotating it with the `@Order` annotation. Given two aspects, the
aspect returning the lower value from `Ordered.getValue()` (or the annotation value) has
the higher precedence.

Expand Down Expand Up @@ -1643,9 +1643,9 @@ expression so that only `@Idempotent` operations match, as follows:
== Schema-based AOP Support

If you prefer an XML-based format, Spring also offers support for defining aspects
using the new `aop` namespace tags. The exact same pointcut expressions and advice kinds
using the `aop` namespace tags. The exact same pointcut expressions and advice kinds
as when using the @AspectJ style are supported. Hence, in this section we focus on
the new syntax and refer the reader to the discussion in the previous section
that syntax and refer the reader to the discussion in the previous section
(<<aop-ataspectj>>) for an understanding of writing pointcut expressions and the binding
of advice parameters.

Expand Down Expand Up @@ -1675,7 +1675,7 @@ When you use the schema support, an aspect is a regular Java object defined as a
your Spring application context. The state and behavior are captured in the fields and
methods of the object, and the pointcut and advice information are captured in the XML.

You can declare an aspect by using the <aop:aspect> element, and reference the backing bean
You can declare an aspect by using the `<aop:aspect>` element, and reference the backing bean
by using the `ref` attribute, as the following example shows:

====
Expand Down Expand Up @@ -1801,9 +1801,10 @@ parameters of the matching names, as follows:
----
====

When combining pointcut sub-expressions, `&&` is awkward within an XML document, so
you can use the `and`, `or`, and `not` keywords in place of `&&`, `||`, and `!`,
respectively. For example, the previous pointcut can be better written as follows:
When combining pointcut sub-expressions, `+&amp;&amp;+` is awkward within an XML
document, so you can use the `and`, `or`, and `not` keywords in place of `+&amp;&amp;+`,
`||`, and `!`, respectively. For example, the previous pointcut can be better written as
follows:

====
[source,xml,indent=0]
Expand Down Expand Up @@ -1913,8 +1914,8 @@ shows how to declare it:
----
====

As in the @AspectJ style, you can get the return value within the
advice body. To do so, use the returning attribute to specify the name of the parameter to which
As in the @AspectJ style, you can get the return value within the advice body.
To do so, use the `returning` attribute to specify the name of the parameter to which
the return value should be passed, as the following example shows:

====
Expand Down Expand Up @@ -1951,7 +1952,7 @@ example, you can declare the method signature as follows:
==== After Throwing Advice

After throwing advice executes when a matched method execution exits by throwing an
exception. It is declared inside an `<aop:aspect>` by using the after-throwing element,
exception. It is declared inside an `<aop:aspect>` by using the `after-throwing` element,
as the following example shows:

====
Expand All @@ -1970,8 +1971,8 @@ as the following example shows:
----
====

As in the @AspectJ style, you can get the thrown exception within
the advice body. To do so, use the throwing attribute to specify the name of the parameter to
As in the @AspectJ style, you can get the thrown exception within the advice body.
To do so, use the `throwing` attribute to specify the name of the parameter to
which the exception should be passed as the following example shows:

====
Expand Down Expand Up @@ -2030,7 +2031,7 @@ by using the `after` element, as the following example shows:
[[aop-schema-advice-around]]
==== Around Advice

The last kind of advice is around advice. Around advice runs "`around`" a matched method
The last kind of advice is around advice. Around advice runs "around" a matched method
execution. It has the opportunity to do work both before and after the method executes
and to determine when, how, and even if the method actually gets to execute at all.
Around advice is often used to share state before and after a method
Expand Down Expand Up @@ -2233,10 +2234,11 @@ ms % Task name
[[aop-ordering]]
==== Advice Ordering

When multiple advice needs to execute at the same join point (executing method) the
ordering rules are as described in <<aop-ataspectj-advice-ordering>>. The precedence
between aspects is determined by either adding the `Order` annotation to the bean
that backs the aspect or by having the bean implement the `Ordered` interface.
When multiple pieces of advice need to execute at the same join point (executing method)
the ordering rules are as described in <<aop-ataspectj-advice-ordering>>. The precedence
between aspects is determined via the `order` attribute in the `<aop:aspect>` element or
by either adding the `@Order` annotation to the bean that backs the aspect or by having
the bean implement the `Ordered` interface.



Expand Down Expand Up @@ -2781,7 +2783,7 @@ following example shows:
public static void main(String[] args) {
ProxyFactory factory = new ProxyFactory(new SimplePojo());
factory.adddInterface(Pojo.class);
factory.addInterface(Pojo.class);
factory.addAdvice(new RetryAdvice());
factory.setExposeProxy(true);
Expand Down Expand Up @@ -3472,7 +3474,7 @@ for AspectJ LTW:
* `spring-aop.jar`
* `aspectjweaver.jar`

If you use the <<aop-aj-ltw-environment-generic, Spring-provided agent to enable
If you use the <<aop-aj-ltw-environments-generic, Spring-provided agent to enable
instrumentation>>, you also need:

* `spring-instrument.jar`
Expand Down

0 comments on commit 4f81ab7

Please sign in to comment.