default ComplexTypeDefinition getComplexTypeDefinition() { PrismContainerDefinition def = getDefinition(); return def != null ? def.getComplexTypeDefinition() : null; } }
@Override public void acceptParentVisitor(Visitor visitor) { visitor.visit(this); PrismContainerable<C> parent = getParent(); if (parent != null) { parent.acceptParentVisitor(visitor); } }
private Class<C> resolveClass(@Nullable Class<C> requiredClass) { if (complexTypeDefinition != null && complexTypeDefinition.getCompileTimeClass() != null) { Class<?> actualClass = complexTypeDefinition.getCompileTimeClass(); if (requiredClass != null && !requiredClass.isAssignableFrom(actualClass)) { throw new IllegalStateException("asContainerable was called to produce " + requiredClass + ", but the actual class in PCV is " + actualClass); } else { return (Class<C>) actualClass; } } else { PrismContainerable parent = getParent(); if (parent != null) { Class<?> parentClass = parent.getCompileTimeClass(); if (parentClass != null) { if (requiredClass != null && !requiredClass.isAssignableFrom(parentClass)) { // mismatch; but this can occur (see ShadowAttributesType vs ShadowIdentifiersType in ShadowAssociationType) // but TODO maybe this is only a workaround and the problem is in the schema itself (?) return requiredClass; } else { return (Class<C>) parentClass; } } } } return requiredClass; }
@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(); }
protected void deepCloneDefinition(boolean ultraDeep, PrismContainerDefinition<C> clonedContainerDef, Consumer<ItemDefinition> postCloneAction) { // special treatment of CTD (we must not simply overwrite it with clonedPCD.CTD!) PrismContainerable parent = getParent(); if (parent != null && complexTypeDefinition != null) { if (complexTypeDefinition == parent.getComplexTypeDefinition()) { replaceComplexTypeDefinition(clonedContainerDef.getComplexTypeDefinition()); } else { replaceComplexTypeDefinition(complexTypeDefinition.deepClone(ultraDeep ? null : new HashMap<>(), new HashMap<>(), postCloneAction)); // OK? } } if (items != null) { for (Item<?,?> item: items) { deepCloneDefinitionItem(item, ultraDeep, clonedContainerDef, postCloneAction); } } }
@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; }
private C asContainerableInternal(Class<C> clazz) { if (clazz == null) { String elementName = getParent() != null ? String.valueOf(getParent().getElementName()) : String.valueOf(this); throw new SystemException("Unknown compile time class of container value of '" + elementName + "'."); } if (Modifier.isAbstract(clazz.getModifiers())) { throw new SystemException("Can't create instance of class '" + clazz.getSimpleName() + "', it's abstract."); } try { if (prismContext != null) { containerable = clazz.getConstructor(PrismContext.class).newInstance(prismContext); } else { containerable = clazz.newInstance(); } containerable.setupContainerValue(this); return containerable; } catch (SystemException ex) { throw ex; } catch (Exception ex) { throw new SystemException("Couldn't create jaxb object instance of '" + clazz + "': "+ex.getMessage(), ex); } }
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; }
private ComplexTypeDefinition determineComplexTypeDefinition() { PrismContainerable<C> parent = getParent(); ComplexTypeDefinition parentCTD = parent != null && parent.getDefinition() != null ? parent.getDefinition().getComplexTypeDefinition() : null; if (containerable == null) { return parentCTD; } if (prismContext == null) { // check if parentCTD matches containerable if (parentCTD != null && containerable.getClass().equals(parentCTD.getCompileTimeClass())) { return parentCTD; } else { //throw new IllegalStateException("Cannot determine complexTypeDefinition for PrismContainerValue because prismContext is missing; PCV = " + this); return null; } } ComplexTypeDefinition def = prismContext.getSchemaRegistry().findComplexTypeDefinitionByCompileTimeClass(containerable.getClass()); return def; // may be null at this place }
private <IV extends PrismValue,ID extends ItemDefinition> Item<IV,ID> findItemByQName(QName subName) throws SchemaException { if (items == null) { return null; } Item<IV,ID> matching = null; for (Item<?,?> item : items) { if (QNameUtil.match(subName, item.getElementName())) { if (matching != null) { String containerName = getParent() != null ? DebugUtil.formatElementName(getParent().getElementName()) : ""; throw new SchemaException("More than one items matching " + subName + " in container " + containerName); } else { matching = (Item<IV, ID>) item; } } } return matching; }
} else if (value instanceof PrismContainerValue<?>) { PrismContainerValue<?> pval = (PrismContainerValue<?>)value; if (pval.getParent().getCompileTimeClass() == null) {
private QName determineElementQName(Containerable containerable) { PrismContainerValue prismContainerValue = containerable.asPrismContainerValue(); PrismContainerDefinition<?> definition = prismContainerValue.getParent() != null ? prismContainerValue.getParent().getDefinition() : null; if (definition != null) { if (definition.getName() != null) { return definition.getName(); } } throw new IllegalStateException("Cannot determine element name of " + containerable + " (parent = " + prismContainerValue.getParent() + ", definition = " + definition + ")"); }
if (parent != null && parent.getDefinition() != null) { multivalue = parent.getDefinition().isMultiValue();
private S_ValuesEntry getDeltaItemFragment(PrismContainerValue<AssignmentType> cval) throws SchemaException { PrismContainerDefinition<AssignmentType> definition = cval.getParent() != null ? cval.getParent().getDefinition() : null; if (definition == null) { // we use custom definition, if available; if not, we find the standard one definition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(AssignmentHolderType.class) .findItemDefinition(AssignmentHolderType.F_ASSIGNMENT); } definition = definition.clone(); definition.toMutable().setMaxOccurs(1); return prismContext.deltaFor(AssignmentHolderType.class) .item(AssignmentHolderType.F_ASSIGNMENT, definition); }
@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; }
private void checkExtension(ExtensionType extension, String sourceDescription) throws SchemaException { PrismContainerValue<ExtensionType> extensionValueFromJaxb = extension.asPrismContainerValue(); assertNotNull("No extension container in "+sourceDescription+" (jaxb)", extensionValueFromJaxb); assertNotNull("No extension definition in "+sourceDescription+" (jaxb)", extensionValueFromJaxb.getParent().getDefinition()); assertTrue("Not runtime in definition in "+sourceDescription+" (jaxb)", extensionValueFromJaxb.getParent().getDefinition().isRuntimeSchema()); PrismProperty<Integer> intProperty = extensionValueFromJaxb.findOrCreateProperty(EXTENSION_INT_TYPE_ELEMENT); PrismAsserts.assertDefinition(intProperty.getDefinition(), EXTENSION_INT_TYPE_ELEMENT, DOMUtil.XSD_INT, 0, -1); intProperty.setRealValue(15); PrismProperty<String> stringProperty = extensionValueFromJaxb.findOrCreateItem(EXTENSION_STRING_TYPE_ELEMENT, PrismProperty.class); PrismAsserts.assertDefinition(stringProperty.getDefinition(), EXTENSION_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1); stringProperty.setRealValue("fifteen men on a dead man chest"); }
@Test public void testExtensionTypeConstruction() throws Exception { System.out.println("\n\n ===[ testExtensionTypeConstruction ]===\n"); // GIVEN PrismContext prismContext = PrismTestUtil.getPrismContext(); GenericObjectType object = new GenericObjectType(); prismContext.adopt(object.asPrismObject(), GenericObjectType.class); ExtensionType extension = new ExtensionType(); object.setExtension(extension); PrismContainerValue extValue = extension.asPrismContainerValue(); assertNotNull("No extension definition", extValue.getParent().getDefinition()); // WHEN Item item = extValue.findOrCreateItem(SchemaTestConstants.EXTENSION_STRING_TYPE_ELEMENT); // THEN assertNotNull(item); object.asPrismObject().checkConsistence(); }
private void checkSchema(AssignmentPathSegmentImpl segment, EvaluationContext ctx) throws SchemaException { AssignmentType assignmentType = getAssignmentType(segment, ctx); PrismContainerValue<AssignmentType> assignmentContainerValue = assignmentType.asPrismContainerValue(); PrismContainerable<AssignmentType> assignmentContainer = assignmentContainerValue.getParent(); if (assignmentContainer == null) { throw new SchemaException("The assignment "+assignmentType+" does not have a parent in "+segment.sourceDescription); } if (assignmentContainer.getDefinition() == null) { throw new SchemaException("The assignment "+assignmentType+" does not have definition in "+segment.sourceDescription); } PrismContainer<Containerable> extensionContainer = assignmentContainerValue.findContainer(AssignmentType.F_EXTENSION); if (extensionContainer != null) { if (extensionContainer.getDefinition() == null) { throw new SchemaException("Extension does not have a definition in assignment "+assignmentType+" in "+segment.sourceDescription); } for (Item<?,?> item: extensionContainer.getValue().getItems()) { if (item == null) { throw new SchemaException("Null item in extension in assignment "+assignmentType+" in "+segment.sourceDescription); } if (item.getDefinition() == null) { throw new SchemaException("Item "+item+" has no definition in extension in assignment "+assignmentType+" in "+segment.sourceDescription); } } } }
PrismAsserts.assertDefinition(assignmentType.asPrismContainerValue().getParent().getDefinition(), UserType.F_ASSIGNMENT, AssignmentType.COMPLEX_TYPE, 0, -1); PrismAsserts.assertDefinition(assignmentExtensionValueFromJaxb.getParent().getDefinition(), AssignmentType.F_EXTENSION, ExtensionType.COMPLEX_TYPE, 0, 1); assertTrue("assignment extension definition is not runtime", assignmentExtensionValueFromJaxb.getParent().getDefinition().isRuntimeSchema()); assertTrue("assignment extension definition is not dynamic", assignmentExtensionValueFromJaxb.getParent().getDefinition().isDynamic()); PrismAsserts.assertDefinition(intProperty.getDefinition(), EXTENSION_INT_TYPE_ELEMENT, DOMUtil.XSD_INT, 0, -1); PrismAsserts.assertDefinition(stringProperty.getDefinition(), EXTENSION_STRING_TYPE_ELEMENT, DOMUtil.XSD_STRING, 0, -1);