Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFCORE-6347 Add method to cast service descriptor instance as subtype. #5825

Merged
merged 7 commits into from
Jan 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ default boolean isDynamicDependent() {
*
* @param name the name of the attribute.
* @param address the registration address of the resource definition that has the capability and its requirement.
* N.B. This parameter is only specified in association with a ResourcDefinition.
* When associated with an AttributeDefinition, address will always be {@link PathAddress#EMPTY_ADDRESS}.
* @return the elements to be added to the baseRequirementName to build the capability name pattern.
*/
default String[] getRequirementPatternSegments(String name, PathAddress address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,8 @@ public ServiceName getCapabilityServiceName(String capabilityBaseName, String dy

@Override
public ServiceName getCapabilityServiceName(String capabilityBaseName, Class<?> serviceType, String ... dynamicParts) {
return getCapabilityServiceName(capabilityBaseName, serviceType).append(dynamicParts);
ServiceName name = getCapabilityServiceName(capabilityBaseName, serviceType);
return (dynamicParts.length > 0) ? name.append(dynamicParts) : name;
}

ServiceName getCapabilityServiceName(String capabilityName, Class<?> serviceType, final PathAddress address) {
Expand Down Expand Up @@ -2664,7 +2665,8 @@ public ServiceName getCapabilityServiceName(String capabilityName) {

@Override
public ServiceName getCapabilityServiceName(String capabilityBaseName, String ... dynamicPart) {
return getCapabilityServiceName(capabilityBaseName).append(dynamicPart);
ServiceName name = getCapabilityServiceName(capabilityBaseName);
return (dynamicPart.length > 0) ? name.append(dynamicPart) : name;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void performRuntime(OperationContext context, ModelNode operation, Mod

for (RuntimeCapability<?> capability : capabilitySet) {
if (capability.getCapabilityServiceValueType() != null) {
context.removeService(capability.getCapabilityServiceName(address));
context.removeService(capability.isDynamicallyNamed() ? capability.getCapabilityServiceName(address) : capability.getCapabilityServiceName());
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ default Map.Entry<String, String[]> resolve(String parent, String child) {
});
}

@Override
default <U extends T> BinaryServiceDescriptor<U> asType(Class<U> type) {
return new BinaryServiceDescriptor<>() {
@Override
public String getName() {
return BinaryServiceDescriptor.this.getName();
}

@Override
public Class<U> getType() {
return type;
}

@Override
public Map.Entry<String, String[]> resolve(String parent, String child) {
return BinaryServiceDescriptor.this.resolve(parent, child);
}
};
}

/**
* Provides a two segment service descriptor.
* Typically implemented by enumerations providing service descriptors of the same type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ default Map.Entry<String, String[]> resolve() {
return Map.entry(this.getName(), new String[0]);
}

@Override
default <U extends T> NullaryServiceDescriptor<U> asType(Class<U> type) {
return new NullaryServiceDescriptor<>() {
@Override
public String getName() {
return NullaryServiceDescriptor.this.getName();
}

@Override
public Class<U> getType() {
return type;
}

@Override
public Map.Entry<String, String[]> resolve() {
return NullaryServiceDescriptor.this.resolve();
}
};
}

/**
* Provides a zero segment service descriptor.
* Typically implemented by enumerations providing service descriptors of the same type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ default Map.Entry<String, String[]> resolve(String greatGrandparent, String gran
});
}

@Override
default <U extends T> QuaternaryServiceDescriptor<U> asType(Class<U> type) {
return new QuaternaryServiceDescriptor<>() {
@Override
public String getName() {
return QuaternaryServiceDescriptor.this.getName();
}

@Override
public Class<U> getType() {
return type;
}

@Override
public Map.Entry<String, String[]> resolve(String greatGrandparent, String grandparent, String parent, String child) {
return QuaternaryServiceDescriptor.this.resolve(greatGrandparent, grandparent, parent, child);
}
};
}

/**
* Provides a four segment service descriptor.
* Typically implemented by enumerations providing service descriptors of the same type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public interface ServiceDescriptor<T> {
*/
Class<T> getType();

/**
* Returns a sub-class view of this service descriptor.
* @param <U> the subclass type
* @param type a sub-class of this descriptor's type
* @return a sub-class view of this service descriptor.
*/
<U extends T> ServiceDescriptor<U> asType(Class<U> type);

/**
* Provides a service descriptor.
* Typically implemented by enumerations providing service descriptors of the same type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ default Map.Entry<String, String[]> resolve(String grandparent, String parent, S
});
}

@Override
default <U extends T> TernaryServiceDescriptor<U> asType(Class<U> type) {
return new TernaryServiceDescriptor<>() {
@Override
public String getName() {
return TernaryServiceDescriptor.this.getName();
}

@Override
public Class<U> getType() {
return type;
}

@Override
public Map.Entry<String, String[]> resolve(String grandparent, String parent, String child) {
return TernaryServiceDescriptor.this.resolve(grandparent, parent, child);
}
};
}

/**
* Provides a three segment service descriptor.
* Typically implemented by enumerations providing service descriptors of the same type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ default Map.Entry<String, String[]> resolve(String reference) {
});
}

@Override
default <U extends T> UnaryServiceDescriptor<U> asType(Class<U> type) {
return new UnaryServiceDescriptor<>() {
@Override
public String getName() {
return UnaryServiceDescriptor.this.getName();
}

@Override
public Class<U> getType() {
return type;
}

@Override
public Map.Entry<String, String[]> resolve(String name) {
return UnaryServiceDescriptor.this.resolve(name);
}
};
}

/**
* Provides a one segment service descriptor.
* Typically implemented by enumerations providing service descriptors of the same type.
Expand Down
Loading