org.apache.camel.language.wasm.WasmLanguage Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.language.wasm;
import org.apache.camel.CamelContext;
import org.apache.camel.Expression;
import org.apache.camel.Predicate;
import org.apache.camel.spi.PropertyConfigurer;
import org.apache.camel.spi.annotations.Language;
import org.apache.camel.support.ExpressionToPredicateAdapter;
import org.apache.camel.support.TypedLanguageSupport;
import org.apache.camel.support.component.PropertyConfigurerSupport;
import org.apache.camel.wasm.Wasm;
@Language(Wasm.SCHEME)
public class WasmLanguage extends TypedLanguageSupport implements PropertyConfigurer {
private String module;
public WasmLanguage() {
}
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
@Override
public boolean configure(CamelContext camelContext, Object target, String name, Object value, boolean ignoreCase) {
if (target != this) {
throw new IllegalStateException("Can only configure our own instance !");
}
switch (ignoreCase ? name.toLowerCase() : name) {
case "module":
setModule(PropertyConfigurerSupport.property(camelContext, String.class, value));
return true;
default:
return false;
}
}
@Override
public Predicate createPredicate(String expression) {
return ExpressionToPredicateAdapter.toPredicate(createExpression(expression));
}
@Override
public Expression createExpression(String expression) {
return createExpression(expression, null);
}
@Override
public Predicate createPredicate(String expression, Object[] properties) {
return ExpressionToPredicateAdapter.toPredicate(createExpression(expression, properties));
}
@Override
public Expression createExpression(String expression, Object[] properties) {
WasmExpression answer = new WasmExpression(expression);
answer.setResultType(property(Class.class, properties, 0, null));
answer.setModule(property(String.class, properties, 1, getModule()));
if (getCamelContext() != null) {
answer.init(getCamelContext());
}
return answer;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy