Much of the code for getting all the superclasses and superinterfaces of a
class is coded in the upcoming [lang] reflection code. Maybe the next
collections release should depend on [lang]?

Stephen

----- Original Message -----
From: "Michael A. Smith" <[EMAIL PROTECTED]>
To: "Jakarta Commons Developers List" <[EMAIL PROTECTED]>
Sent: Wednesday, October 23, 2002 5:13 AM
Subject: Re: cvs commit:
jakarta-commons/collections/src/java/org/apache/commons/collections
ClassMap.java


> [EMAIL PROTECTED] wrote:
> > bayard      2002/10/22 20:35:23
> >
> >   Added:       collections/src/test/org/apache/commons/collections
> >                         TestClassMap.java
> >                collections/src/java/org/apache/commons/collections
> >                         ClassMap.java
> >   Log:
> >   Uses inheritence in the get() value lookup to decide which value to
return.
> >   I find this very useful when implementing registries of which Class
acts
> >   upon which value. So in a ConvertUtils class, a ClassMap would handle
the
> >   many Converters, deciding which Converter to use on which value.
> >   1.1
jakarta-commons/collections/src/java/org/apache/commons/collections/ClassMap
.java
> >
> >   Index: ClassMap.java
>
> [snip]
>
> ClassMap looks like it needs more documentation describing the selection
> process if more than one superclass/interface matches the requested
> class passed to get.  More specifically...
>
> >       public Object get(Object key) {
> >           if(key == null) {
> >               return null;
> >           }
> >           Class clss = null;
> >
> >           if(key instanceof Class) {
> >               clss = (Class)key;
> >           } else {
> >               clss = key.getClass();
> >           }
> >
> >           Object obj = super.get(clss);
> >
> >           if(obj == null) {
> >
> >               // if this is null, let's go up the inheritence tree
> >               obj = getInterfaces(clss);
>
> ... should document that interfaces have a higher priority for matching
> than superclasses.
>
> >               if(obj == null) {
> >                   obj = getSuperclass(clss);
> >               }
> >           }
> >
> >           return obj;
> >       }
> >
> >       private Object getInterfaces(Class clss) {
> >           if(clss == null) {
> >               return null;
> >           }
> >           Object obj = null;
> >           Class[] interfaces = clss.getInterfaces();
> >           for(int i=0; i<interfaces.length; i++) {
> >               obj = (Object)super.get(interfaces[i]);
>
> ... and that the interfaces are checked in the order in which they are
> declared in the "implements" clause of the class.
>
> >               if(obj != null) {
> >                   return obj;
> >               }
>
> ... and that interfaces that implement other interfaces for a declared
> interface are checked before the next declared interface.
>
> >               obj = getInterfaces(interfaces[i]);
> >               if(obj != null) {
> >                   return obj;
> >               }
>
> .. followed by super interfaces to a declared interface
>
> >               obj = getSuperclass(interfaces[i]);
> >               if(obj != null) {
> >                   return obj;
> >               }
> >           }
> >           return null;
> >       }
>
> in other words, the semantics of the interface selection stuff is pretty
> unclear without looking at the code, and even then, can be a bit
confusing.
>
> >       private Object getSuperclass(Class clss) {
> >           if(clss == null) {
> >               return null;
> >           }
> >           Object obj = null;
> >           Class superclass = clss.getSuperclass();
> >           obj = (Object)super.get(superclass);
> >           if(obj != null) {
> >               return obj;
> >           }
> >           obj = getInterfaces(superclass);
>
> especially when you add in the interfaces of super classse
>
> >           if(obj != null) {
> >               return obj;
> >
> >           obj = getSuperclass(superclass);
>
> and super-super classes.
>
> >           if(obj != null) {
> >               return obj;
> >           }
> >           return null;
> >       }
>
>
> :)
>
> michael
> --
> Michael A. Smith
> [EMAIL PROTECTED]
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@;jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-dev-help@;jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>

Reply via email to