Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
17 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/groovy/org/grails/plugins/marshallers/ActionConfigBuilder.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.grails.plugins.marshallers | ||
|
||
public class ActionConfigBuilder{ | ||
def config=[:] | ||
def methodMissing(String name,args){ | ||
if(args.size()==1 && args[0] instanceof Closure){ | ||
config[name]=args[0] | ||
}else{ | ||
throw new IllegalStateException('Illegal syntax encountered while building serializers config: '+ name) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 27 additions & 13 deletions
40
src/groovy/org/grails/plugins/marshallers/config/MarshallingConfigBuilder.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,44 @@ | ||
package org.grails.plugins.marshallers.config | ||
|
||
import java.util.Map; | ||
import org.grails.plugins.marshallers.ActionConfigBuilder | ||
|
||
|
||
|
||
class MarshallingConfigBuilder { | ||
def static singleValueAttrs=['elementName'] | ||
|
||
def static rules=[ | ||
singleAttr:[ | ||
members:['elementName'], | ||
rule:{args-> args[0] } | ||
], | ||
actions:[ | ||
members:['serializer'], | ||
rule:{args-> | ||
ActionConfigBuilder builder=new ActionConfigBuilder(); | ||
def closure = args[0] | ||
closure.delegate = builder | ||
closure.resolveStrategy = Closure.DELEGATE_FIRST; | ||
closure.call(); | ||
builder.config; | ||
} | ||
] | ||
] | ||
|
||
def config=[:]; | ||
|
||
def methodMissing(String name,args){ | ||
if(args.size()==1 && args[0] instanceof Closure){ | ||
def entry=rules.find{key,value->value.members.contains(name)}; | ||
if(entry!=null){ | ||
config[name]=entry.value.rule.call(args) | ||
}else if(args.size()==1 && args[0] instanceof Closure){ | ||
MarshallingConfigBuilder builder=new MarshallingConfigBuilder(); | ||
def closure = args[0] | ||
closure.delegate = builder | ||
closure.resolveStrategy = Closure.DELEGATE_FIRST; | ||
closure.call(); | ||
config[name]=builder.config; | ||
}else{ | ||
boolean singleValue=singleValueAttrs.find {it==name}!=null; | ||
if(singleValue){ | ||
if(args.size()==1){ | ||
config[name]=args[0]; | ||
}else{ | ||
throw new IllegalStateException('Illegal syntax for '+ name) | ||
} | ||
}else{ | ||
config[name]=args; | ||
} | ||
config[name]=args | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters