use of org.qi4j.api.composite.CompositeDescriptor in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method stringToCompositeDescriptor.
protected static <TCompositeDescriptor extends CompositeDescriptor> TCompositeDescriptor stringToCompositeDescriptor(final Class<TCompositeDescriptor> descriptorClass, ApplicationDescriptor appDesc, String str) {
Matcher matcher = DESCRIPTOR_TEXTUAL_REGEXP.matcher(str);
if (!matcher.matches()) {
throw new IllegalArgumentException("Descriptor textual description " + str + " was invalid.");
}
final String layerName = matcher.group(1);
final String moduleName = matcher.group(2);
final Set<String> classNames = new HashSet<>();
Matcher typesMatcher = DESCRIPTOR_TYPES_REGEXP.matcher(matcher.group(3));
while (typesMatcher.find()) {
classNames.add(typesMatcher.group(0));
}
final CompositeDescriptor[] result = new CompositeDescriptor[1];
appDesc.accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {
@Override
public boolean visitEnter(Object visited) {
boolean thisResult = true;
if (visited instanceof LayerDescriptor) {
thisResult = ((LayerDescriptor) visited).name().equals(layerName);
} else if (visited instanceof ModuleDescriptor) {
thisResult = ((ModuleDescriptor) visited).name().equals(moduleName);
} else if (descriptorClass.isAssignableFrom(visited.getClass())) {
CompositeDescriptor desc = (CompositeDescriptor) visited;
if (classNames.equals(new HashSet<>(Iterables.toList(Iterables.map(new Function<Class<?>, String>() {
@Override
public String map(Class<?> from) {
return from.getName();
}
}, desc.types()))))) {
result[0] = desc;
thisResult = false;
}
}
return thisResult;
}
@Override
public boolean visitLeave(Object visited) {
return result[0] == null;
}
});
return (TCompositeDescriptor) result[0];
}
Aggregations