Re: [Simple-support] Getting location context in validate(), commit() methods
Brought to you by:
niallg
|
From: Johannes P. <joh...@we...> - 2008-07-28 09:01:33
|
Hi,
yes, superb, this works and helped. Many thanks for the quick reply.
So as first tactics I'll use the Strategy ... :-)
Best regards
Johannes
>Re: [Simple-support] Getting location context in validate(), commit()
methods
>From: Niall Gallagher <gallagher_niall@ya...> - 2008-07-25 19:17
>Hi,
>Yes, you can. You need to look at Strategy interface. There is an
>implementation
>org.simpleframework.xml.load.DefaultStrategy which provides a good
>template. In this method
>you can add the NodeMap object to the Map provided. For example
>
>public Type getElement(Class field, NodeMap node, Map map) {
>map.put("node", node);
return defaultStrategy.getElement(field, node, map);
>}
>
>Once you have done this the session map for serialization contains the
>node. So you can
>implement your commit and validate like so.
>
>@Commit
>private void doCommit(Map map) throws Exception {
>NodeMap node = map.get("node");
>InputNode element = (InputNode)node.getParent();
>Position line = element.getPosition();
>int lineNumber = line.getLine();
>
>// do whatever with the line number
>}
>
>The next release will contain a more straight forward Strategy which
>will allow you to do
>this kind of thing a little easier. There is a TestCase which provides
>more information on
>how to use the Strategy.
>
>
>http://simple.svn.sourceforge.net/viewvc/simple/trunk/download/stream/src/test/java/org/simpleframework/xml/load/StrategyTest.java
>
>Hope this helps,
>Niall
|