private boolean isSchemaless() { return containerValue.getComplexTypeDefinition() == null; }
private <C extends Containerable> ItemDefinition getItemDefinition(PrismContainerValue<C> cval, Item<?, ?> item) { if (item.getDefinition() != null) { return item.getDefinition(); } ComplexTypeDefinition ctd = cval.getComplexTypeDefinition(); if (ctd == null) { return null; } return ctd.findLocalItemDefinition(item.getElementName()); }
@Deprecated static void copyDefinition(Containerable aClone, Containerable original, PrismContext prismContext) { try { Validate.notNull(original.asPrismContainerValue().getParent(), "original PrismContainerValue has no parent"); ComplexTypeDefinition definition = original.asPrismContainerValue().getComplexTypeDefinition(); Validate.notNull(definition, "original PrismContainer definition is null"); PrismContainer<?> aCloneParent = prismContext.getSchemaRegistry() .findContainerDefinitionByCompileTimeClass((Class<? extends Containerable>) definition.getCompileTimeClass()) .instantiate(); aCloneParent.add(aClone.asPrismContainerValue()); } catch (SchemaException e) { throw new SystemException("Unexpected SchemaException when copying definition from original object to its clone", e); } }
/** * 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; }
@Deprecated public static void copyDefinition(Containerable aClone, Containerable original, PrismContext prismContext) { try { Validate.notNull(original.asPrismContainerValue().getParent(), "original PrismContainerValue has no parent"); ComplexTypeDefinition definition = original.asPrismContainerValue().getComplexTypeDefinition(); Validate.notNull(definition, "original PrismContainer definition is null"); PrismContainer<?> aCloneParent = prismContext.getSchemaRegistry() .findContainerDefinitionByCompileTimeClass((Class<? extends Containerable>) definition.getCompileTimeClass()) .instantiate(); aCloneParent.add(aClone.asPrismContainerValue()); } catch (SchemaException e) { throw new SystemException("Unexpected SchemaException when copying definition from original object to its clone", e); } }
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; }
protected T createItemInternal(PrismContainerValue value) { ComplexTypeDefinition concreteDef = value.getComplexTypeDefinition(); if (concreteDef != null && (container.getCompileTimeClass() == null || !container.getCompileTimeClass().equals(concreteDef.getCompileTimeClass()))) { // the dynamic definition exists and the compile time class is different from the one at the container level // ("different" here means it is a subclass) // so we have to instantiate dynamically T bean = null; try { bean = (T) concreteDef.getCompileTimeClass().newInstance(); } catch (InstantiationException|IllegalAccessException|RuntimeException e) { throw new SystemException("Couldn't instantiate " + concreteDef.getCompileTimeClass()); } bean.setupContainerValue(value); return bean; } else { // otherwise let's use the static (faster) way return createItem(value); } } protected abstract T createItem(PrismContainerValue value);
@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); } }
@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; }
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()); }
protected void assertDefinitions(Visitable value) { value.accept(v -> { if (v instanceof Item) { Item item = (Item) v; String label = item.getPath() + ": " + v; //System.out.println("Checking " + label); if (item.getDefinition() == null) { assertTrue("No definition in " + label, isDynamic(item.getPath())); } else { assertNotNull("No prism context in definition of " + label, item.getDefinition().getPrismContext()); } } else if (v instanceof PrismContainerValue) { PrismContainerValue pcv = (PrismContainerValue) v; String label = pcv.getPath() + ": " + v; //System.out.println("Checking " + label); if (pcv.getComplexTypeDefinition() == null) { fail("No complex type definition in " + label); } else { assertNotNull("No prism context in definition of " + label, pcv.getComplexTypeDefinition().getPrismContext()); } } }); }