public static PrismContainerValue<?> getParentContainerValue(PrismValue value) { Itemable parent = value.getParent(); if (parent instanceof Item) { PrismValue parentParent = ((Item) parent).getParent(); return parentParent instanceof PrismContainerValue ? (PrismContainerValue) parentParent : null; } else { return null; } }
@Override public boolean canBeDefinitionOf(PrismValue pvalue) { if (pvalue == null) { return false; } if (!(pvalue instanceof PrismReferenceValue)) { return false; } Itemable parent = pvalue.getParent(); if (parent != null) { if (!(parent instanceof PrismReference)) { return false; } return canBeDefinitionOf((PrismReference)parent); } else { return true; } }
@Override public boolean canBeDefinitionOf(PrismValue pvalue) { if (pvalue == null) { return false; } if (!(pvalue instanceof PrismPropertyValue<?>)) { return false; } Itemable parent = pvalue.getParent(); if (parent != null) { if (!(parent instanceof PrismProperty<?>)) { return false; } return canBeDefinitionOf((PrismProperty)parent); } else { // TODO: maybe look actual value java type? return true; } }
@Override public boolean canBeDefinitionOf(PrismValue pvalue) { if (pvalue == null) { return false; } if (!(pvalue instanceof PrismContainerValue<?>)) { return false; } Itemable parent = pvalue.getParent(); if (parent != null) { if (!(parent instanceof PrismContainer<?>)) { return false; } return canBeDefinitionOf((PrismContainer)parent); } else { // TODO: maybe look at the subitems? return true; } }
private void assertSetConsistence(Collection<V> values, String type, boolean requireDefinitions, boolean prohibitRaw, ConsistencyCheckScope scope) { if (values == null) { return; } // This may be not be 100% correct but we can tolerate it now // if (values.isEmpty()) { // throw new // IllegalStateException("The "+type+" values set in "+this+" is not-null but it is empty"); // } for (V val : values) { if (scope.isThorough()) { if (val == null) { throw new IllegalStateException("Null value in the " + type + " values set in " + this); } if (val.getParent() != this) { throw new IllegalStateException("Wrong parent for " + val + " in " + type + " values set in " + this + ": " + val.getParent()); } } val.checkConsistenceInternal(this, requireDefinitions, prohibitRaw, scope); } }
public void checkConsistenceInternal(Itemable rootItem, boolean requireDefinitions, boolean prohibitRaw, ConsistencyCheckScope scope) { ItemPath path = getPath(); if (elementName == null) { throw new IllegalStateException("Item "+this+" has no name ("+path+" in "+rootItem+")"); } if (definition != null) { checkDefinition(definition); } else if (requireDefinitions && !isRaw()) { throw new IllegalStateException("No definition in item "+this+" ("+path+" in "+rootItem+")"); } for (V val: values) { if (prohibitRaw && val.isRaw()) { throw new IllegalStateException("Raw value "+val+" in item "+this+" ("+path+" in "+rootItem+")"); } if (val == null) { throw new IllegalStateException("Null value in item "+this+" ("+path+" in "+rootItem+")"); } if (val.getParent() == null) { throw new IllegalStateException("Null parent for value "+val+" in item "+this+" ("+path+" in "+rootItem+")"); } if (val.getParent() != this) { throw new IllegalStateException("Wrong parent for value "+val+" in item "+this+" ("+path+" in "+rootItem+"), "+ "bad parent: " + val.getParent()); } val.checkConsistenceInternal(rootItem, requireDefinitions, prohibitRaw, scope); } }
public void checkConsistence() { Visitor visitor = visitable -> { if (visitable instanceof PrismValue) { if (((PrismValue)visitable).isEmpty()) { throw new IllegalStateException("Empty value "+visitable+" in triple "+PrismValueDeltaSetTripleImpl.this); } } }; accept(visitor); Processor<V> processor = pval -> { if (pval.getParent() != null) { throw new IllegalStateException("Value "+pval+" in triple "+PrismValueDeltaSetTripleImpl.this+" has parent, looks like it was not cloned properly"); } }; foreach(processor); }
public static PrismObject getParentObject(Containerable containerable) { if (containerable == null) { return null; } PrismContainerable<? extends Containerable> parent1 = containerable.asPrismContainerValue().getParent(); if (parent1 == null) { return null; } if (!(parent1 instanceof PrismContainer)) { throw new IllegalArgumentException("Parent of " + containerable + " is not a PrismContainer. It is " + parent1.getClass()); } PrismValue parent2 = ((PrismContainer) parent1).getParent(); if (parent2 == null) { return null; } if (!(parent2 instanceof PrismContainerValue)) { throw new IllegalArgumentException("Grandparent of " + containerable + " is not a PrismContainerValue. It is " + parent2.getClass()); } Itemable parent3 = parent2.getParent(); if (parent3 == null) { return null; } if (!(parent3 instanceof PrismObject)) { throw new IllegalArgumentException("Grandgrandparent of " + containerable + " is not a PrismObject. It is " + parent3.getClass()); } return (PrismObject) parent3; }
@NotNull @Override public T serialize(@NotNull PrismValue value) throws SchemaException { QName nameToUse; if (itemName != null) { nameToUse = itemName; } else if (itemDefinition != null) { nameToUse = itemDefinition.getName(); } else if (value.getParent() != null) { nameToUse = value.getParent().getElementName(); } else { nameToUse = null; } // else { // // TODO derive from the value type itself? Not worth the effort. // throw new IllegalArgumentException("Item name nor definition is not known for " + value); // } RootXNodeImpl xroot = getMarshaller().marshalPrismValueAsRoot(value, nameToUse, itemDefinition, context); checkPostconditions(xroot); // TODO find better way return target.write(xroot, context); }
if (info.itemDefinition == null && value.getParent() != null) { info.itemDefinition = itemDefinition = value.getParent().getDefinition(); if (info.itemDefinition == null) { info.itemDefinition = schemaRegistry.findItemDefinitionByElementName(value.getParent().getElementName()); if (info.itemName == null && value.getParent() != null) { info.itemName = value.getParent().getElementName();
public static void assertParentConsistency(Item<?,?> item) { for (PrismValue pval: item.getValues()) { assert pval.getParent() == item : "Wrong parent of "+pval+" in "+PrettyPrinter.prettyPrint(item.getElementName()); if (pval instanceof PrismContainerValue) { assertParentConsistency((PrismContainerValue)pval); } } }
public boolean add(@NotNull V newValue, boolean checkUniqueness, @NotNull EquivalenceStrategy equivalenceStrategy) throws SchemaException { checkMutability(); if (newValue.getPrismContext() == null) { newValue.setPrismContext(prismContext); } Itemable originalParent = newValue.getParent(); newValue.setParent(this); // needed e.g. because of PrismReferenceValue comparisons if (checkUniqueness && contains(newValue, equivalenceStrategy)) { newValue.setParent(originalParent); return false; } D definition = getDefinition(); if (definition != null) { if (!values.isEmpty() && definition.isSingleValue()) { throw new SchemaException("Attempt to put more than one value to single-valued item " + this + "; newly added value: " + newValue); } newValue.applyDefinition(definition, false); } return values.add(newValue); }
private void cleanupAllTheWayUp(Item<?,?> item) { if (item.isEmpty()) { PrismValue itemParent = item.getParent(); if (itemParent != null) { ((PrismContainerValue<?>)itemParent).remove(item); if (itemParent.isEmpty()) { Itemable itemGrandparent = itemParent.getParent(); if (itemGrandparent != null) { if (itemGrandparent instanceof Item<?,?>) { cleanupAllTheWayUp((Item<?,?>)itemGrandparent); } } } } } }
public RAnyValue convertToRValue(PrismValue value, boolean assignment, RObjectExtensionType ownerType) throws SchemaException { RAnyValue rValue; ItemDefinition definition = value.getParent().getDefinition(); if (!isIndexed(definition, value.getParent().getElementName(), areDynamicsOfThisKindIndexed(ownerType), prismContext)) { return null; } if (value instanceof PrismPropertyValue) { PrismPropertyValue propertyValue = (PrismPropertyValue) value; rValue = extractAndCreateValue(definition, propertyValue, assignment); } else if (value instanceof PrismReferenceValue) { if (assignment) { PrismReferenceValue referenceValue = (PrismReferenceValue) value; rValue = RAExtReference.createReference(referenceValue); } else { PrismReferenceValue referenceValue = (PrismReferenceValue) value; rValue = ROExtReference.createReference(referenceValue); } } else { // shouldn't get here because if isIndexed test above throw new AssertionError("Wrong value type: " + value); } rValue.setItemId(extItemDictionary.createOrFindItemDefinition(definition).getId()); return rValue; }
return null; Itemable parent = value.getParent(); if (parent == null) { throw new IllegalStateException("Couldn't convert parent-less prism value to xsd:any: " + value);
ListXNodeImpl valuesNode = new ListXNodeImpl(); for (V val : values) { if (val.getParent() == null) { val.setParent(filter);