This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 118e8da  Context API refactoring.
118e8da is described below

commit 118e8da5945eaab05f9b41ecc49b521d33bc23cd
Author: JamesBognar <[email protected]>
AuthorDate: Sun Aug 29 11:14:17 2021 -0400

    Context API refactoring.
---
 .../java/org/apache/juneau/rest/RestContext.java   | 115 +-------------------
 .../org/apache/juneau/rest/RestContextBuilder.java | 117 ++++++++++++++++-----
 .../org/apache/juneau/rest/annotation/Rest.java    |   2 +-
 .../juneau/rest/annotation/RestAnnotation.java     |   2 +-
 4 files changed, 93 insertions(+), 143 deletions(-)

diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index 131df45..ee76301 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -270,119 +270,6 @@ public class RestContext extends BeanContext {
        public static final String REST_callLoggerDefault = PREFIX + 
".callLoggerDefault.o";
 
        /**
-        * Configuration property:  Children.
-        *
-        * <h5 class='section'>Property:</h5>
-        * <ul class='spaced-list'>
-        *      <li><b>ID:</b>  {@link 
org.apache.juneau.rest.RestContext#REST_children REST_children}
-        *      <li><b>Name:</b>  <js>"RestContext.children.lo"</js>
-        *      <li><b>Data type:</b>  <c>List&lt;Class|Object|{@link 
org.apache.juneau.rest.RestChild}&gt;</c>
-        *      <li><b>Default:</b>  empty list
-        *      <li><b>Session property:</b>  <jk>false</jk>
-        *      <li><b>Annotations:</b>
-        *              <ul>
-        *                      <li class='ja'>{@link 
org.apache.juneau.rest.annotation.Rest#children()}
-        *              </ul>
-        *      <li><b>Methods:</b>
-        *              <ul>
-        *                      <li class='jm'>{@link 
org.apache.juneau.rest.RestContextBuilder#child(String,Object)}
-        *                      <li class='jm'>{@link 
org.apache.juneau.rest.RestContextBuilder#children(Class...)}
-        *                      <li class='jm'>{@link 
org.apache.juneau.rest.RestContextBuilder#children(Object...)}
-        *              </ul>
-        * </ul>
-        *
-        * <h5 class='section'>Description:</h5>
-        * <p>
-        * Defines children of this resource.
-        *
-        * <p>
-        * A REST child resource is simply another servlet or object that is 
initialized as part of the ascendant resource and has a
-        * servlet path directly under the ascendant resource object path.
-        * <br>The main advantage to defining servlets as REST children is that 
you do not need to define them in the
-        * <c>web.xml</c> file of the web application.
-        * <br>This can cut down on the number of entries that show up in the 
<c>web.xml</c> file if you are defining
-        * large numbers of servlets.
-        *
-        * <p>
-        * Child resources must specify a value for {@link Rest#path() 
@Rest(path)} that identifies the subpath of the child resource
-        * relative to the ascendant path UNLESS you use the {@link 
RestContextBuilder#child(String, Object)} method to register it.
-        *
-        * <p>
-        * Child resources can be nested arbitrarily deep using this technique 
(i.e. children can also have children).
-        *
-        * <dl>
-        *      <dt>Servlet initialization:</dt>
-        *      <dd>
-        *              <p>
-        *                      A child resource will be initialized 
immediately after the ascendant servlet/resource is initialized.
-        *                      <br>The child resource receives the same 
servlet config as the ascendant servlet/resource.
-        *                      <br>This allows configuration information such 
as servlet initialization parameters to filter to child
-        *                      resources.
-        *              </p>
-        *      </dd>
-        *      <dt>Runtime behavior:</dt>
-        *      <dd>
-        *              <p>
-        *                      As a rule, methods defined on the 
<c>HttpServletRequest</c> object will behave as if the child
-        *                      servlet were deployed as a top-level resource 
under the child's servlet path.
-        *                      <br>For example, the <c>getServletPath()</c> 
and <c>getPathInfo()</c> methods on the
-        *                      <c>HttpServletRequest</c> object will behave as 
if the child resource were deployed using the
-        *                      child's servlet path.
-        *                      <br>Therefore, the runtime behavior should be 
equivalent to deploying the child servlet in the
-        *                      <c>web.xml</c> file of the web application.
-        *              </p>
-        *      </dd>
-        * </dl>
-        *
-        * <h5 class='section'>Example:</h5>
-        * <p class='bcode w800'>
-        *      <jc>// Our child resource.</jc>
-        *      <ja>@Rest</ja>(path=<js>"/child"</js>)
-        *      <jk>public class</jk> MyChildResource {...}
-        *
-        *      <jc>// Option #1 - Registered via annotation.</jc>
-        *      <ja>@Rest</ja>(children={MyChildResource.<jk>class</jk>})
-        *      <jk>public class</jk> MyResource {
-        *
-        *              <jc>// Option #2 - Registered via builder passed in 
through resource constructor.</jc>
-        *              <jk>public</jk> MyResource(RestContextBuilder 
<jv>builder</jv>) <jk>throws</jk> Exception {
-        *
-        *                      <jc>// Using method on builder.</jc>
-        *                      
<jv>builder</jv>.children(MyChildResource.<jk>class</jk>);
-        *
-        *                      <jc>// Same, but using property.</jc>
-        *                      
<jv>builder</jv>.addTo(<jsf>REST_children</jsf>, 
MyChildResource.<jk>class</jk>));
-        *
-        *                      <jc>// Use a pre-instantiated object 
instead.</jc>
-        *                      <jv>builder</jv>.child(<js>"/child"</js>, 
<jk>new</jk> MyChildResource());
-        *              }
-        *
-        *              <jc>// Option #3 - Registered via builder passed in 
through init method.</jc>
-        *              <ja>@RestHook</ja>(<jsf>INIT</jsf>)
-        *              <jk>public void</jk> init(RestContextBuilder 
<jv>builder</jv>) <jk>throws</jk> Exception {
-        *                      
<jv>builder</jv>.children(MyChildResource.<jk>class</jk>);
-        *              }
-        *      }
-        * </p>
-        *
-        * <ul class='notes'>
-        *      <li>
-        *              When defined as classes, instances are resolved using 
the registered {@link #REST_beanStore} which
-        *              by default is {@link BeanStore} which requires the 
class have one of the following
-        *              constructors:
-        *              <ul>
-        *                      <li><code><jk>public</jk> 
T(RestContextBuilder)</code>
-        *                      <li><code><jk>public</jk> T()</code>
-        *              </ul>
-        * </ul>
-        *
-        * <ul class='seealso'>
-        *      <li class='link'>{@doc RestChildren}
-        * </ul>
-        */
-       public static final String REST_children = PREFIX + ".children.lo";
-
-       /**
         * Configuration property:  Class-level response converters.
         *
         * <h5 class='section'>Property:</h5>
@@ -4165,7 +4052,7 @@ public class RestContext extends BeanContext {
                        .implClass(builder.childrenClass);
 
                // Initialize our child resources.
-               for (Object o : 
builder.getContextProperties().getArray(REST_children, Object.class).orElse(new 
Object[0])) {
+               for (Object o : builder.children) {
                        String path = null;
 
                        if (o instanceof RestChild) {
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
index 17ee05a..b6508e4 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContextBuilder.java
@@ -129,6 +129,7 @@ public class RestContextBuilder extends BeanContextBuilder 
implements ServletCon
        Class<? extends RestChildren> childrenClass = RestChildren.class;
        Class<? extends RestOpContext> opContextClass = RestOpContext.class;
        Class<? extends RestOperations> operationsClass = RestOperations.class;
+       List<Object> children = new ArrayList<>();
 
        RestContextBuilder(Optional<RestContext> parentContext, 
Optional<ServletConfig> servletConfig, Class<?> resourceClass, Optional<Object> 
resource) throws ServletException {
                try {
@@ -762,47 +763,112 @@ public class RestContextBuilder extends 
BeanContextBuilder implements ServletCon
        }
 
        /**
-        * <i><l>RestContext</l> configuration property:&emsp;</i>  Children.
+        * Child REST resources.
         *
         * <p>
         * Defines children of this resource.
         *
         * <p>
-        * A REST child resource is simply another servlet that is initialized 
as part of the parent resource and has a
-        * servlet path directly under the parent servlet path.
+        * A REST child resource is simply another servlet or object that is 
initialized as part of the ascendant resource and has a
+        * servlet path directly under the ascendant resource object path.
+        * <br>The main advantage to defining servlets as REST children is that 
you do not need to define them in the
+        * <c>web.xml</c> file of the web application.
+        * <br>This can cut down on the number of entries that show up in the 
<c>web.xml</c> file if you are defining
+        * large numbers of servlets.
+        *
+        * <p>
+        * Child resources must specify a value for {@link Rest#path() 
@Rest(path)} that identifies the subpath of the child resource
+        * relative to the ascendant path UNLESS you use the {@link 
RestContextBuilder#child(String, Object)} method to register it.
+        *
+        * <p>
+        * Child resources can be nested arbitrarily deep using this technique 
(i.e. children can also have children).
+        *
+        * <dl>
+        *      <dt>Servlet initialization:</dt>
+        *      <dd>
+        *              <p>
+        *                      A child resource will be initialized 
immediately after the ascendant servlet/resource is initialized.
+        *                      <br>The child resource receives the same 
servlet config as the ascendant servlet/resource.
+        *                      <br>This allows configuration information such 
as servlet initialization parameters to filter to child
+        *                      resources.
+        *              </p>
+        *      </dd>
+        *      <dt>Runtime behavior:</dt>
+        *      <dd>
+        *              <p>
+        *                      As a rule, methods defined on the 
<c>HttpServletRequest</c> object will behave as if the child
+        *                      servlet were deployed as a top-level resource 
under the child's servlet path.
+        *                      <br>For example, the <c>getServletPath()</c> 
and <c>getPathInfo()</c> methods on the
+        *                      <c>HttpServletRequest</c> object will behave as 
if the child resource were deployed using the
+        *                      child's servlet path.
+        *                      <br>Therefore, the runtime behavior should be 
equivalent to deploying the child servlet in the
+        *                      <c>web.xml</c> file of the web application.
+        *              </p>
+        *      </dd>
+        * </dl>
         *
-        * <ul class='seealso'>
-        *      <li class='jf'>{@link RestContext#REST_children}
-        * </ul>
+        * <h5 class='section'>Example:</h5>
+        * <p class='bcode w800'>
+        *      <jc>// Our child resource.</jc>
+        *      <ja>@Rest</ja>(path=<js>"/child"</js>)
+        *      <jk>public class</jk> MyChildResource {...}
         *
-        * @param values The values to add to this setting.
-        * @return This object (for method chaining).
-        */
-       @FluentSetter
-       public RestContextBuilder children(Class<?>...values) {
-               return prependTo(REST_children, values);
-       }
-
-       /**
-        * <i><l>RestContext</l> configuration property:&emsp;</i>  Children.
+        *      <jc>// Option #1 - Registered via annotation.</jc>
+        *      <ja>@Rest</ja>(children={MyChildResource.<jk>class</jk>})
+        *      <jk>public class</jk> MyResource {
         *
-        * <p>
-        * Same as {@link #children(Class...)} except input is pre-constructed 
instances.
+        *              <jc>// Option #2 - Registered via builder passed in 
through resource constructor.</jc>
+        *              <jk>public</jk> MyResource(RestContextBuilder 
<jv>builder</jv>) <jk>throws</jk> Exception {
+        *
+        *                      <jc>// Using method on builder.</jc>
+        *                      
<jv>builder</jv>.children(MyChildResource.<jk>class</jk>);
+        *
+        *                      <jc>// Use a pre-instantiated object 
instead.</jc>
+        *                      <jv>builder</jv>.child(<js>"/child"</js>, 
<jk>new</jk> MyChildResource());
+        *              }
+        *
+        *              <jc>// Option #3 - Registered via builder passed in 
through init method.</jc>
+        *              <ja>@RestHook</ja>(<jsf>INIT</jsf>)
+        *              <jk>public void</jk> init(RestContextBuilder 
<jv>builder</jv>) <jk>throws</jk> Exception {
+        *                      
<jv>builder</jv>.children(MyChildResource.<jk>class</jk>);
+        *              }
+        *      }
+        * </p>
+        *
+        * <ul class='notes'>
+        *      <li>
+        *              When defined as classes, instances are resolved using 
the registered {@link #REST_beanStore} which
+        *              by default is {@link BeanStore} which requires the 
class have one of the following
+        *              constructors:
+        *              <ul>
+        *                      <li><code><jk>public</jk> 
T(RestContextBuilder)</code>
+        *                      <li><code><jk>public</jk> T()</code>
+        *              </ul>
+        * </ul>
         *
         * <ul class='seealso'>
-        *      <li class='jf'>{@link RestContext#REST_children}
+        *      <li class='link'>{@doc RestChildren}
+        *      <li class='ja'>{@link Rest#children()}
         * </ul>
         *
-        * @param values The values to add to this setting.
+        * @param values
+        *      The values to add to this setting.
+        *      <br>Objects can be any of the specified types:
+        *      <ul>
+        *              <li>A class that has a constructor described above.
+        *              <li>An instantiated resource object (such as a servlet 
object instantiated by a servlet container).
+        *              <li>An instance of {@link RestChild} containing an 
instantied resource object and a subpath.
+        *      </ul>
         * @return This object (for method chaining).
         */
        @FluentSetter
        public RestContextBuilder children(Object...values) {
-               return prependTo(REST_children, values);
+               children.addAll(asList(values));
+               return this;
        }
 
        /**
-        * <i><l>RestContext</l> configuration property:&emsp;</i>  Children.
+        * Add a child REST resource.
         *
         * <p>
         * Shortcut for adding a single child to this resource.
@@ -810,17 +876,14 @@ public class RestContextBuilder extends 
BeanContextBuilder implements ServletCon
         * <p>
         * This can be used for resources that don't have a {@link Rest#path() 
@Rest(path)} annotation.
         *
-        * <ul class='seealso'>
-        *      <li class='jf'>{@link RestContext#REST_children}
-        * </ul>
-        *
         * @param path The child path relative to the parent resource URI.
         * @param child The child to add to this resource.
         * @return This object (for method chaining).
         */
        @FluentSetter
        public RestContextBuilder child(String path, Object child) {
-               return prependTo(REST_children, new RestChild(path, child));
+               children.add(new RestChild(path, child));
+               return this;
        }
 
        /**
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Rest.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Rest.java
index b3fe5cb..3b47db9 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Rest.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Rest.java
@@ -209,7 +209,7 @@ public @interface Rest {
         * Defines children of this resource.
         *
         * <ul class='seealso'>
-        *      <li class='jf'>{@link RestContext#REST_children}
+        *      <li class='jm'>{@link RestContextBuilder#children}
         * </ul>
         */
        Class<?>[] children() default {};
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestAnnotation.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestAnnotation.java
index aeb6521..7c5eefa 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestAnnotation.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestAnnotation.java
@@ -1051,7 +1051,7 @@ public class RestAnnotation {
                        b.appendToIfNotEmpty(REST_defaultRequestHeaders, 
accept(string(a.defaultAccept())));
                        b.appendToIfNotEmpty(REST_defaultRequestHeaders, 
contentType(string(a.defaultContentType())));
                        b.prependTo(REST_responseProcessors, 
a.responseProcessors());
-                       b.prependTo(REST_children, a.children());
+                       b.children((Object[])a.children());
                        b.prependTo(REST_restOperationArgs, a.restOpArgs());
                        value(a.contextClass(), 
RestContext.Null.class).ifPresent(x -> b.contextClass(x));
                        value(a.uriContext()).ifPresent(x -> b.uriContext(x));

Reply via email to