use of eu.esdihumboldt.hale.common.schema.model.TypeIndex in project hale by halestudio.
the class SchemaBuilderReader method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Run schema builder", ProgressIndicator.UNKNOWN);
try {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
compilerConfiguration.setScriptBaseClass(DelegatingScript.class.getName());
// Configure the GroovyShell and pass the compiler configuration.
GroovyShell shell = new GroovyShell(getClass().getClassLoader(), new Binding(), compilerConfiguration);
DelegatingScript script;
try (InputStream in = getSource().getInput();
InputStreamReader reader = new InputStreamReader(in, getCharset())) {
script = (DelegatingScript) shell.parse(reader);
}
SchemaBuilder builder = new SchemaBuilder();
script.setDelegate(builder);
Object res = script.run();
if (res == null) {
throw new IllegalStateException("Null returned by script");
} else if (res instanceof Schema) {
schema = (Schema) res;
} else if (res instanceof TypeIndex) {
DefaultSchema s = new DefaultSchema(null, getSource().getLocation());
for (TypeDefinition type : ((TypeIndex) res).getTypes()) {
s.addType(type);
}
schema = s;
} else if (res instanceof TypeDefinition) {
DefaultSchema s = new DefaultSchema(null, getSource().getLocation());
s.addType((TypeDefinition) res);
schema = s;
} else {
throw new IllegalStateException("Unrecognised return type: " + res.getClass().getName());
}
reporter.setSuccess(true);
} catch (Exception e) {
reporter.setSuccess(false);
reporter.error("Error running schema builder", e);
} finally {
progress.end();
}
return reporter;
}
use of eu.esdihumboldt.hale.common.schema.model.TypeIndex in project hale by halestudio.
the class EntityTypeIndexHierarchy method getElements.
/**
* @see ITreeContentProvider#getElements(Object)
*/
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof TypeIndex) {
validTypes = new HashSet<TypeDefinition>();
List<TypeEntityDefinition> roots = new ArrayList<TypeEntityDefinition>();
Queue<TypeDefinition> types = new LinkedList<TypeDefinition>();
if (onlyMappingRelevant)
types.addAll(((TypeIndex) inputElement).getMappingRelevantTypes());
else {
for (TypeDefinition type : ((TypeIndex) inputElement).getTypes()) if (type.getConstraint(MappableFlag.class).isEnabled())
types.add(type);
}
// collect types and super types in valid types set
while (!types.isEmpty()) {
TypeDefinition type = types.poll();
if (!validTypes.contains(type)) {
validTypes.add(type);
TypeDefinition superType = type.getSuperType();
if (superType != null && !validTypes.contains(superType)) {
types.add(superType);
}
if (superType == null) {
// add default type as root
roots.add(new TypeEntityDefinition(type, schemaSpace, null));
}
}
}
// }
return roots.toArray();
} else {
throw new IllegalArgumentException("Content provider only applicable for type indexes.");
}
}
Aggregations