Skip to content

Commit

Permalink
PrismObjectValue as a subtype of PrismContainerValue
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 31, 2016
1 parent 99f0c61 commit d8d2c3b
Show file tree
Hide file tree
Showing 31 changed files with 556 additions and 392 deletions.
Expand Up @@ -52,7 +52,7 @@ public abstract class Item<V extends PrismValue, D extends ItemDefinition> imple
protected QName elementName;
protected PrismValue parent;
protected D definition;
@NotNull private final List<V> values = new ArrayList<>();
@NotNull protected final List<V> values = new ArrayList<>();
private transient Map<String,Object> userData = new HashMap<>();;

protected boolean immutable;
Expand Down Expand Up @@ -392,11 +392,11 @@ public boolean addAll(Collection<V> newValues) throws SchemaException {
return changed;
}

public boolean add(V newValue) throws SchemaException {
public boolean add(@NotNull V newValue) throws SchemaException {
return add(newValue, true);
}

public boolean add(V newValue, boolean checkUniqueness) throws SchemaException {
public boolean add(@NotNull V newValue, boolean checkUniqueness) throws SchemaException {
checkMutability();
if (newValue.getPrismContext() == null) {
newValue.setPrismContext(prismContext);
Expand Down
Expand Up @@ -26,6 +26,7 @@
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import org.jetbrains.annotations.NotNull;

import javax.xml.namespace.QName;

Expand Down Expand Up @@ -171,7 +172,7 @@ public PrismContainerValue<C> getValue() {
}
}

public void setValue(PrismContainerValue<C> value) throws SchemaException {
public void setValue(@NotNull PrismContainerValue<C> value) throws SchemaException {
checkMutability();
if (getDefinition() != null) {
if (getDefinition().isSingleValue()) {
Expand All @@ -187,7 +188,7 @@ public void setValue(PrismContainerValue<C> value) throws SchemaException {
}

@Override
public boolean add(PrismContainerValue newValue, boolean checkUniqueness) throws SchemaException {
public boolean add(@NotNull PrismContainerValue newValue, boolean checkUniqueness) throws SchemaException {
checkMutability();
// when a context-less item is added to a contextful container, it is automatically adopted
if (newValue.getPrismContext() == null && this.prismContext != null) {
Expand Down Expand Up @@ -437,21 +438,21 @@ <IV extends PrismValue,ID extends ItemDefinition,I extends Item<IV,ID>> I findCr
return getValue().findCreateItem(itemQName, type, null, create);
}

public <IV extends PrismValue,ID extends ItemDefinition,I extends Item<IV,ID>> I findItem(ItemPath propPath, Class<I> type) {
public <IV extends PrismValue,ID extends ItemDefinition,I extends Item<IV,ID>> I findItem(ItemPath path, Class<I> type) {
try {
return findCreateItem(propPath, type, null, false);
return findCreateItem(path, type, null, false);
} catch (SchemaException e) {
// This should not happen
throw new SystemException("Internal Error: "+e.getMessage(),e);
throw new SystemException("Internal Error:(path="+path+",type="+type+"): "+e.getMessage(),e);
}
}

public <IV extends PrismValue,ID extends ItemDefinition> Item<IV,ID> findItem(ItemPath propPath) {
public <IV extends PrismValue,ID extends ItemDefinition> Item<IV,ID> findItem(ItemPath path) {
try {
return findCreateItem(propPath, Item.class, null, false);
return findCreateItem(path, Item.class, null, false);
} catch (SchemaException e) {
// This should not happen
throw new SystemException("Internal Error: "+e.getMessage(),e);
throw new SystemException("Internal Error:(path="+path+"): "+e.getMessage(),e);
}
}

Expand Down Expand Up @@ -794,12 +795,22 @@ public void accept(Visitor visitor, ItemPath path, boolean recursive) {
}
}

/**
* Note: hashcode and equals compare the objects in the "java way". That means the objects must be
* almost precisely equal to match (e.g. including source demarcation in values and other "annotations").
* For a method that compares the "meaningful" parts of the objects see equivalent().
*/
@Override
public int hashCode() {
int result = super.hashCode();
return result;
}

/**
* Note: hashcode and equals compare the objects in the "java way". That means the objects must be
* almost precisely equal to match (e.g. including source demarcation in values and other "annotations").
* For a method that compares the "meaningful" parts of the objects see equivalent().
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
Expand Down
Expand Up @@ -51,41 +51,32 @@ public class PrismContainerValue<C extends Containerable> extends PrismValue imp

// This is list. We need to maintain the order internally to provide consistent
// output in DOM and other ordering-sensitive representations
private List<Item<?,?>> items = null;
protected List<Item<?,?>> items = null;
private Long id;

private C containerable = null;

// Definition of this value. Usually it is the same as CTD declared in the parent container.
// However, in order to support polymorphism (as well as parent-less values) we distinguish between PC and PCV type definition.
private ComplexTypeDefinition complexTypeDefinition = null;
protected ComplexTypeDefinition complexTypeDefinition = null;

public PrismContainerValue() {
}

public PrismContainerValue(C containerable) {
this(containerable, null, null);
this(containerable, null);
}

public PrismContainerValue(PrismContext prismContext) {
this(null, null, prismContext);
}

public PrismContainerValue(ComplexTypeDefinition complexTypeDefinition, PrismContext prismContext) {
this(null, complexTypeDefinition, prismContext);
this(null, prismContext);
}

public PrismContainerValue(C containerable, PrismContext prismContext) {
this(containerable, null, prismContext);
}

public PrismContainerValue(C containerable, ComplexTypeDefinition complexTypeDefinition, PrismContext prismContext) {
super(prismContext);
this.containerable = containerable;
this.complexTypeDefinition = complexTypeDefinition;

if (complexTypeDefinition == null && prismContext != null) {
getComplexTypeDefinition(); // to determine CTD
if (prismContext != null) {
getComplexTypeDefinition(); // to determine CTD (could be also called with null prismContext, but non-null prismContext provides additional information in some cases)
}
}

Expand Down Expand Up @@ -1363,8 +1354,8 @@ public String debugDump(int indent) {
if (DebugUtil.isDetailedDebugDump()) {
DebugUtil.indentDebugDump(sb, indent);
wasIndent = true;
sb.append("PCV").append(": ");
}
detailedDebugDumpStart(sb);
}
boolean multivalue = true;
PrismContainerable<C> parent = getParent();
if (parent != null && parent.getDefinition() != null) {
Expand All @@ -1376,8 +1367,8 @@ public String debugDump(int indent) {
DebugUtil.indentDebugDump(sb, indent);
wasIndent = true;
}
sb.append("id=").append(PrettyPrinter.prettyPrint(getId()));
}
debugDumpIdentifiers(sb);
}
appendOriginDump(sb);
List<Item<?,?>> items = getItems();
if (items != null) {
Expand All @@ -1396,6 +1387,14 @@ public String debugDump(int indent) {
return sb.toString();
}

protected void debugDumpIdentifiers(StringBuilder sb) {
sb.append("id=").append(PrettyPrinter.prettyPrint(getId()));
}

protected void detailedDebugDumpStart(StringBuilder sb) {
sb.append("PCV").append(": ");
}

@Override
public boolean match(PrismValue otherValue) {
return equalsRealValue(otherValue);
Expand Down

0 comments on commit d8d2c3b

Please sign in to comment.