Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 20E8D18B6E for ; Wed, 17 Jun 2015 06:36:30 +0000 (UTC) Received: (qmail 2112 invoked by uid 500); 17 Jun 2015 06:36:30 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 2070 invoked by uid 500); 17 Jun 2015 06:36:30 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 2059 invoked by uid 99); 17 Jun 2015 06:36:29 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Jun 2015 06:36:29 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 7F9DF1A5BA8 for ; Wed, 17 Jun 2015 06:36:29 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.9 X-Spam-Level: *** X-Spam-Status: No, score=3.9 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 0-IHaOSjuuhz for ; Wed, 17 Jun 2015 06:36:19 +0000 (UTC) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com [209.85.215.47]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 5C94C47C0D for ; Wed, 17 Jun 2015 06:36:09 +0000 (UTC) Received: by labbc20 with SMTP id bc20so25656374lab.1 for ; Tue, 16 Jun 2015 23:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=+gQRuaspSX06j3cArQ1X2PX9L4By06vUITNsxIXUbzs=; b=I5VDlsRTIs0XLwJeg4idFs9dSZgUTw03f5NV6h5zf8MNe+9dwXpVUHKPigktAd0ppS fbvw+xz15MGBakDX66qZEaB9wF/NnVVJlbauneor9vvqqsAnwBZHZpv0qQ6Ax2vP6wGt v9szc5cU4HVt1hqC+ZTZh7r1J2P33ppFmLv6l+hKnCx9VBw1nIK9y1zmDxJPJ0pMC+cY qnkLWEE0LczxHEUNHP87p5kNrJmqijIiSIwEfLRsp/Wd1LbYPApxnJilKxvSsatxlsG6 BH5yWUI17fsIOq0dJqp3nLrZwpx2/QQFtnmV9eI/p06XdDQZCN4Z9+G6R02mEJFGHtEr +ntg== MIME-Version: 1.0 X-Received: by 10.152.29.6 with SMTP id f6mr5891325lah.85.1434522968321; Tue, 16 Jun 2015 23:36:08 -0700 (PDT) Received: by 10.114.199.52 with HTTP; Tue, 16 Jun 2015 23:36:08 -0700 (PDT) In-Reply-To: References: Date: Tue, 16 Jun 2015 23:36:08 -0700 Message-ID: Subject: Re: No Such Property - When executing script from Java. From: Erick Nelson To: users@groovy.incubator.apache.org Content-Type: multipart/alternative; boundary=089e0158c78af2f8450518b0e767 --089e0158c78af2f8450518b0e767 Content-Type: text/plain; charset=UTF-8 try this for your groovy script... import groovy.transform.Field class Action { String actionName void execute () { println "Doing '$actionName'" } } @Field formFilled = new Action(actionName: "Form Filled").&execute @Field mailSent = new Action(actionName: "Mail Sent").&execute void invoke (String action) { "${action}"() } On Tue, Jun 16, 2015 at 7:35 PM, Owen Rubel wrote: > The 'Bugger' exception is an internationalized error for people in Great > Britain to let them know they are truly fucked. > > Seriously though, in the script you sent, it doesn't look like you > declared 'formFilled'. > > At a minimum, declare it with def: > > def formFilled = new Action("Form Filled") > > > Owen Rubel > 415-971-0976 > orubel@gmail.com > > On Tue, Jun 16, 2015 at 6:57 PM, Paul Henry wrote: > >> Hi All, >> >> I am trying to run a groovy script from Java and getting the following >> error >> >> Exception in thread "main" >> org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack: No >> such property: formFilled for class: Bugger >> >> My script looks like this. >> >> >> class Action { >> String actionName >> Action(actionName) { >> this.actionName = actionName; >> } >> void execute() { >> println "Doing $actionName" >> } >> } >> >> formFilled = new Action("Form Filled") >> >> mailSent = new Action("Mail Sent") >> >> def invoke(action) { >> this."$action".execute() >> } >> >> //----- These are runnable when run as a script. >> formFilled.execute() >> invoke("mailSent") >> >> >> If i execute the script directly then the last two lines execute and >> produce the expected Strings printed to the standard out. >> >> >> Doing Form Filled >> Doing Mail Sent >> >> >> I am trying to run it from Java with something like the following. >> >> >> Class scriptClass = new GroovyClassLoader().parseClass(new >> File(Bugger.groovy)); >> Object scriptInstance = scriptClass.newInstance(); >> scriptClass.getDeclaredMethod("invoke", new Class[] >> {}).invoke(scriptInstance, new Object[] {"formFilled"}); >> >> >> But I keep getting the No Such property exception. Ive looked around for >> solutions, but either Im missing something so basic its generally >> understood, or i haven't found the right part of the internet. >> >> So Two questions. >> >> 1) why is the property not available / hidden. I don't understand why its >> not available to a method within what I expect is the class. >> >> 2) what change do I have to make to my code snippets to get it to work. >> >> (Note: I've created a simple example of the problem, rather than post my >> actual code. I am using groovy to define a DSL for describing actions. We >> then parse a script in that DSL defining different actions. During >> operation we want to trigger individual actions to execute on certain >> occurrences) >> >> Cheers >> >> -Paul >> >> >> >> Paul Henry >> Senior Technical Developer | >> 79 Boulcott Street, Level 2, Wellington 6011, New Zealand >> >> >> tel +64 4 499 1327 | mob +64 22 161 8700 >> paul.henry@futrix.com | www.futrix.com | LinkedIn >> >> >> > --089e0158c78af2f8450518b0e767 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
try this for your groovy script...

import groovy.transform.Field

class Action {
=C2=A0 =C2=A0 String actionName
=C2=A0 =C2=A0 void execute = () {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 println "Doing '$action= Name'"
=C2=A0 =C2=A0 }
}

<= div>@Field formFilled =3D new Action(actionName: "Form Filled").&= amp;execute
@Field mailSent =3D new Action(actionName: "Mail= Sent").&execute

void invoke (String acti= on) {
=C2=A0 =C2=A0 "${action}"()
}

On Tue, J= un 16, 2015 at 7:35 PM, Owen Rubel <orubel@gmail.com> wrote:<= br>
The 'Bugger' exc= eption is an internationalized error for people in Great Britain to let the= m know they are truly fucked.

Seriously though, in the s= cript you sent, it doesn't look like you declared 'formFilled'.=

At a minimum, declare it with def:

=
def formFilled =3D = new Action("Form Filled")



On Tue, Jun 16, 2015 at 6:57 PM, Paul Henry = <paul.henry@futrix.com> wrote:
Hi All,

I am trying to run a g= roovy script from Java and getting the following error

=
<quote>Exception= in thread "main" org.codehaus.groovy.runtime.metaclass.MissingPr= opertyExceptionNoStack: No such property: formFilled for class: Bugger</quote>

My script looks like this.

<quote>
class Act= ion {
=C2=A0 =C2=A0 String actionName
=C2=A0 =C2=A0 Act= ion(actionName) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 this.actionName =3D= actionName;
=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 void execute= () {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 println "Doing $actionName&= quot;
=C2=A0 =C2=A0 }
}

formFi= lled =3D new Action("Form Filled")

mailS= ent =3D new Action("Mail Sent")

def invo= ke(action) {
=C2=A0 =C2=A0 this."$action".execute()
}

//----- These are runnable when run as a = script.
formFilled.execute()
invoke("mailSent"= ;)
</quote><= /span>

If i execute the script directly then t= he last two lines execute and produce the expected Strings printed to the s= tandard out.

<quote>
Doing Form Filled
Doi= ng Mail Sent
</= quote>

I am trying to run it from Java with something like the following.

<quote>
<= div>
Class scriptClass= =3D new GroovyClassLoader().parseClass(new File(Bugger.groovy));
Object scriptInstance =3D scriptClass.newInstance();
scriptClass= .getDeclaredMethod("invoke", new Class[] {}).invoke(scriptInstanc= e, new Object[] {"formFilled"});
</quote>

But I keep getting the No Such property exception. Iv= e looked around for solutions, but either Im missing something so basic its= generally understood, or i haven't found the right part of the interne= t.

So Two questions.=C2=A0

1) why is the property not available / hidden. I don't understand why= its not available to a method within what I expect is the class.

2) what change do I have to make to my code snippets to get= it to work.

(Note: I've created a simple exam= ple of the problem, rather than post my actual code. I am using groovy to d= efine a DSL for describing actions. We then parse a script in that DSL defi= ning different actions. During operation we want to trigger individual acti= ons to execute on certain occurrences)

Cheers

=
-Paul

=C2=A0

P= aul Henry=C2=A0
Senior Technical Developer=C2=A0|=C2=A0= =C2=A0
79 Boulcott Street, Level 2, Wellington 6011= , New Zealand=C2=A0
tel=C2= =A0+64 4 499 1327=C2=A0|=C2=A0mob=C2=A0+64 22 161 8700 = =C2=A0
paul.henry@futrix.com= =C2=A0|=C2=A0www.futrix.com=C2=A0|= =C2=A0LinkedIn




--089e0158c78af2f8450518b0e767--