public QName getTypeName() { ItemDefinition definition = getDefinition(); return definition != null ? definition.getTypeName() : null; }
JpaAnyItemLinkDefinition(ItemDefinition<?> itemDefinition, String jpaName, CollectionSpecification collectionSpecification, RObjectExtensionType ownerType, JpaDataNodeDefinition targetDefinition) { super(itemDefinition.getName(), jpaName, collectionSpecification, false, targetDefinition); this.ownerType = ownerType; this.itemDefinition = itemDefinition; }
public Item<V,D> getEmptyItem() throws SchemaException { ItemDefinition definition = getDefinition(); if (definition == null) { throw new IllegalStateException("No definition in source "+this); } return definition.instantiate(getElementName()); }
@Override public void adoptElementDefinitionFrom(ItemDefinition otherDef) { if (otherDef == null) { return; } setName(otherDef.getName()); setMinOccurs(otherDef.getMinOccurs()); setMaxOccurs(otherDef.getMaxOccurs()); }
/** * Answers the question: "If the receiver would get itemName without any other information, will it be able to * derive suitable typeName from it?" If not, we have to provide explicit type definition for serialization. * * By suitable we mean such that can be used to determine specific object type. */ public boolean hasImplicitTypeDefinition(@NotNull QName itemName, @NotNull QName typeName) { List<ItemDefinition> definitions = findItemDefinitionsByElementName(itemName, ItemDefinition.class); if (definitions.isEmpty() || definitions.size() > 1) { return false; } ItemDefinition definition = definitions.get(0); if (definition.isAbstract()) { return false; } // TODO other conditions? return definition.getTypeName().equals(typeName); }
public static void assertDefinitionTypeLoose(ItemDefinition definition, QName itemName, QName type, int minOccurs, int maxOccurs) { assertNotNull("No definition for "+itemName, definition); assertTrue("Wrong definition type for "+itemName+": expected: " + type + ", real: " + definition.getTypeName(), QNameUtil.match(type, definition.getTypeName())); assertEquals("Wrong definition minOccurs for "+itemName, minOccurs, definition.getMinOccurs()); assertEquals("Wrong definition maxOccurs for "+itemName, maxOccurs, definition.getMaxOccurs()); }
List<? extends ItemDefinition> subDefinitions = ((PrismContainerDefinition<?>)containerDefinition).getDefinitions(); for (ItemDefinition subDef: subDefinitions) { ItemPath subPath = ItemPath.create(nameOnlyItemPath, subDef.getName()); if (subDef.isElaborate()) { LOGGER.trace("applySecurityConstraints(itemDef): {}: skip (elaborate)", subPath); continue; if (!subDef.getName().equals(ShadowType.F_ATTRIBUTES)) { // Shadow attributes have special handling applySecurityConstraintsItemDef(subDef, definitionsSeen, subPath, securityConstraints, readDecision, addDecision, modifyDecision, phase); if (subDef.canRead()) { anySubElementRead = true; if (subDef.canAdd()) { anySubElementAdd = true; if (subDef.canModify()) { anySubElementModify = true; itemDefinition.toMutable().setCanRead(false); itemDefinition.toMutable().setCanAdd(false); itemDefinition.toMutable().setCanModify(false); itemDefinition.toMutable().setCanRead(true); itemDefinition.toMutable().setCanAdd(true);
public static RExtItem.Key createKeyFromDefinition(ItemDefinition<?> definition) { String name = RUtil.qnameToString(definition.getName()); String type = RUtil.qnameToString(definition.getTypeName()); RItemKind kind = RItemKind.getTypeFromItemDefinitionClass(definition.getClass()); return new Key(name, type, kind); }
@NotNull protected StringBuilder debugDumpCommon(int indent) { StringBuilder sb = new StringBuilder(); DebugUtil.indentDebugDump(sb, indent); sb.append("Item: ").append(name).append(" [rel-path: ").append(sourceRelPath).append("]"); if (sourceItem != null) { sb.append(" ITEM"); final ItemDefinition def = sourceItem.getDefinition(); if (def != null) { sb.append(" DEF(").append(def.getName().getLocalPart()).append("/").append(def.getDisplayName()).append(":").append(def.getDisplayOrder()).append(")"); } } if (operational) { sb.append(" OPER"); } return sb; }
private static boolean isIndexed(ItemDefinition definition, QName elementName, boolean indexAlsoDynamics, PrismContext prismContext) throws SchemaException { if (definition instanceof PrismContainerDefinition) { return false; } if (definition instanceof PrismReferenceDefinition) { return true; // TODO make reference indexing configurable } if (!(definition instanceof PrismPropertyDefinition)) { throw new UnsupportedOperationException("Unknown definition type '" + definition + "', can't say if '" + elementName + "' is indexed or not."); } PrismPropertyDefinition pDefinition = (PrismPropertyDefinition) definition; Boolean isIndexed = pDefinition.isIndexed(); if (definition.isDynamic() && !indexAlsoDynamics && BooleanUtils.isNotTrue(isIndexed)) { return false; } if (isIndexed != null) { if (isIndexed && !isIndexedByDefault(definition, prismContext)) { throw new SchemaException("Item is marked as indexed (definition " + definition.debugDump() + ") but definition type (" + definition.getTypeName() + ") doesn't support indexing"); } return isIndexed; } return isIndexedByDefault(definition, prismContext); }
@SuppressWarnings("unchecked") private <V extends PrismValue, D extends ItemDefinition> SceneDeltaItemImpl createSceneDeltaItemCommon(ItemDelta<V, D> itemDelta, SceneImpl owningScene) throws SchemaException { String simpleName = itemDelta.getElementName() != null ? itemDelta.getElementName().getLocalPart() : ""; NameImpl name = new NameImpl(simpleName); if (itemDelta.getDefinition() != null) { name.setDisplayName(itemDelta.getDefinition().getDisplayName()); } name.setId(simpleName); name.setNamesAreResourceKeys(true); SceneDeltaItemImpl si = new SceneDeltaItemImpl(name); si.setSourceDelta(itemDelta); D def = itemDelta.getDefinition(); if (def != null) { Item<V,D> item = def.instantiate(); if (itemDelta.getEstimatedOldValues() != null) { item.addAll(CloneUtil.cloneCollectionMembers(itemDelta.getEstimatedOldValues())); } si.setSourceItem(item); si.setOperational(def.isOperational()); } ItemPath remainder = itemDelta.getPath().remainder(owningScene.getSourceRelPath()); if (remainder.startsWithNullId()) { remainder = remainder.rest(); } si.setSourceRelPath(remainder); return si; }
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 testParseToXNode() throws Exception { displayTestTitle("testParseToXNode"); ItemDefinition sequenceDef = getPrismContext().getSchemaRegistry().findItemDefinitionByElementName(SchemaConstants.S_SEQUENCE); System.out.println("sequence.substitutionHead = " + sequenceDef.getSubstitutionHead()); System.out.println("sequence.heterogeneousListItem = " + sequenceDef.isHeterogeneousListItem()); ComplexTypeDefinition sequenceCtd = getPrismContext().getSchemaRegistry().findComplexTypeDefinitionByType(sequenceDef.getTypeName()); System.out.println("ExpressionSequenceType.list = " + sequenceCtd.isListMarker()); System.out.println("\n\n-----------------------------------\n"); String file = MiscUtil.readFile(getFile()); System.out.println("Original text:\n" + file); RootXNode xnode = getPrismContext().parserFor(file).parseToXNode(); System.out.println("XNode:\n" + xnode.debugDump()); System.out.println("source -> XNode -> JSON:\n" + getPrismContext().jsonSerializer().serialize(xnode)); System.out.println("source -> XNode -> YAML:\n" + getPrismContext().yamlSerializer().serialize(xnode)); System.out.println("source -> XNode -> XML:\n" + getPrismContext().xmlSerializer().serialize(xnode)); }
boolean hasRange, boolean isDelete) throws SchemaException { ItemDelta outputFocusItemDelta = outputDefinition.createEmptyDelta(outputPath); Item<V, D> targetFocusItem = null; if (focusNew != null) { Item shouldBeItem = outputDefinition.instantiate(); if (consolidatedTriples != null) { outputFocusItemDelta = outputDefinition.createEmptyDelta(originMapping.getOutputPath()); if (targetFocusItem != null && !targetFocusItem.getDefinition().isMultiValue() && !targetFocusItem.isEmpty()) { Collection<V> replace = new ArrayList<>();
QName propName = valueFilter.getDefinition().getName(); String icfName = icfNameMapper.convertAttributeNameToConnId(propName, getInterpreter() .getObjectClassDefinition(), "(attribute in the filter)"); } else { Attribute attr = AttributeBuilder.build(icfName, convertedValues); if (valueFilter.getDefinition().isSingleValue()) { return FilterBuilder.equalTo(attr); } else { QName propName = valueFilter.getDefinition().getName(); EqualFilter<T> eq = (EqualFilter<T>) objectFilter; List<PrismPropertyValue<T>> values = eq.getValues(); if (valueFilter.getDefinition().isSingleValue()) { return FilterBuilder.equalTo(attr); } else {
@SuppressWarnings("unchecked") @NotNull private XNodeImpl marshalItemValue(@NotNull PrismValue itemValue, @Nullable ItemDefinition definition, @Nullable QName typeName, SerializationContext ctx) throws SchemaException { XNodeImpl xnode; if (definition == null && typeName == null && itemValue instanceof PrismPropertyValue) { return serializePropertyRawValue((PrismPropertyValue<?>) itemValue); } else if (itemValue instanceof PrismReferenceValue) { xnode = serializeReferenceValue((PrismReferenceValue)itemValue, (PrismReferenceDefinition) definition, ctx); } else if (itemValue instanceof PrismPropertyValue<?>) { xnode = serializePropertyValue((PrismPropertyValue<?>)itemValue, (PrismPropertyDefinition) definition, typeName); } else if (itemValue instanceof PrismContainerValue<?>) { xnode = marshalContainerValue((PrismContainerValue<?>)itemValue, (PrismContainerDefinition) definition, ctx); } else { throw new IllegalArgumentException("Unsupported value type "+itemValue.getClass()); } if (definition != null && (definition.isDynamic() || shouldPutTypeInExportMode(ctx, definition)) && isInstantiable(definition)) { if (xnode.getTypeQName() == null) { xnode.setTypeQName(definition.getTypeName()); } xnode.setExplicitTypeDeclaration(true); } return xnode; }
@Test public void testExtensionEnum() throws Exception { Session session = getFactory().openSession(); QName valueName = new QName(NS_P, "enumType"); ItemDefinition def = getDefinition(GenericObjectType.class, ItemPath.create(ObjectType.F_EXTENSION, valueName)); AssertJUnit.assertNotNull(def); PrismProperty item = (PrismProperty) def.instantiate(); item.setRealValue(BeforeAfterType.AFTER); def.toMutable().setName(valueName); RAnyConverter converter = new RAnyConverter(prismContext, extItemDictionary); Set<RAnyValue<?>> values; try { values = converter.convertToRValue(item, false, RObjectExtensionType.EXTENSION); AssertJUnit.fail("Should have throw serialization related exception after creating ext item"); } catch (DtoTranslationException ex) { AssertJUnit.assertTrue(SerializationRelatedException.class.equals(ex.getCause().getClass())); } values = converter.convertToRValue(item, false, RObjectExtensionType.EXTENSION); AssertJUnit.assertEquals("Expected only one enum value, but was " + values.size(), 1, values.size()); RAnyValue value = values.iterator().next(); AssertJUnit.assertEquals("after", value.getValue()); session.close(); }
@Override public <ID extends ItemDefinition> ID findNamedItemDefinition(@NotNull QName firstName, @NotNull ItemPath rest, @NotNull Class<ID> clazz) { for (ItemDefinition def : getDefinitions()) { if (QNameUtil.match(firstName, def.getName())) { return (ID) def.findItemDefinition(rest, clazz); } } if (complexTypeDefinition != null && complexTypeDefinition.isXsdAnyMarker()) { SchemaRegistry schemaRegistry = getSchemaRegistry(); if (schemaRegistry != null) { ItemDefinition def = schemaRegistry.findItemDefinitionByElementName(firstName); if (def != null) { return (ID) def.findItemDefinition(rest, clazz); } } } return null; }
@Override public void replaceDefinition(QName itemName, ItemDefinition newDefinition) { for (int i=0; i<itemDefinitions.size(); i++) { ItemDefinition itemDef = itemDefinitions.get(i); if (itemDef.getName().equals(itemName)) { if (!itemDef.getClass().isAssignableFrom(newDefinition.getClass())) { throw new IllegalArgumentException("The provided definition of class "+newDefinition.getClass().getName()+" does not match existing definition of class "+itemDef.getClass().getName()); } if (!itemDef.getName().equals(newDefinition.getName())) { newDefinition = newDefinition.clone(); ((ItemDefinitionImpl) newDefinition).setName(itemName); } // Make sure this is set, not add. set will keep correct ordering itemDefinitions.set(i, newDefinition); return; } } throw new IllegalArgumentException("The definition with name "+ itemName +" was not found in complex type "+getTypeName()); }
private boolean shouldPutTypeInExportMode(SerializationContext ctx, ItemDefinition definition) { if (!SerializationContext.isSerializeForExport(ctx) || definition == null || !definition.isRuntimeSchema()) { return false; } QName itemName = definition.getName(); if (StringUtils.isEmpty(itemName.getNamespaceURI())) { return true; // ambiguous item name - let's put xsi:type, to be on the safe side } // we assume that all runtime elements which are part of the schema registry are retrievable by element name // (might not be the case for sub-items of custom extension containers! we hope providing xsi:type there will cause no harm) List<ItemDefinition> definitionsInRegistry = getSchemaRegistry() .findItemDefinitionsByElementName(itemName, ItemDefinition.class); return definitionsInRegistry.isEmpty(); // no definition in registry => xsi:type should be put }