cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andre Juffer <ajuf...@cc.oulu.fi>
Subject Re: C2.2: Accessing static method on Java object with Flowscript
Date Sun, 14 Aug 2011 18:20:28 GMT
On 08/14/2011 03:04 PM, Thomas Markus wrote:
> Hi,
>
> or create an instance without spring:
>
> var bean = new com.foo.bar.Useful();
> bean.someMethod(arg1, arg2);

Actually, this would (should) not work as the constructor of Useful is 
private. It may be that this would not matter in flow, that is, one can 
call private constructors (did not try). In Spring this is possible.
>
> regards
> Thomas
>
> Am 12.08.2011 15:34, schrieb Andre Juffer:
>> To answer my own question. I created a new entry in the application's
>> Spring configuration file,
>>
>> <bean id="com.foo.bar.Useful" class="com.foo.bar.Useful" />
>>
>> In script, I used
>>
>> var useful = cocoon.getComponent("com.foo.bar.Useful");
>> useful.someMethod(arg1, arg2);
>>
>> This does not require any modification to the source code of the class
>> (that is, the private constructor remains private). It is bit
>> cheating, but alas, such is life.
>>
>> On 08/12/2011 02:53 PM, Andre Juffer wrote:
>>> Hi,
>>>
>>> I am dealing with the following. An extremely useful Java class provides
>>> a static method for completing a particular task, like
>>>
>>> class Useful {
>>> private Useful() {}
>>>
>>> public static void someMethod(String arg1, String arg2)
>>> {
>>> ...
>>> }
>>>
>>> }
>>>
>>> In flow, I do something like
>>>
>>> var arg1 = "test1";
>>> var arg2 = "test2";
>>> Packages.com.foo.bar.Useful.someMethod(arg1, arg2);
>>>
>>> The error I get is
>>>
>>> Java constructor for "com.foo.bar.Useful.someMethod" with arguments
>>> "java.lang.String,java.lang.String" not found.
>>>
>>> My question is now. How can I call a static method on a Java class, if
>>> at all, in Flowscript. One solution is to make the constructor of the
>>> class public (certainly not my preference).
>>>
>>> Thanks,
>>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>


-- 
Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juffer@oulu.fi
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat                   | WWW: www.strubiocat.oulu.fi
NordProt                     | WWW: www.nordprot.org
Triacle Biocomputing         | WWW: www.triacle-bc.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message