if (checkSuperTypes(session.getWorkspace().getNodeTypeManager(),
classDescriptor.getJcrSuperTypes())) {
javax.jcr.nodetype.NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
final NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
if (classDescriptor.getJcrType() == null) {
ntt.setName(classDescriptor.getClassName());
} else {
ntt.setName(classDescriptor.getJcrType());
}
ntt.setAbstract(classDescriptor.isAbstract());
if (classDescriptor.getJcrSuperTypes() != null && classDescriptor.getJcrSuperTypes().length() > 0) {
String[] superTypesArray = classDescriptor.getJcrSuperTypes().split(",");
//TODO combine the mixins here as well as supertypes
// Add classDescriptor.getJcrMixinTypes() to superTypesArray
for (String s : classDescriptor.getJcrMixinTypes()) {
System.out.println(s);
}
ntt.setDeclaredSuperTypeNames(superTypesArray);
}
// should we also support mixins to be created?
ntt.setMixin(false);
ntt.setQueryable(true);
ntt.setOrderableChildNodes(true);
final List nodeDefinitionTemplates = ntt.getNodeDefinitionTemplates();
final List propertyDefinitionTemplates = ntt.getPropertyDefinitionTemplates();
if (classDescriptor.getFieldDescriptors() != null) {
Iterator fieldIterator = classDescriptor.getFieldDescriptors().iterator();
while (fieldIterator.hasNext()) {
FieldDescriptor field = (FieldDescriptor) fieldIterator.next();
if (!field.isPath()) {
final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm, session.getValueFactory(), field);
// add the just created pdt to the nodetypetemplate
propertyDefinitionTemplates.add(pdt);
}
}
if (classDescriptor.getBeanDescriptors() != null) {
Iterator beanIterator = classDescriptor.getBeanDescriptors().iterator();
while (beanIterator.hasNext()) {
BeanDescriptor field = (BeanDescriptor) beanIterator.next();
if (this.isPropertyType(field.getJcrType())) {
final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm, session.getValueFactory(), field);
// add the just created pdt to the nodetypetemplate
propertyDefinitionTemplates.add(pdt);
} else {
final NodeDefinitionTemplate ndt = getNodeDefinition(ntm, session.getValueFactory(), field);
// add the just created pdt to the nodetypetemplate
nodeDefinitionTemplates.add(ndt);
}
}
}
if (classDescriptor.getCollectionDescriptors() != null) {
Iterator collectionIterator = classDescriptor.getCollectionDescriptors().iterator();
while (collectionIterator.hasNext()) {
CollectionDescriptor field = (CollectionDescriptor) collectionIterator.next();
if (this.isPropertyType(field.getJcrType())) {
final PropertyDefinitionTemplate pdt = getPropertyDefinition(ntm, session.getValueFactory(), field);
// add the just created pdt to the nodetypetemplate
propertyDefinitionTemplates.add(pdt);
} else {
final NodeDefinitionTemplate ndt = getNodeDefinition(ntm, session.getValueFactory(), field);
// add the just created pdt to the nodetypetemplate
nodeDefinitionTemplates.add(ndt);
}
}
}
ntm.registerNodeType(ntt, false);
log.info("Registered JCR node type '" + ntt.getName() +
"' for class '" + classDescriptor.getClassName() + "'");
}
} else {
throw new NodeTypeCreationException("JCR supertypes could not be resolved.");
}