for (ItemDefinition item : ctd.getDefinitions()) { if (!(item instanceof PrismContainerDefinition)) { continue; continue; if (child.getTypeName().equals(itemPcd.getComplexTypeDefinition().getTypeName())) { if (!rest.isEmpty() && ctd.findItemDefinition(rest) == null) { continue; throw new IllegalStateException("Couldn't find definition for parent for " + child.getTypeName() + ", path=" + rest); } else if (found.size() > 1) { Map<ComplexTypeDefinition, ItemDefinition> notInherited = found.entrySet().stream() if (notInherited.isEmpty()) { throw new IllegalStateException( "Couldn't find parent definition for " + child.getTypeName() + ": More than one candidate found: " + notInherited); } else if (notInherited.isEmpty()) { throw new IllegalStateException( "Couldn't find parent definition for " + child.getTypeName() + ": More than one candidate found - and all are inherited: " + found); } else {
private void applySchemaExtensions() throws SchemaException { for (Entry<QName,ComplexTypeDefinition> entry: extensionSchemas.entrySet()) { QName typeQName = entry.getKey(); ComplexTypeDefinition extensionCtd = entry.getValue(); ComplexTypeDefinition primaryCtd = findComplexTypeDefinition(typeQName); PrismContainerDefinition extensionContainer = primaryCtd.findContainerDefinition( new ItemName(primaryCtd.getTypeName().getNamespaceURI(), PrismConstants.EXTENSION_LOCAL_NAME)); if (extensionContainer == null) { throw new SchemaException("Attempt to extend type "+typeQName+" with "+extensionCtd.getTypeClass()+" but the original type does not have extension container"); } extensionContainer.toMutable().setComplexTypeDefinition(extensionCtd.clone()); extensionContainer.toMutable().setTypeName(extensionCtd.getTypeName()); } }
public static void assertPropertyDefinition(ComplexTypeDefinition container, QName propertyName, QName type, int minOccurs, int maxOccurs) { PrismPropertyDefinition<?> definition = container.findPropertyDefinition(ItemName.fromQName(propertyName)); assertDefinition(definition, propertyName, type, minOccurs, maxOccurs); }
private void detectExtensionSchema(PrismSchema schema) throws SchemaException { for (ComplexTypeDefinition def: schema.getDefinitions(ComplexTypeDefinition.class)) { QName extType = def.getExtensionForType(); if (extType != null) { LOGGER.trace("Processing {} as an extension for {}", def, extType); if (extensionSchemas.containsKey(extType)) { ComplexTypeDefinition existingExtension = extensionSchemas.get(extType); existingExtension.merge(def); } else { extensionSchemas.put(extType, def.clone()); } } } }
@Override public ItemDefinition locateItemDefinition(@NotNull QName itemName, @Nullable ComplexTypeDefinition complexTypeDefinition, @Nullable Function<QName, ItemDefinition> dynamicDefinitionProvider) throws SchemaException { if (complexTypeDefinition != null) { ItemDefinition def = complexTypeDefinition.findLocalItemDefinition(itemName); if (def != null) { return def; } } // not sure about this: shouldn't extension schemas have xsdAnyMarker set? if (complexTypeDefinition == null || complexTypeDefinition.isXsdAnyMarker() || complexTypeDefinition.getExtensionForType() != null) { ItemDefinition def = resolveGlobalItemDefinition(itemName, complexTypeDefinition); if (def != null) { return def; } } if (dynamicDefinitionProvider != null) { ItemDefinition def = dynamicDefinitionProvider.apply(itemName); if (def != null) { return def; } } return null; } //endregion
if (definition.getTypeName() == null) { throw new UnsupportedOperationException("Anonymous complex types as containers are not supported yet"); setAttribute(complexType, "name", definition.getTypeName().getLocalPart()); Element annotation = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "annotation")); complexType.appendChild(annotation); if (definition.getSuperType() != null) { Element complexContent = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "complexContent")); complexType.appendChild(complexContent); Element extension = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "extension")); complexContent.appendChild(extension); setQNameAttribute(extension, "base", definition.getSuperType()); containingElement = extension; Collection<? extends ItemDefinition> definitions = definition.getDefinitions(); for (ItemDefinition def : definitions) { if (def instanceof PrismPropertyDefinition) { if (definition.isXsdAnyMarker()) { addXsdAnyDefinition(sequence); if (definition.isObjectMarker()) { addAnnotation(A_OBJECT, definition.getDisplayName(), appinfo); } else if (definition.isContainerMarker()) { addAnnotation(A_PROPERTY_CONTAINER, definition.getDisplayName(), appinfo);
private static QName determineTypeName(ComplexTypeDefinition complexTypeDefinition) { if (complexTypeDefinition == null) { // Property container without type: xsd:any // FIXME: this is kind of hack, but it works now return DOMUtil.XSD_ANY; } return complexTypeDefinition.getTypeName(); }
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) { for (;;) { if (path.isEmpty()) { if (clazz.isAssignableFrom(PrismContainerDefinition.class)) { return (ID) this; } else { return null; } } Object first = path.first(); if (ItemPath.isName(first)) { return findNamedItemDefinition(ItemPath.toName(first), path.rest(), clazz); } else if (ItemPath.isId(first)) { path = path.rest(); } else if (ItemPath.isParent(first)) { ItemPath rest = path.rest(); ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(getComplexTypeDefinition(), rest); if (rest.isEmpty()) { // requires that the parent is defined as an item (container, object) return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName()); } else { return parent.findItemDefinition(rest, clazz); } } else if (ItemPath.isObjectReference(first)) { throw new IllegalStateException("Couldn't use '@' path segment in this context. PCD=" + getTypeName() + ", path=" + path); } else { throw new IllegalStateException("Unexpected path segment: " + first + " in " + path); } } }
@Override public List<? extends ResourceAttributeDefinition> getAttributeDefinitions() { List<ResourceAttributeDefinition> attrs = new ArrayList<>(); for (ItemDefinition def: complexTypeDefinition.getDefinitions()) { if (def instanceof ResourceAttributeDefinition) { attrs.add((ResourceAttributeDefinition)def); } else { throw new IllegalStateException("Found "+def+" in resource attribute container, only attribute definitions are expected here"); } } return attrs; }
return; // there's a definition already if (!complexTypeDefinition.getTypeName().equals(containerDef.getTypeName())) { if (!definitionToUse.isRuntimeSchema() && definitionToUse.getCompileTimeClass() != null) { ComplexTypeDefinition freshCtd = prismContext.getSchemaRegistry().findComplexTypeDefinitionByType(complexTypeDefinition.getTypeName()); if (freshCtd != null) { System.out.println("Using " + freshCtd + " instead of " + definitionToUse);
PrismAsserts.assertItemDefinitionDisplayName(complexTypeDefinition, ObjectType.F_DESCRIPTION, "ObjectType.description"); PrismAsserts.assertItemDefinitionDisplayOrder(complexTypeDefinition, ObjectType.F_DESCRIPTION, 10); assertFalse(""+defDesc+" definition is marked as runtime", complexTypeDefinition.isRuntimeSchema()); PrismContainerDefinition extensionContainer = complexTypeDefinition.findContainerDefinition(UserType.F_EXTENSION); PrismAsserts.assertDefinition(extensionContainer, UserType.F_EXTENSION, ExtensionType.COMPLEX_TYPE, 0, 1); assertTrue("Extension is NOT runtime", extensionContainer.isRuntimeSchema()); PrismContainerDefinition<ActivationType> activationContainer = complexTypeDefinition.findContainerDefinition(UserType.F_ACTIVATION); PrismAsserts.assertDefinition(activationContainer, UserType.F_ACTIVATION, ActivationType.COMPLEX_TYPE, 0, 1); assertFalse("Activation is runtime", activationContainer.isRuntimeSchema()); PrismContainerDefinition<AssignmentType> assignmentContainer = complexTypeDefinition.findContainerDefinition(UserType.F_ASSIGNMENT); PrismAsserts.assertDefinition(assignmentContainer, UserType.F_ASSIGNMENT, AssignmentType.COMPLEX_TYPE, 0, -1); assertFalse("Assignment is runtime", assignmentContainer.isRuntimeSchema()); PrismReferenceDefinition accountRefDef = complexTypeDefinition.findItemDefinition(UserType.F_LINK_REF, PrismReferenceDefinition.class); PrismAsserts.assertDefinition(accountRefDef, UserType.F_LINK_REF, ObjectReferenceType.COMPLEX_TYPE, 0, -1); assertEquals("Wrong target type in accountRef", ShadowType.COMPLEX_TYPE, accountRefDef.getTargetTypeName()); assertEquals("Wrong composite object element name in accountRef", UserType.F_LINK, accountRefDef.getCompositeObjectElementName()); PrismContainerDefinition<MetadataType> metadataContainer = complexTypeDefinition.findContainerDefinition(UserType.F_METADATA);PrismAsserts.assertDefinition(extensionContainer, UserType.F_EXTENSION, ExtensionType.COMPLEX_TYPE, 0, 1); assertFalse("Metadata is runtime", metadataContainer.isRuntimeSchema()); assertFalse("Metadata is dynamic", metadataContainer.isDynamic()); PrismReferenceDefinition tenantRefDef = complexTypeDefinition.findItemDefinition(UserType.F_TENANT_REF, PrismReferenceDefinition.class); PrismAsserts.assertDefinition(tenantRefDef, UserType.F_TENANT_REF, ObjectReferenceType.COMPLEX_TYPE, 0, 1); assertEquals("Wrong target type in tenantRef", ShadowType.COMPLEX_TYPE, accountRefDef.getTargetTypeName());
private <C extends Containerable> QName getSpecificTypeName(PrismContainerValue<C> cval) { if (cval.getParent() == null) { return null; } ComplexTypeDefinition ctdValue = cval.getComplexTypeDefinition(); ComplexTypeDefinition ctdParent = cval.getParent().getComplexTypeDefinition(); QName typeValue = ctdValue != null ? ctdValue.getTypeName() : null; QName typeParent = ctdParent != null ? ctdParent.getTypeName() : null; if (typeValue == null || typeValue.equals(typeParent)) { return null; } if (ctdValue.getCompileTimeClass() == null) { // TODO................. return null; } return typeValue; }
definition = (PrismReferenceDefinitionImpl) containingCtd.findItemDefinition(ItemName.fromQName(primaryElementName), PrismReferenceDefinition.class); definition.setInherited(inherited); if (containingCtd != null) { containingCtd.toMutable().add(definition);
public static ItemDefinition findItemDefinition(ItemPath parentPath, ComplexTypeDefinition complexTypeDefinition) { ItemDefinition itemDef = complexTypeDefinition.findItemDefinition(parentPath); if (itemDef == null) { throw new IllegalStateException("No definition for item " + parentPath + " in complex type definition " + complexTypeDefinition); } return itemDef; }
private PrismSchema constructSchema(PrismContext prismContext) { PrismSchemaImpl schema = new PrismSchemaImpl(NS_MY_SCHEMA, prismContext); MutableComplexTypeDefinition weaponTypeDef = schema.createComplexTypeDefinition(WEAPON_TYPE_QNAME).toMutable(); MutablePrismPropertyDefinition<?> kindPropertyDef = weaponTypeDef.createPropertyDefinition(WEAPON_KIND_QNAME, DOMUtil.XSD_STRING); kindPropertyDef.setDisplayName("Weapon kind"); weaponTypeDef.createPropertyDefinition(WEAPON_BRAND_LOCAL_NAME, PrismInternalTestUtil.WEAPONS_WEAPON_BRAND_TYPE_QNAME); weaponTypeDef.createPropertyDefinition(WEAPON_PASSWORD_LOCAL_NAME, PrismInternalTestUtil.DUMMY_PROTECTED_STRING_TYPE); weaponTypeDef.createPropertyDefinition(WEAPON_BLADE_LOCAL_NAME, PrismInternalTestUtil.EXTENSION_BLADE_TYPE_QNAME); MutablePrismPropertyDefinition<?> createTimestampPropertyDef = weaponTypeDef.createPropertyDefinition(WEAPON_CREATE_TIMESTAMP_QNAME, DOMUtil.XSD_DATETIME); createTimestampPropertyDef.setDisplayName("Create timestamp"); createTimestampPropertyDef.setOperational(true); schema.createPropertyContainerDefinition(WEAPON_LOCAL_NAME, WEAPON_TYPE_LOCAL_NAME); return schema; }
@Override public Class<C> getCompileTimeClass() { if (compileTimeClass != null) { return compileTimeClass; } if (complexTypeDefinition == null) { return null; } return (Class<C>) complexTypeDefinition.getCompileTimeClass(); }
/** * Adds XSD definitions from PropertyContainerDefinition. This is complexType and element. * If the property container is an ResourceObjectDefinition, it will add only annotated * complexType definition. * * @param definition PropertyContainerDefinition to process * @param parent element under which the XSD definition will be added */ private void addContainerDefinition(PrismContainerDefinition definition, Element elementParent, Element complexTypeParent) { ComplexTypeDefinition complexTypeDefinition = definition.getComplexTypeDefinition(); if (complexTypeDefinition != null && // Check if the complex type is a top-level complex type. If it is then it was already processed and we can skip it schema.findComplexTypeDefinition(complexTypeDefinition.getTypeName()) == null && // If the definition is not in this schema namespace then skip it. It is only a "ref" getNamespace().equals(complexTypeDefinition.getTypeName().getNamespaceURI()) ) { addComplexTypeDefinition(complexTypeDefinition,complexTypeParent); } Element elementElement = addElementDefinition(definition.getName(), definition.getTypeName(), definition.getMinOccurs(), definition.getMaxOccurs(), elementParent); if (complexTypeDefinition == null || !complexTypeDefinition.isContainerMarker()) { // Need to add a:container annotation to the element as the complex type does not have it addAnnotationToDefinition(elementElement, A_PROPERTY_CONTAINER); } }
private PrismContainerDefinition<ActivationType> getActivationDefinition() { if (activationDefinition == null) { ComplexTypeDefinition focusDefinition = prismContext.getSchemaRegistry().findComplexTypeDefinition(FocusType.COMPLEX_TYPE); activationDefinition = focusDefinition.findContainerDefinition(FocusType.F_ACTIVATION); } return activationDefinition; }
@NotNull @Override public ResourceAttributeContainerDefinitionImpl clone() { ResourceAttributeContainerDefinitionImpl clone = new ResourceAttributeContainerDefinitionImpl(name, (ObjectClassComplexTypeDefinition)complexTypeDefinition.clone(), prismContext); copyDefinitionData(clone); return clone; }
@Override public PrismContext getPrismContext() { if (prismContext != null) { return prismContext; } if (complexTypeDefinition != null && complexTypeDefinition.getPrismContext() != null) { return complexTypeDefinition.getPrismContext(); } if (getParent() != null) { return getParent().getPrismContext(); } return null; }