shashank90 | 24 Apr 08:01 2014
Picon

[groovy-user] Cast Error while converting String to Set

Am trying to pull the elements out of xml String and getting Cast Error. Here
is my code 

def x =
'<root><element><email1>xyz@...</email1><date>22/04/2014</date></element><element><email1>xyz@...</email1><status>open</status></element><element><email1>xyz@...</email1></element></root>'
def records = new XmlSlurper().parseText(x);
Set e1= records.element.email1*.text();

and the error is  *Cannot cast object 'xyz@... xyz@...
xyz@...’ with class 'java.lang.String' to class 'java.util.Set'*. I
googled it but unable to find proper solution. Could you provide me where I
went wrong? Is this because of missing jar file??

--
View this message in context: http://groovy.329449.n5.nabble.com/Cast-Error-while-converting-String-to-Set-tp5719345.html
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Steve Amerige | 23 Apr 16:47 2014
Picon

[groovy-user] Workflow Engine for Groovy

Hi all,

I'm looking for an open source workflow engine to be part of some code that I'm writing.  The full code can be run either as a cronjob or as a daemon on a RHEL server and needs to run entirely headlessly.  It is perfectly fine to have GUIs for workflow rule creation and editing, or for monitoring, but I need (at least) to have the daemon/cronjob that exercises the workflow rules to run headlessly.

For the above, I'm hoping to find a Groovy-friendly solution.  A quick web search shows Grailsflow (grailsflow.org).  Does anyone know if this would satisfy my needs above?  Other popular workflow engines include Activiti, and others.  Any and all other thoughts and recommendations are welcome.

Many thanks!
Steve Amerige, Principal Software Developer


Guillaume Laforge | 23 Apr 00:01 2014
Picon

[groovy-user] [ANN] Groovy Weekly #18

Hi all,

Easter bunnies won't stop me from delivering the 18th edition of Groovy Weekly!

Enjoy!

--
Guillaume Laforge
Groovy Project Manager
Pivotal, Inc.

lexandtobysdad | 22 Apr 19:29 2014
Picon

[groovy-user] [Oracle] java.sql.SQLException: No suitable driver found

I've been trying the past few days to connect to an Oracle 11g database
on-site, but haven't been able to. I keep getting the,
"java.sql.SQLException: No suitable driver found.." error. I've installed
the Oracle 11g client, and tried adding it's jars in GroovyConsole. I'm
doing something like this,

import groovy.sql.Sql
sql = Sql.newInstance( "jdbc:oracle:thin: <at> localhost:1521:devh", "yeah",
"right", "oracle.jdbc.OracleDriver" )

I'm really curious if I'm even passing the correct driver name to the
class(?). What's the easiest way that I can find out which libraries I have
installed on my system which Java can see?

Thanks so much,

Henson

--
View this message in context: http://groovy.329449.n5.nabble.com/Oracle-java-sql-SQLException-No-suitable-driver-found-tp5719319.html
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

OC | 22 Apr 18:25 2014
Picon

[groovy-user] something fishy with Character.isAlphabetic...

Hello,

with code

===
if (!Character.isAlphabetic(format.charAt(format.length-1) as int)) ...
===

which works perfectly on my testing site, I'm getting an error

===
No signature of method: static java.lang.Character.isAlphabetic() is applicable for argument types:
(java.lang.Integer) values: [48]
===

at the deployment site.

Any idea what might be the cuplrit? Looks like some autoboxing trick, and I regret to say I don't grok
autoboxing at all...

Thanks!
OC

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

shashank90 | 22 Apr 15:36 2014
Picon

[groovy-user] Store xml data into a Linked Hash Set

I need to pull unique data from xml and store it using Linked Hash set Here
is my code

def x = '''
    <root>
<element>
  xyz
  <date>22/04/2014</date>
</element>
<element>
  xyz
  <status>open</status>
</element>
<element>
  xyz
</element>
</root>
  '''
def records = new XmlSlurper().parseText(x)
def allRecords = records.element.email

As the data in email is repeating I need only unique value from email.
Please suggest me an idea i.e., only I need only xyz. Can I use Linked Hash
set?? 

--
View this message in context: http://groovy.329449.n5.nabble.com/Store-xml-data-into-a-Linked-Hash-Set-tp5719305.html
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Marko Rodriguez | 22 Apr 14:43 2014
Picon

[groovy-user] Question regarding Java8 Lambda var args and Closures

Hello,

Please see this simple Java8 class:

import java.util.function.*;
class Marko {
  public isA(Supplier<String> supplier) {
    return supplier.get();   
  }

  public isA(Supplier<String>... suppliers) {
    String temp = "";
    for(int i=0; i<suppliers.length; i++) {
       temp = temp + suppliers[i].get();
    }   
    return temp;
  }
}

I am delighted that Groovy 2.3.0-beta-2 supports the following auto-conversion from closure to Java8 lambda.

gremlin> m.isA{'human'}
==>human

However, note the issue with the Supplier[] var args method call.

gremlin> m.isA{'human'}{'animal'}
No signature of method: Marko.isA() is applicable for argument types: (groovysh_evaluate$_run_closure1, groovysh_evaluate$_run_closure2) values: [groovysh_evaluate$_run_closure1 <at> 39d9314d, groovysh_evaluate$_run_closure2 <at> b978d10]
Possible solutions: isA([Ljava.util.function.Supplier;), isA(java.util.function.Supplier), is(java.lang.Object), find(), any(), use([Ljava.lang.Object;)
Display stack trace? [yN]
gremlin> m.isA({'human'}{'animal'})
No signature of method: Marko.isA() is applicable for argument types: (java.lang.String) values: [human]
Possible solutions: isA([Ljava.util.function.Supplier;), isA(java.util.function.Supplier), is(java.lang.Object), use([Ljava.lang.Object;), find(), any()
Display stack trace? [yN]
gremlin>

It is interesting to note that this conversion works:

gremlin> suppliers = [{'human'},{'animal'}] as Supplier[]
==>groovysh_evaluate$_run_closure1 <at> 727eb8cb
==>groovysh_evaluate$_run_closure2 <at> 39d9314d
gremlin> m.isA(suppliers)
==>humananimal

It would be excellent if Groovy 2.3.0 GA provided support for auto-conversion of closure varargs to Java8 function varargs.

Thank you very much for your time,
Marko.

Dinko Srkoč | 22 Apr 14:13 2014
Picon

[groovy-user] Some observations on traits

Hi all,

this morning I finally downloaded Groovy 2.3 (beta 2) and tried me
some traits for great good! Here are a couple of things that caught my
eye:

1. multiple inheritance of traits

Classes can inherit from more than one trait, and traits can inherit
other traits. But can traits inherit more than one trait? This is not
documented[1], but I was pleasantly surprised to find out that they
can:

    trait Foo { def foo() { 42 } }
    trait Bar { def bar() { 43 } }
    trait Baz { def baz() { 44 } }

    trait FooBarBaz implements Foo, Bar, Baz {}
    // it works like this too:
    // trait FooBarBaz extends Foo implements Bar, Baz {}

    class Quux implements FooBarBaz {}

    def quux = new Quux()
    assert quux.foo() == 42
    assert quux.bar() == 43
    assert quux.baz() == 44

2. "anonymous" traits

Since it is possible to instantiate an anonymous class implementing
interface I expected to do the same with traits. Alas, this is not
possible.

Interfaces or abstract classes can be implemented/extended by anonymous class:

    interface Foo { def foo() }
    assert new Foo() { def foo() { 42 }}.foo() == 42

Traits, surprisingly (to me at least), cannot:

    trait Bar { def bar() { 42 } }
    new Bar() {} // compiler complains

The compiler message is: You are not allowed to extend the interface
'Bar', use implements instead.

Should this be considered a bug, or is it a limitation of the model
that can't, or shouldn't be worked around?

3. runtime trait implementation for interfaces/abstract classes

Failing with the above (2), I tried to do the same at runtime. My
first attempt failed:

    trait Foo { def foo() { 42 } }
    abstract class Bar { abstract foo() }

    new Bar() as Foo // compiler complains

The compiler message is: You cannot create an instance from the
abstract class 'Bar'.

This is unsurprising and, I guess, correct. My second attempt fared better:

    trait Foo {  <at> groovy.transform.ForceOverride foo() { 42 } }
    abstract class Bar { abstract foo() }

    assert (new Bar() { def foo() { 1 }} as Foo).foo() == 42

... although I wanted to avoid having to provide default
implementation of unimplemented methods and ` <at> ForceOverride` in trait.

Would it be possible to use something like this:

    def bar = new Bar() implements Foo {}

It might be of interest to note that Scala can do both (2) and (3 -
the proposal above), albeit using a different keyword - `with`.

4. possible error in documentation?

In the section "Static methods, properties and fields"[2] there is the
following text:

"""
... Anyway, should you want this, you must understand that the
following code would fail:

    Foo.CALLED = true

because there is no static field CALLED defined on the trait itself.
"""

Should the code perhaps be:

    TestHelper.CALLED = true

as `TestHelper` is the trait in question.

Anyway, to quickly bring to an end already too long a mail - traits
are indeed groovy. :-)

Cheers,
Dinko

[1]: http://beta.groovy-lang.org/docs/groovy-2.3.0-beta-2/html/documentation/#_extending_traits
[2]: http://beta.groovy-lang.org/docs/groovy-2.3.0-beta-2/html/documentation/#_static_methods_properties_and_fields

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Eric MacAdie | 22 Apr 05:51 2014
Picon

[groovy-user] Groovy website down

Is there a mirror of the Groovy web site anywhere? It seems to be down at the moment.

= Eric MacAdie

Ralph Johnson | 22 Apr 03:27 2014
Picon

[groovy-user] AST transforms on scripts

I'm working on an application that is in Groovy and Java.   Users can enter expressions, which are interpreted as Groovy expressions.    We have implemented a "Function" class that holds on to the source text and that has the same interface as a closure.   A "Function" uses a GroovyShell to compile the source text.

I'd like to apply AST transforms on the expressions.   I ought to be able to do it by changing the Function class, probably by applying AST transforms somewhere along
the way.   But the "parse" method on GroovyShell converts a string into a script, and I can't see a way to access the AST along the way.  Do I need to actually put annotations in the source string before I "parse" it?  

Note that I do NOT want the transforms to apply to any of the normal Groovy code that I write, only the code in these scripts.

There are several transformations I want to perform.   1) My users don't like to use = for assignment and == for equality; they don't use assignment much and think that equality ought to be =, like it is in Excel.  (Yes, they are not programmers.)   2) The system is a little like a spreadsheet, and I need to be able to compute the objects that an expression depends on so that I can recalculate the expression if any of those objects change.

I don't see much problem in writing the transforms.  I've hacked lots of compilers in the past and written visitors (in several languages) that transform ASTs.   From what I can read, the Groovy system is as good as the ones I've used.   But I can't see how to introduce the transforms into the GroovyShell compilation process.  Any suggestions?

-Ralph Johnson
Jorge Franco Leza | 19 Apr 21:40 2014
Picon

[groovy-user] Compiler configuration question

Hello!

I have next code, and I have 2 behaviors. 

Running in IDEA the final println is: *************[[files.script]]
Running in a test in gradle i get: *************[[files.script], [files.Car]]

Dunno why Car source is added or not. I want to be added always. Anyone has some information or tip about this?

Thank you! 

        def text = 'package files; def car = new Car(); assert car'
        GroovyClassLoader classLoader = new GroovyClassLoader()
        GroovyCodeSource codeSource =
                new GroovyCodeSource(text, 'script.groovy', '/groovy/script')
        CompilerConfiguration conf = new CompilerConfiguration()

        def compilationUnitFinal = new CompilationUnit(conf, codeSource.codeSource, classLoader)
        compilationUnitFinal.addSource(codeSource.getName(), text)
        compilationUnitFinal.compile(CompilePhase.SEMANTIC_ANALYSIS.phaseNumber)

        println '*************'+compilationUnitFinal.ast.modules.classes
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane