There are a few ways to integrate with Java-based technology and obtain the ESDL Java source code. This can be obtained manually using option 1, but we also provide a external maven repository and maven tools to generate the source code on the command line.
1. Use our maven repository
Add the following repository entry to your pom.xml file:
You can also manually extract the main EMF-jar files from your local P2 Eclipse repository and add them to your classpath. You require the following EMF-jars:
(Optional) If you want to be able to extend the ESDLPackage to create your own implementations for the ESDL classes, please manually add this constructor definition…
… to the EsdlPackageImpl.java class in ESDL/esdl/src-gen/esdl/impl/EsdlPackageImpl.java
You can then add the folder ESDL/esdl/src-gen to the build path of your code in your IDE.
Don't forget to add the EMF dependencies mentioned above.
3. Use the Eclipse platform for code generation (and application creation)
When loading the ESDL project into Eclipse, you can right-click the esdl.genmodel file to generate the ESDL model Java code. Then use this project in other Eclipse based plugins.
Note: this approach is outdated now and hasn't been tested recently, we mostly create stand-alone Java applications outside of the Eclipse environment using the maven repository and dependencies.
Examples
E.g. creating an Energy System with an Area programmatically:
EnergySystem energySystem = EsdlFactory.eINSTANCE.createEnergySystem();
energySystem.setName("My First EnergySystem");
energySystem.setId("firstEnergySystem");
Area area = EsdlFactory.eINSTANCE.createArea();
area.setId("Test");
area.setName("Amsterdam municipality")
energySystem.getArea().add(area);
The following code allows you to load and save ESDL-model instances:
Loading of an ESDL-file
public static EnergySystem loadESDLModel(String fileName) throws IOException {
// Initialize the model
EsdlPackage.eINSTANCE.eClass();
XMIResource resource = new XMIResourceImpl(URI.createURI(fileName));
resource.load(null);
return (EnergySystem) resource.getContents().get(0);
}
If the models grow large with a lot of internal references, add the following lines to speed up the loading of the files:
public static EnergySystem loadESDLModel(String fileName) throws IOException {
// Initialize the model
EsdlPackage.eINSTANCE.eClass();
XMIResource resource = new XMIResourceImpl(URI.createURI(fileName));
// speed up loading of large files by defering ID references lookup.
resource.getDefaultLoadOptions().put(XMIResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
resource.setIntrinsicIDToEObjectMap(new HashMap<String, EObject>());
// load the resource
resource.load(null);
return (EnergySystem) resource.getContents().get(0);
}
Saving an ESDL-file
Saving to an ESDL-file is as follows:
public static XMIResource saveESDLModel(EnergySystem energySystem, String fileName) throws IOException {
XMIResource resource = new XMIResourceImpl(URI.createURI(fileName));
resource.getContents().add(energySystem);
HashMap<String, Object> opts = new HashMap<String, Object>();
// Produce an xsi:schemaLocation in the resource
opts.put(XMIResource.OPTION_SCHEMA_LOCATION, true);
resource.save(opts);
return resource;
}
This is currently used for the Edit, Editor and Designer plugins: they are Eclipse plugins that leverage the feature-rich Eclipse platform. Explaining how to do this can be read elsewhere on the internet. Options include using to create the Designer plugin, using to create attractive UIs to edit model instances, or creating a stand-alone ESDL-based application using .