String attrNamespace = definition.getName().getNamespaceURI(); if (attrNamespace != null && attrNamespace.equals(getNamespace())) { setAttribute(property, "name", definition.getName().getLocalPart()); setQNameAttribute(property, "type", definition.getTypeName()); } else { setQNameAttribute(property, "ref", definition.getName()); if (definition.getCompositeObjectElementName() == null) { setMultiplicityAttribute(property, "minOccurs", 0); setMultiplicityAttribute(property, "maxOccurs", definition.getMaxOccurs()); if (definition.getTargetTypeName() != null) { addAnnotation(A_OBJECT_REFERENCE_TARGET_TYPE, definition.getTargetTypeName(), appinfo); if (definition.getCompositeObjectElementName() == null) { return; QName elementName = definition.getCompositeObjectElementName(); attrNamespace = elementName.getNamespaceURI(); if (attrNamespace != null && attrNamespace.equals(getNamespace())) { setAttribute(property, "name", elementName.getLocalPart()); setQNameAttribute(property, "type", definition.getTargetTypeName()); } else { setQNameAttribute(property, "ref", elementName); setMultiplicityAttribute(property, "maxOccurs", definition.getMaxOccurs()); addAnnotation(A_OBJECT_REFERENCE, definition.getName(), appinfo);
@NotNull private PrismReference parseReference(@NotNull XNodeImpl node, @NotNull QName itemName, @NotNull PrismReferenceDefinition definition, @NotNull ParsingContext pc) throws SchemaException { PrismReference ref = definition.instantiate(); if (node instanceof ListXNodeImpl) { ListXNodeImpl listNode = (ListXNodeImpl) node; if (!definition.isMultiValue() && listNode.size() > 1) { throw new SchemaException("Attempt to store multiple values in single-valued reference " + itemName); } for (XNodeImpl subNode : listNode) { ref.add(parseReferenceValueFromXNode(subNode, definition, itemName, pc)); } } else if (node instanceof MapXNodeImpl) { ref.add(parseReferenceValueFromXNode(node, definition, itemName, pc)); } else if (node instanceof PrimitiveXNodeImpl) { // empty } else { throw new IllegalArgumentException("Cannot parse reference from " + node); } return ref; }
public static void assertRefFilter(ObjectFilter objectFilter, QName expectedFilterDef, QName expectedTypeName, ItemPath path) { assertTrue("Wrong filter class: " + objectFilter.getClass(), objectFilter instanceof RefFilter); RefFilter filter = (RefFilter) objectFilter; assertEquals("Wrong filter definition element name", expectedFilterDef, filter.getDefinition().getName()); assertEquals("Wrong filter definition type", expectedTypeName, filter.getDefinition().getTypeName()); assertPathEquivalent("Wrong filter path", path, filter.getFullPath()); }
private PrismReferenceValue parseReferenceValueAsCompositeObject(XNodeImpl node, PrismReferenceDefinition definition, ParsingContext pc) throws SchemaException { if (!(node instanceof MapXNodeImpl)) { throw new IllegalArgumentException("Cannot parse reference composite object from " + node); } MapXNodeImpl map = (MapXNodeImpl) node; QName targetTypeName = definition.getTargetTypeName(); PrismObjectDefinition<Objectable> objectDefinition = null; if (map.getTypeQName() != null) { objectDefinition = getSchemaRegistry().findObjectDefinitionByType(map.getTypeQName()); } if (objectDefinition == null && targetTypeName != null) { objectDefinition = getSchemaRegistry().findObjectDefinitionByType(targetTypeName); } if (objectDefinition == null) { throw new SchemaException("No object definition for composite object in reference element " + definition.getCompositeObjectElementName()); } PrismObject<Objectable> compositeObject; try { compositeObject = parseObject(map, objectDefinition, pc); } catch (SchemaException e) { throw new SchemaException(e.getMessage() + " while parsing composite object in reference element " + definition.getCompositeObjectElementName(), e); } PrismReferenceValue refVal = new PrismReferenceValueImpl(); setReferenceObject(refVal, compositeObject); ((PrismReferenceDefinitionImpl) definition).setComposite(true); // TODO why do we modify the definition? is that safe? return refVal; }
private boolean equalsTargetType(PrismReferenceValue other) { QName otherTargetType = other.getTargetType(); if (otherTargetType == null && other.getDefinition() != null) { otherTargetType = other.getDefinition().getTargetTypeName(); } QName thisTargetType = this.getTargetType(); if (thisTargetType == null && this.getDefinition() != null) { thisTargetType = this.getDefinition().getTargetTypeName(); } return QNameUtil.match(thisTargetType, otherTargetType); }
if (type == null) { if (!pc.isAllowMissingRefTypes() && !allowMissingRefTypesOverride) { type = definition.getTargetTypeName(); if (type == null) { throw new SchemaException("Target type in reference " + definition.getName() + " not specified in reference nor in the schema"); type = getSchemaRegistry().resolveUnqualifiedTypeName(type); QName defTargetType = definition.getTargetTypeName(); if (defTargetType != null) { if (!(prismContext.getSchemaRegistry().isAssignableFrom(defTargetType, type))) { throw new SchemaException("Target type specified in reference " + definition.getName() + " (" + type + ") does not match target type in schema (" + defTargetType + ")");
public void applyDefinition(PrismReferenceDefinition definition, boolean force) throws SchemaException { super.applyDefinition(definition, force); if (object == null) { return; } if (object.getDefinition() != null && !force) { return; } PrismContext prismContext = definition.getPrismContext(); QName targetTypeName = definition.getTargetTypeName(); if (targetTypeName == null) { throw new SchemaException("Cannot apply definition to composite object in reference "+getParent() +": the target type name is not specified in the reference schema"); } PrismObjectDefinition<? extends Objectable> objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(object.getCompileTimeClass()); if (objectDefinition == null) { objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByType(targetTypeName); } if (objectDefinition == null) { throw new SchemaException("Cannot apply definition to composite object in reference "+getParent() +": no definition for object type "+targetTypeName); } // this should do it object.applyDefinition((PrismObjectDefinition)objectDefinition, force); }
public PrismReference findReferenceByCompositeObjectElementName(QName elementName) { if (items == null){ return null; } for (Item item: items) { if (item instanceof PrismReference) { PrismReference ref = (PrismReference)item; PrismReferenceDefinition refDef = ref.getDefinition(); if (refDef != null) { if (elementName.equals(refDef.getCompositeObjectElementName())) { return ref; } } } } return null; }
boolean multiline = true; if (definition != null) { multiline = definition.isMultiValue() || definition.isComposite();
PrismReference reference = ((PrismReferenceDefinition)itemDefinition).instantiate(); PrismReferenceValue refValue = ((Referencable) jaxbBean).asReferenceValue(); reference.merge(refValue);
private XNodeImpl serializeReferenceValue(PrismReferenceValue value, PrismReferenceDefinition definition, SerializationContext ctx) throws SchemaException { MapXNodeImpl xmap = new MapXNodeImpl(); boolean containsOid = false; String namespace = definition != null ? definition.getNamespace() : null; // namespace for filter and description if (StringUtils.isNotBlank(value.getOid())){ containsOid = true; isComposite = definition.isComposite();
@Override public void checkConsistenceInternal(Itemable rootItem, boolean requireDefinitions, boolean prohibitRaw, ConsistencyCheckScope scope) { if (!scope.isThorough()) { return; } ItemPath myPath = getPath(); if (StringUtils.isBlank(oid) && object == null && filter == null) { boolean mayBeEmpty = false; if (getParent() != null && getParent().getDefinition() != null) { ItemDefinition itemDefinition = getParent().getDefinition(); if (itemDefinition instanceof PrismReferenceDefinition) { PrismReferenceDefinition prismReferenceDefinition = (PrismReferenceDefinition) itemDefinition; mayBeEmpty = prismReferenceDefinition.isComposite(); } } if (!mayBeEmpty) { throw new IllegalStateException("Neither OID, object nor filter specified in reference value "+this+" ("+myPath+" in "+rootItem+")"); } } if (object != null) { try { object.checkConsistence(); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(e.getMessage()+" in reference "+myPath+" in "+rootItem, e); } catch (IllegalStateException e) { throw new IllegalStateException(e.getMessage()+" in reference "+myPath+" in "+rootItem, e); } } }
@NotNull private PrismReferenceValue parseReferenceValueFromXNode(@NotNull XNodeImpl node, @NotNull PrismReferenceDefinition definition, @NotNull QName itemName, @NotNull ParsingContext pc) throws SchemaException { /* * We distinguish between "real" references and composite objects by * (1) looking at type QName of XNode passed (whether it's ObjectType or ObjectReferenceType) * (2) comparing itemName and name from reference definition - e.g. linkRef vs. link */ boolean isComposite; if (node.getTypeQName() != null) { QName typeName = node.getTypeQName(); ItemDefinition contentDefinition = getSchemaRegistry().findItemDefinitionByType(typeName); isComposite = contentDefinition instanceof PrismObjectDefinition; } else { isComposite = !QNameUtil.match(itemName, definition.getName()); } if (isComposite) { return parseReferenceValueAsCompositeObject(node, definition, pc); // This is a composite object (complete object stored inside reference) } else { // TODO fix this hack: for delta values of ObjectReferenceType we will not // insist on having reference type (because the target definition could be such that it won't require it) boolean allowMissingRefTypesOverride = node.isExplicitTypeDeclaration(); return parseReferenceValueAsReference(node, definition, pc, allowMissingRefTypesOverride); // This is "real" reference (oid, and nothing more) } }
assertEquals("Wrong target type in accountRef", ShadowType.COMPLEX_TYPE, accountRefDef.getTargetTypeName()); assertEquals("Wrong composite object element name in accountRef", UserType.F_LINK, accountRefDef.getCompositeObjectElementName()); assertEquals("Wrong target type in tenantRef", ShadowType.COMPLEX_TYPE, accountRefDef.getTargetTypeName());
public <O extends ObjectType> PrismObject<O> resolve(PrismReferenceValue refVal, String string, GetOperationOptions options, Task task, OperationResult result) throws ObjectNotFoundException { String oid = refVal.getOid(); Class<?> typeClass = ObjectType.class; QName typeQName = refVal.getTargetType(); if (typeQName == null && refVal.getParent() != null && refVal.getParent().getDefinition() != null) { PrismReferenceDefinition refDef = (PrismReferenceDefinition) refVal.getParent().getDefinition(); typeQName = refDef.getTargetTypeName(); } if (typeQName != null) { typeClass = prismContext.getSchemaRegistry().determineCompileTimeClass(typeQName); } return (PrismObject<O>) (getObjectSimple((Class<O>)typeClass, oid, options, task, result)).asPrismObject(); }
} else if (itemDefinition instanceof PrismReferenceDefinition) { PrismReference reference = ((PrismReferenceDefinition) itemDefinition).instantiate(); for (IV val : parsedValues) { PrismReferenceValue ref;
@Test public void testExtensionSchema() throws SchemaException, SAXException, IOException { System.out.println("===[ testExtensionSchema ]==="); // GIVEN PrismContext prismContext = constructInitializedPrismContext(); assertNotNull("No prism context", prismContext); SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry(); assertNotNull("No schema registry in context", schemaRegistry); PrismPropertyDefinition ignoredTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_IGNORED_TYPE_ELEMENT); PrismAsserts.assertDefinition(ignoredTypeDef, EXTENSION_IGNORED_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); assertTrue("Element "+EXTENSION_IGNORED_TYPE_ELEMENT+" is NOT ignored", ignoredTypeDef.isIgnored()); PrismPropertyDefinition stringTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_STRING_TYPE_ELEMENT); PrismAsserts.assertDefinition(stringTypeDef, EXTENSION_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); assertFalse("Element "+EXTENSION_STRING_TYPE_ELEMENT+" is ignored", stringTypeDef.isIgnored()); PrismPropertyDefinition singleStringTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_SINGLE_STRING_TYPE_ELEMENT); PrismAsserts.assertDefinition(singleStringTypeDef, EXTENSION_SINGLE_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, 1); assertFalse("Element "+EXTENSION_SINGLE_STRING_TYPE_ELEMENT+" is ignored", singleStringTypeDef.isIgnored()); PrismPropertyDefinition intTypeDef = schemaRegistry.findPropertyDefinitionByElementName(EXTENSION_INT_TYPE_ELEMENT); PrismAsserts.assertDefinition(intTypeDef, EXTENSION_INT_TYPE_ELEMENT, DOMUtil.XSD_INT, 0, -1); assertFalse("Element "+EXTENSION_INT_TYPE_ELEMENT+" is ignored", intTypeDef.isIgnored()); PrismContainerDefinition meleeContextDefinition = schemaRegistry.findContainerDefinitionByElementName(EXTENSION_MELEE_CONTEXT_ELEMENT); PrismAsserts.assertDefinition(meleeContextDefinition, EXTENSION_MELEE_CONTEXT_ELEMENT, EXTENSION_MELEE_CONTEXT_TYPE_QNAME, 0, 1); assertTrue("Melee context container is NOT marked as runtime", meleeContextDefinition.isRuntimeSchema()); PrismReferenceDefinition opponentRefDef = meleeContextDefinition.findReferenceDefinition(EXTENSION_MELEE_CONTEXT_OPPONENT_REF_ELEMENT); assertTrue("opponentRef definition is NOT composite", opponentRefDef.isComposite()); }
assertEquals("Wrong target type in accountRef", ACCOUNT_TYPE_QNAME, accountRefDef.getTargetTypeName()); assertEquals("Wrong composite object element name in accountRef", USER_ACCOUNT_QNAME, accountRefDef.getCompositeObjectElementName());
PrismReferenceDefinition definition = (PrismReferenceDefinition) refVal.getParent().getDefinition(); if (definition != null) { typeQName = definition.getTargetTypeName();
PrismReference refPR = refPRD.instantiate(); refPR.add(ObjectTypeUtil.createObjectRef("oid1", ObjectTypes.USER).asReferenceValue()); refPR.setImmutable(true);