public PrismContainerValue<C> findValue(long id) { for (PrismContainerValue<C> pval : getValues()) { if (id == pval.getId()) { return pval; } } return null; }
@Override protected void propagateDeepCloneDefinition(boolean ultraDeep, PrismContainerDefinition<C> clonedDef, Consumer<ItemDefinition> postCloneAction) { for(PrismContainerValue<C> cval: getValues()) { ((PrismContainerValueImpl<C>) cval).deepCloneDefinition(ultraDeep, clonedDef, postCloneAction); } }
public boolean isEmpty() { for (PrismContainerValue<C> pval : getValues()) { if (!pval.isEmpty()) { return false; } } return true; }
/** * Remove all empty values */ public void trim() { Iterator<PrismContainerValue<C>> iterator = getValues().iterator(); while (iterator.hasNext()) { PrismContainerValue<C> pval = iterator.next(); if (pval.isEmpty()) { checkMutability(); iterator.remove(); } } }
private void checkIds() { Set<Long> oidsUsed = new HashSet<>(); for (PrismContainerValue value : getValues()) { Long id = value.getId(); if (id != null) { if (oidsUsed.contains(id)) { throw new IllegalArgumentException("There are more container values with the id of " + id + " in " + getElementName()); } else { oidsUsed.add(id); } } } }
public PrismContainerValue<C> getValue(Long id) { for (PrismContainerValue<C> pval: getValues()) { if ((id == null && pval.getId() == null) || id.equals(pval.getId())) { return pval; } } return null; }
@Override public String toString() { return getDebugDumpClassName() + "(" + getElementName() + "):" + getValues(); }
private boolean canAssumeSingleValue() { if (getDefinition() != null) { return getDefinition().isSingleValue(); } else { if (getValues().size() <= 1) { return true; } else { return false; } } }
/** * Returns true if the object and all contained prisms have proper definition. */ @Override public boolean hasCompleteDefinition() { if (getDefinition() == null) { return false; } for (PrismContainerValue<C> cval: getValues()) { if (!cval.hasCompleteDefinition()) { return false; } } return true; }
public boolean containsItem(ItemPath itemPath, boolean acceptEmptyItem) throws SchemaException { if (itemPath == null || itemPath.isEmpty()) { throw new IllegalArgumentException("Empty path specified"); } ItemPath rest = skipFirstId(itemPath); for (PrismContainerValue<C> value: getValues()) { if (value.containsItem(rest, acceptEmptyItem)) { return true; } } return false; }
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 assertDefinitions(boolean tolerateRaw, String sourceDescription) throws SchemaException { super.assertDefinitions(tolerateRaw, sourceDescription); for (PrismContainerValue<C> val: getValues()) { val.assertDefinitions(tolerateRaw, this.toString()+" in "+sourceDescription); } }
Iterator<PrismContainerValue<C>> i = getValues().iterator(); if (i.hasNext()) { sb.append("\n");
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); }
@Override public boolean add(@NotNull PrismContainerValue newValue, boolean checkUniqueness) throws SchemaException { checkMutability(); // when a context-less item is added to a contextful container, it is automatically adopted if (newValue.getPrismContext() == null && this.prismContext != null) { prismContext.adopt(newValue); } if (newValue.getId() != null) { for (PrismContainerValue existingValue : getValues()) { if (existingValue.getId() != null && existingValue.getId().equals(newValue.getId())) { throw new IllegalStateException("Attempt to add a container value with an id that already exists: " + newValue.getId()); } } } return super.add(newValue, checkUniqueness); }
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); } } }
/** * Sets applicable property container definition. * * @param definition the definition to set */ public void setDefinition(PrismContainerDefinition<C> definition) { checkMutability(); if (definition != null) { for (PrismContainerValue<C> value : getValues()) { // TODO reconsider this - sometimes we want to change CTDs, sometimes not boolean safeToOverwrite = value.getComplexTypeDefinition() == null || this.definition == null // TODO highly dangerous (the definition might be simply unknown) || this.definition.getComplexTypeDefinition() == null || this.definition.getComplexTypeDefinition().getTypeName().equals(value.getComplexTypeDefinition().getTypeName()); if (safeToOverwrite) { ((PrismContainerValueImpl) value).replaceComplexTypeDefinition(definition.getComplexTypeDefinition()); } } } this.definition = definition; }
@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); } } } }