public ScriptNested(R builder) { super(new AstPropertyNode(), builder); }
@Override protected boolean equalTo(AstRegion that) { return that instanceof AstPropertyNode && equalTo((AstPropertyNode) that); }
public AstPropertyNodeBuilder setPropertyName(String propertyName) { node.setPropertyName(propertyName); return this; }
@Override public AstPropertyNode visitPropertyNode(PropertyNodeContext ctx) { AstValueVisitor<?> visitor = new AstValueVisitor<>(factory, environment, Object.class); AstValue<?> value = visitor.visit(ctx.value); childInfos().add(value.getRegionInfo()); node = new AstPropertyNode(); node.setRegionInfo(asSequentialRegion(childInfos, ctx)); node.setPropertyName(ctx.name.getText()); node.setPropertyValue(value); node.setEnvironment(environment); return node; }
@Override protected void describe(StringBuilder buf) { super.describe(buf); buf.append(format("property %s %s\n", getPropertyName(), getPropertyValue())); }
@Override public Configuration visit(AstPropertyNode propertyNode, State state) { String propertyName = propertyNode.getPropertyName(); Object value = propertyNode.resolve(); if (value instanceof AutoCloseable) { state.configuration.getResources().add((AutoCloseable) value); } if (LOGGER.isDebugEnabled()) { Object formatValue = (value instanceof byte[]) ? AstLiteralBytesValue.toString((byte[]) value) : value; LOGGER.debug(format("Setting value for ${%s} to %s", propertyName, formatValue)); } return state.configuration; }
private String injectOverridenProperties(String aggregatedScript, List<String> scriptProperties) throws Exception, ScriptParseException { ScriptParserImpl parser = new ScriptParserImpl(); for (String propertyToInject : scriptProperties) { String propertyName = parser.parseWithStrategy(propertyToInject, PROPERTY_NODE).getPropertyName(); StringBuilder replacementScript = new StringBuilder(); Pattern pattern = Pattern.compile("property\\s+" + propertyName + "\\s+.+"); boolean matchFound = false; for (String scriptLine : aggregatedScript.split("\\r?\\n")) { if (pattern.matcher(scriptLine).matches()) { matchFound = true; replacementScript.append(propertyToInject + "\n"); } else { replacementScript.append(scriptLine + "\n"); } } if (!matchFound) { String errorMsg = "Received " + propertyToInject + " in PREPARE but found no where to substitute it"; LOGGER.error(errorMsg); throw new Exception(errorMsg); } aggregatedScript = replacementScript.toString(); } return aggregatedScript; }
@Override protected void describe(StringBuilder buf) { if (properties != null) { for (AstPropertyNode property : properties) { property.describe(buf); } } if (streams != null) { for (AstStreamNode stream : streams) { stream.describe(buf); } } } }
@Override public AstScriptNode visitPropertyNode(PropertyNodeContext ctx) { AstPropertyNodeVisitor visitor = new AstPropertyNodeVisitor(factory, environment); AstPropertyNode propertyNode = visitor.visitPropertyNode(ctx); if (propertyNode != null) { node.getProperties().add(propertyNode); childInfos().add(propertyNode.getRegionInfo()); } return node; }
@Override public Configuration visit(AstScriptNode script, State state) { state.configuration = new Configuration(); for (AstPropertyNode property : script.getProperties()) { property.accept(this, state); } for (AstStreamNode stream : script.getStreams()) { stream.accept(this, state); } return state.configuration; }
public ScriptNested<R> setOptionName(String propertyName) { node.setPropertyName(propertyName); return this; }
public AstPropertyNodeBuilder() { this(new AstPropertyNode()); }