@Override public PrismContainer<C> cloneComplex(CloneStrategy strategy) { PrismContainerImpl<C> clone = new PrismContainerImpl<>(getElementName(), getDefinition(), prismContext); copyValues(strategy, clone); return clone; }
public void setValue(@NotNull PrismContainerValue<C> value) throws SchemaException { checkMutability(); if (getDefinition() != null) { if (getDefinition().isSingleValue()) { clear(); add(value); } else { throw new IllegalStateException("Attempt to set single value to a multivalued container "+ getElementName()); } } else { clear(); add(value); } }
@Override public void applyDefinition(PrismContainerDefinition<O> definition) throws SchemaException { if (!(definition instanceof PrismObjectDefinition)) { throw new IllegalArgumentException("Cannot apply "+definition+" to object"); } super.applyDefinition(definition); }
public PrismContainerDefinition<C> deepCloneDefinition(boolean ultraDeep, Consumer<ItemDefinition> postCloneAction) { PrismContainerDefinition<C> clonedDef = (PrismContainerDefinition<C>) getDefinition().deepClone(ultraDeep, postCloneAction); propagateDeepCloneDefinition(ultraDeep, clonedDef, postCloneAction); setDefinition(clonedDef); return clonedDef; }
public void mergeValue(PrismContainerValue<C> otherValue) throws SchemaException { checkMutability(); Iterator<PrismContainerValue<C>> iterator = getValues().iterator(); while (iterator.hasNext()) { PrismContainerValue<C> thisValue = iterator.next(); if (thisValue.equals(otherValue)) { // Same values, nothing to merge return; } if (thisValue.getId() != null && thisValue.getId().equals(otherValue.getId())) { // Different value but same id. New value overwrites. iterator.remove(); } } PrismContainerValue<C> clonedOtherValue = otherValue.clone(); if (getDefinition() != null) { clonedOtherValue.applyDefinition(getDefinition()); } add(clonedOtherValue); }
@NotNull public PrismContainerValue<C> getValue() { if (getValues().size() == 1) { return getValues().get(0); if (getValues().size() > 1) { throw new IllegalStateException("Attempt to get single value from a multivalued container "+ getElementName()); if (getDefinition() != null && !getDefinition().isDynamic()) { if (getDefinition().isSingleValue()) { add(pValue); } catch (SchemaException e) { throw new IllegalStateException("Attempt to get single value from a multivalued container "+ getElementName()); add(pValue); } catch (SchemaException e) {
DebugUtil.indentDebugDump(sb, indent); if (DebugUtil.isDetailedDebugDump()) { sb.append(getDebugDumpClassName()).append(": "); sb.append(DebugUtil.formatElementName(getElementName())); sb.append(": "); appendDebugDumpSuffix(sb); PrismContainerDefinition<C> def = getDefinition(); if (DebugUtil.isDetailedDebugDump()) { if (def != null) { Iterator<PrismContainerValue<C>> i = getValues().iterator(); if (i.hasNext()) { sb.append("\n");
@Override public void checkConsistenceInternal(Itemable rootItem, boolean requireDefinitions, boolean prohibitRaw, ConsistencyCheckScope scope) { checkIds(); if (scope.isThorough()) { // Containers that are from run-time schema cannot have compile-time class. if (getDefinition() != null && !getDefinition().isRuntimeSchema()) { if (getCompileTimeClass() == null) { throw new IllegalStateException("No compile-time class in "+this+" ("+getPath()+" in "+rootItem+")"); } } } super.checkConsistenceInternal(rootItem, requireDefinitions, prohibitRaw, scope); }
@Override public ContainerDelta<C> createDelta() { return new ContainerDeltaImpl<>(getPath(), getDefinition(), getPrismContext()); }
private PrismContainerValue<C> findValue(Long id) { if (id == null) { if (canAssumeSingleValue()) { return this.getValue(); } else { throw new IllegalArgumentException("Attempt to get segment without an ID from a multi-valued container "+ getElementName()); } } else { for (PrismContainerValue<C> pval : getValues()) { if (id.equals(pval.getId())) { return pval; } } return null; } }
@Override public void accept(Visitor visitor, ItemPath path, boolean recursive) { if (path == null || path.isEmpty()) { // We are at the end of path, continue with regular visits all the way to the bottom if (recursive) { accept(visitor); } else { visitor.visit(this); } } else { Long id = ItemPath.firstToIdOrNull(path); ItemPath rest = skipFirstId(path); if (id == null) { // visit all values for (PrismContainerValue<C> cval: getValues()) { cval.accept(visitor, rest, recursive); } } else { PrismContainerValue<C> cval = findValue(id); if (cval != null) { cval.accept(visitor, rest, recursive); } } } }
@Override public PrismContainer createContainer(QName name) { return new PrismContainerImpl(name, prismContext); }
private boolean canAssumeSingleValue() { if (getDefinition() != null) { return getDefinition().isSingleValue(); } else { if (getValues().size() <= 1) { return true; } else { return false; } } }
@Override public PrismObjectDefinition<O> getDefinition() { return (PrismObjectDefinition<O>) super.getDefinition(); }
@Override public ContainerDelta<C> createDelta(ItemPath path) { return new ContainerDeltaImpl<>(path, getDefinition(), getPrismContext()); }
public PrismContainerValue<C> createNewValue() { checkMutability(); PrismContainerValue<C> pValue = new PrismContainerValueImpl<>(prismContext); try { // No need to check uniqueness, we know that this value is new and therefore // it will change anyway and therefore the check is pointless. // However, the check is expensive (especially if there are many values). // So we are happy to avoid it. add(pValue, false); } catch (SchemaException e) { // This should not happen throw new SystemException("Internal Error: "+e.getMessage(),e); } return pValue; }
@Override public void add(ResourceAttribute<?> attribute) throws SchemaException { super.add(attribute); }
protected void copyValues(CloneStrategy strategy, PrismContainerImpl<C> clone) { super.copyValues(strategy, clone); clone.compileTimeClass = this.compileTimeClass; for (PrismContainerValue<C> pval : getValues()) { try { clone.add(pval.cloneComplex(strategy)); } catch (SchemaException e) { // This should not happen throw new SystemException("Internal Error: "+e.getMessage(),e); } } }
/** * Optimizes (trims) definition tree by removing any definitions not corresponding to items in this container. * Works recursively by sub-containers of this one. * USE WITH CARE. Make sure the definitions are not shared by other objects! */ public void trimDefinitionTree(Collection<? extends ItemPath> alwaysKeep) { PrismContainerDefinition<C> def = getDefinition(); if (def == null || def.getComplexTypeDefinition() == null) { return; } Set<ItemPath> allPaths = getAllItemPaths(alwaysKeep); def.getComplexTypeDefinition().trimTo(allPaths); values.forEach(v -> ((PrismContainerValueImpl<C>) v).trimItemsDefinitionsTrees(alwaysKeep)); }
@Override public void checkConsistenceInternal(Itemable rootItem, boolean requireDefinitions, boolean prohibitRaw, ConsistencyCheckScope scope) { super.checkConsistenceInternal(rootItem, requireDefinitions, prohibitRaw, scope); List<PrismContainerValue> values = getValues(); if (values == null) { throw new IllegalStateException("Null values in ResourceAttributeContainer"); } if (values.isEmpty()) { return; } if (values.size() > 1) { throw new IllegalStateException(values.size()+" values in ResourceAttributeContainer, expected just one"); } PrismContainerValue value = values.get(0); List<Item<?,?>> items = value.getItems(); if (items == null) { return; } for (Item item: items) { if (!(item instanceof ResourceAttribute)) { throw new IllegalStateException("Found illegal item in ResourceAttributeContainer: "+item+" ("+item.getClass()+")"); } } }