Search in sources :

Example 11 with IClientPlugin

use of com.servoy.j2db.plugins.IClientPlugin in project servoy-client by Servoy.

the class JSApplication method js_readFile.

/**
 * @deprecated  As of release 2.x, replaced by {@link plugins.file#readFile(Object[])}.
 */
@Deprecated
public byte[] js_readFile(Object[] args) {
    // $NON-NLS-1$
    IClientPlugin cp = application.getPluginManager().getPlugin(IClientPlugin.class, "file");
    if (cp != null) {
        IScriptable so = cp.getScriptObject();
        if (so != null) {
            try {
                // $NON-NLS-1$
                Method m = so.getClass().getMethod("js_readFile", getClassArrayFromObjectArgs(args));
                return (byte[]) m.invoke(so, args);
            } catch (Exception e) {
                Debug.error(e);
            }
        }
    }
    application.reportError("Reading file failed", "For this operation the file plugin is needed\nNote this method is deprecated, use the plugin directly in your code");
    return null;
}
Also used : IClientPlugin(com.servoy.j2db.plugins.IClientPlugin) Method(java.lang.reflect.Method) ApplicationException(com.servoy.j2db.ApplicationException) ExitScriptException(com.servoy.j2db.ExitScriptException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException)

Example 12 with IClientPlugin

use of com.servoy.j2db.plugins.IClientPlugin in project servoy-client by Servoy.

the class PluginScope method get.

/**
 * @see com.servoy.j2db.scripting.DefaultScope#get(java.lang.String, org.mozilla.javascript.Scriptable)
 */
@Override
public Object get(String name, Scriptable start) {
    if (// $NON-NLS-1$
    "length".equals(name)) {
        return new Integer(application.getPluginManager().getPlugins(IClientPlugin.class).size());
    }
    if (// $NON-NLS-1$
    "allnames".equals(name)) {
        Context.enter();
        try {
            List<IClientPlugin> lst = application.getPluginManager().getPlugins(IClientPlugin.class);
            Object[] array = new String[lst.size()];
            for (int i = 0; i < lst.size(); i++) {
                IClientPlugin plugin = lst.get(i);
                array[i] = plugin.getName();
            }
            Arrays.sort(array);
            return new NativeJavaArray(this, array);
        } finally {
            Context.exit();
        }
    }
    String realName = name;
    // we bought, just map, has to backwards compatible anyway //$NON-NLS-1$ //$NON-NLS-2$
    if ("it2be_menubar".equals(realName))
        realName = "menubar";
    Object o = super.get(realName, start);
    if (o == Scriptable.NOT_FOUND || o == null) {
        if (// performance optimize //$NON-NLS-1$
        realName.equals("Function")) {
            return Scriptable.NOT_FOUND;
        }
        IScriptable tocall = null;
        IClientPlugin plugin = application.getPluginManager().getPlugin(IClientPlugin.class, realName);
        if (plugin == null) {
            // original name not found, try updated name
            realName = getUpdatedPluginName(name);
            if (!name.equals(realName)) {
                plugin = application.getPluginManager().getPlugin(IClientPlugin.class, realName);
            }
        }
        if (plugin != null) {
            try {
                Method method = plugin.getClass().getMethod("getScriptObject", (Class[]) null);
                if (method != null) {
                    tocall = (IScriptable) method.invoke(plugin, (Object[]) null);
                }
            } catch (Exception e) {
                Debug.error(e);
            }
        }
        if (tocall != null) {
            // first register the script object itself
            ScriptObjectRegistry.registerScriptObjectForClass(tocall.getClass(), tocall);
            ServoyNativeJavaObject s_tocall = null;
            Context.enter();
            try {
                InstanceJavaMembers ijm = new InstanceJavaMembers(this, tocall.getClass());
                s_tocall = new ServoyNativeJavaObject(this, tocall, ijm);
                setLocked(false);
                // save so we do not all this again
                put(realName, this, s_tocall);
                setLocked(true);
                IExecutingEnviroment scriptEngine = application.getScriptEngine();
                if (scriptEngine != null && tocall instanceof IReturnedTypesProvider) {
                    scriptEngine.registerScriptObjectReturnTypes((IReturnedTypesProvider) tocall, s_tocall);
                }
            } finally {
                Context.exit();
            }
            return s_tocall;
        }
        return Scriptable.NOT_FOUND;
    }
    return o;
}
Also used : Method(java.lang.reflect.Method) NativeJavaArray(org.mozilla.javascript.NativeJavaArray) IClientPlugin(com.servoy.j2db.plugins.IClientPlugin)

Example 13 with IClientPlugin

use of com.servoy.j2db.plugins.IClientPlugin in project servoy-client by Servoy.

the class JSDatabaseManager method js_executeStoredProcedure.

/**
 * @deprecated As of release 3.5, replaced by {@link plugins.rawSQL#executeStoredProcedure(String, String, Object[], int[], int)}.
 */
@Deprecated
public Object js_executeStoredProcedure(String serverName, String procedureDeclaration, Object[] args, int[] inOutType, int maxNumberOfRowsToRetrieve) throws ServoyException {
    checkAuthorized();
    // $NON-NLS-1$
    IClientPlugin cp = application.getPluginManager().getPlugin(IClientPlugin.class, "rawSQL");
    if (cp != null) {
        IScriptable so = cp.getScriptObject();
        if (so != null) {
            try {
                Method m = // $NON-NLS-1$
                so.getClass().getMethod(// $NON-NLS-1$
                "js_executeStoredProcedure", new Class[] { String.class, String.class, Object[].class, int[].class, int.class });
                return m.invoke(so, new Object[] { serverName, procedureDeclaration, args, inOutType, new Integer(maxNumberOfRowsToRetrieve) });
            } catch (Exception e) {
                Debug.error(e);
            }
        }
    }
    // $NON-NLS-1$
    application.reportError(// $NON-NLS-1$
    "Writing to file failed", // $NON-NLS-1$
    "For this operation the file plugin is needed\nNote this method is deprecated, use the plugin directly in your code");
    return null;
}
Also used : IClientPlugin(com.servoy.j2db.plugins.IClientPlugin) NativeObject(org.mozilla.javascript.NativeObject) Method(java.lang.reflect.Method) IScriptable(com.servoy.j2db.scripting.IScriptable) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) SQLException(java.sql.SQLException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Aggregations

IClientPlugin (com.servoy.j2db.plugins.IClientPlugin)13 Method (java.lang.reflect.Method)12 ApplicationException (com.servoy.j2db.ApplicationException)11 ServoyException (com.servoy.j2db.util.ServoyException)11 ExitScriptException (com.servoy.j2db.ExitScriptException)10 JavaScriptException (org.mozilla.javascript.JavaScriptException)10 ScriptableObject (org.mozilla.javascript.ScriptableObject)7 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 IScriptable (com.servoy.j2db.scripting.IScriptable)1 RemoteException (java.rmi.RemoteException)1 SQLException (java.sql.SQLException)1 NativeJavaArray (org.mozilla.javascript.NativeJavaArray)1 NativeObject (org.mozilla.javascript.NativeObject)1