public Condition build(String script) throws IllegalAccessException, CompileException, InstantiationException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException { ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.setImplementedInterfaces(new Class[]{Condition.class}); cbe.setExtendedClass(PropertyWrapperForScripts.class); cbe.setParentClassLoader(ClassBodyEvaluator.class.getClassLoader()); cbe.cook(SCRIPT_PREFIX + script + SCRIPT_SUFFIX); Class<?> clazz = cbe.getClazz(); Condition instance = (Condition) clazz.newInstance(); Method setMapMethod = clazz.getMethod("setPropertyContainers", PropertyContainer.class, PropertyContainer.class); setMapMethod.invoke(instance, localPropContainer, context); return instance; }
public static String propertyLookup(String key, PropertyContainer pc1, PropertyContainer pc2) { String value = null; // first try the props passed as parameter value = pc1.getProperty(key); // then try the pc2 if (value == null && pc2 != null) { value = pc2.getProperty(key); } // then try in System properties if (value == null) { value = getSystemProperty(key, null); } if (value == null) { value = getEnv(key); } return value; }
/** * See http://logback.qos.ch/manual/configuration.html#variableSubstitution */ public static String substVars(String input, PropertyContainer pc0, PropertyContainer pc1) { try { return NodeToStringTransformer.substituteVariable(input, pc0, pc1); } catch (ScanException e) { throw new IllegalArgumentException("Failed to parse input [" + input + "]", e); } }
public PropertyContainer getContext() { return this.context; }
public NodeToStringTransformer(Node node, PropertyContainer propertyContainer0, PropertyContainer propertyContainer1) { this.node = node; this.propertyContainer0 = propertyContainer0; this.propertyContainer1 = propertyContainer1; }
public NodeToStringTransformer(Node node, PropertyContainer propertyContainer0) { this(node, propertyContainer0, null); }
public static String substituteVariable(String input, PropertyContainer pc0, PropertyContainer pc1) throws ScanException { Node node = tokenizeAndParseString(input); NodeToStringTransformer nodeToStringTransformer = new NodeToStringTransformer(node, pc0, pc1); return nodeToStringTransformer.transform(); }
PropertyEvalScriptBuilder(PropertyContainer localPropContainer) { this.localPropContainer = localPropContainer; }
public void setPropertyContainers(PropertyContainer local, PropertyContainer context) { this.local = local; this.context = context; }
/** * @see #substVars(String, PropertyContainer, PropertyContainer) */ public static String substVars(String val, PropertyContainer pc1) { return substVars(val, pc1, null); }