Search the web
Sign In
New User? Sign Up
jena-dev · Jena Developers
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
conversion from String to Resource   Message List  
Reply | Forward Message #40668 of 42071 |
Re: [jena-dev] conversion from String to Resource

Ian Dickinson wrote:
> Hi Muhammad,
> On 07/03/2009 01:24 PM, Muhammad Javed wrote:
>> Can anyone help me how
>> one can cast/convert a String object to Resource.
>>
>> String list = (String) JComboBox.getSelectedItem();
>> DatatypeProperty.addRange ( (Resource) list); <<<<<<<<<<<<<
>> Inconvertible Types.
> There's a simple answer and a more complicated answer to your question.
> First of all, if the combo box contains the actual URI's of the values
> you want your users to select, you can just convert the URI to a Resource:
>
> String uri = .. get the selected item string .. ;
> Resource r = yourModel.createResource( uri );
>
> However, that's unlikely to be an acceptable solution for your users,
> because URI's are not very readable things to have in a UI. What you
> probably want is some table or other datastructure (like a HashMap) that
> associates resource URI's with a readable label, such as the value of
> the rdfs:label property (there are a number of other alternatives to
> rdfs:label, including SKOS).


I remember facing a similar issue a couple of years back; my solution
was to put the Resources as elements in the combobox, and specify a
Renderer (? I might remember the name wrong) which is basically a class
that knows how to display a specific kind of objects. That way, the URIs
were nicely embellished (namespace abbreviations, localnames, what you
like the most) while I had no problem with conversions since I was
retrieving Resources with getSelectedItem. I don't have that code around
but I hope this generally nudges you in the right direction.
HTH,
I.


>
> How you set up that mapping is up to you: it's not something that Jena
> cares about or has anything to offer. If it was me, I would probably
> consider creating a custom ComboBoxModel which was populated initially
> with a SPARQL query into your model. Another possibility would be to
> populate the ComboBoxModel with actual resources, but use a custom
> ListCellRenderer to display the rdfs:label instead of the resource's
> URI. Using the renderer approach, there would be no need to convert the
> selected value to a resource, since the user would be selecting the
> resource directly.
>
> However, without knowing your business goals or user requirements, it's
> really not something that we can advise on on this list.
>
> Ian
>
> ____________________________________________________________
> Ian Dickinson http://www.hpl.hp.com/people/ian_dickinson
> HP Laboratories Bristol mailto:ian.dickinson@...
> Hewlett-Packard Limited Registered No: 690597 England
> Registered Office: Cain Road, Bracknell, Berks RG12 1HN
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>




Fri Jul 3, 2009 3:23 pm

ignazio_io
Offline Offline
Send Email Send Email

Forward
Message #40668 of 42071 |
Expand Messages Author Sort by Date

Hi, Can anyone help me how one can cast/convert a String object to Resource. String list = (String) JComboBox.getSelectedItem(); DatatypeProperty.addRange (...
Muhammad Javed
xavi.khan
Offline Send Email
Jul 3, 2009
12:35 pm

Hi Muhammad, ... There's a simple answer and a more complicated answer to your question. First of all, if the combo box contains the actual URI's of the values...
Ian Dickinson
ian_j_dickinson
Offline Send Email
Jul 3, 2009
1:18 pm

... I remember facing a similar issue a couple of years back; my solution was to put the Resources as elements in the combobox, and specify a Renderer (? I...
Ignazio Palmisano
ignazio_io
Offline Send Email
Jul 3, 2009
3:26 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help