Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Problem with IAdapter recoginzing class equality
Problem with IAdapter recoginzing class equality [message #444251] Sat, 11 February 2006 10:23 Go to next message
Eclipse UserFriend
I have a project for an elementary classroom and I'm trying to use eclipse
to access a MySQL database. I have a class called Student and I want to
show a properties view for the students.

I'm new to Eclipse and I'm having a hard time figuring out the IAdapter
interface. I've made Student implement IAdapter and included a getAdapter()
method.


public Object getAdapter(Class adapter) {
return Platform.getAdapterManager().getAdapter(this,adapter);
}


I have also an AdapterFactory: The StudentPropertySource(Student) has the
methods to return the necessary information to the properties view.


public Object getAdapter(Object adaptableObject, Class adapterType) {
System.out.println("MadMinAdapterFactory.getAdapter called.
adaptableObject= "+adaptableObject.getClass()+". adapterType=
"+adapterType.getName());

System.out.println("MadMinAdapterFactory.getAdapter>adapterType==IPropertySo
urce = "+(adapterType == IPropertySource.class));

if (adapterType == IPropertySource.class) {
return new StudentPropertySource((Student) adaptableObject);
}
return null;
}


But, when I run this, I get the following:


MadMinAdapterFactory.getAdapter called. adaptableObject= class
madmin.Student. adapterType= org.eclipse.ui.views.properties.IPropertySource
MadMinAdapterFactory.getAdapter>adapterType == IPropertySource = false


I'm showing that the adapterType is IPropertySource, but the == operator
returns false. using equals() does the same. What gives?

Roy
Re: Problem with IAdapter recoginzing class equality [message #444252 is a reply to message #444251] Sat, 11 February 2006 13:59 Go to previous message
Eclipse UserFriend
You seem to know what the IAdaptable (as opposed to the IAdapter :-) interface is all about, and you're going down the right path. I think you've run into the classic classpath problem.

It's possible to have two classes in Java with the same name but that are actually different (and hence incomaptible) from each other. It's a bit weird, but you can have:

+--classloader1--IPropertySource.class
|
\--classloader2--IPropertySource.class

It's like two people being called John Smith (John Doe?) -- just because their names are the same, doesn't mean that they are the same.

That would put the suspicion on how you're launching this bit of code. If it's an Eclipse plugin, then just ensuring that there's a plugin dependency on org.eclipse.ui.views (or wherever it is) should be enough.

I'd expect to see this kind of problem if you were bundling your own copy of org.eclipse.ui.views_3.1.0.jar on the classpath, rather than as a plugin dependency. That way, you'd have two different (non-identical) copies of IPropertySource, and although they'd have the same name, they'd be different classes. You should be able to verify that they're different (apart from using ==, which you have :-) using

System.identityHashCode(a);
System.identityHashCode(b);


you'll probably find that although they give the same name, they have different hashCode values. (System.identityHashCode ensures that if it's been overridden, then it's still the original one which is based on object identity and not field content.)

What's your classpath set, and how are you running this?

Alex.
Previous Topic:[DataBinding] MasterDetails: Table + Text
Next Topic:When is dragSetData called?
Goto Forum:
  


Current Time: Mon Jul 07 01:47:26 EDT 2025

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

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

Back to the top