use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.
the class ModelTransformer method transform.
public Device transform() {
this.factory = ModelFactoryImpl.init();
this.device = this.factory.createDevice();
this.device.setName(this.infomodel.getName());
this.device.setInfomodel(this.infomodel);
IMapped<InformationModel> map = this.context.getMappedElement(infomodel, "DeviceInfoProfile");
if (map.hasAttribute("modelNumber")) {
String modelNumber = map.getAttributeValue("modelNumber", "0");
Service service = this.factory.createService();
service.setName("DeviceInformation");
service.setUuid("0000180a-0000-1000-8000-00805f9b34fb");
Characteristic characteristic = this.factory.createCharacteristic();
characteristic.setName("ModelNumber");
characteristic.setUuid("00002a24-0000-1000-8000-00805f9b34fb");
characteristic.setLength(modelNumber.length() / 2);
StringBuffer mnBuf = new StringBuffer();
mnBuf.append("{");
for (int i = 0; i < modelNumber.length(); i += 2) {
mnBuf.append("0x" + modelNumber.substring(i, i + 2));
if (i < modelNumber.length() - 2) {
mnBuf.append(", ");
}
}
mnBuf.append("}");
characteristic.setValue(mnBuf.toString());
service.getCharacteristics().add(characteristic);
this.device.getServices().add(service);
}
for (FunctionblockProperty property : infomodel.getProperties()) {
transformFunctionblock(property.getType());
}
return this.device;
}
use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.
the class InformationModelElement method addModelReference.
@Override
public void addModelReference(IModelElement modelElementReference) {
ModelReference modelReference = modelElementReference.getId().asModelReference();
if (!containsModelReference(modelReference)) {
getModel().getReferences().add(modelReference);
getModel().eResource().getContents().add(modelElementReference.getModel());
}
InformationModel infomodel = (InformationModel) getModel();
infomodel.getProperties().add(createFunctionblockProperty((FunctionblockModel) modelElementReference.getModel(), getVariableNames(infomodel.getProperties())));
}
use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.
the class CodeGeneratorInvocationHandler method evaluate.
private boolean evaluate(String generatorServiceKey) {
IModelElement selectedElement = ModelProjectFactory.getInstance().getModelElementFromSelection();
if (selectedElement == null) {
selectedElement = ModelProjectFactory.getInstance().getSelectedModel();
}
if (selectedElement == null) {
MessageDisplayFactory.getMessageDisplay().displayWarning("Model was not properly selected. Please try again.");
return false;
}
if (!hasNoErrors(selectedElement)) {
MessageDisplayFactory.getMessageDisplay().displayError("Model has errors. Cannot generate.");
return false;
}
InformationModel informationModel = getInformationModel(selectedElement.getModel());
try {
IVortoCodeGenerator generator = lookupService.lookupByKey(generatorServiceKey);
IGenerationResult result = generator.generate(informationModel, createInvocationContext(selectedElement.getProject(), generator.getServiceKey()), VortoCodeGenProgressMonitorFactory.getCodeGenStatusReporter());
CodeGenerationHelper.createEclipseProject(ModelIdFactory.newInstance(informationModel), generator.getServiceKey(), result);
VortoProgressMonitor.getDefault().display();
} catch (Exception e) {
MessageDisplayFactory.getMessageDisplay().displayError(e);
}
return true;
}
use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.
the class EclipseDittoGenerator method generate.
@Override
public IGenerationResult generate(InformationModel infomodel, InvocationContext invocationContext, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
generator.addTask(new SchemaValidatorTask());
generator.generate(infomodel, invocationContext, zipOutputter);
GenerationResultBuilder result = GenerationResultBuilder.from(zipOutputter);
return result.build();
}
use of org.eclipse.vorto.core.api.model.informationmodel.InformationModel in project vorto by eclipse.
the class EclipseHonoGenerator method generate.
@Override
public IGenerationResult generate(InformationModel model, InvocationContext context, IVortoCodeGenProgressMonitor monitor) {
GenerationResultZip output = new GenerationResultZip(model, getServiceKey());
ChainedCodeGeneratorTask<InformationModel> generator = new ChainedCodeGeneratorTask<InformationModel>();
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new PomFileTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new Log4jTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new CertificateTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new AppTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new IDataServiceTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new HonoDataService()));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new HonoMqttClientTemplate()));
generator.addTask(new GeneratorTaskFromFileTemplate<InformationModel>(new InformationModelTemplate()));
generator.generate(model, context, output);
for (FunctionblockProperty fbProperty : model.getProperties()) {
new GeneratorTaskFromFileTemplate<>(new FunctionblockTemplate(model)).generate(fbProperty.getType(), context, output);
}
return output;
}
Aggregations