Search in sources :

Example 1 with IExtensionPoint

use of org.jumpmind.extension.IExtensionPoint in project symmetric-ds by JumpMind.

the class ExtensionService method registerExtension.

protected void registerExtension(Extension extension) {
    if (extension.getExtensionText() != null) {
        if (extension.getExtensionType().equalsIgnoreCase(Extension.EXTENSION_TYPE_JAVA)) {
            try {
                Object ext = SimpleClassCompiler.getInstance().getCompiledClass(extension.getExtensionText());
                registerExtension(extension.getExtensionId(), (IExtensionPoint) ext);
            } catch (Exception e) {
                log.error("Error while compiling Java extension " + extension.getExtensionId(), e);
            }
        } else if (extension.getExtensionType().equalsIgnoreCase(Extension.EXTENSION_TYPE_BSH)) {
            try {
                Interpreter interpreter = new Interpreter();
                interpreter.eval(extension.getExtensionText());
                Object ext = interpreter.getInterface(Class.forName(extension.getInterfaceName()));
                registerExtension(extension.getExtensionId(), (IExtensionPoint) ext);
            } catch (EvalError e) {
                log.error("Error while parsing BSH extension " + extension.getExtensionId(), e);
            } catch (ClassNotFoundException e) {
                log.error("Interface class not found for BSH extension " + extension.getExtensionId(), e);
            }
        } else {
            log.error("Skipping extension " + extension.getExtensionId() + ", unknown extension type " + extension.getExtensionType());
        }
    }
}
Also used : Interpreter(bsh.Interpreter) IExtensionPoint(org.jumpmind.extension.IExtensionPoint) EvalError(bsh.EvalError)

Example 2 with IExtensionPoint

use of org.jumpmind.extension.IExtensionPoint in project symmetric-ds by JumpMind.

the class ExtensionService method refresh.

public synchronized void refresh() {
    extensionsByClassByName = new HashMap<Class, Map<String, IExtensionPoint>>();
    extensionMetaData = new ArrayList<ExtensionPointMetaData>();
    for (Class extensionClass : staticExtensionsByClassByName.keySet()) {
        Map<String, IExtensionPoint> byNameMap = staticExtensionsByClassByName.get(extensionClass);
        for (String name : byNameMap.keySet()) {
            IExtensionPoint ext = byNameMap.get(name);
            getExtensionsByNameMap(extensionClass).put(name, ext);
            addExtensionPointMetaData(ext, name, extensionClass, true);
        }
    }
    String prefix = parameterService.getString(ParameterConstants.RUNTIME_CONFIG_TABLE_PREFIX);
    if (platform.getTableFromCache(TableConstants.getTableName(prefix, TableConstants.SYM_EXTENSION), false) != null) {
        List<Extension> extensionList = sqlTemplate.query(getSql("selectEnabled"), new ExtensionRowMapper(), parameterService.getNodeGroupId());
        log.info("Found {} extension points from the database that will be registered", extensionList.size());
        for (Extension extension : extensionList) {
            registerExtension(extension);
        }
    }
}
Also used : Extension(org.jumpmind.symmetric.model.Extension) IExtensionPoint(org.jumpmind.extension.IExtensionPoint) HashMap(java.util.HashMap) Map(java.util.Map) ExtensionPointMetaData(org.jumpmind.symmetric.ext.ExtensionPointMetaData)

Aggregations

IExtensionPoint (org.jumpmind.extension.IExtensionPoint)2 EvalError (bsh.EvalError)1 Interpreter (bsh.Interpreter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExtensionPointMetaData (org.jumpmind.symmetric.ext.ExtensionPointMetaData)1 Extension (org.jumpmind.symmetric.model.Extension)1