throws ItemExistsException, RepositoryException {
// check for an existing property
PropertyEntry existing = properties.get(propName);
if (existing != null) {
try {
PropertyState existingState = existing.getPropertyState();
int status = existingState.getStatus();
if (Status.isTerminal(status)) {
// an old property-entry that is not valid any more
properties.remove(existing);
} else if (status == Status.EXISTING_REMOVED) {
// transiently removed -> move it to the attic
propertiesInAttic.put(propName, existing);
} else {
// existing is still existing -> cannot add same-named property
throw new ItemExistsException(propName.toString());
}
} catch (ItemNotFoundException e) {
// entry does not exist on the persistent layer
// -> therefore remove from properties map
properties.remove(existing);
} catch (RepositoryException e) {
// some other error -> remove from properties map
properties.remove(existing);
}
}
// add the property entry
PropertyEntry entry = factory.createPropertyEntry(this, propName);
PropertyState state = factory.getItemStateFactory().createNewPropertyState(entry, definition, values, propertyType);
entry.setItemState(state);
// add the property entry if creating the new state was successful
properties.add(entry);