Revision 44592 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/CreateFnFunction.java

View differences:

CreateFnFunction.java
67 67
        String script_path = null;
68 68
        String script_function = null;
69 69
        String language = null;
70
        // name, body
71
        // name, args, body
72
        // name, script_name, script_func, lang
73
        // name, args, script_name, script_func, lang
70 74
        switch(args.size()) {
71 75
            case 2:
72 76
                name = (String) getObject(interpreter, args, 0);
......
90 94
                    argNames = (List<String>) getObject(interpreter, args, 1);
91 95
                }
92 96
                body = args.get(2);
93
                script_path = Objects.toString(args.get(2),null);
94
                script_function = Objects.toString(args.get(3),null);
95
                language = Objects.toString(args.get(4),null);
97
                script_path = (args.get(3)==null)? null:((String)((Code.Constant)args.get(3)).value());
98
                script_function = (args.get(4)==null)? null:((String)((Code.Constant)args.get(4)).value());
99
                language = (args.get(5)==null)? null:((String)((Code.Constant)args.get(5)).value()).toLowerCase();
96 100
                break;
97 101
            default:
98 102
                throw new ExpressionRuntimeException("Incorrect number of arguments");
......
171 175

  
172 176
        private final String script_path;
173 177
        private final String script_function;
178
        private final Script script;
174 179

  
175 180
        public ExternalFunction(String name, String script_path, String script_function) {
176 181
            super(GROUP_OTHER, name, Range.between(0, Integer.MAX_VALUE));
177 182
            this.script_path = script_path;
178 183
            this.script_function = script_function;
179
        }
180
        
181
        @Override
182
        public Object call(Interpreter interpreter, Object[] args) throws Exception {
183 184
            ScriptManager scriptManager = ToolsLocator.getScriptManager();
184 185
            ExpressionEvaluatorManager expressionManager = ExpressionEvaluatorLocator.getExpressionEvaluatorManager();
185 186
            ResourcesStorage resourcesStorage = expressionManager.getScriptsResourcesStorage();
186
            Script sc = scriptManager.loadScript(resourcesStorage, script_path);
187
            if( sc == null ) {
187
            this.script = scriptManager.loadScript(resourcesStorage, script_path);
188
            if( this.script == null ) {
188 189
                throw new ExpressionRuntimeException("Can't locate '"+this.script_path+"'.");
189 190
            }
190
            Object r = sc.invokeFunction(this.script_function, args);
191
        }
192
        
193
        @Override
194
        public Object call(Interpreter interpreter, Object[] args) throws Exception {
195
            Object r = this.script.invokeFunction(this.script_function, args);
191 196
            return r;
192 197
        }
193 198
        

Also available in: Unified diff