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(); }
@Override public QName getTypeName() { return getComplexTypeDefinition() != null ? getComplexTypeDefinition().getTypeName() : null; }
protected String desc() { return descWithDetails("complex type definition " + PrettyPrinter.prettyPrint(complexTypeDefinition.getTypeName())); }
public ComplexTypeDefinitionAsserter<RA> assertTypeQName(QName expected) { assertEquals("Wrong type QName in "+desc(), expected, complexTypeDefinition.getTypeName()); return this; }
@Override public String toString() { // we don't delegate to PrismObject, because various exceptions during that process could in turn call this method StringBuilder sb = new StringBuilder(); sb.append("POV:"); if (getParent() != null) { sb.append(getParent().getElementName().getLocalPart()).append(":"); } else if (getComplexTypeDefinition() != null) { sb.append(getComplexTypeDefinition().getTypeName().getLocalPart()).append(":"); } sb.append(oid).append("("); PrismProperty nameProperty = findProperty(new ItemName(PrismConstants.NAME_LOCAL_NAME)); sb.append(nameProperty != null ? nameProperty.getRealValue() : null); sb.append(")"); return sb.toString(); }
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 PrismReferenceDefinition createAdHocReferenceDefinition(QName elementName, ComplexTypeDefinition ctd, int minOccurs, int maxOccurs) { PrismReferenceDefinitionImpl def = new PrismReferenceDefinitionImpl(elementName, ctd.getTypeName(), prismContext); def.setMinOccurs(minOccurs); def.setMaxOccurs(maxOccurs); return def; }
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; }
@Override public S_FilterEntryOrEmpty type(Class<? extends Containerable> type) { ComplexTypeDefinition ctd = queryBuilder.getPrismContext().getSchemaRegistry().findComplexTypeDefinitionByCompileTimeClass(type); if (ctd == null) { throw new IllegalArgumentException("Unknown type: " + type); } QName typeName = ctd.getTypeName(); if (typeName == null) { throw new IllegalStateException("No type name for " + ctd); } return new R_Filter(queryBuilder, type, OrFilterImpl.createOr(), null, false, this, typeName, null, null, null, null, null); }
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()); } }
/** * Sets applicable property container definition. * * @param definition the definition to set */ public void setDefinition(PrismContainerDefinition<C> definition) { checkMutability(); if (definition != null) { for (PrismContainerValue<C> value : getValues()) { // TODO reconsider this - sometimes we want to change CTDs, sometimes not boolean safeToOverwrite = value.getComplexTypeDefinition() == null || this.definition == null // TODO highly dangerous (the definition might be simply unknown) || this.definition.getComplexTypeDefinition() == null || this.definition.getComplexTypeDefinition().getTypeName().equals(value.getComplexTypeDefinition().getTypeName()); if (safeToOverwrite) { ((PrismContainerValueImpl) value).replaceComplexTypeDefinition(definition.getComplexTypeDefinition()); } } } this.definition = definition; }
/** * 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); } }
return; // there's a definition already if (!complexTypeDefinition.getTypeName().equals(containerDef.getTypeName())) { ComplexTypeDefinition freshCtd = prismContext.getSchemaRegistry().findComplexTypeDefinitionByType(complexTypeDefinition.getTypeName()); if (freshCtd != null) { System.out.println("Using " + freshCtd + " instead of " + definitionToUse);
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); } } }
if (rest.isEmpty()) { return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName()); } else { return parent.findItemDefinition(rest, clazz);
@SuppressWarnings("unchecked") Item<?, ?> parseItem(@NotNull RootXNodeImpl root, ItemDefinition<?> itemDefinition, QName itemName, QName typeName, Class<?> typeClass, @NotNull ParsingContext pc) throws SchemaException { ItemInfo itemInfo = ItemInfo.determine(itemDefinition, root.getRootElementName(), itemName, ARTIFICIAL_OBJECT_NAME, root.getTypeQName(), typeName, typeClass, ItemDefinition.class, pc, getSchemaRegistry()); ItemDefinition realDefinition; if (itemInfo.getItemDefinition() == null && itemInfo.getComplexTypeDefinition() != null) { // let's create container definition dynamically QName actualTypeName = itemInfo.getComplexTypeDefinition().getTypeName(); if (getSchemaRegistry().isContainer(actualTypeName)) { // TODO what about objects? PrismContainerDefinitionImpl def = new PrismContainerDefinitionImpl(itemInfo.getItemName(), itemInfo.getComplexTypeDefinition(), prismContext); def.setDynamic(true); realDefinition = def; } else { PrismPropertyDefinitionImpl def = new PrismPropertyDefinitionImpl(itemInfo.getItemName(), actualTypeName, prismContext); def.setDynamic(true); realDefinition = def; } } else { realDefinition = itemInfo.getItemDefinition(); } return parseItemInternal(root.getSubnode(), itemInfo.getItemName(), realDefinition, pc); }
@Override public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { if (value == null) { return false; // just for safety } ComplexTypeDefinition definition = value.getComplexTypeDefinition(); if (definition == null) { if (!(value.getParent() instanceof PrismContainer)) { LOGGER.trace("Parent of {} is not a PrismContainer, returning false; it is {}", value, value.getParent()); return false; } PrismContainer container = (PrismContainer) value.getParent(); PrismContainerDefinition pcd = container.getDefinition(); if (pcd == null) { LOGGER.trace("Parent of {} has no definition, returning false", value); return false; } definition = pcd.getComplexTypeDefinition(); } // TODO TODO TODO subtypes!!!!!!!! if (!QNameUtil.match(definition.getTypeName(), type)) { return false; } if (filter == null) { return true; } else { return filter.match(value, matchingRuleRegistry); } }
protected void assertPrismValue(PrismContainerValue<AccessCertificationCaseType> pcv) { assertEquals("Wrong id", (Long) 4L, pcv.getId()); ComplexTypeDefinition ctd = pcv.getComplexTypeDefinition(); assertNotNull("No CTD", ctd); //noinspection ConstantConditions assertEquals("Wrong CTD typeName", AccessCertificationAssignmentCaseType.COMPLEX_TYPE, ctd.getTypeName()); assertEquals("Wrong real class in PCV", AccessCertificationAssignmentCaseType.class, pcv.getRealClass()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private MutablePrismContainerDefinition<?> createPropertyContainerDefinition(XSType xsType, XSElementDecl elementDecl, ComplexTypeDefinition complexTypeDefinition, XSAnnotation annotation, XSParticle elementParticle, boolean topLevel) throws SchemaException { QName elementName = new QName(elementDecl.getTargetNamespace(), elementDecl.getName()); MutablePrismContainerDefinition<?> pcd; SchemaDefinitionFactory definitionFactory = getDefinitionFactory(); Class compileTimeClass = null; if (getSchemaRegistry() != null && complexTypeDefinition != null) { compileTimeClass = getSchemaRegistry().determineCompileTimeClass(complexTypeDefinition.getTypeName()); } if (isObjectDefinition(xsType)) { pcd = definitionFactory.createObjectDefinition(elementName, complexTypeDefinition, prismContext, compileTimeClass); // Multiplicity is fixed to a single-value here pcd.setMinOccurs(1); pcd.setMaxOccurs(1); } else { pcd = definitionFactory.createContainerDefinition(elementName, complexTypeDefinition, prismContext, compileTimeClass); setMultiplicity(pcd, elementParticle, elementDecl.getAnnotation(), topLevel); } markRuntime(pcd); parseItemDefinitionAnnotations(pcd, annotation); parseItemDefinitionAnnotations(pcd, elementDecl.getAnnotation()); if (elementParticle != null) { parseItemDefinitionAnnotations(pcd, elementParticle.getAnnotation()); } return pcd; }
@SuppressWarnings("unused") private SceneImpl visualize(PrismContainerValue<?> containerValue, SceneImpl owner, VisualizationContext context, Task task, OperationResult result) { SceneImpl scene = new SceneImpl(owner); scene.setChangeType(null); NameImpl name = new NameImpl("id " + containerValue.getId()); // TODO name.setNamesAreResourceKeys(false); scene.setName(name); scene.setSourceRelPath(EMPTY_PATH); scene.setSourceAbsPath(EMPTY_PATH); if (containerValue.getComplexTypeDefinition() != null) { // TEMPORARY!!! PrismContainerDefinition<?> pcd = prismContext.getSchemaRegistry().findContainerDefinitionByType(containerValue.getComplexTypeDefinition().getTypeName()); scene.setSourceDefinition(pcd); } else if (containerValue.getParent() != null && containerValue.getParent().getDefinition() != null) { scene.setSourceDefinition(containerValue.getParent().getDefinition()); } scene.setSourceValue(containerValue); scene.setSourceDelta(null); visualizeItems(scene, containerValue.getItems(), false, context, task, result); return scene; }