if (!(secondaryTypeId instanceof String)) {
throw new IllegalArgumentException("Secondary types property contains an invalid entry: "
+ secondaryTypeId);
}
ObjectType secondaryType = session.getTypeDefinition(secondaryTypeId.toString());
if (!(secondaryType instanceof SecondaryType)) {
throw new IllegalArgumentException(
"Secondary types property contains a type that is not a secondary type: "
+ secondaryType.getId());
}
allSecondaryTypes.add((SecondaryType) secondaryType);
}
}
if (secondaryTypes != null && allSecondaryTypes == null) {
allSecondaryTypes = secondaryTypes;
}
// some preparation
BindingsObjectFactory bof = getBindingsObjectFactory();
List<PropertyData<?>> propertyList = new ArrayList<PropertyData<?>>();
// the big loop
for (Map.Entry<String, ?> property : properties.entrySet()) {
if ((property == null) || (property.getKey() == null)) {
continue;
}
String id = property.getKey();
Object value = property.getValue();
if (value instanceof Property<?>) {
Property<?> p = (Property<?>) value;
if (!id.equals(p.getId())) {
throw new IllegalArgumentException("Property id mismatch: '" + id + "' != '" + p.getId() + "'!");
}
value = (p.getDefinition().getCardinality() == Cardinality.SINGLE ? p.getFirstValue() : p.getValues());
}
// get the property definition
PropertyDefinition<?> definition = type.getPropertyDefinitions().get(id);
if (definition == null && allSecondaryTypes != null) {
for (SecondaryType secondaryType : allSecondaryTypes) {
if (secondaryType != null && secondaryType.getPropertyDefinitions() != null) {
definition = (PropertyDefinition<?>) secondaryType.getPropertyDefinitions().get(id);
if (definition != null) {
break;
}
}
}