All,

I've patched org.apache.ojb.broker.metadata.RepositoryXmlHandler so that it 
would automatically include field, reference and collection descriptors of a 
superclass (specified via the "extends" attribute of the class descriptor) 
into a subclass' own class descriptor.

Since I've seen quite a few posts on the users list regarding this 
(apparently pending) feature, I thought it might be of use to you.

The repository handler now checks, at the end of the class-descriptor tag, 
whether the mapped class has a superclass ("extends=someClass" is present). 
If it does, the handler will include all mappings defined in the superclass 
that have NOT YET BEEN DEFINED in the subclass (this is so a subclass can 
override mappings).

The attached diff was generated from a comparison against RC6.

Hope it'll be useful.

Regards,

Luis.

________________________________

Luis Fernando Pollo
Analista de Desenvolvimento
Indados Solu��es em Tecnologia
Salvador, BA

29a30,33
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.Iterator;
> import java.util.List;
265d268
<                         // set row-reader attribute
1012a1016,1070
> 
>                         // lpollo: if the class has a superclass, add all of the 
>                         // superclass field descriptors that haven't already been 
>                         // mapped by field descriptors in the current class 
> descriptor.
>                         if (m_CurrentCLD.getSuperClass() != null) {
>                             ClassDescriptor superCLD = 
> m_repository.getDescriptorFor(m_CurrentCLD.getSuperClass());
> 
>                             // add the field descriptors for the columns that have 
>                             // not yet been mapped
>                             FieldDescriptor[] superFLDs = 
> superCLD.getFieldDescriptions();
>                             for (int i = 0; superFLDs != null && i < 
> superFLDs.length; i++) {
>                                 if 
> (m_CurrentCLD.getFieldDescriptorByName(superFLDs[i].getPersistentField().getName()) 
> == null) { 
>                                     if (isDebug) logger.debug("      * adding 
> superclass field descriptor: " + 
>                                                               
> superFLDs[i].getPersistentField().getName() + 
>                                                               " -> " + 
> superFLDs[i].getFullColumnName());
>                                     m_CurrentCLD.addFieldDescriptor(superFLDs[i]);
>                                 }
>                                 else {
>                                     if (isDebug) logger.debug("      * field " + 
> superFLDs[i].getPersistentField().getName() +
>                                                               " already mapped.");
>                                 }
>                             }
> 
>                             // do the same for references
>                             Collection superORDs = 
> superCLD.getObjectReferenceDescriptors();
>                             for (Iterator i = superORDs.iterator(); i.hasNext(); ) {
>                                 ObjectReferenceDescriptor aSuperORD = 
> (ObjectReferenceDescriptor) i.next();
>                                 if 
> (m_CurrentCLD.getObjectReferenceDescriptorByName(aSuperORD.getPersistentField().getName())
>  == null) {
>                                     if (isDebug) logger.debug("      * adding 
> superclass reference descriptor: " +
>                                                               
> aSuperORD.getPersistentField().getName());
>                                     
> m_CurrentCLD.addObjectReferenceDescriptor(aSuperORD);
>                                 }
>                                 else {
>                                     if (isDebug) logger.debug("      * reference " + 
> aSuperORD.getPersistentField().getName() +
>                                                               " already mapped.");
>                                 }
>                             }
>                             
>                             // and for collections as well
>                             Collection superCODs = 
> superCLD.getCollectionDescriptors();
>                             for (Iterator i = superCODs.iterator(); i.hasNext(); ) {
>                                 CollectionDescriptor aSuperCOD = 
> (CollectionDescriptor) i.next();
>                                 if 
> (m_CurrentCLD.getCollectionDescriptorByName(aSuperCOD.getPersistentField().getName())
>  == null) {
>                                     if (isDebug) logger.debug("      * adding 
> superclass collection descriptor: " +
>                                                               
> aSuperCOD.getPersistentField().getName());
>                                     m_CurrentCLD.addCollectionDescriptor(aSuperCOD);
>                                 }
>                                 else {
>                                     if (isDebug) logger.debug("      * collection " 
> + aSuperCOD.getPersistentField().getName() +
>                                                               " already mapped.");
>                                 }
>                             }
>                         }
>                         
> 
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to