use of com.dexels.navajo.expression.api.FunctionDefinition in project navajo by Dexels.
the class JarFunctionFactory method init.
@Override
public void init() {
Map<String, FunctionDefinition> fuds = getDefaultConfig();
if (fuds == null) {
fuds = new HashMap<>();
setDefaultConfig(fuds);
}
ClassLoader myClassLoader = null;
if (DispatcherFactory.getInstance() != null) {
myClassLoader = DispatcherFactory.getInstance().getNavajoConfig().getClassloader();
} else {
myClassLoader = getClass().getClassLoader();
}
try {
Iterator<?> iter = java.util.ServiceLoader.load(Class.forName("navajo.ExtensionDefinition", true, myClassLoader), myClassLoader).iterator();
while (iter.hasNext()) {
ExtensionDefinition ed = (ExtensionDefinition) iter.next();
readDefinitionFile(fuds, ed);
}
} catch (Throwable e) {
logger.debug("ServiceLookup failed. Normal in OSGi environment", e);
if (!Version.osgiActive()) {
logger.error("But OSGi isn't active, so something is definitely wrong.", e);
}
}
}
use of com.dexels.navajo.expression.api.FunctionDefinition in project navajo by Dexels.
the class JarFunctionFactory method parseAdapters.
public void parseAdapters(Map<String, FunctionDefinition> fuds, ExtensionDefinition fd, XMLElement element) {
String name = element.getElementByTagName("tagname").getContent();
String className = element.getElementByTagName("object").getContent();
if (fd != null) {
FunctionDefinition functionDefinition = new FunctionDefinition(className, null, null, null);
getAdapterConfig(fd).put(name, functionDefinition);
try {
MapMetaData.getInstance().addMapDefinition(element);
} catch (Exception e) {
logger.error("Error: ", e);
}
} else {
throw new UnsupportedOperationException("Can not register adapter (pre-OSGi) without a ExtensionDefinition.");
}
}
use of com.dexels.navajo.expression.api.FunctionDefinition in project navajo by Dexels.
the class FunctionFactoryInterface method getInstance.
// public void clearAdapterNames() {
// adapterConfig.clear();
// }
@SuppressWarnings("unchecked")
public FunctionInterface getInstance(final ClassLoader cl, final String functionName) {
try {
FunctionDefinition fd = getDef(functionName);
if (fd == null) {
logger.error("Missing function definition: {}", functionName);
return null;
}
Class<FunctionInterface> myClass = (Class<FunctionInterface>) Class.forName(fd.getObject(), true, cl);
FunctionInterface fi = myClass.getDeclaredConstructor().newInstance();
fi.setDefinition(fd);
if (!fi.isInitialized()) {
fi.setTypes(fd.getInputParams(), fd.getResultParam());
}
return fi;
} catch (Exception e) {
logger.error("Function: " + functionName + " not found!", e);
return null;
}
}
use of com.dexels.navajo.expression.api.FunctionDefinition in project navajo by Dexels.
the class JarFunctionFactory method parseFunction.
public FunctionDefinition parseFunction(Map<String, FunctionDefinition> fuds, XMLElement element) {
Vector<XMLElement> def = element.getChildren();
String name = (String) element.getAttribute("name");
String object = (String) element.getAttribute("class");
String description = null;
String inputParams = null;
String resultParam = null;
for (int j = 0; j < def.size(); j++) {
if (def.get(j).getName().equals("description")) {
description = def.get(j).getContent();
}
if (def.get(j).getName().equals("input")) {
inputParams = def.get(j).getContent();
}
if (def.get(j).getName().equals("result")) {
resultParam = def.get(j).getContent();
}
}
if (name != null) {
FunctionDefinition functionDefinition = new FunctionDefinition(object, description, inputParams, resultParam);
functionDefinition.setXmlElement(element);
fuds.put(name, functionDefinition);
return functionDefinition;
}
return null;
}
use of com.dexels.navajo.expression.api.FunctionDefinition in project navajo by Dexels.
the class OSGiFunctionFactoryFactory method getFunctionInterface.
public static FunctionInterface getFunctionInterface(final String functionName) {
if (cache.containsKey(functionName)) {
return cache.get(functionName).getFunctionInstance();
}
FunctionDefinition fd = (FunctionDefinition) getComponent(functionName, "functionName", FunctionDefinition.class);
if (fd == null) {
throw NavajoFactory.getInstance().createNavajoException("No such function: " + functionName);
}
cache.put(functionName, fd);
FunctionInterface instance = fd.getFunctionInstance();
instance.setDefinition(fd);
return instance;
}
Aggregations