use of org.obeonetwork.dsl.ecorebinding.BPackage in project InformationSystem by ObeoNetwork.
the class EcorebindingModelWizardSpec method createInitialModel.
/**
* (non-Javadoc)
* @see org.obeonetwork.dsl.ecorebinding.presentation.EcorebindingModelWizard#createInitialModel()
*/
@Override
protected EObject createInitialModel() {
IPath ecoreFilePath = this.ecoreSelectionWizardPage.getEcoreFilePath();
ResourceSet ecorers = new ResourceSetImpl();
Resource ecoreResource = ecorers.getResource(URI.createFileURI(ecoreFilePath.toFile().getAbsolutePath()), true);
try {
ecoreResource.load(new HashMap<String, String>());
} catch (IOException e) {
e.printStackTrace();
}
ResourceSet rs = new ResourceSetImpl();
IPath ecoreBindingModelPath = ecoreFilePath;
ecoreBindingModelPath = ecoreFilePath.removeFileExtension().addFileExtension("ecorebinding");
Resource resource = rs.createResource(URI.createFileURI(ecoreBindingModelPath.toFile().getAbsolutePath()));
BModel ecoreBindingModel = EcorebindingFactory.eINSTANCE.createBModel();
List<EObject> contents = ecoreResource.getContents();
for (EObject eObject : contents) {
// We only support EPackage as root element.
if (eObject instanceof EPackage) {
EPackage rootPackage = (EPackage) eObject;
BPackage ecoreBindingPackage = EcorebindingFactory.eINSTANCE.createBPackage();
ecoreBindingPackage.setEcorePackage(rootPackage);
ecoreBindingModel.getBPackages().add(ecoreBindingPackage);
explore(rootPackage, ecoreBindingPackage);
} else {
throw new IllegalArgumentException("The Ecore Binding only supports EPackage as root element");
}
}
resource.getContents().add(ecoreBindingModel);
try {
resource.save(new HashMap<String, String>());
} catch (IOException e) {
e.printStackTrace();
}
return ecoreBindingModel;
}
use of org.obeonetwork.dsl.ecorebinding.BPackage in project InformationSystem by ObeoNetwork.
the class EcorebindingModelWizardSpec method explore.
/**
* Expore the EPackage and init the BPackage.
* @param ePackage The ecore Package input to read
* @param bPackage The Binding Package to build
*/
private static void explore(EPackage ePackage, BPackage bPackage) {
EList<EClassifier> eClassifiers = ePackage.getEClassifiers();
for (EClassifier eClassifier : eClassifiers) {
if (eClassifier instanceof EClass) {
EClass eClass = (EClass) eClassifier;
// Create BClass
BClass bClass = EcorebindingFactory.eINSTANCE.createBClass();
bClass.setEcoreClass(eClass);
bPackage.getBClasses().add(bClass);
bPackage.getBClassifiers().add(bClass);
explore(eClass, bClass);
} else if (eClassifier instanceof EEnum) {
EEnum eEnum = (EEnum) eClassifier;
// Create BEnum
BEnum bEnum = EcorebindingFactory.eINSTANCE.createBEnum();
bEnum.setEcoreEnum(eEnum);
bEnum.setEcoreDataType(eEnum);
bPackage.getBEnums().add(bEnum);
bPackage.getBClassifiers().add(bEnum);
List<EEnumLiteral> eLiterals = eEnum.getELiterals();
for (EEnumLiteral eLiteral : eLiterals) {
// Create BEnumLiteral
BEnumLiteral bEnumLiteral = EcorebindingFactory.eINSTANCE.createBEnumLiteral();
bEnumLiteral.setBEnum(bEnum);
bEnumLiteral.setEcoreEnumLiteral(eLiteral);
}
} else if (eClassifier instanceof EDataType) {
EDataType eDataType = (EDataType) eClassifier;
// Create BDataType
BDataType bDataType = EcorebindingFactory.eINSTANCE.createBDataType();
bDataType.setEcoreDataType(eDataType);
bPackage.getBDataTypes().add(bDataType);
bPackage.getBClassifiers().add(bDataType);
}
}
List<EPackage> eSubpackages = ePackage.getESubpackages();
for (EPackage subEPackage : eSubpackages) {
// Create BPackage
BPackage subBPackage = EcorebindingFactory.eINSTANCE.createBPackage();
subBPackage.setEcorePackage(subEPackage);
bPackage.getNestedBPackages().add(subBPackage);
explore(subEPackage, subBPackage);
}
}
Aggregations