wood burning stoves 2.0*
The moose likes Groovy and the fly likes Caught: groovy.lang.MissingPropertyException while excuting my DSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Caught: groovy.lang.MissingPropertyException while excuting my DSL" Watch "Caught: groovy.lang.MissingPropertyException while excuting my DSL" New topic
Author

Caught: groovy.lang.MissingPropertyException while excuting my DSL

Anish Nath
Greenhorn

Joined: Sep 21, 2011
Posts: 19
package stack

/**
* Created by IntelliJ IDEA.
* User: aninath
* Date: 9/20/11
* Time: 3:40 PM
* To change this template use File | Settings | File Templates.
*/
class EmployeeDSL {

Employee root

List propchain = []

EmployeeDSL( Employee root ) {
this.root = root
}

def propertyMissing( String name ) {
// if name is 'add' and we have a chain of names
if( name == 'add' && propchain ) {
println("inside if--> "+name)
// add a new employee
root.empList << new EmployeeData( firstName:propchain.take( 1 ).join( ' ' ), lastName:propchain.drop( 1 ).join( ' ' ) )
// and reset the chain of names
propchain = []
}
else {
// add this name to the chain of names
println("inside else--> "+name)

propchain << name
this
}
}

static void main(args) {
Employee emp = new Employee( [] )

new EmployeeDSL( emp ).with {
anish.nath.add
//tim.yates.add
"4"."nath".add // this is the pont where exception throws
}

emp.empList.each {
println it.firstName
println it.lastName
}

}

}


class Employee {
List<EmployeeData> empList = []

Employee( List<EmployeeData> list ) {
empList = list
}
}
// #@groovy.transform.Canonical
class EmployeeData {
String firstName
String lastName
}



Exception in thread "main" groovy.lang.MissingPropertyException: No such property: nath for class: java.lang.String
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:63)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
at stack.EmployeeDSL$_main_closure1.doCall(EmployeeDSL.groovy:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:883)
at groovy.lang.Closure.call(Closure.java:410)
at groovy.lang.Closure.call(Closure.java:423)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:194)
at org.codehaus.groovy.runtime.dgm$876.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:308)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:64)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at stack.EmployeeDSL.main(EmployeeDSL.groovy:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 1


new EmployeeDSL( emp ).with {
anish.nath.add
//tim.yates.add
"4"."nath".add // this is the pont where exception throws if i comment this line my programe will be fine can any one suggest what code i have to change
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Caught: groovy.lang.MissingPropertyException while excuting my DSL
 
Similar Threads
How to autharize against Oracle DB with an LDAP Authentication
problem with tomcat Native library
Getting java.lang.NoClassDefFoundError
NamedStoredProcedureQuery gets no result
Problem at connection