Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
BaSyx.Examples.Snippets.AASSMCreation.Java
This code snippet illustrates the creation of an Asset Administration Shell (AAS) sub model using the Java SDK with the SubModel<code>. The BaSys setup for this code snippet is the following:
The BaSys setup consists of a Apache Tomcat server that runs BaSyx Servlets. It contains a sub model provider that exports the created example sub model. The snippet code runs in context of a servlet in the tomcat server and creates an AAS sub model. The sub model is created as following:
/** * Example sub model. This example sub model is created with the BaSyx SDK factory and defines the AAS meta model properties */ static class SampleSubModel extends SubModel { /** * Constructor - create sub model * * This sub model contains static properties, i.e. properties that have a static value assigned. */ @SuppressWarnings("unchecked") public SampleSubModel() { // Set sub model ID setIdShort("sm-001"); // Add example properties // - Add simple property Property prop1 = new Property(234); prop1.setIdShort("prop1"); addSubModelElement(prop1); Property prop11 = new Property(123); prop11.setIdShort("prop11"); // - Add container property that holds other properties SubmodelElementCollection container = new SubmodelElementCollection(); container.setIdShort("prop2"); container.addElement(prop11); // - Add container to property map addSubModelElement(container); // Add another property manually to sub model container "properties" Property prop3 = new Property(17); prop3.setIdShort("prop3"); { ((Map<String, Object>) this.get("submodelElements")).put("prop3", prop3); } } }
The sub model exports the following property structure:
- Sub Model "sm-001"
- prop1 : Integer = 234
- prop3 : Integer = 17
- prop2 : Container
- prop11 : Integer = 123
The following code illustrates the deployment of the AAS sub model to the Apache Tomcat server. It maps the path on the HTTP server "/Testsuite/components/BaSys/1.0/SampleModel/*" to an instance of class <code>SubmodelServlet. This class exports a sub model as HTTP accessible servlet using the BaSys API for sub models.
/** * The BaSyx Deployment instantiates and starts context elements for this example. * * This example instantiates the BaSyxExamplesContext_1MemoryAASServer_1SQLDirectory * example context that creates one AAS server, and one SQL based AAS registry. * * BaSyxDeployment contexts instantiate all components on the IP address of the host. * Therefore, all components use the same IP address. */ @ClassRule public static BaSyxDeployment context = new BaSyxDeployment( // Servlets for example snippet new BaSyxExamplesContext_Empty(). // Deploy example specific servlets to Tomcat server in this context addServletMapping("/Testsuite/components/BaSys/1.0/SampleModel/*", new SubmodelServlet(new SampleSubModel())) );
The complete, executable code is available in the basyx.examples project in package org.eclipse.basyx.examples.snippets.aas.submodels.
BaSyx project links: Project BaSyx main wiki page | What is BaSyx? | BaSyx Developer Documentation |