public PrismContainerValue asPrismContainerValue() { if (_containerValue == null) { _containerValue = new PrismContainerValueImpl<>(this); } return _containerValue; }
private <IV extends PrismValue,ID extends ItemDefinition,I extends Item<IV,ID>> I createSubItem(QName name, Class<I> type, ID itemDefinition) throws SchemaException { checkMutability(); I newItem = createDetachedNewItemInternal(name, type, itemDefinition); add(newItem); return newItem; }
public C asContainerable(Class<C> requiredClass) { if (containerable != null) { return containerable; } return asContainerableInternal(resolveClass(requiredClass)); }
public <X> PrismProperty<X> createProperty(QName propertyName) throws SchemaException { checkMutability(); PrismPropertyDefinition propertyDefinition = determineItemDefinition(propertyName, getComplexTypeDefinition()); if (propertyDefinition == null) { // container has definition, but there is no property definition. This is either runtime schema // or an error if (getParent() != null && getDefinition() != null && !getDefinition().isRuntimeSchema()) { // TODO clean this up throw new IllegalArgumentException("No definition for property "+propertyName+" in "+complexTypeDefinition); } } PrismProperty<X> property; if (propertyDefinition == null) { property = new PrismPropertyImpl<>(propertyName, prismContext); // Definitionless } else { property = propertyDefinition.instantiate(); } add(property, false); return property; }
DebugUtil.indentDebugDump(sb, indent); wasIndent = true; detailedDebugDumpStart(sb); PrismContainerable<C> parent = getParent(); if (parent != null && parent.getDefinition() != null) { multivalue = parent.getDefinition().isMultiValue(); Long id = getId(); if (multivalue || id != null || DebugUtil.isDetailedDebugDump()) { if (!wasIndent) { wasIndent = true; debugDumpIdentifiers(sb); appendOriginDump(sb); List<Item<?,?>> items = getItems(); if (items == null || items.isEmpty()) { if (wasIndent) { sb.append("(no items)"); } else { Iterator<Item<?,?>> i = getItems().iterator(); if (wasIndent && i.hasNext()) { sb.append("\n");
public boolean deleteRawElement(Object element) throws SchemaException { checkMutability(); PrismContainerDefinition<C> definition = getDefinition(); if (definition == null) { throw new UnsupportedOperationException("Definition-less containers are not supported any more."); } else { // We have definition here, we can parse it right now Item<?,?> subitem = parseRawElement(element, definition); return subtract(subitem); } }
public boolean addRawElement(Object element) throws SchemaException { checkMutability(); PrismContainerDefinition<C> definition = getDefinition(); if (definition == null) { throw new UnsupportedOperationException("Definition-less containers are not supported any more."); } else { // We have definition here, we can parse it right now Item<?,?> subitem = parseRawElement(element, definition); return merge(subitem); } }
/** * Adds an item to a property container. Existing value will be replaced. * * @param item item to add. */ public <IV extends PrismValue,ID extends ItemDefinition> void addReplaceExisting(Item<IV,ID> item) throws SchemaException { checkMutability(); if (item == null) { return; } Item<IV,ID> existingItem = findItem(item.getElementName(), Item.class); if (existingItem != null && items != null) { items.remove(existingItem); existingItem.setParent(null); } add(item); }
@SuppressWarnings("unchecked") public C asContainerable() { if (containerable != null) { return containerable; } if (getParent() == null && complexTypeDefinition == null) { throw new IllegalStateException("Cannot represent container value without a parent and complex type definition as containerable; value: " + this); } return asContainerableInternal(resolveClass(null)); }
@Override public void applyDefinition(ItemDefinition definition, boolean force) throws SchemaException { checkMutability(); if (!(definition instanceof PrismContainerDefinition)) { throw new IllegalArgumentException("Cannot apply "+definition+" to container " + this); } applyDefinition((PrismContainerDefinition<C>)definition, force); }
/** * Adds a collection of items to a property container. Existing values will be replaced. * * @param itemsToAdd items to add */ public void addAllReplaceExisting(Collection<? extends Item<?,?>> itemsToAdd) throws SchemaException { checkMutability(); // Check for conflicts, remove conflicting values // itemsToAdd.forEach(itemToAdd -> addReplaceExisting(itemToAdd)); for (Item<?,?> item : itemsToAdd) { addReplaceExisting(item); // Item<?,?> existingItem = findItem(item.getElementName(), Item.class); // if (existingItem != null && items != null) { // items.remove(existingItem); // } } // addAll(itemsToAdd); }
public <IV extends PrismValue,ID extends ItemDefinition> void remove(Item<IV,ID> item) { Validate.notNull(item, "Item must not be null."); checkMutability(); Item<IV,ID> existingItem = findItem(item.getElementName(), Item.class); if (existingItem != null && items != null) { items.remove(existingItem); existingItem.setParent(null); } }
public <T> void setPropertyRealValue(QName propertyName, T realValue, PrismContext prismContext) throws SchemaException { checkMutability(); PrismProperty<T> property = findOrCreateProperty(ItemName.fromQName(propertyName)); property.setRealValue(realValue); if (property.getPrismContext() == null) { property.setPrismContext(prismContext); } }
public void setId(Long id) { checkMutability(); this.id = id; }
/** * Set origin type to all values and subvalues */ public void setOriginTypeRecursive(final OriginType originType) { accept((visitable) -> { if (visitable instanceof PrismValue) { ((PrismValue)visitable).setOriginType(originType); } }); }
/** * Adds a collection of items to a property container. * * @param itemsToAdd items to add * @throws IllegalArgumentException an attempt to add value that already exists */ public void addAll(Collection<? extends Item<?,?>> itemsToAdd) throws SchemaException { for (Item<?,?> item : itemsToAdd) { add(item); } }
public C getValue() { return asContainerable(); }
public void assertDefinitions(String sourceDescription) throws SchemaException { assertDefinitions(false, sourceDescription); }
/** * Merges the provided item into this item. The values are joined together. * Returns true if new item or value was added. */ public <IV extends PrismValue,ID extends ItemDefinition> boolean merge(Item<IV,ID> item) throws SchemaException { checkMutability(); Item<IV, ID> existingItem = findItem(item.getElementName(), Item.class); if (existingItem == null) { return add(item); } else { boolean changed = false; for (IV newVal: item.getValues()) { if (existingItem.add((IV) newVal.clone())) { changed = true; } } return changed; } }