Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit b0f9bdf

Browse files
committed
initial classes deserialization
1 parent 467716c commit b0f9bdf

7 files changed

Lines changed: 2348 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.adminshell.aas.v3.dataformat.i4aas;
17+
18+
import java.util.List;
19+
20+
import javax.xml.bind.JAXBException;
21+
22+
import org.opcfoundation.ua._2011._03.uanodeset.UANode;
23+
import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet;
24+
25+
import io.adminshell.aas.v3.dataformat.DeserializationException;
26+
import io.adminshell.aas.v3.dataformat.Deserializer;
27+
import io.adminshell.aas.v3.dataformat.i4aas.parsers.EnvironmentParser;
28+
import io.adminshell.aas.v3.dataformat.i4aas.parsers.ParserContext;
29+
import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;
30+
31+
public class I4AASDeserializer implements Deserializer {
32+
33+
@Override
34+
public AssetAdministrationShellEnvironment read(String value) throws DeserializationException {
35+
try {
36+
UANodeSet unmarshallAsString = new UANodeSetUnmarshaller(value).unmarshallAsString();
37+
UANode aasEnv = findAASEnvironment(unmarshallAsString);
38+
return new EnvironmentParser(aasEnv, new ParserContext()).parse();
39+
} catch (JAXBException e) {
40+
throw new DeserializationException("Deserialization failed due to a JAXBException.", e);
41+
}
42+
}
43+
44+
protected UANode findAASEnvironment(UANodeSet nodeSet) throws DeserializationException {
45+
List<UANode> uaObjectOrUAVariableOrUAMethod = nodeSet.getUAObjectOrUAVariableOrUAMethod();
46+
for (UANode uaNode : uaObjectOrUAVariableOrUAMethod) {
47+
if (uaNode.getBrowseName().contains("AASEnvironment")) {
48+
return uaNode;
49+
}
50+
}
51+
throw new DeserializationException("No AASEnvironment found.");
52+
}
53+
54+
@Override
55+
public <T> void useImplementation(Class<T> aasInterface, Class<? extends T> implementation) {
56+
}
57+
58+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.adminshell.aas.v3.dataformat.i4aas;
17+
18+
import java.io.StringReader;
19+
import java.io.StringWriter;
20+
21+
import javax.xml.bind.JAXBContext;
22+
import javax.xml.bind.JAXBException;
23+
import javax.xml.bind.Marshaller;
24+
import javax.xml.bind.Unmarshaller;
25+
26+
import org.opcfoundation.ua._2008._02.types.ListOfExtensionObject;
27+
import org.opcfoundation.ua._2011._03.uanodeset.UANodeSet;
28+
import org.opcfoundation.ua.i4aas.types.AASKeyDataType;
29+
30+
public class UANodeSetUnmarshaller {
31+
32+
33+
private String nodeset;
34+
35+
public UANodeSetUnmarshaller(String nodeset) {
36+
this.nodeset = nodeset;
37+
}
38+
39+
public UANodeSet unmarshallAsString() throws JAXBException {
40+
JAXBContext jaxbCtx = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[] {UANodeSet.class, ListOfExtensionObject.class, AASKeyDataType.class}, null);
41+
Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller();
42+
return (UANodeSet) unmarshaller.unmarshal(new StringReader(nodeset));
43+
}
44+
45+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.adminshell.aas.v3.dataformat.i4aas.parsers;
17+
18+
import org.opcfoundation.ua._2011._03.uanodeset.UANode;
19+
20+
import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;
21+
import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShellEnvironment;
22+
23+
public class EnvironmentParser extends I4AASParser<UANode, AssetAdministrationShellEnvironment> {
24+
25+
public EnvironmentParser(UANode src, ParserContext ctx) {
26+
super(src, ctx);
27+
}
28+
29+
@Override
30+
protected AssetAdministrationShellEnvironment createTargetObject() {
31+
target = new DefaultAssetAdministrationShellEnvironment();
32+
return target;
33+
}
34+
35+
@Override
36+
protected void parseAndAttachChildren() {
37+
// TODO Auto-generated method stub
38+
}
39+
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.adminshell.aas.v3.dataformat.i4aas.parsers;
17+
18+
import org.opcfoundation.ua._2011._03.uanodeset.UANode;
19+
20+
public abstract class I4AASParser<SOURCE extends UANode, TARGET> {
21+
22+
protected ParserContext ctx;
23+
protected SOURCE source;
24+
protected TARGET target;
25+
26+
public I4AASParser(SOURCE src, ParserContext ctx) {
27+
this.source = src;
28+
this.ctx = ctx;
29+
}
30+
31+
public final TARGET parse() {
32+
target = createTargetObject();
33+
parseAndAttachChildren();
34+
return target;
35+
}
36+
37+
protected abstract void parseAndAttachChildren();
38+
39+
protected abstract TARGET createTargetObject();
40+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.adminshell.aas.v3.dataformat.i4aas.parsers;
17+
18+
public class ParserContext {
19+
20+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.adminshell.aas.v3.dataformat.i4aas;
17+
18+
import java.io.IOException;
19+
import java.io.InputStream;
20+
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
24+
import io.adminshell.aas.v3.dataformat.DeserializationException;
25+
import io.adminshell.aas.v3.dataformat.SerializationException;
26+
import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;
27+
28+
public class DeserializerTest {
29+
30+
@Test
31+
public void testAASSimple()
32+
throws SerializationException, IllegalArgumentException, IllegalAccessException, DeserializationException, IOException {
33+
//arrange
34+
I4AASDeserializer i4aasDeserializer = new I4AASDeserializer();
35+
try (InputStream testResourceAsStream = DeserializerTest.class.getResourceAsStream("/AASSimple_V3Draft.xml")) {
36+
//act
37+
AssetAdministrationShellEnvironment parsedResult = i4aasDeserializer.read(testResourceAsStream);
38+
// TODO assert
39+
Assert.assertNotNull(i4aasDeserializer);
40+
}
41+
}
42+
43+
}

0 commit comments

Comments
 (0)