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 e24dd46  Context API refactoring.
e24dd46 is described below

commit e24dd46da8c5e5c8879d6ea67c1c06a19b07c83a
Author: JamesBognar <[email protected]>
AuthorDate: Sat Sep 11 17:16:47 2021 -0400

    Context API refactoring.
---
 .../org/apache/juneau/rest/RestContextBuilder.java | 179 +++++++++------------
 .../juneau/rest/annotation/RestAnnotation.java     |   2 +-
 .../juneau/rest/annotation/Rest_Messages_Test.java |   3 +-
 3 files changed, 75 insertions(+), 109 deletions(-)

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 30ec709..7b636ee 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
@@ -978,6 +978,79 @@ public class RestContextBuilder extends ContextBuilder 
implements ServletConfig
        /**
         * Instantiates the messages for this REST object.
         *
+        * <p>
+        * By default, the resource bundle name is assumed to match the class 
name.  For example, given the class
+        * <c>MyClass.java</c>, the resource bundle is assumed to be 
<c>MyClass.properties</c>.  This property
+        * allows you to override this setting to specify a different location 
such as <c>MyMessages.properties</c> by
+        * specifying a value of <js>"MyMessages"</js>.
+        *
+        * <p>
+        *      Resource bundles are searched using the following base name 
patterns:
+        *      <ul>
+        *              <li><js>"{package}.{name}"</js>
+        *              <li><js>"{package}.i18n.{name}"</js>
+        *              <li><js>"{package}.nls.{name}"</js>
+        *              <li><js>"{package}.messages.{name}"</js>
+        *      </ul>
+        *
+        * <p>
+        * This annotation is used to provide request-localized (based on 
<c>Accept-Language</c>) messages for the following methods:
+        * <ul class='javatree'>
+        *      <li class='jm'>{@link RestRequest#getMessage(String, Object...)}
+        *      <li class='jm'>{@link RestContext#getMessages() 
RestContext.getMessages()}
+        * </ul>
+        *
+        * <p>
+        * Request-localized messages are also available by passing either of 
the following parameter types into your Java method:
+        * <ul class='javatree'>
+        *      <li class='jc'>{@link ResourceBundle} - Basic Java resource 
bundle.
+        *      <li class='jc'>{@link Messages} - Extended resource bundle with 
several convenience methods.
+        * </ul>
+        *
+        * The value can be a relative path like <js>"nls/Messages"</js>, 
indicating to look for the resource bundle
+        * <js>"com.foo.sample.nls.Messages"</js> if the resource class is in 
<js>"com.foo.sample"</js>, or it can be an
+        * absolute path like <js>"com.foo.sample.nls.Messages"</js>
+        *
+        * <h5 class='section'>Examples:</h5>
+        * <p class='bcode w800'>
+        *      <cc># Contents of org/apache/foo/nls/MyMessages.properties</cc>
+        *
+        *      <ck>HelloMessage</ck> = <cv>Hello {0}!</cv>
+        * </p>
+        * <p class='bcode w800'>
+        *      <jc>// Contents of org/apache/foo/MyResource.java</jc>
+        *
+        *      <ja>@Rest</ja>(messages=<js>"nls/MyMessages"</js>)
+        *      <jk>public class</jk> MyResource {...}
+        *
+        *              <ja>@RestGet</ja>(<js>"/hello/{you}"</js>)
+        *              <jk>public</jk> Object helloYou(RestRequest 
<jv>req</jv>, Messages <jv>messages</jv>, <ja>@Path</ja>(<js>"name"</js>) 
String <jv>you</jv>) {
+        *                      String <jv>s</jv>;
+        *
+        *                      <jc>// Get it from the RestRequest object.</jc>
+        *                      <jv>s</jv> = 
<jv>req</jv>.getMessage(<js>"HelloMessage"</js>, <jv>you</jv>);
+        *
+        *                      <jc>// Or get it from the method parameter.</jc>
+        *                      <jv>s</jv> = 
<jv>messages</jv>.getString(<js>"HelloMessage"</js>, <jv>you</jv>);
+        *
+        *                      <jc>// Or get the message in a locale different 
from the request.</jc>
+        *                      <jv>s</jv> = 
<jv>messages</jv>.forLocale(Locale.<jsf>UK</jsf>).getString(<js>"HelloMessage"</js>,
 <jv>you</jv>);
+        *
+        *                      <jk>return</jk> <jv>s</jv>;
+        *              }
+        *      }
+        * </p>
+        *
+        * <ul class='notes'>
+        *      <li>Mappings are cumulative from super classes.
+        *              <br>Therefore, you can find and retrieve messages up 
the class-hierarchy chain.
+        * </ul>
+        *
+        * <ul class='seealso'>
+        *      <li class='jc'>{@link Messages}
+        *      <li class='link'>{@doc RestMessages}
+        * </ul>
+        *
         * @param beanStore
         *      The factory used for creating beans and retrieving injected 
beans.
         * @param resource
@@ -2275,112 +2348,6 @@ public class RestContextBuilder extends ContextBuilder 
implements ServletConfig
        }
 
        /**
-        * Messages.
-        *
-        * <p>
-        * Identifies the location of the resource bundle for this class if 
it's different from the class name.
-        *
-        * <p>
-        * By default, the resource bundle name is assumed to match the class 
name.  For example, given the class
-        * <c>MyClass.java</c>, the resource bundle is assumed to be 
<c>MyClass.properties</c>.  This property
-        * allows you to override this setting to specify a different location 
such as <c>MyMessages.properties</c> by
-        * specifying a value of <js>"MyMessages"</js>.
-        *
-        * <p>
-        *      Resource bundles are searched using the following base name 
patterns:
-        *      <ul>
-        *              <li><js>"{package}.{name}"</js>
-        *              <li><js>"{package}.i18n.{name}"</js>
-        *              <li><js>"{package}.nls.{name}"</js>
-        *              <li><js>"{package}.messages.{name}"</js>
-        *      </ul>
-        *
-        * <p>
-        * This annotation is used to provide request-localized (based on 
<c>Accept-Language</c>) messages for the following methods:
-        * <ul class='javatree'>
-        *      <li class='jm'>{@link RestRequest#getMessage(String, Object...)}
-        *      <li class='jm'>{@link RestContext#getMessages() 
RestContext.getMessages()}
-        * </ul>
-        *
-        * <p>
-        * Request-localized messages are also available by passing either of 
the following parameter types into your Java method:
-        * <ul class='javatree'>
-        *      <li class='jc'>{@link ResourceBundle} - Basic Java resource 
bundle.
-        *      <li class='jc'>{@link Messages} - Extended resource bundle with 
several convenience methods.
-        * </ul>
-        *
-        * The value can be a relative path like <js>"nls/Messages"</js>, 
indicating to look for the resource bundle
-        * <js>"com.foo.sample.nls.Messages"</js> if the resource class is in 
<js>"com.foo.sample"</js>, or it can be an
-        * absolute path like <js>"com.foo.sample.nls.Messages"</js>
-        *
-        * <h5 class='section'>Examples:</h5>
-        * <p class='bcode w800'>
-        *      <cc># Contents of org/apache/foo/nls/MyMessages.properties</cc>
-        *
-        *      <ck>HelloMessage</ck> = <cv>Hello {0}!</cv>
-        * </p>
-        * <p class='bcode w800'>
-        *      <jc>// Contents of org/apache/foo/MyResource.java</jc>
-        *
-        *      <ja>@Rest</ja>(messages=<js>"nls/MyMessages"</js>)
-        *      <jk>public class</jk> MyResource {...}
-        *
-        *              <ja>@RestGet</ja>(<js>"/hello/{you}"</js>)
-        *              <jk>public</jk> Object helloYou(RestRequest 
<jv>req</jv>, Messages <jv>messages</jv>, <ja>@Path</ja>(<js>"name"</js>) 
String <jv>you</jv>) {
-        *                      String <jv>s</jv>;
-        *
-        *                      <jc>// Get it from the RestRequest object.</jc>
-        *                      <jv>s</jv> = 
<jv>req</jv>.getMessage(<js>"HelloMessage"</js>, <jv>you</jv>);
-        *
-        *                      <jc>// Or get it from the method parameter.</jc>
-        *                      <jv>s</jv> = 
<jv>messages</jv>.getString(<js>"HelloMessage"</js>, <jv>you</jv>);
-        *
-        *                      <jc>// Or get the message in a locale different 
from the request.</jc>
-        *                      <jv>s</jv> = 
<jv>messages</jv>.forLocale(Locale.<jsf>UK</jsf>).getString(<js>"HelloMessage"</js>,
 <jv>you</jv>);
-        *
-        *                      <jk>return</jk> <jv>s</jv>;
-        *              }
-        *      }
-        * </p>
-        *
-        * <ul class='notes'>
-        *      <li>Mappings are cumulative from super classes.
-        *              <br>Therefore, you can find and retrieve messages up 
the class-hierarchy chain.
-        * </ul>
-        *
-        * <ul class='seealso'>
-        *      <li class='jc'>{@link Messages}
-        *      <li class='link'>{@doc RestMessages}
-        * </ul>
-        *
-        * @param baseClass
-        *      The base class that the bundle path is relative to.
-        *      <br>If <jk>null</jk>, assumed to be the resource class itself.
-        * @param bundlePath The bundle path relative to the base class.
-        * @return This object (for method chaining).
-        */
-       @FluentSetter
-       public RestContextBuilder messages(Class<?> baseClass, String 
bundlePath) {
-               messages().location(baseClass, bundlePath);
-               return this;
-       }
-
-       /**
-        * Messages.
-        *
-        * <p>
-        * Same as {@link #messages(Class,String)} except assumes the base 
class is the resource class itself.
-        *
-        * @param bundlePath The bundle path relative to the base class.
-        * @return This object (for method chaining).
-        */
-       @FluentSetter
-       public RestContextBuilder messages(String bundlePath) {
-               messages().location(null, bundlePath);
-               return this;
-       }
-
-       /**
         * <i><l>RestContext</l> configuration property:&emsp;</i>  Parser 
listener.
         *
         * <p>
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 c2b2d25..18f9373 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
@@ -1067,7 +1067,7 @@ public class RestAnnotation {
                        string(a.uriAuthority()).ifPresent(x -> 
b.uriAuthority(x));
                        
string(a.uriRelativity()).map(UriRelativity::valueOf).ifPresent(x -> 
b.uriRelativity(x));
                        
string(a.uriResolution()).map(UriResolution::valueOf).ifPresent(x -> 
b.uriResolution(x));
-                       b.messages(c.inner(), 
string(a.messages()).orElse(null));
+                       b.messages().location(c.inner(), 
string(a.messages()).orElse(null));
                        type(a.fileFinder()).ifPresent(x -> b.fileFinder(x));
                        type(a.staticFiles()).ifPresent(x -> b.staticFiles(x));
                        string(a.path()).ifPresent(x -> b.path(x));
diff --git 
a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_Messages_Test.java
 
b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_Messages_Test.java
index 49173e5..f67c57b 100644
--- 
a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_Messages_Test.java
+++ 
b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/Rest_Messages_Test.java
@@ -117,8 +117,7 @@ public class Rest_Messages_Test {
        public static class B3 extends B1 {
                 @RestHook(HookEvent.INIT)
                 public void init(RestContextBuilder builder) throws Exception {
-                        builder.messages("B2x");
-                        builder.messages(B1.class, "B1x");
+                        builder.messages().location(null, 
"B2x").location(B1.class, "B1x");
                 }
        }
 

Reply via email to