typeSet = new HashSet<>();
+ for (IQualifier qualifier : qualifiers) {
+ if (typeSet.contains(qualifier.getType())) {
+ return false;
+ }
+ typeSet.add(qualifier.getType());
+ }
+ return true;
+ }
+
+ private static Pattern constructMatchesXmlSerializableString() {
+ String pattern = "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXmlSerializableString = constructMatchesXmlSerializableString();
+
+ /**
+ * Check that {@code text} conforms to the pattern of the Constraint AASd-130.
+ *
+ * Ensures that encoding is possible and interoperability between different
+ * serializations is possible.
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXmlSerializableString(String text) {
+ return regexMatchesXmlSerializableString.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsAnyUri() {
+ String alphanum = "[a-zA-Z0-9]";
+ String mark = "[-_.!~*\'()]";
+ String unreserved = "(" + alphanum + "|" + mark + ")";
+ String hex = "([0-9]|[aA]|[bB]|[cC]|[dD]|[eE]|[fF]|[aA]|[bB]|[cC]|[dD]|[eE]|[fF])";
+ String escaped = "%" + hex + hex;
+ String pchar = "(" + unreserved + "|" + escaped + "|[:@&=+$,])";
+ String param = "(" + pchar + ")*";
+ String segment = "(" + pchar + ")*(;" + param + ")*";
+ String pathSegments = segment + "(/" + segment + ")*";
+ String absPath = "/" + pathSegments;
+ String scheme = "[a-zA-Z][a-zA-Z0-9+\\-.]*";
+ String userinfo = "(" + unreserved + "|" + escaped + "|[;:&=+$,])*";
+ String domainlabel = "(" + alphanum + "|" + alphanum + "(" + alphanum + "|-)*" + alphanum + ")";
+ String toplabel = "([a-zA-Z]|[a-zA-Z](" + alphanum + "|-)*" + alphanum + ")";
+ String hostname = "(" + domainlabel + "\\.)*" + toplabel + "(\\.)?";
+ String ipv4address = "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}";
+ String hex4 = "[0-9A-Fa-f]{1,4}";
+ String hexseq = hex4 + "(:" + hex4 + ")*";
+ String hexpart = "(" + hexseq + "|" + hexseq + "::(" + hexseq + ")?|::(" + hexseq + ")?)";
+ String ipv6address = hexpart + "(:" + ipv4address + ")?";
+ String ipv6reference = "\\[" + ipv6address + "\\]";
+ String host = "(" + hostname + "|" + ipv4address + "|" + ipv6reference + ")";
+ String port = "[0-9]*";
+ String hostport = host + "(:" + port + ")?";
+ String server = "((" + userinfo + "@)?" + hostport + ")?";
+ String regName = "(" + unreserved + "|" + escaped + "|[$,;:@&=+])+";
+ String authority = "(" + server + "|" + regName + ")";
+ String netPath = "//" + authority + "(" + absPath + ")?";
+ String reserved = "[;/?:@&=+$,\\[\\]]";
+ String uric = "(" + reserved + "|" + unreserved + "|" + escaped + ")";
+ String query = "(" + uric + ")*";
+ String hierPart = "(" + netPath + "|" + absPath + ")(\\?" + query + ")?";
+ String uricNoSlash = "(" + unreserved + "|" + escaped + "|[;?:@&=+$,])";
+ String opaquePart = uricNoSlash + "(" + uric + ")*";
+ String absoluteuri = scheme + ":(" + hierPart + "|" + opaquePart + ")";
+ String fragment = "(" + uric + ")*";
+ String relSegment = "(" + unreserved + "|" + escaped + "|[;@&=+$,])+";
+ String relPath = relSegment + "(" + absPath + ")?";
+ String relativeuri = "(" + netPath + "|" + absPath + "|" + relPath + ")(\\?" + query + ")?";
+ String uriReference = "^(" + absoluteuri + "|" + relativeuri + ")?(#" + fragment + ")?$";
+
+ return Pattern.compile(uriReference);
+ }
+
+ private static final Pattern regexMatchesXsAnyUri = constructMatchesXsAnyUri();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:anyURI}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#anyURI and
+ * https://datatracker.ietf.org/doc/html/rfc2396 and
+ * https://datatracker.ietf.org/doc/html/rfc2732
+ *
+ *
Note, that version 1.0 of the XSD specification defines {@code xs:anyURI} as
+ * "defined by RFC 2396, as amended by RFC 2732". Therefore, we use a
+ * pattern here that implements the amendments of RFC 2732. This should not
+ * be confused with {@code matches_RFC_2396}, which does not include those
+ * amendments and is used in different parts of the specification.
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsAnyUri(String text) {
+ return regexMatchesXsAnyUri.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsBase64Binary() {
+ String b04Char = "[AQgw]";
+ String b04 = b04Char + "\\x{20}?";
+ String b16Char = "[AEIMQUYcgkosw048]";
+ String b16 = b16Char + "\\x{20}?";
+ String b64Char = "[A-Za-z0-9+/]";
+ String b64 = b64Char + "\\x{20}?";
+ String b64quad = "(" + b64 + b64 + b64 + b64 + ")";
+ String b64FinalQuad = "(" + b64 + b64 + b64 + b64Char + ")";
+ String padded8 = b64 + b04 + "= ?=";
+ String padded16 = b64 + b64 + b16 + "=";
+ String b64final = "(" + b64FinalQuad + "|" + padded16 + "|" + padded8 + ")";
+ String base64Binary = "(" + b64quad + "*" + b64final + ")?";
+ String pattern = "^" + base64Binary + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsBase64Binary = constructMatchesXsBase64Binary();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:base64Binary}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#base64Binary
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsBase64Binary(String text) {
+ return regexMatchesXsBase64Binary.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsBoolean() {
+ String pattern = "^(true|false|1|0)$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsBoolean = constructMatchesXsBoolean();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:boolean}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#boolean
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsBoolean(String text) {
+ return regexMatchesXsBoolean.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsDate() {
+ String digit = "[0-9]";
+ String yearFrag = "-?(([1-9]" + digit + digit + digit + "+)|(0" + digit + digit + digit + "))";
+ String monthFrag = "((0[1-9])|(1[0-2]))";
+ String dayFrag = "((0[1-9])|([12]" + digit + ")|(3[01]))";
+ String minuteFrag = "[0-5]" + digit;
+ String timezoneFrag = "(Z|(\\+|-)((0" + digit + "|1[0-3]):" + minuteFrag + "|14:00))";
+ String dateLexicalRep = yearFrag + "-" + monthFrag + "-" + dayFrag + timezoneFrag + "?";
+ String pattern = "^" + dateLexicalRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsDate = constructMatchesXsDate();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:date}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#date
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsDate(String text) {
+ return regexMatchesXsDate.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsDateTime() {
+ String digit = "[0-9]";
+ String yearFrag = "-?(([1-9]" + digit + digit + digit + "+)|(0" + digit + digit + digit + "))";
+ String monthFrag = "((0[1-9])|(1[0-2]))";
+ String dayFrag = "((0[1-9])|([12]" + digit + ")|(3[01]))";
+ String hourFrag = "(([01]" + digit + ")|(2[0-3]))";
+ String minuteFrag = "[0-5]" + digit;
+ String secondFrag = "([0-5]" + digit + ")(\\." + digit + "+)?";
+ String endOfDayFrag = "24:00:00(\\.0+)?";
+ String timezoneFrag = "(Z|(\\+|-)((0" + digit + "|1[0-3]):" + minuteFrag + "|14:00))";
+ String dateTimeLexicalRep = yearFrag + "-" + monthFrag + "-" + dayFrag + "T((" + hourFrag + ":" + minuteFrag + ":" + secondFrag + ")|" + endOfDayFrag + ")" + timezoneFrag + "?";
+ String pattern = "^" + dateTimeLexicalRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsDateTime = constructMatchesXsDateTime();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:dateTime}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#dateTime
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsDateTime(String text) {
+ return regexMatchesXsDateTime.matcher(text).matches();
+ }
+
+ private static final Pattern regexDatePrefix = Pattern.compile("^(-?[0-9]+)-([0-9]{2})-([0-9]{2})");
+ private static final BigInteger FOUR = new BigInteger("4");
+ private static final BigInteger HUNDRED = new BigInteger("100");
+ private static final BigInteger FOUR_HUNDRED = new BigInteger("100");
+
+ /**
+ * Check whether the given year is a leap year.
+ * Year 1 BCE is a leap year.
+ * @param year to be checked
+ * @return True if 'year' is a leap year
+ */
+
+ public static boolean isLeapYear(BigInteger year) {
+ // We consider the years B.C. to be one-off.
+ // See the note at: https://www.w3.org/TR/xmlschema-2/#dateTime:
+ // "'-0001' is the lexical representation of the year 1 Before Common Era
+ // (1 BCE, sometimes written "1 BC")."
+ //
+ // Hence, -1 year in XML is 1 BCE, which is 0 year in astronomical years.
+ if (year.signum() < 0) {
+ year = year.negate().subtract(BigInteger.ONE);
+ }
+
+ // See: See: https://en.wikipedia.org/wiki/Leap_year#Algorithm
+ if (year.mod(FOUR).signum() > 0) {
+ return false;
+ }
+
+ if (year.mod(HUNDRED).signum() > 0) {
+ return true;
+ }
+
+ if (year.mod(FOUR_HUNDRED).signum() > 0) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Check that the value starts with a valid date.
+ * @param value an xs:date, an xs:dateTime,or an xs:dateTimeStamp
+ * @return true if the value starts with a valid date
+ */
+ private static boolean isPrefixedWithValidDate(
+ String value) {
+ Objects.requireNonNull(value);
+
+ Matcher match = regexDatePrefix.matcher(value);
+ if (!match.lookingAt()) {
+ return false;
+ }
+
+ BigInteger year;
+ try {
+ year = new BigInteger(match.group(1));
+ } catch (NumberFormatException exception) {
+ throw new IllegalArgumentException(
+ "Expected to parse the year from " + match.group(1)
+ + "but the parsing failed");
+ }
+
+ int month;
+ try {
+ month = Integer.parseInt(match.group(2));
+ } catch (NumberFormatException exception) {
+ throw new IllegalArgumentException(
+ "Expected to parse the month from " + match.group(2)
+ + "but the parsing failed");
+ }
+
+ int day;
+ try {
+ day = Integer.parseInt(match.group(3));
+ } catch (NumberFormatException exception) {
+ throw new IllegalArgumentException(
+ "Expected to parse the day from " + match.group(3)
+ + "but the parsing failed");
+ }
+
+ // Year zero does not exist, see: https://www.w3.org/TR/xmlschema-2/#dateTime
+ if (year.signum() == 0) {
+ return false;
+ }
+
+ if (day <= 0 || day > 31) {
+ return false;
+ }
+
+ if (month <= 0 || month >= 13) {
+ return false;
+ }
+
+ int maxDaysInMonth;
+ switch (month) {
+ case 1:
+ maxDaysInMonth = 31;
+ break;
+ case 2:
+ maxDaysInMonth = (isLeapYear(year)) ? 29 : 28;
+ break;
+ case 3:
+ maxDaysInMonth = 31;
+ break;
+ case 4:
+ maxDaysInMonth = 30;
+ break;
+ case 5:
+ maxDaysInMonth = 31;
+ break;
+ case 6:
+ maxDaysInMonth = 30;
+ break;
+ case 7:
+ maxDaysInMonth = 31;
+ break;
+ case 8:
+ maxDaysInMonth = 31;
+ break;
+ case 9:
+ maxDaysInMonth = 30;
+ break;
+ case 10:
+ maxDaysInMonth = 31;
+ break;
+ case 11:
+ maxDaysInMonth = 30;
+ break;
+ case 12:
+ maxDaysInMonth = 31;
+ break;
+ default:
+ throw new IllegalArgumentException("Unexpected month: " + month);
+ }
+
+ if (day > maxDaysInMonth) {
+ return false;
+ }
+
+ return true;
+ }
+
+
+
+ /**
+ * Check that value is a xs:dateTime with
+ * the time zone set to UTC.
+ * @param value to check
+ */
+ public static boolean isXsDateTime(String value) {
+ if (!matchesXsDateTime(value)) {
+ return false;
+ }
+
+ return isPrefixedWithValidDate(value);
+ }
+
+ private static Pattern constructMatchesXsDecimal() {
+ String digit = "[0-9]";
+ String unsignedNoDecimalPtNumeral = digit + "+";
+ String noDecimalPtNumeral = "(\\+|-)?" + unsignedNoDecimalPtNumeral;
+ String fracFrag = digit + "+";
+ String unsignedDecimalPtNumeral = "(" + unsignedNoDecimalPtNumeral + "\\." + fracFrag + "|\\." + fracFrag + ")";
+ String decimalPtNumeral = "(\\+|-)?" + unsignedDecimalPtNumeral;
+ String decimalLexicalRep = "(" + decimalPtNumeral + "|" + noDecimalPtNumeral + ")";
+ String pattern = "^" + decimalLexicalRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsDecimal = constructMatchesXsDecimal();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:decimal}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#decimal
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsDecimal(String text) {
+ return regexMatchesXsDecimal.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsDouble() {
+ String doubleRep = "((\\+|-)?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([Ee](\\+|-)?[0-9]+)?|-?INF|NaN)";
+ String pattern = "^" + doubleRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsDouble = constructMatchesXsDouble();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:double}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#double
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsDouble(String text) {
+ return regexMatchesXsDouble.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsDuration() {
+ String durationRep = "-?P((([0-9]+Y([0-9]+M)?([0-9]+D)?|([0-9]+M)([0-9]+D)?|([0-9]+D))(T(([0-9]+H)([0-9]+M)?([0-9]+(\\.[0-9]+)?S)?|([0-9]+M)([0-9]+(\\.[0-9]+)?S)?|([0-9]+(\\.[0-9]+)?S)))?)|(T(([0-9]+H)([0-9]+M)?([0-9]+(\\.[0-9]+)?S)?|([0-9]+M)([0-9]+(\\.[0-9]+)?S)?|([0-9]+(\\.[0-9]+)?S))))";
+ String pattern = "^" + durationRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsDuration = constructMatchesXsDuration();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:duration}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#duration
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsDuration(String text) {
+ return regexMatchesXsDuration.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsFloat() {
+ String floatRep = "((\\+|-)?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([Ee](\\+|-)?[0-9]+)?|-?INF|NaN)";
+ String pattern = "^" + floatRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsFloat = constructMatchesXsFloat();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:float}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#float
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsFloat(String text) {
+ return regexMatchesXsFloat.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsGDay() {
+ String gDayLexicalRep = "---(0[1-9]|[12][0-9]|3[01])(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?";
+ String pattern = "^" + gDayLexicalRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsGDay = constructMatchesXsGDay();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:gDay}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#gDay
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsGDay(String text) {
+ return regexMatchesXsGDay.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsGMonth() {
+ String gMonthLexicalRep = "--(0[1-9]|1[0-2])(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?";
+ String pattern = "^" + gMonthLexicalRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsGMonth = constructMatchesXsGMonth();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:gMonth}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#gMonth
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsGMonth(String text) {
+ return regexMatchesXsGMonth.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsGMonthDay() {
+ String gMonthDayRep = "--(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?";
+ String pattern = "^" + gMonthDayRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsGMonthDay = constructMatchesXsGMonthDay();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:gMonthDay}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#gMonthDay
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsGMonthDay(String text) {
+ return regexMatchesXsGMonthDay.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsGYear() {
+ String gYearRep = "-?([1-9][0-9]{3,}|0[0-9]{3})(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?";
+ String pattern = "^" + gYearRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsGYear = constructMatchesXsGYear();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:gYear}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#gYear
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsGYear(String text) {
+ return regexMatchesXsGYear.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsGYearMonth() {
+ String gYearMonthRep = "-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?";
+ String pattern = "^" + gYearMonthRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsGYearMonth = constructMatchesXsGYearMonth();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:gYearMonth}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#gYearMonth
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsGYearMonth(String text) {
+ return regexMatchesXsGYearMonth.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsHexBinary() {
+ String hexBinary = "([0-9a-fA-F]{2})*";
+ String pattern = "^" + hexBinary + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsHexBinary = constructMatchesXsHexBinary();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:hexBinary}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#hexBinary
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsHexBinary(String text) {
+ return regexMatchesXsHexBinary.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsTime() {
+ String timeRep = "(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?|(24:00:00(\\.0+)?))(Z|(\\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?";
+ String pattern = "^" + timeRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsTime = constructMatchesXsTime();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:time}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#time
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsTime(String text) {
+ return regexMatchesXsTime.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsInteger() {
+ String integerRep = "[-+]?[0-9]+";
+ String pattern = "^" + integerRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsInteger = constructMatchesXsInteger();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:integer}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#integer
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsInteger(String text) {
+ return regexMatchesXsInteger.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsLong() {
+ String longRep = "[-+]?0*[0-9]{1,20}";
+ String pattern = "^" + longRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsLong = constructMatchesXsLong();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:long}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#long
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsLong(String text) {
+ return regexMatchesXsLong.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsInt() {
+ String intRep = "[-+]?0*[0-9]{1,10}";
+ String pattern = "^" + intRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsInt = constructMatchesXsInt();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:int}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#int
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsInt(String text) {
+ return regexMatchesXsInt.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsShort() {
+ String shortRep = "[-+]?0*[0-9]{1,5}";
+ String pattern = "^" + shortRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsShort = constructMatchesXsShort();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:short}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#short
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsShort(String text) {
+ return regexMatchesXsShort.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsByte() {
+ String byteRep = "[-+]?0*[0-9]{1,3}";
+ String pattern = "^" + byteRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsByte = constructMatchesXsByte();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:byte}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#byte
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsByte(String text) {
+ return regexMatchesXsByte.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsNonNegativeInteger() {
+ String nonNegativeIntegerRep = "(-0|\\+?[0-9]+)";
+ String pattern = "^" + nonNegativeIntegerRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsNonNegativeInteger = constructMatchesXsNonNegativeInteger();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:nonNegativeInteger}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#nonNegativeInteger
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsNonNegativeInteger(String text) {
+ return regexMatchesXsNonNegativeInteger.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsPositiveInteger() {
+ String positiveIntegerRep = "\\+?0*[1-9][0-9]*";
+ String pattern = "^" + positiveIntegerRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsPositiveInteger = constructMatchesXsPositiveInteger();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:positiveInteger}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#positiveInteger
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsPositiveInteger(String text) {
+ return regexMatchesXsPositiveInteger.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsUnsignedLong() {
+ String unsignedLongRep = "(-0|\\+?0*[0-9]{1,20})";
+ String pattern = "^" + unsignedLongRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsUnsignedLong = constructMatchesXsUnsignedLong();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:unsignedLong}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#unsignedLong
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsUnsignedLong(String text) {
+ return regexMatchesXsUnsignedLong.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsUnsignedInt() {
+ String unsignedIntRep = "(-0|\\+?0*[0-9]{1,10})";
+ String pattern = "^" + unsignedIntRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsUnsignedInt = constructMatchesXsUnsignedInt();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:unsignedInt}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#unsignedInt
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsUnsignedInt(String text) {
+ return regexMatchesXsUnsignedInt.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsUnsignedShort() {
+ String unsignedShortRep = "(-0|\\+?0*[0-9]{1,5})";
+ String pattern = "^" + unsignedShortRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsUnsignedShort = constructMatchesXsUnsignedShort();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:unsignedShort}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#unsignedShort
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsUnsignedShort(String text) {
+ return regexMatchesXsUnsignedShort.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsUnsignedByte() {
+ String unsignedByteRep = "(-0|\\+?0*[0-9]{1,3})";
+ String pattern = "^" + unsignedByteRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsUnsignedByte = constructMatchesXsUnsignedByte();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:unsignedByte}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#unsignedByte
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsUnsignedByte(String text) {
+ return regexMatchesXsUnsignedByte.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsNonPositiveInteger() {
+ String nonPositiveIntegerRep = "(\\+0|0|-[0-9]+)";
+ String pattern = "^" + nonPositiveIntegerRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsNonPositiveInteger = constructMatchesXsNonPositiveInteger();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:nonPositiveInteger}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#nonPositiveInteger
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsNonPositiveInteger(String text) {
+ return regexMatchesXsNonPositiveInteger.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsNegativeInteger() {
+ String negativeIntegerRep = "(-0*[1-9][0-9]*)";
+ String pattern = "^" + negativeIntegerRep + "$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsNegativeInteger = constructMatchesXsNegativeInteger();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:negativeInteger}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#negativeInteger
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsNegativeInteger(String text) {
+ return regexMatchesXsNegativeInteger.matcher(text).matches();
+ }
+
+ private static Pattern constructMatchesXsString() {
+ String pattern = "^[\\x{09}\\x{0a}\\x{0d}\\x{20}-\\x{d7ff}\\x{e000}-\\x{fffd}\\x{10000}-\\x{10ffff}]*$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexMatchesXsString = constructMatchesXsString();
+
+ /**
+ * Check that {@code text} conforms to the pattern of an {@code xs:string}.
+ *
+ *
See: https://www.w3.org/TR/xmlschema-2/#string
+ *
+ * @param text Text to be checked
+ * @return True if the {@code text} conforms to the pattern
+ */
+ public static Boolean matchesXsString(String text) {
+ return regexMatchesXsString.matcher(text).matches();
+ }
+
+ /**
+ * Check that the value is consistent with
+ * the given valueType.
+ * @param value the value to check
+ * @param valueType the value type
+ */
+ public static boolean valueConsistentWithXsdType(
+ String value,
+ DataTypeDefXsd valueType){
+ Objects.requireNonNull(value);
+ Objects.requireNonNull(valueType);
+
+ switch (valueType) {
+ case ANY_URI: {
+ return matchesXsAnyUri(value);
+ }
+ case BASE_64_BINARY: {
+ return matchesXsBase64Binary(value);
+ }
+ case BOOLEAN: {
+ return matchesXsBoolean(value);
+ }
+ case BYTE: {
+ try {
+ Byte.valueOf(value);
+ return true;
+ } catch (NumberFormatException numberFormatException) {
+ return false;
+ }
+ }
+ case DATE: {
+ if (!matchesXsDate(value)) {
+ return false;
+ }
+
+ return isPrefixedWithValidDate(value);
+ }
+ case DATE_TIME: {
+ if (!matchesXsDateTime(value)) {
+ return false;
+ }
+
+ // The time part and the time zone part will be checked by
+ // MatchesXsDateTime. We need to check that the date part is
+ // correct in sense of the day/month combination.
+ return isPrefixedWithValidDate(value);
+ }
+ case DECIMAL: {
+ return matchesXsDecimal(value);
+ }
+ case DOUBLE: {
+ // We need to check explicitly for the regular expression.
+ // See: https://www.w3.org/TR/xmlschema-2/#double
+ if (!matchesXsDouble(value)) {
+ return false;
+ }
+
+ if("INF".equals(value) || "-INF".equals(value)) return true;
+
+ double converted;
+ try {
+ converted = Double.parseDouble(value);
+ } catch (Exception exception) {
+ return false;
+ }
+ return !Double.isInfinite(converted);
+ }
+ case DURATION: {
+ return matchesXsDuration(value);
+ }
+ case FLOAT: {
+ // We need to check explicitly for the regular expression.
+ // See: https://www.w3.org/TR/xmlschema-2/#float
+ if (!matchesXsFloat(value)) {
+ return false;
+ }
+
+ if("INF".equals(value) || "-INF".equals(value)) return true;
+
+ float converted;
+ try {
+ converted = Float.parseFloat(value);
+ } catch (Exception exception) {
+ return false;
+ }
+ return !Float.isInfinite(converted);
+ }
+ case G_DAY: {
+ return matchesXsGDay(value);
+ }
+ case G_MONTH: {
+ return matchesXsGMonth(value);
+ }
+ case G_MONTH_DAY: {
+ if (!matchesXsGMonthDay(value)) {
+ return false;
+ }
+
+ int month = Integer.parseInt(value.substring(2,4));
+ int day = Integer.parseInt(value.substring(5,7));
+ switch (month)
+ {
+ case 1:
+ case 3:
+ case 5:
+ case 7:
+ case 8:
+ case 10:
+ case 12:
+ return day <= 31;
+ case 4:
+ case 6:
+ case 9:
+ case 11:
+ return day <= 30;
+ case 2:
+ return day <= 29;
+ default:
+ throw new IllegalArgumentException(
+ "Unhandled month: " + month +
+ "is there maybe a bug in MatchesXsGMonthDay?"
+ );
+ }
+ }
+ case G_YEAR: {
+ return matchesXsGYear(value);
+ }
+ case G_YEAR_MONTH: {
+ return matchesXsGYearMonth(value);
+ }
+ case HEX_BINARY: {
+ return matchesXsHexBinary(value);
+ }
+ case INT: {
+ try {
+ Integer.parseInt(value);
+ return true;
+ } catch (Exception exception) {
+ return false;
+ }
+ }
+ case INTEGER: {
+ return matchesXsInteger(value);
+ }
+ case LONG: {
+ try {
+ Long.parseLong(value);
+ return true;
+ } catch (Exception exception) {
+ return false;
+ }
+ }
+ case NEGATIVE_INTEGER: {
+ return matchesXsNegativeInteger(value);
+ }
+ case NON_NEGATIVE_INTEGER: {
+ return matchesXsNonNegativeInteger(value);
+ }
+ case NON_POSITIVE_INTEGER: {
+ return matchesXsNonPositiveInteger(value);
+ }
+ case POSITIVE_INTEGER: {
+ return matchesXsPositiveInteger(value);
+ }
+ case SHORT: {
+ try {
+ Short.parseShort(value);
+ return true;
+ } catch (Exception exception) {
+ return false;
+ }
+ }
+ case STRING: {
+ return matchesXsString(value);
+ }
+ case TIME: {
+ return matchesXsTime(value);
+ }
+ case UNSIGNED_BYTE: {
+ if (value.isEmpty()) {
+ return false;
+ }
+
+ // We need to allow negative zeros which are allowed in the lexical
+ // representation of an unsigned byte.
+ // See: https://www.w3.org/TR/xmlschema11-2/#unsignedByte
+ if (value.equals("-0")) {
+ return true;
+ }
+
+ try {
+ int converted = Integer.parseInt(value);
+ return 0 <= converted && converted <= 255;
+ } catch (Exception exception) {
+ return false;
+ }
+ }
+ case UNSIGNED_INT: {
+ if (value.isEmpty()) {
+ return false;
+ }
+
+ // We need to allow negative zeros which are allowed in the lexical
+ // representation of an unsigned int.
+ // See: https://www.w3.org/TR/xmlschema11-2/#unsignedInt
+ if (value.equals("-0")) {
+ return true;
+ }
+
+ try {
+ //Java does not support UInt32 like C#, so we need to use long.
+ long converted = Long.parseUnsignedLong(value);
+ return converted <= 4294967295L;
+ } catch (Exception exception) {
+ return false;
+ }
+ }
+ case UNSIGNED_LONG: {
+ if (value.isEmpty()) {
+ return false;
+ }
+
+ // We need to allow negative zeros which are allowed in the lexical
+ // representation of an unsigned long.
+ // See: https://www.w3.org/TR/xmlschema11-2/#unsignedLong
+ if (value.equals("-0")) {
+ return true;
+ }
+
+ try {
+ Long.parseUnsignedLong(value);
+ return true;
+ } catch (Exception exception) {
+ return false;
+ }
+ }
+ case UNSIGNED_SHORT: {
+ if (value.isEmpty()) {
+ return false;
+ }
+
+ // We need to allow negative zeros which are allowed in the lexical
+ // representation of an unsigned short.
+ // See: https://www.w3.org/TR/xmlschema11-2/#unsignedShort
+ if (value.equals("-0")) {
+ return true;
+ }
+
+ try {
+ int converted = Integer.parseInt(value);
+ return 0 <= converted && converted <= 65535;
+ } catch (Exception exception) {
+ return false;
+ }
+ }
+ default:
+ throw new IllegalArgumentException(
+ "valueType is an invalid DataTypeDefXsd: " + valueType
+ );
+ }
+ }
+
+ /**
+ * Check that the target of the model reference matches the {@code expectedType}.
+ */
+ public static Boolean isModelReferenceTo(
+ IReference reference,
+ KeyTypes expectedType) {
+ return reference.getType() == ReferenceTypes.MODEL_REFERENCE
+ && reference.getKeys().size() != 0
+ && ListHelpers.at(reference.getKeys(), -1).getType() == expectedType;
+ }
+
+ /**
+ * Check that the target of the reference matches a {@link aas_core.aas3_2.constants.Constants#aasReferables}.
+ */
+ public static Boolean isModelReferenceToReferable(
+ IReference reference) {
+ return reference.getType() == ReferenceTypes.MODEL_REFERENCE
+ && reference.getKeys().size() != 0
+ && Constants.aasReferables.contains(ListHelpers.at(reference.getKeys(), -1).getType());
+ }
+
+ /**
+ * Check that all {@link IReferable#getIdShort() idShort} are unique among referables.
+ * @param referables the referables.
+ */
+ public static boolean idShortsAreUnique(
+ Iterable extends IReferable> referables) {
+ Objects.requireNonNull(referables);
+
+ Set idShortSet = new HashSet<>();
+
+ for (IReferable referable : referables) {
+ if (referable.getIdShort().isPresent()) {
+ if (idShortSet.contains(referable.getIdShort().get())) {
+ return false;
+ }
+ idShortSet.add(referable.getIdShort().get());
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Check that all {@link IReferable#getIdShort idShort} 's are among all the inputVariables, outputVariables and inoutputVariables are unique.
+ * @param inputVariables the inputVariables
+ * @param outputVariables the outputVariables
+ * @param inoutputVariables the inoutputVariables
+ */
+ public static boolean idShortsOfVariablesAreUnique(
+ Optional extends List extends IOperationVariable>> inputVariables,
+ Optional extends List extends IOperationVariable>> outputVariables,
+ Optional extends List extends IOperationVariable>> inoutputVariables) {
+
+ Set idShortSet = new HashSet<>();
+
+ if (inputVariables.isPresent()) {
+ for(IOperationVariable variable : inputVariables.get()) {
+ if (variable.getValue().getIdShort().isPresent()) {
+ if (idShortSet.contains(variable.getValue().getIdShort().get())) {
+ return false;
+ }
+ idShortSet.add(variable.getValue().getIdShort().get());
+ }
+ }
+ }
+
+ if (outputVariables.isPresent()) {
+ for (IOperationVariable variable : outputVariables.get()) {
+ if (variable.getValue().getIdShort().isPresent()) {
+ if (idShortSet.contains(variable.getValue().getIdShort().get())) {
+ return false;
+ }
+ idShortSet.add(variable.getValue().getIdShort().get());
+ }
+ }
+ }
+
+ if (inoutputVariables.isPresent()) {
+ for (IOperationVariable variable : inoutputVariables.get()) {
+ if (variable.getValue().getIdShort().isPresent()) {
+ if (idShortSet.contains(variable.getValue().getIdShort().get())) {
+ return false;
+ }
+ idShortSet.add(variable.getValue().getIdShort().get());
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Check that all {@link IExtension#getName() name} are unique among extensions.
+ * @param extensions the extensions
+ */
+ public static boolean extensionNamesAreUnique(
+ Iterable extends IExtension> extensions) {
+ Objects.requireNonNull(extensions);
+
+ Set nameSet = new HashSet<>();
+
+ for (IExtension extension : extensions) {
+ if (nameSet.contains(extension.getName())) {
+ return false;
+ }
+ nameSet.add(extension.getName());
+ }
+ return true;
+ }
+
+ /**
+ * Check that all elements have the identical
+ * {@link IHasSemantics#getSemanticId() semanticId}'s.
+ */
+ public static boolean submodelElementsHaveIdenticalSemanticIds(
+ Iterable extends ISubmodelElement> elements) {
+ Objects.requireNonNull(elements);
+
+ IReference thatSemanticId = null;
+
+ for (ISubmodelElement element : elements) {
+ if (!element.getSemanticId().isPresent()) {
+ continue;
+ }
+
+ if (thatSemanticId == null) {
+ thatSemanticId = element.getSemanticId().get();
+ continue;
+ }
+
+ IReference thisSemanticId = element.getSemanticId().get();
+
+ if (thatSemanticId.getKeys().size() != thisSemanticId.getKeys().size()) {
+ return false;
+ }
+
+ for (int i = 0; i < thisSemanticId.getKeys().size(); i++) {
+ if (!Objects.equals(thatSemanticId.getKeys().get(i).getValue(),
+ thisSemanticId.getKeys().get(i).getValue())) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean submodelElementIsOfType(
+ ISubmodelElement element,
+ AasSubmodelElements expectedType
+ ) {
+ Objects.requireNonNull(element);
+ Objects.requireNonNull(expectedType);
+
+ switch (expectedType) {
+ case ANNOTATED_RELATIONSHIP_ELEMENT:
+ return element instanceof IAnnotatedRelationshipElement;
+
+ case BASIC_EVENT_ELEMENT:
+ return element instanceof IBasicEventElement;
+
+ case BLOB:
+ return element instanceof IBlob;
+
+ case CAPABILITY:
+ return element instanceof ICapability;
+
+ case DATA_ELEMENT:
+ return element instanceof IDataElement;
+
+ case ENTITY:
+ return element instanceof IEntity;
+
+ case EVENT_ELEMENT:
+ return element instanceof IEventElement;
+
+ case FILE:
+ return element instanceof IFile;
+
+ case MULTI_LANGUAGE_PROPERTY:
+ return element instanceof IMultiLanguageProperty;
+
+ case OPERATION:
+ return element instanceof IOperation;
+
+ case PROPERTY:
+ return element instanceof IProperty;
+
+ case RANGE:
+ return element instanceof IRange;
+
+ case REFERENCE_ELEMENT:
+ return element instanceof IReferenceElement;
+
+ case RELATIONSHIP_ELEMENT:
+ return element instanceof IRelationshipElement;
+
+ case SUBMODEL_ELEMENT:
+ return element instanceof ISubmodelElement;
+
+ case SUBMODEL_ELEMENT_LIST:
+ return element instanceof ISubmodelElementList;
+
+ case SUBMODEL_ELEMENT_COLLECTION:
+ return element instanceof ISubmodelElementCollection;
+
+ default:
+ throw new IllegalArgumentException(
+ "expectedType is not a valid AasSubmodelElements: " + expectedType
+ );
+ }
+ }
+
+ /**
+ * Check that the elements which are
+ * {@link IProperty} or {@link IRange}
+ * have the given valueType.
+ * @param elements the elements.
+ * @param valueType the valueType.
+ */
+ public static boolean propertiesOrRangesHaveValueType(
+ Iterable extends ISubmodelElement> elements,
+ DataTypeDefXsd valueType
+ ) {
+ Objects.requireNonNull(elements);
+ Objects.requireNonNull(valueType);
+
+ for (ISubmodelElement element : elements) {
+ if(element instanceof IProperty) {
+ if (((IProperty) element).getValueType() != valueType) {
+ return false;
+ }
+ } else if (element instanceof IRange) {
+ if (((IRange) element).getValueType() != valueType) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Check that the two references,'that' and
+ * 'other', are equal by comparing
+ * their {@link IReference#getKeys() keys} by
+ * {@link IKey#getValue() value}'s.
+ */
+ public static boolean referenceKeyValuesEqual(
+ IReference that,
+ IReference other) {
+ Objects.requireNonNull(that);
+ Objects.requireNonNull(other);
+
+ if (that.getKeys().size() != other.getKeys().size()) {
+ return false;
+ }
+
+ for (int i = 0; i < that.getKeys().size(); i++) {
+ if (!Objects.equals(that.getKeys().get(i).getValue(), other.getKeys().get(i).getValue())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ *Check that the {@link IDataSpecificationIec61360#getValue() dataType} is defined
+ *appropriately for all data specifications whose content is given as IEC 61360.
+ */
+ public static boolean dataSpecificationIec61360sForPropertyOrValueHaveAppropriateDataType(
+ Iterable extends IEmbeddedDataSpecification> embeddedDataSpecifications){
+ Objects.requireNonNull(embeddedDataSpecifications);
+
+ for (IEmbeddedDataSpecification embeddedDataSpecification : embeddedDataSpecifications){
+ IDataSpecificationIec61360 iec61360 =
+ (IDataSpecificationIec61360) embeddedDataSpecification.getDataSpecificationContent();
+ if(iec61360 != null){
+ if (!iec61360.getDataType().isPresent()
+ || !Constants.dataTypeIec61360ForPropertyOrValue.contains(
+ iec61360.getDataType().get())) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Check that the {@link IDataSpecificationIec61360#getDataType() dataType} is defined
+ * appropriately for all data specifications whose content is given as IEC 61360.
+ */
+ public static boolean dataSpecificationIec61360sForReferenceHaveAppropriateDataType(
+ Iterable extends IEmbeddedDataSpecification> embeddedDataSpecifications) {
+ Objects.requireNonNull(embeddedDataSpecifications);
+
+ for(IEmbeddedDataSpecification embeddedDataSpecification :embeddedDataSpecifications) {
+ IDataSpecificationIec61360 iec61360 =
+ (IDataSpecificationIec61360) embeddedDataSpecification.getDataSpecificationContent();
+ if (iec61360 != null) {
+ if (!iec61360.getDataType().isPresent()
+ || !Constants.dataTypeIec61360ForReference.contains(
+ iec61360.getDataType().get())) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Check that the {@link IDataSpecificationIec61360#getDataType dataType} is defined
+ * appropriately for all data specifications whose content is given as IEC 61360.
+ */
+ public static boolean dataSpecificationIec61360sForDocumentHaveAppropriateDataType(
+ Iterable extends IEmbeddedDataSpecification> embeddedDataSpecifications) {
+ Objects.requireNonNull(embeddedDataSpecifications);
+
+ for (IEmbeddedDataSpecification embeddedDataSpecification : embeddedDataSpecifications) {
+ IDataSpecificationIec61360 iec61360 =
+ (IDataSpecificationIec61360) embeddedDataSpecification.getDataSpecificationContent();
+ if(iec61360 != null) {
+ if (!iec61360.getDataType().isPresent()
+ || !Constants.dataTypeIec61360ForDocument.contains(
+ iec61360.getDataType().get())) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Check that the {@link IDataSpecificationIec61360#getDataType() dataType} is defined
+ * for all data specifications whose content is given as IEC 61360.
+ */
+ public static boolean dataSpecificationIec61360sHaveDataType(
+ Iterable extends IEmbeddedDataSpecification> embeddedDataSpecifications){
+ Objects.requireNonNull(embeddedDataSpecifications);
+
+ for (IEmbeddedDataSpecification embeddedDataSpecification : embeddedDataSpecifications) {
+ IDataSpecificationIec61360 iec61360
+ = (IDataSpecificationIec61360) embeddedDataSpecification.getDataSpecificationContent();
+ if (iec61360 != null) {
+ if (!iec61360.getDataType().isPresent()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /** Check that the {@link IDataSpecificationIec61360#getValue() value} is defined
+ * for all data specifications whose content is given as IEC 61360.
+ */
+ public static boolean dataSpecificationIec61360sHaveValue(
+ Iterable extends IEmbeddedDataSpecification> embeddedDataSpecifications) {
+ Objects.requireNonNull(embeddedDataSpecifications);
+
+ for (IEmbeddedDataSpecification embeddedDataSpecification : embeddedDataSpecifications) {
+ IDataSpecificationIec61360 iec61360 =
+ (IDataSpecificationIec61360) embeddedDataSpecification.getDataSpecificationContent();
+ if (iec61360 != null) {
+ if (!iec61360.getValue().isPresent()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Check that the {@link IDataSpecificationIec61360#getDefinition() definition} is defined
+ * for all data specifications whose content is given as IEC 61360 at least in English.
+ */
+ public static boolean dataSpecificationIec61360sHaveDefinitionAtLeastInEnglish(
+ Iterable extends IEmbeddedDataSpecification> embeddedDataSpecifications){
+ Objects.requireNonNull(embeddedDataSpecifications);
+
+ for (IEmbeddedDataSpecification embeddedDataSpecification : embeddedDataSpecifications) {
+ IDataSpecificationIec61360 iec61360 =
+ (IDataSpecificationIec61360) embeddedDataSpecification.getDataSpecificationContent();
+ if (iec61360 != null) {
+ if (!iec61360.getDefinition().isPresent()) {
+ return false;
+ }
+
+ boolean noDefinitionInEnglish = true;
+ for (ILangStringDefinitionTypeIec61360 langString : iec61360.getDefinition().get()) {
+ if (isBcp47ForEnglish(langString.getLanguage())) {
+ noDefinitionInEnglish = false;
+ break;
+ }
+ }
+
+ if (noDefinitionInEnglish) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private static Pattern constructIsBcp47ForEnglish() {
+ String pattern = "^(en|EN)(-.*)?$";
+
+ return Pattern.compile(pattern);
+ }
+
+ private static final Pattern regexIsBcp47ForEnglish = constructIsBcp47ForEnglish();
+
+ /**
+ * Check that the {@code text} corresponds to a BCP47 code for english.
+ */
+ public static Boolean isBcp47ForEnglish(String text) {
+ return regexIsBcp47ForEnglish.matcher(text).matches();
+ }
+
+ /**
+ * Hash allowed enum values for efficient validation of enums.
+ */
+ private static class _EnumValueSet {
+ private static final Set forModellingKind;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(ModellingKind.TEMPLATE);
+ temp.add(ModellingKind.INSTANCE);
+
+ if (!temp.containsAll(Arrays.asList(ModellingKind.values()))) {
+ throw new IllegalStateException("Uncovered ModellingKind");
+ }
+
+ forModellingKind = Collections.unmodifiableSet(temp);
+ }
+
+ private static final Set forQualifierKind;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(QualifierKind.VALUE_QUALIFIER);
+ temp.add(QualifierKind.CONCEPT_QUALIFIER);
+ temp.add(QualifierKind.TEMPLATE_QUALIFIER);
+
+ if (!temp.containsAll(Arrays.asList(QualifierKind.values()))) {
+ throw new IllegalStateException("Uncovered QualifierKind");
+ }
+
+ forQualifierKind = Collections.unmodifiableSet(temp);
+ }
+
+ private static final Set forAssetKind;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(AssetKind.TYPE);
+ temp.add(AssetKind.INSTANCE);
+ temp.add(AssetKind.ROLE);
+ temp.add(AssetKind.NOT_APPLICABLE);
+
+ if (!temp.containsAll(Arrays.asList(AssetKind.values()))) {
+ throw new IllegalStateException("Uncovered AssetKind");
+ }
+
+ forAssetKind = Collections.unmodifiableSet(temp);
+ }
+
+ private static final Set forAasSubmodelElements;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(AasSubmodelElements.ANNOTATED_RELATIONSHIP_ELEMENT);
+ temp.add(AasSubmodelElements.BASIC_EVENT_ELEMENT);
+ temp.add(AasSubmodelElements.BLOB);
+ temp.add(AasSubmodelElements.CAPABILITY);
+ temp.add(AasSubmodelElements.DATA_ELEMENT);
+ temp.add(AasSubmodelElements.ENTITY);
+ temp.add(AasSubmodelElements.EVENT_ELEMENT);
+ temp.add(AasSubmodelElements.FILE);
+ temp.add(AasSubmodelElements.MULTI_LANGUAGE_PROPERTY);
+ temp.add(AasSubmodelElements.OPERATION);
+ temp.add(AasSubmodelElements.PROPERTY);
+ temp.add(AasSubmodelElements.RANGE);
+ temp.add(AasSubmodelElements.REFERENCE_ELEMENT);
+ temp.add(AasSubmodelElements.RELATIONSHIP_ELEMENT);
+ temp.add(AasSubmodelElements.SUBMODEL_ELEMENT);
+ temp.add(AasSubmodelElements.SUBMODEL_ELEMENT_LIST);
+ temp.add(AasSubmodelElements.SUBMODEL_ELEMENT_COLLECTION);
+
+ if (!temp.containsAll(Arrays.asList(AasSubmodelElements.values()))) {
+ throw new IllegalStateException("Uncovered AasSubmodelElements");
+ }
+
+ forAasSubmodelElements = Collections.unmodifiableSet(temp);
+ }
+
+ private static final Set forEntityType;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(EntityType.CO_MANAGED_ENTITY);
+ temp.add(EntityType.SELF_MANAGED_ENTITY);
+
+ if (!temp.containsAll(Arrays.asList(EntityType.values()))) {
+ throw new IllegalStateException("Uncovered EntityType");
+ }
+
+ forEntityType = Collections.unmodifiableSet(temp);
+ }
+
+ private static final Set forDirection;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(Direction.INPUT);
+ temp.add(Direction.OUTPUT);
+
+ if (!temp.containsAll(Arrays.asList(Direction.values()))) {
+ throw new IllegalStateException("Uncovered Direction");
+ }
+
+ forDirection = Collections.unmodifiableSet(temp);
+ }
+
+ private static final Set forStateOfEvent;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(StateOfEvent.ON);
+ temp.add(StateOfEvent.OFF);
+
+ if (!temp.containsAll(Arrays.asList(StateOfEvent.values()))) {
+ throw new IllegalStateException("Uncovered StateOfEvent");
+ }
+
+ forStateOfEvent = Collections.unmodifiableSet(temp);
+ }
+
+ private static final Set forReferenceTypes;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(ReferenceTypes.EXTERNAL_REFERENCE);
+ temp.add(ReferenceTypes.MODEL_REFERENCE);
+
+ if (!temp.containsAll(Arrays.asList(ReferenceTypes.values()))) {
+ throw new IllegalStateException("Uncovered ReferenceTypes");
+ }
+
+ forReferenceTypes = Collections.unmodifiableSet(temp);
+ }
+
+ private static final Set forKeyTypes;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(KeyTypes.ANNOTATED_RELATIONSHIP_ELEMENT);
+ temp.add(KeyTypes.ASSET_ADMINISTRATION_SHELL);
+ temp.add(KeyTypes.BASIC_EVENT_ELEMENT);
+ temp.add(KeyTypes.BLOB);
+ temp.add(KeyTypes.CAPABILITY);
+ temp.add(KeyTypes.CONCEPT_DESCRIPTION);
+ temp.add(KeyTypes.DATA_ELEMENT);
+ temp.add(KeyTypes.ENTITY);
+ temp.add(KeyTypes.EVENT_ELEMENT);
+ temp.add(KeyTypes.FILE);
+ temp.add(KeyTypes.FRAGMENT_REFERENCE);
+ temp.add(KeyTypes.GLOBAL_REFERENCE);
+ temp.add(KeyTypes.IDENTIFIABLE);
+ temp.add(KeyTypes.MULTI_LANGUAGE_PROPERTY);
+ temp.add(KeyTypes.OPERATION);
+ temp.add(KeyTypes.PROPERTY);
+ temp.add(KeyTypes.RANGE);
+ temp.add(KeyTypes.REFERABLE);
+ temp.add(KeyTypes.REFERENCE_ELEMENT);
+ temp.add(KeyTypes.RELATIONSHIP_ELEMENT);
+ temp.add(KeyTypes.SUBMODEL);
+ temp.add(KeyTypes.SUBMODEL_ELEMENT);
+ temp.add(KeyTypes.SUBMODEL_ELEMENT_COLLECTION);
+ temp.add(KeyTypes.SUBMODEL_ELEMENT_LIST);
+
+ if (!temp.containsAll(Arrays.asList(KeyTypes.values()))) {
+ throw new IllegalStateException("Uncovered KeyTypes");
+ }
+
+ forKeyTypes = Collections.unmodifiableSet(temp);
+ }
+
+ private static final Set forDataTypeDefXsd;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(DataTypeDefXsd.ANY_URI);
+ temp.add(DataTypeDefXsd.BASE_64_BINARY);
+ temp.add(DataTypeDefXsd.BOOLEAN);
+ temp.add(DataTypeDefXsd.BYTE);
+ temp.add(DataTypeDefXsd.DATE);
+ temp.add(DataTypeDefXsd.DATE_TIME);
+ temp.add(DataTypeDefXsd.DECIMAL);
+ temp.add(DataTypeDefXsd.DOUBLE);
+ temp.add(DataTypeDefXsd.DURATION);
+ temp.add(DataTypeDefXsd.FLOAT);
+ temp.add(DataTypeDefXsd.G_DAY);
+ temp.add(DataTypeDefXsd.G_MONTH);
+ temp.add(DataTypeDefXsd.G_MONTH_DAY);
+ temp.add(DataTypeDefXsd.G_YEAR);
+ temp.add(DataTypeDefXsd.G_YEAR_MONTH);
+ temp.add(DataTypeDefXsd.HEX_BINARY);
+ temp.add(DataTypeDefXsd.INT);
+ temp.add(DataTypeDefXsd.INTEGER);
+ temp.add(DataTypeDefXsd.LONG);
+ temp.add(DataTypeDefXsd.NEGATIVE_INTEGER);
+ temp.add(DataTypeDefXsd.NON_NEGATIVE_INTEGER);
+ temp.add(DataTypeDefXsd.NON_POSITIVE_INTEGER);
+ temp.add(DataTypeDefXsd.POSITIVE_INTEGER);
+ temp.add(DataTypeDefXsd.SHORT);
+ temp.add(DataTypeDefXsd.STRING);
+ temp.add(DataTypeDefXsd.TIME);
+ temp.add(DataTypeDefXsd.UNSIGNED_BYTE);
+ temp.add(DataTypeDefXsd.UNSIGNED_INT);
+ temp.add(DataTypeDefXsd.UNSIGNED_LONG);
+ temp.add(DataTypeDefXsd.UNSIGNED_SHORT);
+
+ if (!temp.containsAll(Arrays.asList(DataTypeDefXsd.values()))) {
+ throw new IllegalStateException("Uncovered DataTypeDefXsd");
+ }
+
+ forDataTypeDefXsd = Collections.unmodifiableSet(temp);
+ }
+
+ private static final Set forDataTypeIec61360;
+ static {
+ final Set temp = new HashSet<>();
+
+ temp.add(DataTypeIec61360.DATE);
+ temp.add(DataTypeIec61360.STRING);
+ temp.add(DataTypeIec61360.STRING_TRANSLATABLE);
+ temp.add(DataTypeIec61360.INTEGER_MEASURE);
+ temp.add(DataTypeIec61360.INTEGER_COUNT);
+ temp.add(DataTypeIec61360.INTEGER_CURRENCY);
+ temp.add(DataTypeIec61360.REAL_MEASURE);
+ temp.add(DataTypeIec61360.REAL_COUNT);
+ temp.add(DataTypeIec61360.REAL_CURRENCY);
+ temp.add(DataTypeIec61360.BOOLEAN);
+ temp.add(DataTypeIec61360.IRI);
+ temp.add(DataTypeIec61360.IRDI);
+ temp.add(DataTypeIec61360.RATIONAL);
+ temp.add(DataTypeIec61360.RATIONAL_MEASURE);
+ temp.add(DataTypeIec61360.TIME);
+ temp.add(DataTypeIec61360.TIMESTAMP);
+ temp.add(DataTypeIec61360.FILE);
+ temp.add(DataTypeIec61360.HTML);
+ temp.add(DataTypeIec61360.BLOB);
+
+ if (!temp.containsAll(Arrays.asList(DataTypeIec61360.values()))) {
+ throw new IllegalStateException("Uncovered DataTypeIec61360");
+ }
+
+ forDataTypeIec61360 = Collections.unmodifiableSet(temp);
+ }
+ }
+
+ private static final _Transformer transformer = new _Transformer();
+
+ private static class _Transformer extends AbstractTransformer> {
+ @Override
+ public Stream transformExtension(
+ IExtension that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSupplementalSemanticIds().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Supplemental semantic IDs must be either not set or have at " +
+ "least one item.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSemanticId().isPresent()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-118: If there are supplemental semantic IDs " +
+ "defined then there shall be also a main semantic ID.")));
+ }
+
+ if (!(
+ !(that.getRefersTo().isPresent())
+ || (that.getRefersTo().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Refers-to must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getValue().isPresent())
+ || valueConsistentWithXsdType(
+ that.getValue().orElse(null),
+ that.valueTypeOrDefault()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "The value must match the value type.")));
+ }
+
+ if (that.getSemanticId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSemanticId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("semanticId"));
+ return error;
+ }));
+ }
+
+ if (that.getSupplementalSemanticIds().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSupplementalSemanticIds().get())
+ .flatMap(Verification::verifyListOf_IReference)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("supplementalSemanticIds"));
+ return error;
+ }));
+ }
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getName())
+ .flatMap(Verification::verifyNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("name"));
+ return error;
+ }));
+
+ if (that.getValueType().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValueType().get())
+ .flatMap(Verification::verifyDataTypeDefXsd)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("valueType"));
+ return error;
+ }));
+ }
+
+ if (that.getValue().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValue().get())
+ .flatMap(Verification::verifyValueDataType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("value"));
+ return error;
+ }));
+ }
+
+ if (that.getRefersTo().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getRefersTo().get())
+ .flatMap(Verification::verifyListOf_IReference)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("refersTo"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformAdministrativeInformation(
+ IAdministrativeInformation that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getEmbeddedDataSpecifications().isPresent())
+ || (that.getEmbeddedDataSpecifications().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Embedded data specifications must be either not set or have " +
+ "at least one item.")));
+ }
+
+ if (!(
+ !(that.getRevision().isPresent())
+ || (that.getVersion().isPresent()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-005: If version is not specified then also " +
+ "revision shall be unspecified. This means, a revision " +
+ "requires a version. If there is no version there is no " +
+ "revision either. Revision is optional.")));
+ }
+
+ if (that.getEmbeddedDataSpecifications().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getEmbeddedDataSpecifications().get())
+ .flatMap(Verification::verifyListOf_IEmbeddedDataSpecification)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("embeddedDataSpecifications"));
+ return error;
+ }));
+ }
+
+ if (that.getVersion().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getVersion().get())
+ .flatMap(Verification::verifyVersionType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("version"));
+ return error;
+ }));
+ }
+
+ if (that.getRevision().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getRevision().get())
+ .flatMap(Verification::verifyRevisionType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("revision"));
+ return error;
+ }));
+ }
+
+ if (that.getCreator().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getCreator().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("creator"));
+ return error;
+ }));
+ }
+
+ if (that.getTemplateId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getTemplateId().get())
+ .flatMap(Verification::verifyIdentifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("templateId"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformQualifier(
+ IQualifier that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSupplementalSemanticIds().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Supplemental semantic IDs must be either not set or have at " +
+ "least one item.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSemanticId().isPresent()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-118: If there are supplemental semantic IDs " +
+ "defined then there shall be also a main semantic ID.")));
+ }
+
+ if (!(
+ !(that.getValue().isPresent())
+ || valueConsistentWithXsdType(that.getValue().orElse(null), that.getValueType()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-020: The value shall be consistent to " +
+ "the data type as defined in value type.")));
+ }
+
+ if (that.getSemanticId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSemanticId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("semanticId"));
+ return error;
+ }));
+ }
+
+ if (that.getSupplementalSemanticIds().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSupplementalSemanticIds().get())
+ .flatMap(Verification::verifyListOf_IReference)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("supplementalSemanticIds"));
+ return error;
+ }));
+ }
+
+ if (that.getKind().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getKind().get())
+ .flatMap(Verification::verifyQualifierKind)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("kind"));
+ return error;
+ }));
+ }
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getType())
+ .flatMap(Verification::verifyQualifierType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("type"));
+ return error;
+ }));
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValueType())
+ .flatMap(Verification::verifyDataTypeDefXsd)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("valueType"));
+ return error;
+ }));
+
+ if (that.getValue().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValue().get())
+ .flatMap(Verification::verifyValueDataType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("value"));
+ return error;
+ }));
+ }
+
+ if (that.getValueId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValueId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("valueId"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformAssetAdministrationShell(
+ IAssetAdministrationShell that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || (that.getExtensions().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Extensions must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || extensionNamesAreUnique(that.getExtensions().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-077: The name of an extension within " +
+ "Has-Extensions needs to be unique.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || (that.getDescription().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDescription().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || (that.getDisplayName().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDisplayName().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getEmbeddedDataSpecifications().isPresent())
+ || (that.getEmbeddedDataSpecifications().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Embedded data specifications must be either not set or have " +
+ "at least one item.")));
+ }
+
+ if (!(
+ !(that.getSubmodels().isPresent())
+ || (that.getSubmodels().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Submodels must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getDerivedFrom().isPresent())
+ || isModelReferenceTo(
+ that.getDerivedFrom().orElse(null),
+ KeyTypes.ASSET_ADMINISTRATION_SHELL))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Derived-from must be a model reference to an asset " +
+ "administration shell.")));
+ }
+
+ if (!(
+ !(that.getSubmodels().isPresent())
+ || (
+ that.getSubmodels().get().stream().allMatch(
+ reference -> isModelReferenceTo(reference, KeyTypes.SUBMODEL))
+ ))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "All submodels must be model references to a submodel.")));
+ }
+
+ if (that.getExtensions().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getExtensions().get())
+ .flatMap(Verification::verifyListOf_IExtension)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("extensions"));
+ return error;
+ }));
+ }
+
+ if (that.getCategory().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getCategory().get())
+ .flatMap(Verification::verifyNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("category"));
+ return error;
+ }));
+ }
+
+ if (that.getIdShort().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getIdShort().get())
+ .flatMap(Verification::verifyIdShortType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("idShort"));
+ return error;
+ }));
+ }
+
+ if (that.getDisplayName().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDisplayName().get())
+ .flatMap(Verification::verifyListOf_ILangStringNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("displayName"));
+ return error;
+ }));
+ }
+
+ if (that.getDescription().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDescription().get())
+ .flatMap(Verification::verifyListOf_ILangStringTextType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("description"));
+ return error;
+ }));
+ }
+
+ if (that.getAdministration().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getAdministration().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("administration"));
+ return error;
+ }));
+ }
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getId())
+ .flatMap(Verification::verifyIdentifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("id"));
+ return error;
+ }));
+
+ if (that.getEmbeddedDataSpecifications().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getEmbeddedDataSpecifications().get())
+ .flatMap(Verification::verifyListOf_IEmbeddedDataSpecification)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("embeddedDataSpecifications"));
+ return error;
+ }));
+ }
+
+ if (that.getDerivedFrom().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDerivedFrom().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("derivedFrom"));
+ return error;
+ }));
+ }
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getAssetInformation())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("assetInformation"));
+ return error;
+ }));
+
+ if (that.getSubmodels().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSubmodels().get())
+ .flatMap(Verification::verifyListOf_IReference)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("submodels"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformAssetInformation(
+ IAssetInformation that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getSpecificAssetIds().isPresent())
+ || (
+ that.getSpecificAssetIds().get().stream().allMatch(
+ specificAssetId -> !Objects.equals(specificAssetId.getName(), "globalAssetId")
+ || (
+ (that.getGlobalAssetId().isPresent())
+ && Objects.equals(specificAssetId.getName(), "globalAssetId")
+ && Objects.equals(specificAssetId.getValue(), that.getGlobalAssetId().get())
+ ))
+ ))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-116: ``globalAssetId`` is a reserved key. " +
+ "If used as value for the name of specific asset ID then " +
+ "the value of specific asset ID shall be identical to " +
+ "the global asset ID.")));
+ }
+
+ if (!(
+ (
+ (that.getGlobalAssetId().isPresent())
+ || (that.getSpecificAssetIds().isPresent())
+ )
+ && (
+ !(that.getSpecificAssetIds().isPresent())
+ || (that.getSpecificAssetIds().get().size() >= 1)
+ ))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-131: Either the global asset ID shall be " +
+ "defined or at least one specific asset ID.")));
+ }
+
+ if (!(
+ !(that.getSpecificAssetIds().isPresent())
+ || (that.getSpecificAssetIds().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Specific asset IDs must be either not set or have at least " +
+ "one item.")));
+ }
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getAssetKind())
+ .flatMap(Verification::verifyAssetKind)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("assetKind"));
+ return error;
+ }));
+
+ if (that.getGlobalAssetId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getGlobalAssetId().get())
+ .flatMap(Verification::verifyIdentifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("globalAssetId"));
+ return error;
+ }));
+ }
+
+ if (that.getSpecificAssetIds().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSpecificAssetIds().get())
+ .flatMap(Verification::verifyListOf_ISpecificAssetId)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("specificAssetIds"));
+ return error;
+ }));
+ }
+
+ if (that.getAssetType().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getAssetType().get())
+ .flatMap(Verification::verifyIdentifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("assetType"));
+ return error;
+ }));
+ }
+
+ if (that.getDefaultThumbnail().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDefaultThumbnail().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("defaultThumbnail"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformResource(
+ IResource that) {
+ Stream errorStream = Stream.empty();
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getPath())
+ .flatMap(Verification::verifyPathType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("path"));
+ return error;
+ }));
+
+ if (that.getContentType().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getContentType().get())
+ .flatMap(Verification::verifyContentType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("contentType"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformSpecificAssetId(
+ ISpecificAssetId that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSupplementalSemanticIds().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Supplemental semantic IDs must be either not set or have at " +
+ "least one item.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSemanticId().isPresent()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-118: If there are supplemental semantic IDs " +
+ "defined then there shall be also a main semantic ID.")));
+ }
+
+ if (!(
+ !(that.getExternalSubjectId().isPresent())
+ || (that.getExternalSubjectId().get().getType() == ReferenceTypes.EXTERNAL_REFERENCE))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-133: External subject ID shall be " +
+ "an external reference.")));
+ }
+
+ if (that.getSemanticId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSemanticId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("semanticId"));
+ return error;
+ }));
+ }
+
+ if (that.getSupplementalSemanticIds().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSupplementalSemanticIds().get())
+ .flatMap(Verification::verifyListOf_IReference)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("supplementalSemanticIds"));
+ return error;
+ }));
+ }
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getName())
+ .flatMap(Verification::verifyLabelType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("name"));
+ return error;
+ }));
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValue())
+ .flatMap(Verification::verifyIdentifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("value"));
+ return error;
+ }));
+
+ if (that.getExternalSubjectId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getExternalSubjectId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("externalSubjectId"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformSubmodel(
+ ISubmodel that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || (that.getExtensions().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Extensions must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || extensionNamesAreUnique(that.getExtensions().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-077: The name of an extension within " +
+ "Has-Extensions needs to be unique.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || (that.getDescription().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDescription().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || (that.getDisplayName().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDisplayName().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSupplementalSemanticIds().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Supplemental semantic IDs must be either not set or have at " +
+ "least one item.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSemanticId().isPresent()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-118: If there are supplemental semantic IDs " +
+ "defined then there shall be also a main semantic ID.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || (that.getQualifiers().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Qualifiers must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || qualifierTypesAreUnique(that.getQualifiers().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-021: Every qualifiable can only have one " +
+ "qualifier with the same type.")));
+ }
+
+ if (!(
+ !(that.getEmbeddedDataSpecifications().isPresent())
+ || (that.getEmbeddedDataSpecifications().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Embedded data specifications must be either not set or have " +
+ "at least one item.")));
+ }
+
+ if (!(
+ !(that.getSubmodelElements().isPresent())
+ || (that.getSubmodelElements().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Submodel elements must be either not set or have at least " +
+ "one item.")));
+ }
+
+ if (!(
+ !(that.getSubmodelElements().isPresent())
+ || (
+ that.getSubmodelElements().get().stream().allMatch(
+ item -> item.getIdShort().isPresent())
+ ))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "ID-shorts need to be defined for all the items of submodel " +
+ "elements according to AASd-117 (ID-short of Referables not " +
+ "being a direct child of a Submodel element list shall be " +
+ "specified).")));
+ }
+
+ if (!(
+ !(that.getSubmodelElements().isPresent())
+ || idShortsAreUnique(that.getSubmodelElements().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-022: ID-short of non-identifiable " +
+ "referables within the same name space shall be unique " +
+ "(case-sensitive).")));
+ }
+
+ if (!(
+ !(that.getSubmodelElements().isPresent())
+ || (
+ !(that.kindOrDefault() != ModellingKind.TEMPLATE)
+ || (
+ that.getSubmodelElements().get().stream().allMatch(
+ submodelElement -> !(submodelElement.getQualifiers().isPresent())
+ || (
+ submodelElement.getQualifiers().get().stream().allMatch(
+ qualifier -> qualifier.kindOrDefault() != QualifierKind.TEMPLATE_QUALIFIER)
+ ))
+ )
+ ))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-129: If any qualifier kind value of " +
+ "a Submodel element qualifier (attribute qualifier inherited " +
+ "via Qualifiable) is equal to Template Qualifier then " +
+ "the submodel element shall be part of a submodel template, " +
+ "i.e. a Submodel with submodel kind (attribute kind " +
+ "inherited via Has-Kind) value is equal to Template.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || (
+ !(
+ that.getQualifiers().get().stream().anyMatch(
+ qualifier -> qualifier.kindOrDefault() == QualifierKind.TEMPLATE_QUALIFIER)
+ )
+ || (that.kindOrDefault() == ModellingKind.TEMPLATE)
+ ))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-119: If any qualifier kind value of " +
+ "a qualifiable qualifier is equal to template qualifier and " +
+ "the qualified element has kind then the qualified element " +
+ "shall be of kind template.")));
+ }
+
+ if (that.getExtensions().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getExtensions().get())
+ .flatMap(Verification::verifyListOf_IExtension)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("extensions"));
+ return error;
+ }));
+ }
+
+ if (that.getCategory().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getCategory().get())
+ .flatMap(Verification::verifyNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("category"));
+ return error;
+ }));
+ }
+
+ if (that.getIdShort().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getIdShort().get())
+ .flatMap(Verification::verifyIdShortType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("idShort"));
+ return error;
+ }));
+ }
+
+ if (that.getDisplayName().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDisplayName().get())
+ .flatMap(Verification::verifyListOf_ILangStringNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("displayName"));
+ return error;
+ }));
+ }
+
+ if (that.getDescription().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDescription().get())
+ .flatMap(Verification::verifyListOf_ILangStringTextType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("description"));
+ return error;
+ }));
+ }
+
+ if (that.getAdministration().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getAdministration().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("administration"));
+ return error;
+ }));
+ }
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getId())
+ .flatMap(Verification::verifyIdentifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("id"));
+ return error;
+ }));
+
+ if (that.getKind().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getKind().get())
+ .flatMap(Verification::verifyModellingKind)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("kind"));
+ return error;
+ }));
+ }
+
+ if (that.getSemanticId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSemanticId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("semanticId"));
+ return error;
+ }));
+ }
+
+ if (that.getSupplementalSemanticIds().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSupplementalSemanticIds().get())
+ .flatMap(Verification::verifyListOf_IReference)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("supplementalSemanticIds"));
+ return error;
+ }));
+ }
+
+ if (that.getQualifiers().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getQualifiers().get())
+ .flatMap(Verification::verifyListOf_IQualifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("qualifiers"));
+ return error;
+ }));
+ }
+
+ if (that.getEmbeddedDataSpecifications().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getEmbeddedDataSpecifications().get())
+ .flatMap(Verification::verifyListOf_IEmbeddedDataSpecification)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("embeddedDataSpecifications"));
+ return error;
+ }));
+ }
+
+ if (that.getSubmodelElements().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSubmodelElements().get())
+ .flatMap(Verification::verifyListOf_ISubmodelElement)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("submodelElements"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformRelationshipElement(
+ IRelationshipElement that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || (that.getExtensions().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Extensions must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || extensionNamesAreUnique(that.getExtensions().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-077: The name of an extension within " +
+ "Has-Extensions needs to be unique.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || (that.getDescription().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDescription().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || (that.getDisplayName().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDisplayName().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSupplementalSemanticIds().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Supplemental semantic IDs must be either not set or have at " +
+ "least one item.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSemanticId().isPresent()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-118: If there are supplemental semantic IDs " +
+ "defined then there shall be also a main semantic ID.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || (that.getQualifiers().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Qualifiers must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || qualifierTypesAreUnique(that.getQualifiers().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-021: Every qualifiable can only have one " +
+ "qualifier with the same type.")));
+ }
+
+ if (!(
+ !(that.getEmbeddedDataSpecifications().isPresent())
+ || (that.getEmbeddedDataSpecifications().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Embedded data specifications must be either not set or have " +
+ "at least one item.")));
+ }
+
+ if (that.getExtensions().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getExtensions().get())
+ .flatMap(Verification::verifyListOf_IExtension)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("extensions"));
+ return error;
+ }));
+ }
+
+ if (that.getCategory().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getCategory().get())
+ .flatMap(Verification::verifyNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("category"));
+ return error;
+ }));
+ }
+
+ if (that.getIdShort().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getIdShort().get())
+ .flatMap(Verification::verifyIdShortType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("idShort"));
+ return error;
+ }));
+ }
+
+ if (that.getDisplayName().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDisplayName().get())
+ .flatMap(Verification::verifyListOf_ILangStringNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("displayName"));
+ return error;
+ }));
+ }
+
+ if (that.getDescription().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDescription().get())
+ .flatMap(Verification::verifyListOf_ILangStringTextType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("description"));
+ return error;
+ }));
+ }
+
+ if (that.getSemanticId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSemanticId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("semanticId"));
+ return error;
+ }));
+ }
+
+ if (that.getSupplementalSemanticIds().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSupplementalSemanticIds().get())
+ .flatMap(Verification::verifyListOf_IReference)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("supplementalSemanticIds"));
+ return error;
+ }));
+ }
+
+ if (that.getQualifiers().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getQualifiers().get())
+ .flatMap(Verification::verifyListOf_IQualifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("qualifiers"));
+ return error;
+ }));
+ }
+
+ if (that.getEmbeddedDataSpecifications().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getEmbeddedDataSpecifications().get())
+ .flatMap(Verification::verifyListOf_IEmbeddedDataSpecification)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("embeddedDataSpecifications"));
+ return error;
+ }));
+ }
+
+ if (that.getFirst().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getFirst().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("first"));
+ return error;
+ }));
+ }
+
+ if (that.getSecond().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSecond().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("second"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformSubmodelElementList(
+ ISubmodelElementList that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || (that.getExtensions().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Extensions must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || extensionNamesAreUnique(that.getExtensions().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-077: The name of an extension within " +
+ "Has-Extensions needs to be unique.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || (that.getDescription().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDescription().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || (that.getDisplayName().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDisplayName().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSupplementalSemanticIds().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Supplemental semantic IDs must be either not set or have at " +
+ "least one item.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSemanticId().isPresent()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-118: If there are supplemental semantic IDs " +
+ "defined then there shall be also a main semantic ID.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || (that.getQualifiers().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Qualifiers must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || qualifierTypesAreUnique(that.getQualifiers().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-021: Every qualifiable can only have one " +
+ "qualifier with the same type.")));
+ }
+
+ if (!(
+ !(that.getEmbeddedDataSpecifications().isPresent())
+ || (that.getEmbeddedDataSpecifications().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Embedded data specifications must be either not set or have " +
+ "at least one item.")));
+ }
+
+ if (!(
+ !(that.getValue().isPresent())
+ || (that.getValue().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Value must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(
+ (that.getValue().isPresent())
+ && (that.getSemanticIdListElement().isPresent())
+ )
+ || (
+ that.getValue().get().stream().allMatch(
+ child -> !(child.getSemanticId().isPresent())
+ || referenceKeyValuesEqual(
+ child.getSemanticId().orElse(null),
+ that.getSemanticIdListElement().orElse(null)))
+ ))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-107: If a first level child element has " +
+ "a semantic ID it shall be identical to semantic ID list " +
+ "element.")));
+ }
+
+ if (!(
+ !(that.getValue().isPresent())
+ || submodelElementsHaveIdenticalSemanticIds(that.getValue().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-114: If two first level child elements have " +
+ "a semantic ID then they shall be identical.")));
+ }
+
+ if (!(
+ !(that.getValue().isPresent())
+ || (
+ that.getValue().get().stream().allMatch(
+ element -> submodelElementIsOfType(element, that.getTypeValueListElement()))
+ ))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-108: All first level child elements shall " +
+ "have the same submodel element type as specified in type " +
+ "value list element.")));
+ }
+
+ if (!(
+ !(
+ (that.getValue().isPresent())
+ && (
+ that.getTypeValueListElement() == AasSubmodelElements.PROPERTY
+ || that.getTypeValueListElement() == AasSubmodelElements.RANGE
+ )
+ )
+ || (
+ (that.getValueTypeListElement().isPresent())
+ && propertiesOrRangesHaveValueType(
+ that.getValue().orElse(null),
+ that.getValueTypeListElement().orElse(null))
+ ))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-109: If type value list element is equal to " +
+ "Property or Range value type list element shall be set and " +
+ "all first level child elements shall have the value type as " +
+ "specified in value type list element.")));
+ }
+
+ if (!(
+ !(that.getValue().isPresent())
+ || idShortsAreUnique(that.getValue().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "ID-shorts of the value must be unique.")));
+ }
+
+ if (that.getExtensions().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getExtensions().get())
+ .flatMap(Verification::verifyListOf_IExtension)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("extensions"));
+ return error;
+ }));
+ }
+
+ if (that.getCategory().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getCategory().get())
+ .flatMap(Verification::verifyNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("category"));
+ return error;
+ }));
+ }
+
+ if (that.getIdShort().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getIdShort().get())
+ .flatMap(Verification::verifyIdShortType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("idShort"));
+ return error;
+ }));
+ }
+
+ if (that.getDisplayName().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDisplayName().get())
+ .flatMap(Verification::verifyListOf_ILangStringNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("displayName"));
+ return error;
+ }));
+ }
+
+ if (that.getDescription().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDescription().get())
+ .flatMap(Verification::verifyListOf_ILangStringTextType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("description"));
+ return error;
+ }));
+ }
+
+ if (that.getSemanticId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSemanticId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("semanticId"));
+ return error;
+ }));
+ }
+
+ if (that.getSupplementalSemanticIds().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSupplementalSemanticIds().get())
+ .flatMap(Verification::verifyListOf_IReference)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("supplementalSemanticIds"));
+ return error;
+ }));
+ }
+
+ if (that.getQualifiers().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getQualifiers().get())
+ .flatMap(Verification::verifyListOf_IQualifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("qualifiers"));
+ return error;
+ }));
+ }
+
+ if (that.getEmbeddedDataSpecifications().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getEmbeddedDataSpecifications().get())
+ .flatMap(Verification::verifyListOf_IEmbeddedDataSpecification)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("embeddedDataSpecifications"));
+ return error;
+ }));
+ }
+
+ if (that.getSemanticIdListElement().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSemanticIdListElement().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("semanticIdListElement"));
+ return error;
+ }));
+ }
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getTypeValueListElement())
+ .flatMap(Verification::verifyAasSubmodelElements)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("typeValueListElement"));
+ return error;
+ }));
+
+ if (that.getValueTypeListElement().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValueTypeListElement().get())
+ .flatMap(Verification::verifyDataTypeDefXsd)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("valueTypeListElement"));
+ return error;
+ }));
+ }
+
+ if (that.getValue().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValue().get())
+ .flatMap(Verification::verifyListOf_ISubmodelElement)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("value"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformSubmodelElementCollection(
+ ISubmodelElementCollection that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || (that.getExtensions().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Extensions must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || extensionNamesAreUnique(that.getExtensions().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-077: The name of an extension within " +
+ "Has-Extensions needs to be unique.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || (that.getDescription().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDescription().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || (that.getDisplayName().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDisplayName().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSupplementalSemanticIds().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Supplemental semantic IDs must be either not set or have at " +
+ "least one item.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSemanticId().isPresent()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-118: If there are supplemental semantic IDs " +
+ "defined then there shall be also a main semantic ID.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || (that.getQualifiers().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Qualifiers must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || qualifierTypesAreUnique(that.getQualifiers().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-021: Every qualifiable can only have one " +
+ "qualifier with the same type.")));
+ }
+
+ if (!(
+ !(that.getEmbeddedDataSpecifications().isPresent())
+ || (that.getEmbeddedDataSpecifications().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Embedded data specifications must be either not set or have " +
+ "at least one item.")));
+ }
+
+ if (!(
+ !(that.getValue().isPresent())
+ || (that.getValue().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Value must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getValue().isPresent())
+ || (
+ that.getValue().get().stream().allMatch(
+ item -> item.getIdShort().isPresent())
+ ))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "ID-shorts need to be defined for all the items of value " +
+ "according to AASd-117 (ID-short of Referables not being " +
+ "a direct child of a Submodel element list shall be " +
+ "specified).")));
+ }
+
+ if (!(
+ !(that.getValue().isPresent())
+ || idShortsAreUnique(that.getValue().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "ID-shorts of the value must be unique.")));
+ }
+
+ if (that.getExtensions().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getExtensions().get())
+ .flatMap(Verification::verifyListOf_IExtension)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("extensions"));
+ return error;
+ }));
+ }
+
+ if (that.getCategory().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getCategory().get())
+ .flatMap(Verification::verifyNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("category"));
+ return error;
+ }));
+ }
+
+ if (that.getIdShort().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getIdShort().get())
+ .flatMap(Verification::verifyIdShortType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("idShort"));
+ return error;
+ }));
+ }
+
+ if (that.getDisplayName().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDisplayName().get())
+ .flatMap(Verification::verifyListOf_ILangStringNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("displayName"));
+ return error;
+ }));
+ }
+
+ if (that.getDescription().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDescription().get())
+ .flatMap(Verification::verifyListOf_ILangStringTextType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("description"));
+ return error;
+ }));
+ }
+
+ if (that.getSemanticId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSemanticId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("semanticId"));
+ return error;
+ }));
+ }
+
+ if (that.getSupplementalSemanticIds().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSupplementalSemanticIds().get())
+ .flatMap(Verification::verifyListOf_IReference)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("supplementalSemanticIds"));
+ return error;
+ }));
+ }
+
+ if (that.getQualifiers().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getQualifiers().get())
+ .flatMap(Verification::verifyListOf_IQualifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("qualifiers"));
+ return error;
+ }));
+ }
+
+ if (that.getEmbeddedDataSpecifications().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getEmbeddedDataSpecifications().get())
+ .flatMap(Verification::verifyListOf_IEmbeddedDataSpecification)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("embeddedDataSpecifications"));
+ return error;
+ }));
+ }
+
+ if (that.getValue().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValue().get())
+ .flatMap(Verification::verifyListOf_ISubmodelElement)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("value"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformProperty(
+ IProperty that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || (that.getExtensions().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Extensions must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || extensionNamesAreUnique(that.getExtensions().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-077: The name of an extension within " +
+ "Has-Extensions needs to be unique.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || (that.getDescription().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDescription().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDescription().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Description must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || (that.getDisplayName().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must be either not set or have at least one " +
+ "item.")));
+ }
+
+ if (!(
+ !(that.getDisplayName().isPresent())
+ || langStringsHaveUniqueLanguages(that.getDisplayName().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Display name must specify unique languages.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSupplementalSemanticIds().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Supplemental semantic IDs must be either not set or have at " +
+ "least one item.")));
+ }
+
+ if (!(
+ !(that.getSupplementalSemanticIds().isPresent())
+ || (that.getSemanticId().isPresent()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-118: If there are supplemental semantic IDs " +
+ "defined then there shall be also a main semantic ID.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || (that.getQualifiers().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Qualifiers must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getQualifiers().isPresent())
+ || qualifierTypesAreUnique(that.getQualifiers().orElse(null)))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Constraint AASd-021: Every qualifiable can only have one " +
+ "qualifier with the same type.")));
+ }
+
+ if (!(
+ !(that.getEmbeddedDataSpecifications().isPresent())
+ || (that.getEmbeddedDataSpecifications().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Embedded data specifications must be either not set or have " +
+ "at least one item.")));
+ }
+
+ if (!(
+ !(that.getValue().isPresent())
+ || valueConsistentWithXsdType(that.getValue().orElse(null), that.getValueType()))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Value must be consistent with the value type.")));
+ }
+
+ if (that.getExtensions().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getExtensions().get())
+ .flatMap(Verification::verifyListOf_IExtension)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("extensions"));
+ return error;
+ }));
+ }
+
+ if (that.getCategory().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getCategory().get())
+ .flatMap(Verification::verifyNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("category"));
+ return error;
+ }));
+ }
+
+ if (that.getIdShort().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getIdShort().get())
+ .flatMap(Verification::verifyIdShortType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("idShort"));
+ return error;
+ }));
+ }
+
+ if (that.getDisplayName().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDisplayName().get())
+ .flatMap(Verification::verifyListOf_ILangStringNameType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("displayName"));
+ return error;
+ }));
+ }
+
+ if (that.getDescription().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getDescription().get())
+ .flatMap(Verification::verifyListOf_ILangStringTextType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("description"));
+ return error;
+ }));
+ }
+
+ if (that.getSemanticId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSemanticId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("semanticId"));
+ return error;
+ }));
+ }
+
+ if (that.getSupplementalSemanticIds().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getSupplementalSemanticIds().get())
+ .flatMap(Verification::verifyListOf_IReference)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("supplementalSemanticIds"));
+ return error;
+ }));
+ }
+
+ if (that.getQualifiers().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getQualifiers().get())
+ .flatMap(Verification::verifyListOf_IQualifier)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("qualifiers"));
+ return error;
+ }));
+ }
+
+ if (that.getEmbeddedDataSpecifications().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getEmbeddedDataSpecifications().get())
+ .flatMap(Verification::verifyListOf_IEmbeddedDataSpecification)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("embeddedDataSpecifications"));
+ return error;
+ }));
+ }
+
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValueType())
+ .flatMap(Verification::verifyDataTypeDefXsd)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("valueType"));
+ return error;
+ }));
+
+ if (that.getValue().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValue().get())
+ .flatMap(Verification::verifyValueDataType)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("value"));
+ return error;
+ }));
+ }
+
+ if (that.getValueId().isPresent()) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(that.getValueId().get())
+ .flatMap(Verification::verifyToErrorStream)
+ .map(error -> {
+ error.prependSegment(
+ new Reporting.NameSegment("valueId"));
+ return error;
+ }));
+ }
+
+ return errorStream;
+ }
+
+ @Override
+ public Stream transformMultiLanguageProperty(
+ IMultiLanguageProperty that) {
+ Stream errorStream = Stream.empty();
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || (that.getExtensions().get().size() >= 1))) {
+ errorStream = Stream.concat(errorStream,
+ Stream.of(new Reporting.Error(
+ "Invariant violated:\n" +
+ "Extensions must be either not set or have at least one item.")));
+ }
+
+ if (!(
+ !(that.getExtensions().isPresent())
+ || extensionNamesAreUnique(that.getExtensions().orElse(null)))) {
+ errorStream = Stream.