// Property map
for (PropertyInfo propertyInfo : info.getProperties(Properties.class)) {
Properties propertyAnnotation = propertyInfo.getAnnotation(Properties.class);
if (propertyInfo instanceof MapPropertyInfo) {
MapPropertyInfo mapPropertyInfo = (MapPropertyInfo)propertyInfo;
PropertyMapMapping simpleMapping = new PropertyMapMapping();
PropertyMapping<PropertyMapMapping> propertyMapping = new PropertyMapping<PropertyMapMapping>(mapPropertyInfo, simpleMapping);
propertyMappings.add(propertyMapping);
} else {
throw new IllegalStateException();
}
}
// Node attributes
for (PropertyInfo propertyInfo : info.getProperties()) {
NodeAttributeType nat = null;
if (propertyInfo.getAnnotation(Name.class) != null) {
nat = NodeAttributeType.NAME;
} else if (propertyInfo.getAnnotation(Id.class) != null) {
nat = NodeAttributeType.ID;
} else if (propertyInfo.getAnnotation(Path.class) != null) {
if (propertyInfo.getAnnotation(Property.class) == null) {
// Check it's not a property
nat = NodeAttributeType.PATH;
}
} else if (propertyInfo.getAnnotation(WorkspaceName.class) != null) {
nat = NodeAttributeType.WORKSPACE_NAME;
}
if (nat != null) {
if (propertyInfo instanceof SingleValuedPropertyInfo) {
SingleValuedPropertyInfo svpi = (SingleValuedPropertyInfo)propertyInfo;
ValueInfo vi = svpi.getValue();
if (vi instanceof SimpleValueInfo) {
SimpleValueInfo svi = (SimpleValueInfo)vi;
JCRNodeAttributeMapping memberMapping = new JCRNodeAttributeMapping(nat);
SimpleType simpleType = svi.getSimpleType();
if (nat == NodeAttributeType.PATH) {
if (simpleType != SimpleType.PATH) {
throw new IllegalStateException("Type " + simpleType + " is not accepted for path attribute mapping");
}
} else {
if (simpleType != SimpleType.STRING) {
throw new IllegalStateException("Type " + simpleType + " is not accepted for attribute mapping");
}
}
SimpleMapping<JCRNodeAttributeMapping> simpleMapping = new SimpleMapping<JCRNodeAttributeMapping>(memberMapping);
PropertyMapping<SimpleMapping<JCRNodeAttributeMapping>> propertyMapping = new PropertyMapping<SimpleMapping<JCRNodeAttributeMapping>>(propertyInfo, simpleMapping);
propertyMappings.add(propertyMapping);
} else {
throw new IllegalStateException();
}
} else {
throw new IllegalStateException();
}
}
}
// One to one
for (PropertyInfo propertyInfo : info.getProperties(OneToOne.class)) {
if (propertyInfo instanceof SingleValuedPropertyInfo) {
SingleValuedPropertyInfo svpi = (SingleValuedPropertyInfo)propertyInfo;
ValueInfo vi = svpi.getValue();
if (vi instanceof BeanValueInfo) {
BeanValueInfo bvi = (BeanValueInfo)vi;
ClassTypeInfo typeInfo = bvi.getTypeInfo();
OneToOne oneToOneAnn = propertyInfo.getAnnotation(OneToOne.class);
// The mapped by of a one to one mapping discrimines between the parent and the child
RelationshipMapping hierarchyMapping;
MappedBy mappedBy = propertyInfo.getAnnotation(MappedBy.class);
if (mappedBy != null) {
hierarchyMapping = new NamedOneToOneMapping(typeInfo, mappedBy.value(), RelationshipType.HIERARCHIC, true);
} else {
RelatedMappedBy relatedMappedBy = propertyInfo.getAnnotation(RelatedMappedBy.class);
if (relatedMappedBy != null) {
hierarchyMapping = new NamedOneToOneMapping(typeInfo, relatedMappedBy.value(), RelationshipType.HIERARCHIC, false);
} else {
throw new IllegalStateException("No related by mapping found for property " + propertyInfo + " when introspecting " + info);
}
}
PropertyMapping<RelationshipMapping> oneToOneMapping = new PropertyMapping<RelationshipMapping>(propertyInfo, hierarchyMapping);
propertyMappings.add(oneToOneMapping);
} else {
throw new IllegalStateException();
}
} else {
throw new IllegalStateException();
}
}
// One to many
for (PropertyInfo propertyInfo : info.getProperties(OneToMany.class)) {
OneToMany oneToManyAnn = propertyInfo.getAnnotation(OneToMany.class);
if (propertyInfo instanceof MultiValuedPropertyInfo) {
MultiValuedPropertyInfo multiValuedProperty = (MultiValuedPropertyInfo)propertyInfo;
//
if (multiValuedProperty instanceof MapPropertyInfo) {
MapPropertyInfo mapProperty = (MapPropertyInfo)multiValuedProperty;
if (!(mapProperty.getKeyValue() instanceof SimpleValueInfo)) {
throw new IllegalStateException("Wrong key value type " + mapProperty.getKeyValue());
}
SimpleValueInfo svi = (SimpleValueInfo)mapProperty.getKeyValue();
if (svi.getSimpleType() != SimpleType.STRING) {
throw new IllegalStateException();
}
}