Re: [morph-developer] Damn Verizon
Brought to you by:
orangeherbert,
sgarlatm
From: Matt S. <Mat...@wh...> - 2007-04-05 18:15:57
|
Comments inline.... > :) I think making expressions perfectly safe for this > copier will require more knowledge of how the > expression is parsed, along the lines of my > earlier-voiced thoughts about expressions in Morph. > Maybe I'll try to cook up a BC implementation of this. > One of my original frustrations with BeanUtils is when it encountered something unexpected it would blowup at you and ruin your day. With Morph I strove to just silently fail where possible and only throw exceptions when something really boneheaded happened (like trying to convert "hello world!" to an Integer). I'm pretty sure what will happen if you enter a totally bogus expression is you'll get a blowup. If you enter an expression for an object path and a null is encountered part way through, I'm pretty sure a null will just be returned. Don't be intimidated by the expression parsing stuff, it's really very trivial (in fact SimpleExpressionParser has less than a dozen lines of code). Basically the expression parser is just a StringTokenizer that looks for symbols usually found in languages like . [ ] ( ) and then just treats them all as word breaks. So something.funky]like[this in Morph is equivalent to something.funky.like.this in a more strict language like JSTL. Why be so strict with your syntax when the whole point of this new syntax (as opposed to strongly typed Java calls) is to ignore types and make things easier on yourself? ;) Then for the Language implementation we just traverse the object graph in a loop and try our best to get what was requested: public Object getImpl(Object target, String expression) throws Exception { if (ObjectUtils.isEmpty(expression)) { return target; } Object value = target; String[] tokens = expressionParser.parse(expression); // { "something", "funky", "like", "this" } for (int i=0; i<tokens.length; i++) { String token = tokens[i]; if (value == null) { // just return null, no blowup return null; } value = getReflector().get(value, token); // yay found something! go get it } return value; } > Oh, and I forgot to say before that yes, I will > probably be grateful for help with jots and tittles > wrt the release. And just to be sure we're on the > same page, we're talking 1.0.1, correct? > Actually I released 1.0.1 last year but never updated the homepage since it's such a huge PITA. Next could be 1.0.2 but even if it's still in the sandbox your new stuff might merit a 1.1 designation ;) Up to you... Matt S |