org.eclipse.epsilon.eol.models.ModelGroup Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (c) 2008 The University of York.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* Dimitrios Kolovos - initial API and implementation
******************************************************************************/
package org.eclipse.epsilon.eol.models;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.epsilon.common.util.StringProperties;
import org.eclipse.epsilon.eol.exceptions.EolIllegalPropertyException;
import org.eclipse.epsilon.eol.exceptions.EolRuntimeException;
import org.eclipse.epsilon.eol.exceptions.models.EolEnumerationValueNotFoundException;
import org.eclipse.epsilon.eol.exceptions.models.EolModelElementTypeNotFoundException;
import org.eclipse.epsilon.eol.exceptions.models.EolModelLoadingException;
import org.eclipse.epsilon.eol.exceptions.models.EolModelNotFoundException;
import org.eclipse.epsilon.eol.exceptions.models.EolNotInstantiableModelElementTypeException;
import org.eclipse.epsilon.eol.execute.context.IEolContext;
import org.eclipse.epsilon.eol.execute.introspection.AbstractPropertyGetter;
import org.eclipse.epsilon.eol.execute.introspection.AbstractPropertySetter;
import org.eclipse.epsilon.eol.execute.introspection.IPropertySetter;
public class ModelGroup extends Model {
protected ArrayList models = new ArrayList<>();
public ModelGroup() {}
public ModelGroup(ModelRepository repository, String metaModel) throws EolModelNotFoundException {
this.name = metaModel;
propertyGetter = new DelegatingModelElementPropertyGetter();
for (IModel model : repository.getModels()) {
if (model.getAliases().contains(metaModel)) {
models.add(model);
}
}
if (models.isEmpty()) throw new EolModelNotFoundException(metaModel);
}
public ArrayList getModels() {
return models;
}
@Override
public void load() throws EolModelLoadingException {
for (IModel model : models) {
model.load();
}
}
public String getMetaModel() {
return null;
}
@Override
public Object getEnumerationValue(String enumeration, String label) throws EolEnumerationValueNotFoundException {
for (IModel model : models) {
try {
return model.getEnumerationValue(enumeration,label);
}
catch (Exception ex) {}
}
throw new EolEnumerationValueNotFoundException(enumeration, label, this.getName());
}
@Override
public Collection> getAllOfType(String metaClass) throws EolModelElementTypeNotFoundException {
List filtered = models.stream().filter(m -> m.hasType(metaClass)).collect(Collectors.toList());
if (filtered.size() == 1) {
return filtered.get(0).getAllOfType(metaClass);
}
else {
ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy