diff --git a/service/src/main/java/org/wildfly/service/descriptor/BinaryServiceDescriptor.java b/service/src/main/java/org/wildfly/service/descriptor/BinaryServiceDescriptor.java index 4930523101e..b7d6a2b6db1 100644 --- a/service/src/main/java/org/wildfly/service/descriptor/BinaryServiceDescriptor.java +++ b/service/src/main/java/org/wildfly/service/descriptor/BinaryServiceDescriptor.java @@ -15,6 +15,31 @@ */ public interface BinaryServiceDescriptor extends ServiceDescriptor { + /** + * Resolves the dynamic name of the service using the specified segments. + * @param parent the first dynamic segment + * @param child the second dynamic segment + * @return a tuple containing the resolved name and dynamic segments + */ + default Map.Entry resolve(String parent, String child) { + return Map.entry(this.getName(), new String[] { + Assert.checkNotNullParamWithNullPointerException("parent", parent), + Assert.checkNotNullParamWithNullPointerException("child", child) + }); + } + + /** + * Provides a two segment service descriptor. + * Typically implemented by enumerations providing service descriptors of the same type. + * @param the service value type + */ + interface Provider extends ServiceDescriptor.Provider>, BinaryServiceDescriptor { + @Override + default Map.Entry resolve(String parent, String child) { + return this.get().resolve(parent, child); + } + } + /** * Creates a binary service descriptor with the specified name and type. * @param the service type @@ -61,17 +86,4 @@ public Map.Entry resolve(String parent, String child) { } }; } - - /** - * Resolves the dynamic name of the service using the specified segments. - * @param parent the first dynamic segment - * @param child the second dynamic segment - * @return a tuple containing the resolved name and dynamic segments - */ - default Map.Entry resolve(String parent, String child) { - return Map.entry(this.getName(), new String[] { - Assert.checkNotNullParamWithNullPointerException("parent", parent), - Assert.checkNotNullParamWithNullPointerException("child", child) - }); - } } diff --git a/service/src/main/java/org/wildfly/service/descriptor/NullaryServiceDescriptor.java b/service/src/main/java/org/wildfly/service/descriptor/NullaryServiceDescriptor.java index 8c31efce611..462039e0905 100644 --- a/service/src/main/java/org/wildfly/service/descriptor/NullaryServiceDescriptor.java +++ b/service/src/main/java/org/wildfly/service/descriptor/NullaryServiceDescriptor.java @@ -13,6 +13,26 @@ */ public interface NullaryServiceDescriptor extends ServiceDescriptor { + /** + * Resolves the constant name of the service. + * @return a tuple containing the resolved name and zero segments + */ + default Map.Entry resolve() { + return Map.entry(this.getName(), new String[0]); + } + + /** + * Provides a zero segment service descriptor. + * Typically implemented by enumerations providing service descriptors of the same type. + * @param the service value type + */ + interface Provider extends ServiceDescriptor.Provider>, NullaryServiceDescriptor { + @Override + default Map.Entry resolve() { + return this.get().resolve(); + } + } + /** * Creates a service descriptor with the specified name and type * @param the service type @@ -33,12 +53,4 @@ public Class getType() { } }; } - - /** - * Resolves the constant name of the service. - * @return a tuple containing the resolved name and zero segments - */ - default Map.Entry resolve() { - return Map.entry(this.getName(), new String[0]); - } } diff --git a/service/src/main/java/org/wildfly/service/descriptor/QuaternaryServiceDescriptor.java b/service/src/main/java/org/wildfly/service/descriptor/QuaternaryServiceDescriptor.java index 9ba979f7186..235deeb5c2a 100644 --- a/service/src/main/java/org/wildfly/service/descriptor/QuaternaryServiceDescriptor.java +++ b/service/src/main/java/org/wildfly/service/descriptor/QuaternaryServiceDescriptor.java @@ -15,6 +15,35 @@ */ public interface QuaternaryServiceDescriptor extends ServiceDescriptor { + /** + * Resolves the dynamic name the service using the specified segments. + * @param greatGrandparent the first dynamic segment + * @param grandparent the second dynamic segment + * @param parent the third dynamic segment + * @param child the fourth dynamic segment + * @return a tuple containing the resolved name and dynamic segments + */ + default Map.Entry resolve(String greatGrandparent, String grandparent, String parent, String child) { + return Map.entry(this.getName(), new String[] { + Assert.checkNotNullParamWithNullPointerException("greatGrandparent", greatGrandparent), + Assert.checkNotNullParamWithNullPointerException("grandparent", grandparent), + Assert.checkNotNullParamWithNullPointerException("parent", parent), + Assert.checkNotNullParamWithNullPointerException("child", child) + }); + } + + /** + * Provides a four segment service descriptor. + * Typically implemented by enumerations providing service descriptors of the same type. + * @param the service value type + */ + interface Provider extends ServiceDescriptor.Provider>, QuaternaryServiceDescriptor { + @Override + default Map.Entry resolve(String greatGrandparent, String grandparent, String parent, String child) { + return this.get().resolve(greatGrandparent, grandparent, parent, child); + } + } + /** * Creates a quaternary service descriptor with the specified name and type. * @param the service type @@ -61,21 +90,4 @@ public Map.Entry resolve(String greatGrandparent, String gran } }; } - - /** - * Resolves the dynamic name the service using the specified segments. - * @param greatGrandparent the first dynamic segment - * @param grandparent the second dynamic segment - * @param parent the third dynamic segment - * @param child the fourth dynamic segment - * @return a tuple containing the resolved name and dynamic segments - */ - default Map.Entry resolve(String greatGrandparent, String grandparent, String parent, String child) { - return Map.entry(this.getName(), new String[] { - Assert.checkNotNullParamWithNullPointerException("greatGrandparent", greatGrandparent), - Assert.checkNotNullParamWithNullPointerException("grandparent", grandparent), - Assert.checkNotNullParamWithNullPointerException("parent", parent), - Assert.checkNotNullParamWithNullPointerException("child", child) - }); - } } diff --git a/service/src/main/java/org/wildfly/service/descriptor/ServiceDescriptor.java b/service/src/main/java/org/wildfly/service/descriptor/ServiceDescriptor.java index 1d0c77e3f45..44f28424472 100644 --- a/service/src/main/java/org/wildfly/service/descriptor/ServiceDescriptor.java +++ b/service/src/main/java/org/wildfly/service/descriptor/ServiceDescriptor.java @@ -4,6 +4,8 @@ */ package org.wildfly.service.descriptor; +import java.util.function.Supplier; + /** * Describes a service by its name and provided value type. * @author Paul Ferraro @@ -22,4 +24,22 @@ public interface ServiceDescriptor { * @return the provided value type of this described service. */ Class getType(); + + /** + * Provides a service descriptor. + * Typically implemented by enumerations providing service descriptors of the same type. + * @param the service value type + * @param the provided service descriptor type + */ + interface Provider> extends Supplier, ServiceDescriptor { + @Override + default String getName() { + return this.get().getName(); + } + + @Override + default Class getType() { + return this.get().getType(); + } + } } diff --git a/service/src/main/java/org/wildfly/service/descriptor/TernaryServiceDescriptor.java b/service/src/main/java/org/wildfly/service/descriptor/TernaryServiceDescriptor.java index 27c942eef2f..7cc61ed9e30 100644 --- a/service/src/main/java/org/wildfly/service/descriptor/TernaryServiceDescriptor.java +++ b/service/src/main/java/org/wildfly/service/descriptor/TernaryServiceDescriptor.java @@ -15,6 +15,33 @@ */ public interface TernaryServiceDescriptor extends ServiceDescriptor { + /** + * Resolves the dynamic name the service using the specified segments. + * @param grandparent the first dynamic segment + * @param parent the second dynamic segment + * @param child the third dynamic segment + * @return a tuple containing the resolved name and dynamic segments + */ + default Map.Entry resolve(String grandparent, String parent, String child) { + return Map.entry(this.getName(), new String[] { + Assert.checkNotNullParamWithNullPointerException("grandparent", grandparent), + Assert.checkNotNullParamWithNullPointerException("parent", parent), + Assert.checkNotNullParamWithNullPointerException("child", child) + }); + } + + /** + * Provides a three segment service descriptor. + * Typically implemented by enumerations providing service descriptors of the same type. + * @param the service value type + */ + interface Provider extends ServiceDescriptor.Provider>, TernaryServiceDescriptor { + @Override + default Map.Entry resolve(String grandparent, String parent, String child) { + return this.get().resolve(grandparent, parent, child); + } + } + /** * Creates a ternary service descriptor with the specified name and type. * @param the service type @@ -61,19 +88,4 @@ public Map.Entry resolve(String grandparent, String parent, St } }; } - - /** - * Resolves the dynamic name the service using the specified segments. - * @param grandparent the first dynamic segment - * @param parent the second dynamic segment - * @param child the third dynamic segment - * @return a tuple containing the resolved name and dynamic segments - */ - default Map.Entry resolve(String grandparent, String parent, String child) { - return Map.entry(this.getName(), new String[] { - Assert.checkNotNullParamWithNullPointerException("grandparent", grandparent), - Assert.checkNotNullParamWithNullPointerException("parent", parent), - Assert.checkNotNullParamWithNullPointerException("child", child) - }); - } } diff --git a/service/src/main/java/org/wildfly/service/descriptor/UnaryServiceDescriptor.java b/service/src/main/java/org/wildfly/service/descriptor/UnaryServiceDescriptor.java index 5b9df621394..9b5cba154e9 100644 --- a/service/src/main/java/org/wildfly/service/descriptor/UnaryServiceDescriptor.java +++ b/service/src/main/java/org/wildfly/service/descriptor/UnaryServiceDescriptor.java @@ -15,6 +15,29 @@ */ public interface UnaryServiceDescriptor extends ServiceDescriptor { + /** + * Resolves the dynamic name of the service using the specified segment. + * @param reference a dynamic segment + * @return a tuple containing the resolved name and dynamic segments + */ + default Map.Entry resolve(String reference) { + return Map.entry(this.getName(), new String[] { + Assert.checkNotNullParamWithNullPointerException("reference", reference) + }); + } + + /** + * Provides a one segment service descriptor. + * Typically implemented by enumerations providing service descriptors of the same type. + * @param the service value type + */ + interface Provider extends ServiceDescriptor.Provider>, UnaryServiceDescriptor { + @Override + default Map.Entry resolve(String reference) { + return this.get().resolve(reference); + } + } + /** * Creates a unary service descriptor with the specified name and type. * @param the service type @@ -61,15 +84,4 @@ public Map.Entry resolve(String name) { } }; } - - /** - * Resolves the dynamic name of the service using the specified segment. - * @param reference a dynamic segment - * @return a tuple containing the resolved name and dynamic segments - */ - default Map.Entry resolve(String reference) { - return Map.entry(this.getName(), new String[] { - Assert.checkNotNullParamWithNullPointerException("reference", reference) - }); - } }