Skip to content

Commit

Permalink
WFCORE-6347 Add provider interfaces per service descriptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Jan 4, 2024
1 parent 452acf2 commit 6a05fcd
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@
*/
public interface BinaryServiceDescriptor<T> extends ServiceDescriptor<T> {

/**
* 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<String, String[]> 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 <T> the service value type
*/
interface Provider<T> extends ServiceDescriptor.Provider<T, BinaryServiceDescriptor<T>>, BinaryServiceDescriptor<T> {
@Override
default Map.Entry<String, String[]> resolve(String parent, String child) {
return this.get().resolve(parent, child);
}
}

/**
* Creates a binary service descriptor with the specified name and type.
* @param <T> the service type
Expand Down Expand Up @@ -61,17 +86,4 @@ public Map.Entry<String, String[]> 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<String, String[]> resolve(String parent, String child) {
return Map.entry(this.getName(), new String[] {
Assert.checkNotNullParamWithNullPointerException("parent", parent),
Assert.checkNotNullParamWithNullPointerException("child", child)
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@
*/
public interface NullaryServiceDescriptor<T> extends ServiceDescriptor<T> {

/**
* Resolves the constant name of the service.
* @return a tuple containing the resolved name and zero segments
*/
default Map.Entry<String, String[]> 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 <T> the service value type
*/
interface Provider<T> extends ServiceDescriptor.Provider<T, NullaryServiceDescriptor<T>>, NullaryServiceDescriptor<T> {
@Override
default Map.Entry<String, String[]> resolve() {
return this.get().resolve();
}
}

/**
* Creates a service descriptor with the specified name and type
* @param <T> the service type
Expand All @@ -33,12 +53,4 @@ public Class<T> getType() {
}
};
}

/**
* Resolves the constant name of the service.
* @return a tuple containing the resolved name and zero segments
*/
default Map.Entry<String, String[]> resolve() {
return Map.entry(this.getName(), new String[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@
*/
public interface QuaternaryServiceDescriptor<T> extends ServiceDescriptor<T> {

/**
* 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<String, String[]> 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 <T> the service value type
*/
interface Provider<T> extends ServiceDescriptor.Provider<T, QuaternaryServiceDescriptor<T>>, QuaternaryServiceDescriptor<T> {
@Override
default Map.Entry<String, String[]> 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 <T> the service type
Expand Down Expand Up @@ -61,21 +90,4 @@ public Map.Entry<String, String[]> 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<String, String[]> 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)
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,4 +24,22 @@ public interface ServiceDescriptor<T> {
* @return the provided value type of this described service.
*/
Class<T> getType();

/**
* Provides a service descriptor.
* Typically implemented by enumerations providing service descriptors of the same type.
* @param <T> the service value type
* @param <SD> the provided service descriptor type
*/
interface Provider<T, SD extends ServiceDescriptor<T>> extends Supplier<SD>, ServiceDescriptor<T> {
@Override
default String getName() {
return this.get().getName();
}

@Override
default Class<T> getType() {
return this.get().getType();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@
*/
public interface TernaryServiceDescriptor<T> extends ServiceDescriptor<T> {

/**
* 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<String, String[]> 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 <T> the service value type
*/
interface Provider<T> extends ServiceDescriptor.Provider<T, TernaryServiceDescriptor<T>>, TernaryServiceDescriptor<T> {
@Override
default Map.Entry<String, String[]> 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 <T> the service type
Expand Down Expand Up @@ -61,19 +88,4 @@ public Map.Entry<String, String[]> 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<String, String[]> 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)
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@
*/
public interface UnaryServiceDescriptor<T> extends ServiceDescriptor<T> {

/**
* 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<String, String[]> 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 <T> the service value type
*/
interface Provider<T> extends ServiceDescriptor.Provider<T, UnaryServiceDescriptor<T>>, UnaryServiceDescriptor<T> {
@Override
default Map.Entry<String, String[]> resolve(String reference) {
return this.get().resolve(reference);
}
}

/**
* Creates a unary service descriptor with the specified name and type.
* @param <T> the service type
Expand Down Expand Up @@ -61,15 +84,4 @@ public Map.Entry<String, String[]> 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<String, String[]> resolve(String reference) {
return Map.entry(this.getName(), new String[] {
Assert.checkNotNullParamWithNullPointerException("reference", reference)
});
}
}

0 comments on commit 6a05fcd

Please sign in to comment.