Re: [Simple-support] Getting location context in validate(), commit() methods
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2008-07-25 19:17:12
|
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
--- On Fri, 7/25/08, Johannes Plass <joh...@we...> wrote:
> From: Johannes Plass <joh...@we...>
> Subject: [Simple-support] Getting location context in validate(), commit() methods
> To: sim...@li...
> Date: Friday, July 25, 2008, 3:44 AM
> Hi there,
>
> is there a way to get a location context (line
> number/column number
> in XML file) inside an objects validate(), commit(),
> etc.methods
> (those tagged with @Validate, @Commit) ?
> The location of the object's element start would
> already suffice
> as a context for error reporting.
>
> Just in case there is no way to do it in the present
> version - is there
> some interest to provide this feature in a future version
> (I could
> prepare a first draft patch if volunteers are needed :-) ?
>
> Best regards and many thanks for this simply great tool
>
> Johannes
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move
> Developer's challenge
> Build the coolest Linux based applications with Moblin SDK
> & win great prizes
> Grand prize is a trip for two to an Open Source event
> anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
|