Available since version 1.1
In some cases, you might not be able to provide the end user with a hint about part of your MetadataKey. For example, the universe of options might be too big (a dropdown with all the classes in a classpath makes not sense) or when the starting point of the ID is a free input (for example, a query).
Imagine a MetadataKeyId that has a part that is a String representing a Java class. It can be very time consuming to retrieve all the classes, and it is complicated for the user to have so many options on a dropdown.
So, you can signal that a MetadataKeyPart will not be provided by the resolver and must be inserted by the user. You do this by setting the providedByKeyResolver to false value on the MetadataKeyPart annotation.
Here is an example where the POJO representing the MetadataKeyId represents a Java
method:
public class MethodIdentifier{
@Parameter
@Alias("class")
@MetadataKeyPart(order = 1, providedByKeyResolver = false) (1)
private String clazz;
@Parameter
@Alias("method")
@MetadataKeyPart(order = 2)
private String methodId;
@Override
public String getClazz() {
return clazz;
}
@Override
public String getMethodId() {
return methodId;
}
@Override
public void setClazz(String clazz) {
this.clazz = clazz;
}
@Override
public void setMethodId(String methodId) {
this.methodId = methodId;
}
}
| 1 |
The clazz field must be inserted by the end user without hints. |
In this case, it also means that the getKeys method cannot return all the possible classes:
public class MethodTypeKeysResolver implements PartialTypeKeysResolver<MethodIdentifier> {
@Override
public Set<MetadataKey> getKeys(MetadataContext context) throws MetadataResolvingException, ConnectionException {
return emptySet(); (1)
}
@Override
public MetadataKey resolveChilds(MetadataContext metadataContext, MethodIdentifier key)
throws MetadataResolvingException, ConnectionException {
if(key.getClazz() == null){
throw new MetadataResolvingException("Missing Class name. Cannot resolve Methods without a target Class",
FailureCode.INVALID_METADATA_KEY);
}
MetadataKeyBuilder key = MetadataKeyBuilder.newKey(key.getClazz()); (2)
for(String methodId : getMethodIds(key.getClazz())){
key.withChild(MetadataKeyBuilder.newKey(methodId).build()); (3)
}
return key;
}
}
| 1 |
Return an empty set of MetadataKey because the end user will provide this information. |
| 2 |
Build a single MetadataKey tree with a new, complete level of metadata, in this case, the methodIds level. |
| 3 |
Add the methodIds of that class as children. |