Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » XMLBinding to an element with an attribute with a fixed value
XMLBinding to an element with an attribute with a fixed value [message #1037381] Tue, 09 April 2013 13:34 Go to next message
Max Larsson is currently offline Max LarssonFriend
Messages: 5
Registered: April 2013
Junior Member
Hello,

i want to bind ValueProperty to an element which has an attribute with a fixed value.

Example XML

<xml>
  <value type="int">10</value>
  <value type="string">some text</value>
</xml>


Now i would like to do something like this, which always throws an
exception during element creation:

...
	@Type( base = Integer.class )
	@InitialValue( text = "0" )
	@XmlBinding( path = "value[ @type='int' ]" )
	ValueProperty PROP_NUMBER = new ValueProperty( TYPE,"Number" );

	Value<Integer> getNumber();
	void setNumber( String value );
	void setNumber( Integer value );

	@Type( base = String.class )
	@InitialValue( text = "" )
	@XmlBinding( path = "value[ @type='string' ]" )
	ValueProperty PROP_Text = new ValueProperty( TYPE,"Text" );

	Value<String> getText();
	void setText( String value );

...


Re: XMLBinding to an element with an attribute with a fixed value [message #1037523 is a reply to message #1037381] Tue, 09 April 2013 17:02 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Sapphire XML binding does not support XPath filters, so @XmlBinding( path = "value[ @type='int' ]" ) is not valid. This has to do with the fact that XML binding is bi-directional. I cannot look at an arbitrary XPath and figure out what XML structure to construct on property write.

For complex scenario like this, Sapphire supports custom bindings. See @CustomXmlValueBinding annotation and the corresponding ValueBindingImpl class. For an example, take a look at AreaCodeBinding and LocalNumberBinding classes in the Contacts Repository sample.

- Konstantin
Re: XMLBinding to an element with an attribute with a fixed value [message #1039455 is a reply to message #1037381] Fri, 12 April 2013 07:28 Go to previous message
Max Larsson is currently offline Max LarssonFriend
Messages: 5
Registered: April 2013
Junior Member
Thanks, for the hints where to look. It took me some time to figure
out the details. But now it works! Great project, i have been waiting
7 years for it, without knowing that i missed it Smile
Previous Topic:ReferenceValues with disposed/deleted referenced elements?
Next Topic:How to set Property Editor for password field
Goto Forum:
  


Current Time: Tue Apr 23 15:12:20 GMT 2024

Powered by FUDForum. Page generated in 0.03854 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top