I have been looking at the ObjectConverterImpl and I think I have a
strategy for handling mixins that are defined in the mapper but not
assigned to the nodetype in the mapping file.
For inserts one would get the interfaces on the object and loop through
them. For each interface one would look for a class descriptor and add
it to the objectNode one would also get the field, bean, and collection
descriptors for that mixin's class descriptor and add them to the
object's class descriptor.
// Scan Object Interfaces for mixins
Class[] interfaces = object.getClass().getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
ClassDescriptor interfaceDescriptor =
mapper.getClassDescriptorByClass(interfaces[i]);
objectNode.addMixin(interfaceDescriptor.getJcrType().trim());
for (Iterator it =
interfaceDescriptor.getBeanDescriptors().iterator(); it.hasNext(); ) {
classDescriptor.addBeanDescriptor((BeanDescriptor)it.next());
}
for (Iterator it =
interfaceDescriptor.getFieldDescriptors().iterator(); it.hasNext(); ) {
classDescriptor.addFieldDescriptor((FieldDescriptor)it.next());
}
for (Iterator it =
interfaceDescriptor.getCollectionDescriptors().iterator(); it.hasNext(); ) {
classDescriptor.addCollectionDescriptor((CollectionDescriptor)it.next());
}
}
I need to implement it, however, I think directionally this is the right
way to go (??).
Updates would be very similar to inserts.
For loads we have a more interesting story and somewhere I need to spend
more time. I think the steps are:
1) Retrieve object and load fields as described in the mapping file
2) Grab mixins from node
3) For mixins on node which are not in the class descriptor
1) create mixin impl object based on mixin interface name from class
descriptor + Impl (this way one could have more complex methods than
just get/set beans)
2) load fields into mixin impl object
3) use cglib mixin to create a new object containing the base node +
mixin
4) repeat per mixin
Does this sound about right?
-paddy