sruehl commented on a change in pull request #40: Alias registry for opm
URL: https://github.com/apache/incubator-plc4x/pull/40#discussion_r235885479
##########
File path:
plc4j/utils/opm/src/main/java/org/apache/plc4x/java/opm/OpmUtils.java
##########
@@ -42,4 +48,41 @@ private OpmUtils() {
return annotation;
}
+ static String getOrResolveAddress(AliasRegistry registry, String
addressString) {
+ if (!OpmUtils.isValidExpression(addressString)) {
+ throw new IllegalArgumentException("Invalid Syntax, either use
field address (no starting $) " +
+ "or an alias with Syntax ${xxx}. But given was '" +
addressString + "'");
+ }
+ if (OpmUtils.isAlias(addressString)) {
+ String alias = OpmUtils.getAlias(addressString);
+ if (registry.canResolve(alias)) {
+ return registry.resolve(alias);
+ } else {
+ throw new IllegalArgumentException("Unable to resolve Alias '"
+ alias + "' in Schema Registry");
+ }
+ } else {
+ return addressString;
+ }
+ }
+
+ /**
+ * Checks whether a given String is a valid OPM Expression, this means
+ * either an Address or an alias ${xxx}.
+ */
+ static boolean isValidExpression(String s) {
+ return !s.startsWith("$") || pattern.matcher(s).matches();
+ }
+
+ static boolean isAlias(String s) {
+ return s.startsWith("$") && pattern.matcher(s).matches();
Review comment:
might add a nullcheck here
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services