Easy to set object properties from strings?
Brief background: I have a servlet filter that handles authentication. It wants to auto-register previously unseen users, and update already-registered users, from information in cookies. The information is mostly in the form of strings, but the object's fields might not be. The question: Is there a simple, type-independent method to set an XWiki Object field's value from a string? The question is not "how can this be done", since I can easily work that out, but rather "is there a method currently available"? brain[sic]
Hi Thomas or Brian (which one is it ?) There is a "set" function in BaseObject which either takes a typed object but also a String. It calls "fromString" if it is a String So something like doc.getObject("XWiki.ClassName",0).set("fieldname", "value", context) should work Ludovic THOMAS, BRIAN M (ATTSI) a écrit :
Brief background: I have a servlet filter that handles authentication. It wants to auto-register previously unseen users, and update already-registered users, from information in cookies. The information is mostly in the form of strings, but the object's fields might not be.
The question: Is there a simple, type-independent method to set an XWiki Object field's value from a string? The question is not "how can this be done", since I can easily work that out, but rather "is there a method currently available"?
brain[sic]
------------------------------------------------------------------------
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
-- Ludovic Dubost Blog: http://www.ludovic.org/blog/ XWiki: http://www.xwiki.com Skype: ldubost GTalk: ldubost AIM: nvludo Yahoo: ludovic
Hi Thomas or Brian (which one is it ?)
Brian Matthew Thomas, Western order (given name, "middle" name[s], family name), or Thomas, Brian M. as in alphabetical listings. O the joys of having three common "first" names (even before coming into an international environment, where, as with Wang Ning here recently, the meaning of "first name" is not necessarily the same for all)... For a humourous diversion, consider large family gatherings where each male with the family name is known by wife and associates as "Tom"... hmmm, that may explain why we never had any large Thomas family gatherings... I had always thought it was because we were all descended from ill-tempered and dispreputable Welshmen.
There is a "set" function in BaseObject which either takes a typed object but also a String. It calls "fromString" if it is a String So something like
doc.getObject("XWiki.ClassName",0).set("fieldname", "value", context)
Wonderful; thanks. I'm sure I could have found this eventually, but one of the greatest strengths of XWiki (and of most modern Java and other OO development environments) is also one of its most perplexing features - its flexibility, which comes at the cost of dozens of levels of indirection. As a former C programmer from the ancient '80s, I was astounded to find, when first running XWiki on Tomcat under Eclipse, call stacks sixty, eighty, a hundred levels deep - in an interpreted language! But then, my Firefox browser often takes more real memory in my desktop computer than was available in the whole disk store of the "midrange" computers I worked on in those days, and I carry in my pocket a more powerful processor, and more main memory, than all but the biggest of them had. But I digress; my point was that even with Eclipse's excellent object browsing, and javadoc that, if lacking in humanly-generated content, has at least the advantage of good discipline in the underlying code, like a good object structure and reasonably descriptive class and member names, I often can't navigate to the actual code that I'm interested in except by stepping down, down, down, into it while actually debugging it, because there are so many abstract interfaces and dynamic invocations involved - and how many times have I hit the F3 key to see the declaration of a method, only to land at an interface...?! Aaargh... Thanks again. As I said before, I knew how I could code it - and it wasn't hard at all - but all that indirection means I'm much more comfortable coding to high-level interfaces that are less likely to change in future releases or with different configurations. brain[sic]
participants (2)
-
Ludovic Dubost -
THOMAS, BRIAN M (ATTSI)