public void applyDefinition(D def, boolean force) throws SchemaException { if (itemNew != null) { itemNew.applyDefinition(def, force); } if (itemOld != null) { itemOld.applyDefinition(def, force); } if (delta != null) { delta.applyDefinition(def, force); } }
/** * Adds an item to a property container. * * @param item item to add. * @throws SchemaException * @throws IllegalArgumentException an attempt to add value that already exists */ public <IV extends PrismValue,ID extends ItemDefinition> boolean add(Item<IV,ID> item, boolean checkUniqueness) throws SchemaException { checkMutability(); if (item.getElementName() == null) { throw new IllegalArgumentException("Cannot add item without a name to value of container "+getParent()); } if (checkUniqueness && findItem(item.getElementName(), Item.class) != null) { throw new IllegalArgumentException("Item " + item.getElementName() + " is already present in " + this.getClass().getSimpleName()); } item.setParent(this); PrismContext prismContext = getPrismContext(); if (prismContext != null) { item.setPrismContext(prismContext); } if (getComplexTypeDefinition() != null && item.getDefinition() == null) { item.applyDefinition((ID)determineItemDefinition(item.getElementName(), getComplexTypeDefinition()), false); } if (items == null) { items = new ArrayList<>(); } return items.add(item); }
item.applyDefinition(itemDefinition, force);
item.applyDefinition(getDefinition());
def.setMaxOccurs(-1); def.setRuntimeSchema(true); item.applyDefinition(def, true); } else if (rValType == RItemKind.REFERENCE) { MutablePrismReferenceDefinition def = object.getPrismContext().definitionFactory().createReferenceDefinition(name, type); def.setMaxOccurs(-1); def.setRuntimeSchema(true); item.applyDefinition(def, true); } else { throw new UnsupportedOperationException("Unsupported value type " + rValType);
private void applyAttributeDefinition(ProvisioningContext ctx, PrismValue value) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException { if (!(value instanceof PrismContainerValue)) { return; // should never occur } PrismContainerValue<ShadowAttributesType> pcv = (PrismContainerValue<ShadowAttributesType>) value; for (Item item : pcv.getItems()) { ItemDefinition itemDef = item.getDefinition(); if (itemDef == null || !(itemDef instanceof ResourceAttributeDefinition)) { QName attributeName = item.getElementName(); ResourceAttributeDefinition attributeDefinition = ctx.getObjectClassDefinition() .findAttributeDefinition(attributeName); if (attributeDefinition == null) { throw new SchemaException("No definition for attribute " + attributeName); } if (itemDef != null) { // We are going to rewrite the definition anyway. Let's just // do some basic checks first if (!QNameUtil.match(itemDef.getTypeName(), attributeDefinition.getTypeName())) { throw new SchemaException("The value of type " + itemDef.getTypeName() + " cannot be applied to attribute " + attributeName + " which is of type " + attributeDefinition.getTypeName()); } } item.applyDefinition(attributeDefinition); } } }