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 a791928  PropertyStore refactoring.
a791928 is described below

commit a791928b7e0852773c72836399ccdca0c96aa49b
Author: JamesBognar <[email protected]>
AuthorDate: Sun Feb 7 19:54:47 2021 -0500

    PropertyStore refactoring.
---
 .../main/java/org/apache/juneau/PropertyStore.java | 35 +++++++---------------
 .../org/apache/juneau/html/HtmlDocSerializer.java  |  2 +-
 .../java/org/apache/juneau/xml/XmlSerializer.java  |  2 +-
 .../org/apache/juneau/rest/client/RestClient.java  |  2 +-
 .../java/org/apache/juneau/rest/RestContext.java   | 10 +++----
 .../apache/juneau/rest/RestOperationContext.java   | 18 +++++------
 6 files changed, 28 insertions(+), 41 deletions(-)

diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyStore.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyStore.java
index f20ed3f..e68a211 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyStore.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/PropertyStore.java
@@ -495,40 +495,27 @@ public final class PropertyStore {
        }
 
        /**
-        * Returns the specified property as an array of instantiated objects.
+        * Returns an instance array of the specified class, string, or object 
property.
         *
         * @param key The property name.
         * @param type The class type of the property.
-        * @return A new property instance, or an empty array if it doesn't 
exist.
-        */
-       public <T> T[] getInstanceArray(String key, Class<T> type) {
-               return getInstanceArray(key, type, (T[])Array.newInstance(type, 
0));
-       }
-
-       /**
-        * Returns the specified property as an array of instantiated objects.
-        *
-        * @param key The property name.
-        * @param type The class type of the property.
-        * @param def The default object to return if the property doesn't 
exist.
-        * @return A new property instance.
+        * @param beanFactory The bean factory to use for instantiating the 
bean.
+        * @return A new property instance array.
         */
-       public <T> T[] getInstanceArray(String key, Class<T> type, T[] def) {
-               return getInstanceArray(key, type, def, new BeanFactory());
+       public <T> Optional<T[]> getInstanceArray(String key, Class<T> type, 
BeanFactory beanFactory) {
+               Property p = findProperty(key);
+               return Optional.ofNullable(p == null ? null : 
p.asInstanceArray(type, beanFactory));
        }
 
        /**
-        * Returns the specified property as an array of instantiated objects.
+        * Returns an instance array of the specified class, string, or object 
property.
         *
         * @param key The property name.
         * @param type The class type of the property.
-        * @param def The default object to return if the property doesn't 
exist.
-        * @param beanFactory The bean factory to use for instantiating beans.
-        * @return A new property instance.
+        * @return A new property instance array.
         */
-       public <T> T[] getInstanceArray(String key, Class<T> type, T[] def, 
BeanFactory beanFactory) {
-               Property p = findProperty(key);
-               return p == null ? def : p.asInstanceArray(type, beanFactory);
+       public <T> Optional<T[]> getInstanceArray(String key, Class<T> type) {
+               return getInstanceArray(key, type, null);
        }
 
        /**
@@ -928,7 +915,7 @@ public final class PropertyStore {
        
//-------------------------------------------------------------------------------------------------------------------
 
        static BeanFactory DEFAULT_BEAN_FACTORY = BeanFactory.create().build();
-       
+
        static <T> T instantiate(BeanFactory beanFactory, Class<T> c, Object 
value) {
                if (ClassInfo.of(c).isParentOf(value.getClass()))
                        return (T)value;
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java
index aad4f1e..83d10f5 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/html/HtmlDocSerializer.java
@@ -778,7 +778,7 @@ public class HtmlDocSerializer extends 
HtmlStrippedDocSerializer {
                template = ps.getInstance(HTMLDOC_template, 
HtmlDocTemplate.class).orElseGet(BasicHtmlDocTemplate::new);
 
                widgets = new HtmlWidgetMap();
-               widgets.append(ps.getInstanceArray(HTMLDOC_widgets, 
HtmlWidget.class));
+               widgets.append(ps.getInstanceArray(HTMLDOC_widgets, 
HtmlWidget.class).orElse(new HtmlWidget[0]));
        }
 
        @Override /* Context */
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializer.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializer.java
index 3d7d563..2bc2b61 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializer.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlSerializer.java
@@ -518,7 +518,7 @@ public class XmlSerializer extends WriterSerializer 
implements XmlMetaProvider,
                addNamespaceUrlsToRoot = 
ps.getBoolean(XML_addNamespaceUrisToRoot).orElse(false);
                defaultNamespace = ps.getInstance(XML_defaultNamespace, 
Namespace.class).orElse(DEFAULT_JUNEAU_NAMESPACE);
                addBeanTypes = ps.getFirstBoolean(XML_addBeanTypes, 
SERIALIZER_addBeanTypes).orElse(false);
-               namespaces = ps.getInstanceArray(XML_namespaces, 
Namespace.class);
+               namespaces = ps.getInstanceArray(XML_namespaces, 
Namespace.class).orElse(new Namespace[0]);
        }
 
        @Override /* Context */
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
index ff3ddc3..b74cbcd 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
@@ -2123,7 +2123,7 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
 
                this.callHandler = ps.getInstance(RESTCLIENT_callHandler, 
RestCallHandler.class, 
bf).orElseGet(bf.createBeanSupplier(BasicRestCallHandler.class));
 
-               this.interceptors = 
ps.getInstanceArray(RESTCLIENT_interceptors, RestCallInterceptor.class);
+               this.interceptors = 
ps.getInstanceArray(RESTCLIENT_interceptors, 
RestCallInterceptor.class).orElse(new RestCallInterceptor[0]);
 
                creationStack = isDebug() ? 
Thread.currentThread().getStackTrace() : null;
        }
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 fdc1c56..29036f6 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
@@ -4159,7 +4159,7 @@ public class RestContext extends BeanContext {
 
                ResponseHandlerList x = ResponseHandlerList.create();
 
-               x.append(properties.getInstanceArray(REST_responseHandlers, 
ResponseHandler.class, new ResponseHandler[0], beanFactory));
+               x.append(properties.getInstanceArray(REST_responseHandlers, 
ResponseHandler.class, beanFactory).orElse(new ResponseHandler[0]));
 
                if (x.isEmpty())
                        
x.append(beanFactory.getBean(ResponseHandlerList.class).orElse(null));
@@ -5160,7 +5160,7 @@ public class RestContext extends BeanContext {
 
                HeaderList x = HeaderList.create();
 
-               
x.appendUnique(properties.getInstanceArray(REST_defaultRequestHeaders, 
org.apache.http.Header.class, new org.apache.http.Header[0], beanFactory));
+               
x.appendUnique(properties.getInstanceArray(REST_defaultRequestHeaders, 
org.apache.http.Header.class, beanFactory).orElse(new 
org.apache.http.Header[0]));
 
                x = BeanFactory
                        .of(beanFactory, resource)
@@ -5191,7 +5191,7 @@ public class RestContext extends BeanContext {
 
                HeaderList x = HeaderList.create();
 
-               
x.appendUnique(properties.getInstanceArray(REST_defaultResponseHeaders, 
org.apache.http.Header.class, new org.apache.http.Header[0], beanFactory));
+               
x.appendUnique(properties.getInstanceArray(REST_defaultResponseHeaders, 
org.apache.http.Header.class, beanFactory).orElse(new 
org.apache.http.Header[0]));
 
                x = BeanFactory
                        .of(beanFactory, resource)
@@ -5222,7 +5222,7 @@ public class RestContext extends BeanContext {
 
                NamedAttributeList x = NamedAttributeList.create();
 
-               
x.appendUnique(properties.getInstanceArray(REST_defaultRequestAttributes, 
NamedAttribute.class, new NamedAttribute[0], beanFactory));
+               
x.appendUnique(properties.getInstanceArray(REST_defaultRequestAttributes, 
NamedAttribute.class, beanFactory).orElse(new NamedAttribute[0]));
 
                x = BeanFactory
                        .of(beanFactory, resource)
@@ -5374,7 +5374,7 @@ public class RestContext extends BeanContext {
         */
        protected MessagesBuilder createMessagesBuilder(Object resource, 
PropertyStore properties) throws Exception {
 
-               Tuple2<Class<?>,String>[] mbl = 
properties.getInstanceArray(REST_messages, Tuple2.class);
+               Tuple2<Class<?>,String>[] mbl = 
properties.getInstanceArray(REST_messages, Tuple2.class).orElse(new Tuple2[0]);
                MessagesBuilder x = null;
 
                for (int i = mbl.length-1; i >= 0; i--) {
diff --git 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
index e0634b4..d86316b 100644
--- 
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
+++ 
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestOperationContext.java
@@ -877,7 +877,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
 
                RestConverterList x = RestConverterList.create();
 
-               x.append(properties.getInstanceArray(REST_converters, 
RestConverter.class, new RestConverter[0], beanFactory));
+               x.append(properties.getInstanceArray(REST_converters, 
RestConverter.class, beanFactory).orElse(new RestConverter[0]));
 
                if (x.isEmpty())
                        x = 
beanFactory.getBean(RestConverterList.class).orElse(x);
@@ -929,7 +929,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
 
                RestGuardList x = RestGuardList.create();
 
-               x.append(properties.getInstanceArray(REST_guards, 
RestGuard.class, new RestGuard[0], beanFactory));
+               x.append(properties.getInstanceArray(REST_guards, 
RestGuard.class, beanFactory).orElse(new RestGuard[0]));
 
                if (x.isEmpty())
                        x = beanFactory.getBean(RestGuardList.class).orElse(x);
@@ -990,7 +990,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
 
                RestMatcherList x = RestMatcherList.create();
 
-               x.append(properties.getInstanceArray(RESTOP_matchers, 
RestMatcher.class, new RestMatcher[0], beanFactory));
+               x.append(properties.getInstanceArray(RESTOP_matchers, 
RestMatcher.class, beanFactory).orElse(new RestMatcher[0]));
 
                if (x.isEmpty())
                        x = 
beanFactory.getBean(RestMatcherList.class).orElse(x);
@@ -1043,7 +1043,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
         */
        protected EncoderGroup createEncoders(Object resource, PropertyStore 
properties, BeanFactory beanFactory) throws Exception {
 
-               Encoder[] x = properties.getInstanceArray(REST_encoders, 
Encoder.class, null, beanFactory);
+               Encoder[] x = properties.getInstanceArray(REST_encoders, 
Encoder.class, beanFactory).orElse(null);
 
                if (x == null)
                        x = beanFactory.getBean(Encoder[].class).orElse(null);
@@ -1397,7 +1397,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
 
                x.appendUnique(context.defaultRequestHeaders);
 
-               
x.appendUnique(properties.getInstanceArray(RESTOP_defaultRequestHeaders, 
org.apache.http.Header.class, new org.apache.http.Header[0], beanFactory));
+               
x.appendUnique(properties.getInstanceArray(RESTOP_defaultRequestHeaders, 
org.apache.http.Header.class, beanFactory).orElse(new 
org.apache.http.Header[0]));
 
                for (Annotation[] aa : method.getParameterAnnotations()) {
                        for (Annotation a : aa) {
@@ -1443,7 +1443,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
 
                x.appendUnique(context.defaultResponseHeaders);
 
-               
x.appendUnique(properties.getInstanceArray(RESTOP_defaultResponseHeaders, 
org.apache.http.Header.class, new org.apache.http.Header[0], beanFactory));
+               
x.appendUnique(properties.getInstanceArray(RESTOP_defaultResponseHeaders, 
org.apache.http.Header.class, beanFactory).orElse(new 
org.apache.http.Header[0]));
 
                x = BeanFactory
                        .of(beanFactory, resource)
@@ -1472,7 +1472,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
 
                x.appendUnique(context.defaultRequestAttributes);
 
-               
x.appendUnique(properties.getInstanceArray(RESTOP_defaultRequestAttributes, 
NamedAttribute.class, new NamedAttribute[0], beanFactory));
+               
x.appendUnique(properties.getInstanceArray(RESTOP_defaultRequestAttributes, 
NamedAttribute.class, beanFactory).orElse(new NamedAttribute[0]));
 
                x = BeanFactory
                        .of(beanFactory, resource)
@@ -1499,7 +1499,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
 
                NameValuePairList x = NameValuePairList.create();
 
-               x.appendUnique(properties.getInstanceArray(RESTOP_defaultQuery, 
NameValuePair.class, new NameValuePair[0], beanFactory));
+               x.appendUnique(properties.getInstanceArray(RESTOP_defaultQuery, 
NameValuePair.class, beanFactory).orElse(new NameValuePair[0]));
 
                for (Annotation[] aa : method.getParameterAnnotations()) {
                        for (Annotation a : aa) {
@@ -1543,7 +1543,7 @@ public class RestOperationContext extends BeanContext 
implements Comparable<Rest
 
                NameValuePairList x = NameValuePairList.create();
 
-               
x.appendUnique(properties.getInstanceArray(RESTOP_defaultFormData, 
NameValuePair.class, new NameValuePair[0], beanFactory));
+               
x.appendUnique(properties.getInstanceArray(RESTOP_defaultFormData, 
NameValuePair.class, beanFactory).orElse(new NameValuePair[0]));
 
                for (Annotation[] aa : method.getParameterAnnotations()) {
                        for (Annotation a : aa) {

Reply via email to