Add ability to clone to UriComponentsBuilder hierarchy

Issue: SPR-12494
This commit is contained in:
Rossen Stoyanchev
2014-12-05 12:14:16 -05:00
parent 2fccf3ff44
commit 189ec75789
4 changed files with 127 additions and 14 deletions

View File

@@ -93,6 +93,26 @@ public class MvcUriComponentsBuilder extends UriComponentsBuilder {
}
/**
* Default constructor. Protected to prevent direct instantiation.
*
* @see #fromController(Class)
* @see #fromMethodName(Class, String, Object...)
* @see #fromMethodCall(Object)
* @see #fromMappingName(String)
* @see #fromMethod(java.lang.reflect.Method, Object...)
*/
protected MvcUriComponentsBuilder() {
}
/**
* Create a deep copy of the given MvcUriComponentsBuilder.
* @param other the other builder to copy from
*/
protected MvcUriComponentsBuilder(MvcUriComponentsBuilder other) {
super(other);
}
/**
* Create a {@link UriComponentsBuilder} from the mapping of a controller class
* and current request information including Servlet mapping. If the controller
@@ -431,6 +451,11 @@ public class MvcUriComponentsBuilder extends UriComponentsBuilder {
}
}
@Override
protected Object clone() {
return new MvcUriComponentsBuilder(this);
}
private static class ControllerMethodInvocationInterceptor
implements org.springframework.cglib.proxy.MethodInterceptor, MethodInterceptor {

View File

@@ -51,6 +51,15 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder {
protected ServletUriComponentsBuilder() {
}
/**
* Create a deep copy of the given ServletUriComponentsBuilder.
* @param other the other builder to copy from
*/
protected ServletUriComponentsBuilder(ServletUriComponentsBuilder other) {
super(other);
this.originalPath = other.originalPath;
}
/**
* Prepare a builder from the host, port, scheme, and context path of the
* given HttpServletRequest.
@@ -232,4 +241,9 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder {
return extension;
}
@Override
protected Object clone() {
return new ServletUriComponentsBuilder(this);
}
}