You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Kukosa, Tomas" <to...@siemens-enterprise.com> on 2012/08/10 13:00:47 UTC

[jexl] mathod within namespace not found if parameter is int[]

Hi,

the method log(Object fmt, Object... arr) acessible via namespace is not found if it is called with (String, int[]) parameters.
All other types of parameters work well.
See the example below.

Best regards,
  Tomas


---------
public class Test03 {

	private final static String NS_UTIL = "util";
	private final static ScriptUtil mNsUtil = new ScriptUtil();

	private static class JCtx extends MapContext implements NamespaceResolver {
		@Override
		public Object resolveNamespace(String name) {
            if (name == null) {
                return this;
            }
            if (NS_UTIL.equals(name)) {
                return mNsUtil;
            }
            return null;
		}
	}
	
	private final static String[] SCRIPTS = {
		"var x = null; util:log('x = %s', x);",
		"var x = 'abc'; util:log('x = %s', x);",
		"var x = 333; util:log('x = %s', x);",
		"var x = [1, 2]; util:log('x = %s', x);", // === ERROR ===
		"var x = ['a', 'b']; util:log('x = %s', x);",
		"var x = {1:'A', 2:'B'}; util:log('x = %s', x);",
	};

	public static void main(String[] args) {
		JexlEngine jexl = new JexlEngine();
		JexlContext jc = new JCtx();
		Script script;

		for (String stext : SCRIPTS) {
			System.out.println(stext);
			script = jexl.createScript(stext);
			script.execute(jc);
		}
		
	}

	public static class ScriptUtil {
		public void log(Object fmt, Object... arr) {
			System.out.println(String.format(fmt.toString(), arr));
		}
	}

}

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: [jexl] mathod within namespace not found if parameter is int[]

Posted by "Kukosa, Tomas" <to...@siemens-enterprise.com>.
Hi,

but the 'int[]' is 'Object'

In Java it is found and invoked well:
 Object par1 = "x = %s";
 Object par2 = new int[]{ 1, 2 };
 mNsUtil.log(par1, par2);

BTW I have already tried solution similar to your proposal below but it makes jexl much more confused if the second parameter is Integer.

This problem is not critical I just would like to clarify it if possible. It is not easy if variable parameters are involved.

Regards,
  Tomas

-----Original Message-----
From: henrib [mailto:henrib@apache.org] 
Sent: Friday, August 10, 2012 1:28 PM
To: user@commons.apache.org
Subject: Re: [jexl] mathod within namespace not found if parameter is int[]

Hi Tomas,
An 'int[]' is not an 'Object[]', a solution could be:

    public static class ScriptUtil {
        public void log(Object fmt, Object... arr) {
            System.out.println(String.format(fmt.toString(), arr));
        }
        public void log(Object fmt, int... arr) {
            System.out.println(String.format(fmt.toString(), arr));
        }
    }

Cheers




--
View this message in context: http://apache-commons.680414.n4.nabble.com/jexl-mathod-within-namespace-not-found-if-parameter-is-int-tp4637888p4637892.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [jexl] mathod within namespace not found if parameter is int[]

Posted by henrib <he...@apache.org>.
Hi Tomas,
An 'int[]' is not an 'Object[]', a solution could be:

    public static class ScriptUtil {
        public void log(Object fmt, Object... arr) {
            System.out.println(String.format(fmt.toString(), arr));
        }
        public void log(Object fmt, int... arr) {
            System.out.println(String.format(fmt.toString(), arr));
        }
    }

Cheers




--
View this message in context: http://apache-commons.680414.n4.nabble.com/jexl-mathod-within-namespace-not-found-if-parameter-is-int-tp4637888p4637892.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org