Index: CreateFnFunction.java
===================================================================
--- CreateFnFunction.java	(revision 44749)
+++ CreateFnFunction.java	(revision 44750)
@@ -21,6 +21,7 @@
 import org.gvsig.tools.script.Script;
 import org.gvsig.tools.script.ScriptManager;
 
+@SuppressWarnings("UseSpecificCatch")
 public class CreateFnFunction extends AbstractFunction {
     
     public static final String NAME = "CREATE_FUNCTION";
@@ -54,11 +55,11 @@
                   "They have the form:\n" +
                   "\n" +
                   "<pre>\n" +
-                  "CREATE FUNCTION getCRS (crs) AS 'org.gvsig.fmap.crs.CRSFactory', 'getCRS' LANGUAGE 'java'\n" +
+                  "CREATE FUNCTION parseInt(value) AS 'java.lang.Integer', 'parseInt' LANGUAGE 'java'\n" +
                   "</pre>\n" +
                   "\n" +
-                  "Defines the \"getCRS\" function that receives a single parameter, and links it to the method\n" +
-                  "static 'getCRS' of class 'org.gvsig.fmap.crs.CRSFactory',\n" +
+                  "Defines the \"parseInt\" function that receives a single parameter, and links it to the method\n" +
+                  "static 'parseInt' of the class 'java.lang.Integer',\n" +
                   "\n" +
                   "<b> Functions defined in an external script. </b>\n" +
                   "\n" +
@@ -67,7 +68,7 @@
                   "They have the form:\n" +
                   "\n" +
                   "<pre>\n" +
-                  "CREATE FUNCTION getCRS (crs) AS 'scripts / crs.py', 'getCRS' LANGUAGE 'python'\n" +
+                  "CREATE FUNCTION getCRS(crs) AS 'crs.py', 'getCRS' LANGUAGE 'script'\n" +
                   "</pre>\n" +
                   "\n" +
                   "What defines a \"getCRS\" function that is implemented in the python module\n" +
@@ -81,7 +82,7 @@
 
     @Override
     public boolean isHidden() {
-      return false;
+      return false; 
     }
     
     @Override
@@ -95,15 +96,21 @@
     }
 
     @Override
-    public boolean allowArgNames() {
-      return true;
-    }
-    
-    @Override
     public Object call(Interpreter interpreter, Object[] args) throws Exception {
         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
     }
     
+    private static final int FUNCTION_NAME = 0;
+    private static final int PARAMETERS = 1;
+    private static final int BODY = 2;
+    private static final int SCRIPT_PATH = 3;
+    private static final int SCRIPT_FUNCTION = 4;
+    private static final int LANGUAGE = 5;
+
+    private static final int TYPE_USER_FUNCTION = 0;
+    private static final int TYPE_JAVA_FUNCTION = 1;
+    private static final int TYPE_SCRIPT_FUNCTION = 2;
+
     @Override
     public Object call(Interpreter interpreter, Codes args) throws Exception {
         if( !(interpreter.getSymbolTable() instanceof MutableSymbolTable) ) {
@@ -111,35 +118,52 @@
         }
         MutableSymbolTable symbolTable = (MutableSymbolTable) interpreter.getSymbolTable();
         
-        String name = (String) getObject(interpreter, args, "FUNCTION_NAME");
-        List<String> argNames = (List<String>) getObject(interpreter, args, "PARAMETERS");
-        Code body = args.get("BODY");
-        String script_path = (String) getObject(interpreter, args, "SCRIPT_PATH");
-        String script_function = (String) getObject(interpreter, args, "SCRIPT_FUNCTION");
-        String language = (String) getObject(interpreter, args, "LANGUAGE");
-        Function fn;
-        if( body!=null ) {
-            fn = new UserFunction(name, argNames, body);
-            symbolTable.addFunction(fn);
-            return fn;
-        }
-        if( StringUtils.isBlank(script_path) || StringUtils.isBlank(script_function) ) {
-            throw new ExpressionRuntimeException("boydy and, script path or script function, are empty.");
-        }
+        String name = (String) getObject(interpreter, args, FUNCTION_NAME);
+        List<String> argNames = (List<String>) getObject(interpreter, args, PARAMETERS);
+        Code body = args.get(BODY);
+        String script_path = (String) getObject(interpreter, args, SCRIPT_PATH);
+        String script_function = (String) getObject(interpreter, args, SCRIPT_FUNCTION);
+        String language = (String) getObject(interpreter, args, LANGUAGE);
+        
         if( StringUtils.isBlank(language) ) {
             language = "script";
         }
-        switch(language.toLowerCase()) {
-            case "script":
-                fn = new ExternalFunction(name, script_path, script_function);
-                symbolTable.addFunction(fn);
-                return fn;
-            case "java":
-                fn = new JavaFunction(name, script_path, script_function);
-                symbolTable.addFunction(fn);
-                return fn;
+
+        int type = TYPE_USER_FUNCTION;
+        if( !StringUtils.isBlank(script_path) || !StringUtils.isBlank(script_function))  {
+          switch(language.toLowerCase()) {
+              case "script":
+                type = TYPE_SCRIPT_FUNCTION;
+                break;
+              case "java":
+                type = TYPE_JAVA_FUNCTION;
+                break;
+              default:
+                throw new ExpressionRuntimeException("Unsupported language '"+language+".");
+          }
         }
-        throw new ExpressionRuntimeException("Unsupported language '"+language+".");
+        Function fn = null;
+        switch(type) {
+          case TYPE_USER_FUNCTION:
+            fn = new UserFunction(name, argNames, body);
+            symbolTable.addFunction(fn);
+            break;
+          case TYPE_JAVA_FUNCTION:
+            if( StringUtils.isBlank(script_path) || StringUtils.isBlank(script_function))  {
+                throw new ExpressionRuntimeException("Requiered classname and methodname.");
+            }
+            fn = new JavaFunction(name, script_path, script_function);
+            symbolTable.addFunction(fn);
+            break;
+          case TYPE_SCRIPT_FUNCTION:
+            if( StringUtils.isBlank(script_path) || StringUtils.isBlank(script_function))  {
+                throw new ExpressionRuntimeException("Requiered module and function name.");
+            }
+            fn = new ExternalFunction(name, script_path, script_function);
+            symbolTable.addFunction(fn);
+            break;
+        }
+        return fn;
     }
     
     private static class UserFunction extends AbstractFunction {
@@ -154,11 +178,6 @@
         }
 
         @Override
-        public boolean allowArgNames() {
-          return true;
-        }
-
-        @Override
         public Object call(Interpreter interpreter, Object[] args) throws Exception {
             Object value;
             ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
@@ -232,6 +251,21 @@
         
         @Override
         public Object call(Interpreter interpreter, Object[] args) throws Exception {
+            List<ClassLoader> loaders = ExpressionEvaluatorLocator.getManager().getClassLoaders();
+            Class<?> theClass = null;
+            for (ClassLoader loader : loaders) {
+              try {
+                theClass = loader.loadClass(this.fullClassName);
+                if( theClass!=null ) {
+                  break;
+                }
+              } catch(Throwable th) {
+                // Do nothing skip
+              }
+            }
+            if( theClass == null ) {
+              throw new ExpressionRuntimeException("Can't localte the class '"+this.fullClassName+"'.");
+            }
             Class[] parameterTypes = new Class[args.length];
             for (int i = 0; i < args.length; i++) {
                 if( args[i]==null ) {
@@ -240,7 +274,6 @@
                     parameterTypes[i] = args[i].getClass();
                 }
             }
-            Class<?> theClass = Class.forName(this.fullClassName);
             Method method = theClass.getMethod(this.methodName, parameterTypes);
             Object value = method.invoke(null, args);
             return value;
