Skip to content

Commit

Permalink
TransformableDefinition: Do not use prismContext in instantiate
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
  • Loading branch information
tonydamage committed Jul 28, 2021
1 parent 113b094 commit 8b65ee7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public PrismContainer<C> instantiate() throws SchemaException {
@NotNull
@Override
public PrismContainer<C> instantiate(QName elementName) throws SchemaException {
return this.getPrismContext().itemFactory().createContainer(elementName, this);
return super.instantiate(elementName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import javax.xml.namespace.QName;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.ComplexTypeDefinition;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.ItemDefinition;
Expand All @@ -19,6 +21,7 @@
import com.evolveum.midpoint.prism.PrismReferenceDefinition;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.deleg.ItemDefinitionDelegator;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType;
import com.google.common.base.Preconditions;

Expand Down Expand Up @@ -357,4 +360,10 @@ public String toString() {
return "Transformable:" + delegate.toString();
}

@Override
public @NotNull I instantiate(QName name) throws SchemaException {
var deleg = delegate().instantiate(name);
((Item<?,ItemDefinition>)deleg).setDefinition(this);
return deleg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public PrismObject<O> instantiate() throws SchemaException {

@Override
public @NotNull PrismObject<O> instantiate(QName name) throws SchemaException {
// TODO Auto-generated method stub
return getPrismContext().itemFactory().createObject(name, this);
return (PrismObject<O>) super.instantiate(name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.schema.processor.MutableResourceAttributeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.processor.deleg.AttributeDefinitionDelegator;
import com.evolveum.midpoint.util.exception.SchemaException;

public class TransformablePropertyDefinition<T> extends TransformableItemDefinition<PrismProperty<T>, PrismPropertyDefinition<T>>
implements PropertyDefinitionDelegator<T>, PartiallyMutableItemDefinition.Property<T> {
Expand Down Expand Up @@ -88,7 +89,11 @@ public MutablePrismPropertyDefinition<T> toMutable() {

@Override
public @NotNull PrismProperty<T> instantiate(QName name) {
return getPrismContext().itemFactory().createProperty(name, this);
try {
return super.instantiate(name);
} catch (SchemaException e) {
throw new IllegalStateException("Should not happened");
}
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.evolveum.midpoint.prism.PrismReference;
import com.evolveum.midpoint.prism.PrismReferenceDefinition;
import com.evolveum.midpoint.prism.deleg.ReferenceDefinitionDelegator;
import com.evolveum.midpoint.util.exception.SchemaException;

public class TransformableReferenceDefinition extends TransformableItemDefinition<PrismReference, PrismReferenceDefinition>
implements ReferenceDefinitionDelegator, PartiallyMutableItemDefinition.Reference {
Expand Down Expand Up @@ -46,7 +47,11 @@ public MutablePrismReferenceDefinition toMutable() {

@Override
public @NotNull PrismReference instantiate(QName name) {
return getPrismContext().itemFactory().createReference(name, this);
try {
return super.instantiate(name);
} catch (SchemaException e) {
throw new IllegalStateException("Should not happened",e);
}
}

@Override
Expand Down

0 comments on commit 8b65ee7

Please sign in to comment.