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

Commit 957f83e

Browse files
committed
Modify internal state of AASXDeserializer to be private
1 parent b41d0ed commit 957f83e

2 files changed

Lines changed: 16 additions & 22 deletions

File tree

dataformat-aasx/src/main/java/io/adminshell/aas/v3/dataformat/aasx/AASXDeserializer.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class AASXDeserializer {
5858
private XmlDeserializer deserializer = new XmlDeserializer();
5959

6060
private AssetAdministrationShellEnvironment environment;
61-
public OPCPackage aasxRoot;
61+
private final OPCPackage aasxRoot;
6262

6363
public AASXDeserializer(InputStream inputStream) throws InvalidFormatException, IOException {
6464
aasxRoot = OPCPackage.open(inputStream);
@@ -70,28 +70,27 @@ public AASXDeserializer(XmlDeserializer deserializer, InputStream inputStream) t
7070
}
7171

7272
public AssetAdministrationShellEnvironment read() throws InvalidFormatException, IOException, DeserializationException {
73-
7473
// If the XML was already parsed return cached environment
7574
if (environment != null) {
7675
return environment;
7776
}
78-
7977
environment = deserializer.read(getXMLResourceString(aasxRoot));
80-
8178
return environment;
8279
}
8380

8481
/**
8582
* Return the Content of the xml file in the aasx-package as String
8683
*
87-
* @param aasxPackage
88-
* - the root package of the AASX
84+
* @param aasxPackage - the root package of the AASX
8985
* @return Content of XML as String
9086
* @throws InvalidFormatException
9187
* @throws IOException
9288
*/
93-
public String getXMLResourceString(OPCPackage aasxPackage) throws InvalidFormatException, IOException {
89+
public String getXMLResourceString() throws InvalidFormatException, IOException {
90+
return getXMLResourceString(this.aasxRoot);
91+
}
9492

93+
private String getXMLResourceString(OPCPackage aasxPackage) throws InvalidFormatException, IOException {
9594
// Get the "/aasx/aasx-origin" Part. It is Relationship source for the
9695
// XML-Document
9796
PackagePart originPart = aasxPackage.getPart(PackagingURIHelper.createPartName(AASX_ORIGIN));
@@ -129,11 +128,9 @@ public String getXMLResourceString(OPCPackage aasxPackage) throws InvalidFormatE
129128
*
130129
*/
131130
private List<String> parseReferencedFilePathsFromAASX() throws IOException, InvalidFormatException, DeserializationException {
131+
read();
132132

133-
AssetAdministrationShellEnvironment environment = read();
134-
135-
List<String> paths = new ArrayList<String>();
136-
133+
List<String> paths = new ArrayList<>();
137134
for (Submodel sm : environment.getSubmodels()) {
138135
paths.addAll(parseElements(sm.getSubmodelElements()));
139136
}
@@ -147,8 +144,7 @@ private List<String> parseReferencedFilePathsFromAASX() throws IOException, Inva
147144
* @return the Paths from the File elements
148145
*/
149146
private List<String> parseElements(Collection<SubmodelElement> elements) {
150-
List<String> paths = new ArrayList<String>();
151-
147+
List<String> paths = new ArrayList<>();
152148
for (SubmodelElement element : elements) {
153149
if (element instanceof File) {
154150
File file = (File) element;
@@ -168,13 +164,10 @@ private List<String> parseElements(Collection<SubmodelElement> elements) {
168164

169165
public List<InMemoryFile> getRelatedFiles() throws InvalidFormatException, IOException, DeserializationException {
170166
List<String> filePaths = parseReferencedFilePathsFromAASX();
171-
172167
List<InMemoryFile> files = new ArrayList<>();
173-
174168
for (String filePath : filePaths) {
175169
files.add(readFile(aasxRoot, filePath));
176170
}
177-
178171
return files;
179172
}
180173

dataformat-aasx/src/main/java/io/adminshell/aas/v3/dataformat/aasx/AASXValidator.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
*/
1616
package io.adminshell.aas.v3.dataformat.aasx;
1717

18-
import io.adminshell.aas.v3.dataformat.xml.XmlSchemaValidator;
19-
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
20-
import org.apache.poi.openxml4j.opc.OPCPackage;
21-
import org.xml.sax.SAXException;
22-
2318
import java.io.IOException;
2419
import java.io.InputStream;
2520
import java.util.Set;
2621

22+
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
23+
import org.xml.sax.SAXException;
24+
25+
import io.adminshell.aas.v3.dataformat.xml.XmlSchemaValidator;
26+
2727
/**
2828
* Class to validate the XML file inside an AASX-package
2929
*/
@@ -39,12 +39,13 @@ public AASXValidator(InputStream is) throws SAXException, IOException, InvalidFo
3939

4040
/**
4141
* Calls XML-Validator
42+
*
4243
* @return Set of Strings containing message on AASX-XML-Validation result
4344
* @throws IOException
4445
* @throws InvalidFormatException
4546
*/
4647
public Set<String> validateSchema() throws IOException, InvalidFormatException {
47-
String file = deserializer.getXMLResourceString(deserializer.aasxRoot);
48+
String file = deserializer.getXMLResourceString();
4849
return xmlValidator.validateSchema(file);
4950
}
5051

0 commit comments

Comments
 (0)