Skip to main content
Jump to: navigation, search


Revision as of 18:00, 12 June 2019 by (Talk | contribs) (Created page with "This code snippet illustrates the creation of an Asset Administration Shell (AAS) sub model using the Java SDK with the <code>MetaModelElementFactory</code> class. The BaSys s...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This code snippet illustrates the creation of an Asset Administration Shell (AAS) sub model using the Java SDK with the MetaModelElementFactory class. 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 {
	 * Version number of serialized instance
	private static final long serialVersionUID = 1L;
	 * Constructor - create sub model property
	public SampleSubModel() {
		// Set sub model ID
		// Create factory that helps with property creation
		// - This factory creates sub model properties and ensures presence of all meta data
		MetaModelElementFactory fac = new MetaModelElementFactory();
		// Add example properties
		// - Add simple property
		getProperties().put(fac.create(new Property(), 234, "prop1"));
		// - Add container property that holds other properties
		List<SubmodelElement> containerProperties = fac.createList(
				fac.create(new Property(), 123, "prop11")
		// - Add container to property map
		getProperties().put(fac.createContainer(new SubmodelElementCollection(), containerProperties, fac.emptyList(), "prop2"));
		// Add another property manually to sub model container "properties"
		{((Map<String, Object>) this.get("properties")).put("prop3", fac.create(new Property(), 17, "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 SubmodelServlet. This class exports a sub model as HTTP accessible servlet using the BaSys API for sub models.

 * Instantiate and start context elements for this example. BaSyxDeployment contexts instantiate all
 * components on the IP address of the host. Therefore, all components use the same IP address. 
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 <<<>>>.

BaSyx project links: Project BaSyx main wiki page | What is BaSyx? | BaSyx Developer Documentation

Copyright © Eclipse Foundation, Inc. All Rights Reserved.