views:

208

answers:

2

I have a base class that all of my domain classes extend, for example:

class Customer extends IbidemBaseDomain {

 . . 

}

Is there any way within my base class to determine what class is extending it. So in this example, is there anyway for IbidemBaseDomain to know that it's being extended by Customer?

+2  A: 

See this question This applies to Groovy as well as Java, and it doesn't look like there's a way to do what you want with out using libraries that aren't part of the core Java or Groovy language.

Jared
+1 : Groovy _is_ Java.
Robert Munteanu
+4  A: 

I wrote a classpath searcher utility class a while back that ended up in JMeter - see http://kickjava.com/src/org/apache/jorphan/reflect/ClassFinder.java.htm

But for Grails domain classes you can limit the search by accessing the domain classes from the GrailsApplication. So assuming you have the 'grailsApplication' Spring bean (via DI or whatever), you can find all classes via:

def domainClassClasses = grailsApplication.domainClasses.collect { it.clazz }

and use those to make isInstance() calls or otherwise navigate the class hierarchy.

Burt Beckwith
This definitely helped. I really only need to be concerned when I'm dealing with a Customer, so all I have to do is something like: if (this.class == org.maflt.ibidem.Customer) { log.debug "Processing a customer" } else { log.debug "processing ${this.class}" }
Brad Rhoads