The AdapterUtils was created before the adaptermanager sutff has been added so I would add that to it. I think it can be considered to be a bug

On 10-Sep-08, at 6:14 PM, Amr A. Alam wrote:

Hello,

We've been playing around with Adapters and found this neat problem. This is from section 4 of the udig tutorial, using IAdaptable:

IAdapterManager manager = Platform.getAdapterManager();
 if( manager.hasAdapter(object,"java.net.URL")){
   URL url = (URL) manager.getAdapter( object, URL.class );
   if( url != null ){
buffer.append("AdapterManager has a factory making us into a URL:"+url);
       buffer.append(separator);
   }
}

So in this code snippet, if an IGeoResource object comes in, nothing happens. It doesn't realize that it CAN be adapted to a URL.

However, if I've performed the 'display url' operation from the example first (by right clicking on a georesource in the catalog, and going to Operations->Display URL) then this code works fine.


Alternatively, this code works regardless of whether i've been right clicking or not:

if( AdapterUtil.instance.canAdaptTo(object, URL.class) ) {
 URL url;
 try {
   url = AdapterUtil.instance.adapt("java.net.URL", object, null);
 } catch (IOException e) {
   throw (RuntimeException) new RuntimeException( ).initCause( e );
 }
 if( url != null ){
buffer.append("AdapterManager has a factory making us into a URL:"+url);
   buffer.append(separator);
 }
}


So what's the deal with having to use the AdapterUtil class?!

Thanks,
Amr.
--
Refractions Research
Suite 300 - 1207 Douglas St
Victoria, BC, V8W 2E7, Canada
ph: (250) 383-3022
fax:(250) 383-2140
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel

_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel

Reply via email to