@Override public void add(ResourceAttribute<?> attribute) throws SchemaException { super.add(attribute); }
@Override public boolean add(@NotNull PrismContainerValue newValue, boolean checkUniqueness) throws SchemaException { if (!(newValue instanceof PrismObjectValue)) { throw new IllegalArgumentException("Couldn't add non-PrismObjectValue to a PrismObject: value = " + newValue + ", object = " + this); } if (values.size() > 1) { throw new IllegalStateException("PrismObject with more than one value: " + this); } else if (values.size() == 1) { PrismObjectValue<O> value = (PrismObjectValue<O>) values.get(0); if (value.isEmpty() && value.getOid() == null) { clear(); } else { throw new IllegalStateException("PrismObject cannot have more than one value. New value = " + newValue + ", object = " + this); } } return super.add(newValue, checkUniqueness); }
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); } }
public static <V extends PrismContainerValue> void createParentIfNeeded(V value, ItemDefinition definition) throws SchemaException { if (value.getParent() != null) { return; } if (!(definition instanceof PrismContainerDefinition)) { throw new SchemaException("Missing or invalid definition for a PrismContainer: " + definition); } PrismContainerImpl<?> rv = (PrismContainerImpl) definition.instantiate(); rv.add(value); }
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; }
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); } } }
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); }