default ComplexTypeDefinition getComplexTypeDefinition() { PrismContainerDefinition def = getDefinition(); return def != null ? def.getComplexTypeDefinition() : null; } }
/** * Looks for a top-level definition for the specified element name (in all schemas). */ @Override @Deprecated public ItemDefinition resolveGlobalItemDefinition(QName elementQName, PrismContainerDefinition<?> containerDefinition) throws SchemaException { return resolveGlobalItemDefinition(elementQName, containerDefinition != null ? containerDefinition.getComplexTypeDefinition() : null); }
public <T extends Containerable> ItemDefinition locateItemDefinition( @NotNull PrismContainerDefinition<T> containerDefinition, @NotNull QName itemName, @Nullable XNode xnode) throws SchemaException { return locateItemDefinition(itemName, containerDefinition.getComplexTypeDefinition(), xnode); }
@Override public void trimTo(@NotNull Collection<ItemPath> paths) { if (shared) { // TODO switch this to warning before releasing this code (3.6.1 or 3.7) throw new IllegalStateException("Couldn't trim shared definition: " + this); } for (Iterator<ItemDefinition> iterator = itemDefinitions.iterator(); iterator.hasNext(); ) { ItemDefinition<?> itemDef = iterator.next(); ItemPath itemPath = itemDef.getName(); if (!ItemPathCollectionsUtil.containsSuperpathOrEquivalent(paths, itemPath)) { iterator.remove(); } else if (itemDef instanceof PrismContainerDefinition) { PrismContainerDefinition<?> itemPcd = (PrismContainerDefinition<?>) itemDef; if (itemPcd.getComplexTypeDefinition() != null) { itemPcd.getComplexTypeDefinition().trimTo(ItemPathCollectionsUtil.remainder(paths, itemPath, false)); } } } }
/** * Optimizes (trims) definition tree by removing any definitions not corresponding to items in this container. * Works recursively by sub-containers of this one. * USE WITH CARE. Make sure the definitions are not shared by other objects! */ public void trimDefinitionTree(Collection<? extends ItemPath> alwaysKeep) { PrismContainerDefinition<C> def = getDefinition(); if (def == null || def.getComplexTypeDefinition() == null) { return; } Set<ItemPath> allPaths = getAllItemPaths(alwaysKeep); def.getComplexTypeDefinition().trimTo(allPaths); values.forEach(v -> ((PrismContainerValueImpl<C>) v).trimItemsDefinitionsTrees(alwaysKeep)); }
/** * 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; }
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 }
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); } } }
/** * 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 boolean isInstantiable(ItemDefinition definition) { if (definition.isAbstract()) { return false; } if (definition instanceof PrismContainerDefinition) { PrismContainerDefinition pcd = (PrismContainerDefinition) definition; ComplexTypeDefinition ctd = pcd.getComplexTypeDefinition(); return ctd != null && ctd.getCompileTimeClass() != null; } else if (definition instanceof PrismPropertyDefinition) { PrismPropertyDefinition ppd = (PrismPropertyDefinition) definition; if (ppd.isAnyType()) { return false; } // TODO optimize return getSchemaRegistry().determineClassForType(ppd.getTypeName()) != null || getSchemaRegistry().findTypeDefinitionByType(ppd.getTypeName(), TypeDefinition.class) != null; } else { return false; } }
public void applyDefinition(@NotNull PrismContainerDefinition<C> containerDef, boolean force) throws SchemaException { checkMutability(); ComplexTypeDefinition definitionToUse = containerDef.getComplexTypeDefinition(); if (complexTypeDefinition != null) { if (!force) {
assertEquals("Wrong complex type def in weaponContDef", weaponTypeDef, weaponContDef.getComplexTypeDefinition());
@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); } }
private void changeDefinition(QName piracyShip, QName piracyShipBroken) { PrismObjectDefinition<UserType> userDef = prismContext.getSchemaRegistry() .findObjectDefinitionByCompileTimeClass(UserType.class); PrismContainerDefinition<?> extensionDefinition = userDef.getExtensionDefinition(); List<? extends ItemDefinition> extensionDefs = extensionDefinition.getComplexTypeDefinition().getDefinitions(); for (ItemDefinition itemDefinition : extensionDefs) { if (itemDefinition.getName().equals(piracyShip)) { //iterator.remove(); // not possible as the collection is unmodifiable itemDefinition.toMutable().setName(piracyShipBroken); } } }
@Test public void test103GetAccountRaw() throws Exception { TestUtil.displayTestTitle(this, "test103GetAccountRaw"); // GIVEN Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + ".test103GetAccountRaw"); OperationResult result = task.getResult(); preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE); Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw()); // WHEN PrismObject<ShadowType> account = modelService.getObject(ShadowType.class, accountJackOid, options , task, result); display("Account", account); display("Account def", account.getDefinition()); assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0); PrismContainer<Containerable> accountContainer = account.findContainer(ShadowType.F_ATTRIBUTES); display("Account attributes def", accountContainer.getDefinition()); display("Account attributes def complex type def", accountContainer.getDefinition().getComplexTypeDefinition()); assertDummyAccountShadowRepo(account, accountJackOid, "jack"); assertSuccess("getObject result", result); assertSteadyResources(); }
@Test public void test102GetAccountNoFetch() throws Exception { TestUtil.displayTestTitle(this, "test102GetAccountNoFetch"); // GIVEN Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + ".test102GetAccountNoFetch"); OperationResult result = task.getResult(); preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE); Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch()); // WHEN PrismObject<ShadowType> account = modelService.getObject(ShadowType.class, accountJackOid, options , task, result); display("Account", account); display("Account def", account.getDefinition()); assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0); PrismContainer<Containerable> accountContainer = account.findContainer(ShadowType.F_ATTRIBUTES); display("Account attributes def", accountContainer.getDefinition()); display("Account attributes def complex type def", accountContainer.getDefinition().getComplexTypeDefinition()); assertDummyAccountShadowRepo(account, accountJackOid, "jack"); assertSuccess("getObject result", result); assertSteadyResources(); }
@Test public void test103GetGroupRaw() throws Exception { final String TEST_NAME = "test103GetGroupRaw"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE); Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw()); // WHEN PrismObject<ShadowType> shadow = modelService.getObject(ShadowType.class, groupOid, options , task, result); display("Account", shadow); display("Account def", shadow.getDefinition()); PrismContainer<Containerable> accountContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); display("Account attributes def", accountContainer.getDefinition()); display("Account attributes def complex type def", accountContainer.getDefinition().getComplexTypeDefinition()); assertDummyGroupShadowRepo(shadow, groupOid, GROUP_PIRATE_DUMMY_NAME); result.computeStatus(); TestUtil.assertSuccess("getObject result", result); }
@Test public void test102GetGroupNoFetch() throws Exception { final String TEST_NAME = "test102GetGroupNoFetch"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE); Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch()); // WHEN PrismObject<ShadowType> shadow = modelService.getObject(ShadowType.class, groupOid, options , task, result); display("Account", shadow); display("Account def", shadow.getDefinition()); PrismContainer<Containerable> accountContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES); display("Account attributes def", accountContainer.getDefinition()); display("Account attributes def complex type def", accountContainer.getDefinition().getComplexTypeDefinition()); assertDummyGroupShadowRepo(shadow, groupOid, GROUP_PIRATE_DUMMY_NAME); result.computeStatus(); TestUtil.assertSuccess("getObject result", result); }
private void assertResource(PrismObject<ResourceType> resource, boolean expectSchema) { display("Resource", resource); display("Resource def", resource.getDefinition()); PrismContainer<ConnectorConfigurationType> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION); assertNotNull("No Resource connector configuration def", configurationContainer); PrismContainerDefinition<ConnectorConfigurationType> configurationContainerDefinition = configurationContainer.getDefinition(); display("Resource connector configuration def", configurationContainerDefinition); display("Resource connector configuration def complex type def", configurationContainerDefinition.getComplexTypeDefinition()); assertNotNull("Empty Resource connector configuration def", configurationContainer.isEmpty()); assertEquals("Wrong compile-time class in Resource connector configuration in "+resource, ConnectorConfigurationType.class, configurationContainer.getCompileTimeClass()); assertEquals("configurationContainer maxOccurs", 1, configurationContainerDefinition.getMaxOccurs()); resource.checkConsistence(true, true); Element schema = ResourceTypeUtil.getResourceXsdSchema(resource); if (expectSchema) { assertNotNull("no schema in "+resource, schema); } else { assertNull("Unexpected schema in "+resource+": "+schema, schema); } }
PrismContainer<Containerable> accountContainer = account.findContainer(ShadowType.F_ATTRIBUTES); display("Account attributes def", accountContainer.getDefinition()); display("Account attributes def complex type def", accountContainer.getDefinition().getComplexTypeDefinition()); assertDummyAccountShadowModel(account, accountJackOid, "jack", "Jack Sparrow");