//Listing 1b: Instanziieren und Starten einer In-Memory-Registry

/* Ein Servlet aufbauen und das Directory einbinden */
BaSyxContext context = new BaSyxContext("", "", "192.168.178.21", 4999);
context.addServletMapping("/*",	new VABHTTPInterface<IModelProvider>(new DirectoryModelProvider()));
	
/* Das Servlet auf einem Server ablegen und Server starten */
AASHTTPServer registryServer = new AASHTTPServer(context);
registryServer.start();

//---------------------------
//
//Listing 2b: Beispielhafte Implementierung einer Verwaltungsschale

/* Das Verwaltungsschalenobjekt anlegen */
AssetAdministrationShell shell = new AssetAdministrationShell();

/* Das Asset anlegen, Kind, Identification und IdShort konfigurieren */
Asset asset = new Asset();
asset.setKind(Kind.Instance);
asset.setIdentification(IdentifierType.URI, "http://boschrexroth.com/assets/nutrunner/0608842010/123456790");
asset.setIdShort("NexoNutrunner_Asset");

/* Das Asset der Verwaltungsschale hinzufügen */
shell.setAsset(asset);

/* Die Verwaltungsschale konfigurieren */
shell.setIdentification(IdentifierType.URI, "http://boschrexroth.com/assets/nutrunner/0608842010/123456790");
shell.setDescription(new Description("de-DE", "Nexo Funk-Akkuschrauber"));
shell.setAdministration("1.0", "");

//---------------------------
//
//Listing 3b: Implementierung des Teilmodells TechnicalSpecification inklusive eines Property

/* Das Teilmodell erzeugen, IdShort und Identification setzen  */
SubModel technicalSpecification = new SubModel();
technicalSpecification.setIdShort("TechnicalSpecification");
technicalSpecification.setIdentification(IdentifierType.Custom, "technicalSpecificationSubModel");

/* Einen Property erstellen und einen String hinterlegen */
Property toolSize = new Property("3 / 8 inch external square");

/* SemanticId und ValueId setzen */
toolSize.setSemanticID(new Reference(new Key(KeyElements.ConceptDescription, true, "0173-1#02-AAI027#005", KeyType.IRDI)));
toolSize.setValueId("0173-1#07-AAC563#001");

/* Die DataSpecification samt prefferedName, Definition und Datentyp festlegen */
DataSpecificationIEC61360 spec = new DataSpecificationIEC61360();
spec.setPreferredName("Größe der Werkzeugaufnahme");
spec.setDefinition("Angabe über die Größe der Verbindungsstelle zur Kraftübertragung zwischen Werkzeug und Maschine in Millimeter");
spec.setDataType("String");

/* Die ConceptDescription spezifizieren und die DataSpecification in ihr ablegen */
ConceptDescription conceptDescription = new ConceptDescription();
conceptDescription.setIdentification(IdentifierType.IRDI, "0173-1#07-AAC563#001");
conceptDescription.setIdShort("ToolInsertionSize");
conceptDescription.addDataSpecification(spec);

/* Die ConceptDescription in der Verwaltungsschale ablegen und im Property referenzieren */
shell.addConceptDescription(conceptDescription);
toolSize.addConceptDescription(spec);

/* Das Property dem Teilmodell hinzufügen */
technicalSpecification.addSubModelElement(toolSize);
	
//---------------------------
//
//Listing 4b: Implementierung eines Teilmodells TighteningControl inklusive einer ausführbaren Operation

/* Das Backend des TighteningService erstellen */
TighteningService tighteningService = new TighteningService();

/* Das Teilmodell erzeugen, IdShort und Identification setzen  */
SubModel tighteningControl = new SubModel();
tighteningControl.setIdShort("TighteningControl");
tighteningControl.setIdentification(IdentifierType.Custom, "tighteningControlSubModel");

/* Die Operation erzeugen und die IdShort setzen */
Operation tightenOp = new Operation();
tightenOp.setIdShort("tighten");

/* Die Eingangsvariablen konfigurieren */
OperationVariable programNoOV = new OperationVariable();
programNoOV.setIdShort("ProgramNo");
programNoOV.setType("String");

OperationVariable timesOV = new OperationVariable();
timesOV.setIdShort("Times");
timesOV.setType("Integer");

/* ... und in der Operation ablegen */
List<OperationVariable> in = new ArrayList<>();
in.add(programNoOV);
in.add(timesOV);

tightenOp.SetParameterTypes(in);

/* Die Ausgangsvariable konfigurieren */
OperationVariable ret = new OperationVariable();
ret.setIdShort("TighteningSuccess");
ret.setType("Boolean");

/* ... und in der Operation ablegen */
tightenOp.setReturnTypes(Collections.singletonList(ret));

/* Die Funktion für den Schrauberzugriff als Lambda-Funktion definieren */
Function<Object[], Object> func = (arg) -> {

	/* Die Parameter entpacken */
	String programNo = (String) arg[0];
	int times = (int) arg[1];

	/* ... und die Funktion aufrufen */
	return tighteningService.tightenTimes(programNo, times);
};

/* Die Lambda-Funktion in der Operation hinterlegen */
tightenOp.setInvocable(func);

/* ... und die Operation in dem Teilmodell ablegen */
tighteningControl.addSubModelElement(tightenOp);

//---------------------------
//
//Listing 5b: Konfiguration und Start der Verwaltungsschale

/* Die Verwaltungsschale in einem Provider ablegen */
VABMultiSubmodelProvider provider = new VABMultiSubmodelProvider(new AASModelProvider(aas));
	
/* ... und ihre Teilmodelle ebenfalls  */
provider.addSubmodel("TighteningControl", new SubModelProvider(tighteningControl));
provider.addSubmodel("TechnicalSpecification", new SubModelProvider(technicalSpecification));

/* Ein Servlet aufbauen und den Provider einbinden */
BaSyxContext context = new BaSyxContext("", "", "192.168.178.13", 5080);
context.addServletMapping("/*", new VABHTTPInterface<IModelProvider>(provider));
	
/* Das Servlet auf einem Server ablegen und den Server starten */
AASHTTPServer httpServer = new AASHTTPServer(context);
httpServer.start();

//---------------------------
//
//Listing 6b: Erstellen der Verwaltungsschalen- und Teilmodelldeskriptoren inklusive Endpunktkonfiguration

/* Den Verwaltungsschalen-Deskriptor erzeugen und den Endpunkt/die Adresse festlegen */
AASDescriptor aasDescriptor = new AASDescriptor(aas, "http://192.168.178.13:5080/aas");
	
/* Die Teilmodell-Deskriptoren mit den jeweiligen Endpunkten erstellen und dem Verwaltungsschalen-Deskriptor hinzufügen */
aasDescriptor.addSubmodelDescriptor(new SubmodelDescriptor(tighteningControl, "http://192.168.178.13:5080:5080/aas/submodels/" + tighteningControl.getIdShort() + "/submodel"));
aasDescriptor.addSubmodelDescriptor(new SubmodelDescriptor(technicalSpecification, "http://localhost:5080/aas/submodels/" + technicalSpecification.getIdShort() + "/submodel"));

//---------------------------
//
//Listing 7b: Registrieren des erstellten Verwaltungsschalendeskriptors

/* Den Registry-Proxy über den Endpunkt erstellen */
AASRegistryProxy registry = new AASRegistryProxy("http://192.168.178.21:4999/");
	
/* ... und die Verwaltungsschale registrieren */
	registry.register(aasDescriptor);



	
	
	
	
	
	
	
	
	
	
	---------------------------
Abbildung 15 (Maven-POM):

	<project xmlns="http://maven.apache.org/POM/4.0.0"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
		<modelVersion>4.0.0</modelVersion>
		<groupId>org.eclipse.basyx</groupId>
		<artifactId>basyx.iX.registry</artifactId>
		<!--  
		<artifactId>basyx.iX.aas</artifactId>
		-->
		<version>0.0.1-SNAPSHOT</version>

		<build>
		  <plugins>
			<plugin>
			  <artifactId>maven-assembly-plugin</artifactId>
			  <configuration>
				<archive>
				  <manifest>
					<mainClass>org.eclipse.basyx.iX.Registry</mainClass>
					 <!--  
					<mainClass>org.eclipse.basyx.iX.AAS</mainClass>
					-->
				  </manifest>
				</archive>
				<descriptorRefs>
				  <descriptorRef>jar-with-dependencies</descriptorRef>
				</descriptorRefs>
			  </configuration>
			</plugin>
		  </plugins>
		</build>
		
		<dependencies>
			<dependency>
				<groupId>org.eclipse.basyx</groupId>
				<artifactId>basyx.sdk</artifactId>
				<version>0.0.1-SNAPSHOT</version>
			</dependency>
		</dependencies>

	</project>



