Node objectNode = null;
try {
objectNode = parentNode.addNode(nodeName, jcrType);
} catch (NoSuchNodeTypeException nsnte) {
throw new JcrMappingException("Unknown node type " + jcrType + " for mapped class " + object.getClass(), nsnte);
} catch (RepositoryException re) {
throw new ObjectContentManagerException("Cannot create new node of type " + jcrType + " from mapped class "
+ object.getClass(), re);
}
String[] mixinTypes = classDescriptor.getJcrMixinTypes();
String mixinTypeName = null;
try {
// Add mixin types
if (null != classDescriptor.getJcrMixinTypes()) {
for (int i = 0; i < mixinTypes.length; i++) {
mixinTypeName = mixinTypes[i].trim();
objectNode.addMixin(mixinTypeName);
}
}
// Add mixin types defined in the associated interfaces
if (!classDescriptor.hasDiscriminator() && classDescriptor.hasInterfaces()) {
Iterator interfacesIterator = classDescriptor.getImplements().iterator();
while (interfacesIterator.hasNext()) {
String interfaceName = (String) interfacesIterator.next();
ClassDescriptor interfaceDescriptor = mapper
.getClassDescriptorByClass(ReflectionUtils.forName(interfaceName));
objectNode.addMixin(interfaceDescriptor.getJcrType().trim());
}
}
// If required, add the discriminator node type
if (classDescriptor.hasDiscriminator()) {
mixinTypeName = ManagerConstant.DISCRIMINATOR_NODE_TYPE;
objectNode.addMixin(mixinTypeName);
objectNode.setProperty(ManagerConstant.DISCRIMINATOR_PROPERTY_NAME, ReflectionUtils.getBeanClass(object)
.getName());
}
} catch (NoSuchNodeTypeException nsnte) {
throw new JcrMappingException("Unknown mixin type " + mixinTypeName + " for mapped class " + object.getClass(), nsnte);
} catch (RepositoryException re) {
throw new ObjectContentManagerException("Cannot create new node of type " + jcrType + " from mapped class "
+ object.getClass(), re);
}