Skip to content

Commit

Permalink
Minimalistic support for simple types in schemas (for TestStrangeCase…
Browse files Browse the repository at this point in the history
…s / dynamic enums). Few fixes in RefinedOCD subclasses.
  • Loading branch information
mederly committed Oct 26, 2016
1 parent 06f2851 commit 1b9f611
Show file tree
Hide file tree
Showing 39 changed files with 436 additions and 245 deletions.
Expand Up @@ -21,6 +21,7 @@
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinitionImpl;
import com.evolveum.midpoint.schema.processor.ResourceAttributeContainer;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.util.DebugUtil;
Expand Down Expand Up @@ -420,8 +421,8 @@ public List<String> getIgnoredNamespaces() {
}

@Override
public LayerRefinedObjectClassDefinition forLayer(LayerType layerType) {
throw new UnsupportedOperationException("TODO implement if needed");
public LayerRefinedObjectClassDefinition forLayer(@NotNull LayerType layerType) {
return LayerRefinedObjectClassDefinitionImpl.wrap(this, layerType);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -476,7 +477,7 @@ public boolean hasAuxiliaryObjectClass(QName expectedObjectClassName) {

@Override
public ResourceAttributeContainer instantiate(QName elementName) {
throw new UnsupportedOperationException("TODO implement if needed");
return ObjectClassComplexTypeDefinitionImpl.instantiate(elementName, this);
}

@Override
Expand Down Expand Up @@ -638,7 +639,7 @@ protected String debugDump(int indent, LayerType layer) {
* Return a human readable name of this class suitable for logs.
*/
// @Override
protected String getDebugDumpClassName() {
public String getDebugDumpClassName() {
return "crOCD";
}

Expand Down
Expand Up @@ -169,7 +169,7 @@ public String getIntent() {
}

@Override
public LayerRefinedObjectClassDefinition forLayer(LayerType layerType) {
public LayerRefinedObjectClassDefinition forLayer(@NotNull LayerType layerType) {
return refinedObjectClassDefinition.forLayer(layerType);
}

Expand Down Expand Up @@ -222,7 +222,7 @@ public PrismContext getPrismContext() {

@Override
public ResourceAttributeContainer instantiate(QName name) {
return refinedObjectClassDefinition.instantiate(name);
return ObjectClassComplexTypeDefinitionImpl.instantiate(name, this);
}

// @Override
Expand Down Expand Up @@ -538,8 +538,7 @@ public String getDefaultNamespace() {

@Override
public String debugDump(int indent) {
// TODO fix this hack
return ((RefinedObjectClassDefinitionImpl) refinedObjectClassDefinition).debugDump(indent, layer, getDebugDumpClassName());
return RefinedObjectClassDefinitionImpl.debugDump(indent, layer, this);
}

// Do NOT override&delegate debugDump(int indent, LayerType layer) here.
Expand All @@ -549,7 +548,7 @@ public String debugDump(int indent) {
/**
* Return a human readable name of this class suitable for logs.
*/
protected String getDebugDumpClassName() {
public String getDebugDumpClassName() {
return "LRObjectClassDef";
}

Expand Down
Expand Up @@ -204,8 +204,8 @@ public <C extends Containerable> ComplexTypeDefinition findComplexTypeDefinition

@Override
@Nullable
public ComplexTypeDefinition findComplexTypeDefinitionByType(@NotNull QName typeName) {
return refinedResourceSchema.findComplexTypeDefinitionByType(typeName);
public <TD extends TypeDefinition> TD findTypeDefinitionByType(@NotNull QName typeName, @NotNull Class<TD> definitionClass) {
return refinedResourceSchema.findTypeDefinitionByType(typeName, definitionClass);
}

@Override
Expand Down
Expand Up @@ -17,12 +17,12 @@
package com.evolveum.midpoint.common.refinery;

import com.evolveum.midpoint.common.ResourceObjectPattern;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.ComplexTypeDefinition;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.util.ItemPathUtil;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.PagedSearchCapabilityType;
Expand Down Expand Up @@ -194,7 +194,7 @@ default PrismObject<ShadowType> createBlankShadow() {
RefinedObjectClassDefinition deepClone(Map<QName, ComplexTypeDefinition> ctdMap);
//endregion

LayerRefinedObjectClassDefinition forLayer(LayerType layerType);
LayerRefinedObjectClassDefinition forLayer(@NotNull LayerType layerType);

//region Type variance ========================================================

Expand All @@ -204,6 +204,9 @@ default <X> RefinedAttributeDefinition<X> findAttributeDefinition(String name) {
return findAttributeDefinition(new QName(getTypeName().getNamespaceURI(), name));
}


//endregion

String getDebugDumpClassName();

}
Expand Up @@ -24,10 +24,7 @@
import com.evolveum.midpoint.prism.util.ItemPathUtil;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.processor.ResourceAttributeContainer;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.processor.*;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
Expand Down Expand Up @@ -593,7 +590,7 @@ private List<? extends RefinedAttributeDefinition<?>> cloneDefinitions(Collectio
* @return
*/
@Override
public LayerRefinedObjectClassDefinition forLayer(LayerType layerType) {
public LayerRefinedObjectClassDefinition forLayer(@NotNull LayerType layerType) {
Validate.notNull(layerType);
return LayerRefinedObjectClassDefinitionImpl.wrap(this, layerType);
}
Expand Down Expand Up @@ -762,7 +759,7 @@ public Class getTypeClass() {

@Override
public ResourceAttributeContainer instantiate(QName elementName) {
return originalObjectClassDefinition.instantiate(elementName); // TODO doesn't preserve 'this' in instantiated RAC
return ObjectClassComplexTypeDefinitionImpl.instantiate(elementName, this);
}

//endregion
Expand Down Expand Up @@ -1046,31 +1043,31 @@ public String debugDump() {

@Override
public String debugDump(int indent) {
return debugDump(indent, null, getDebugDumpClassName());
return debugDump(indent, null, this);
}

public String debugDump(int indent, LayerType layer, String debugDumpClassName) {
public static String debugDump(int indent, LayerType layer, RefinedObjectClassDefinition _this) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < indent; i++) {
sb.append(INDENT_STRING);
}
sb.append(debugDumpClassName).append("(");
sb.append(SchemaDebugUtil.prettyPrint(getTypeName()));
if (isDefault()) {
sb.append(_this.getDebugDumpClassName()).append("(");
sb.append(SchemaDebugUtil.prettyPrint(_this.getTypeName()));
if (_this.isDefault()) {
sb.append(",default");
}
if (getKind() != null) {
sb.append(" ").append(getKind().value());
if (_this.getKind() != null) {
sb.append(" ").append(_this.getKind().value());
}
sb.append(",");
if (getIntent() != null) {
sb.append("intent=").append(getIntent());
if (_this.getIntent() != null) {
sb.append("intent=").append(_this.getIntent());
}
if (layer != null) {
sb.append(",layer=").append(layer);
}
sb.append(")");
for (RefinedAttributeDefinition rAttrDef: getAttributeDefinitions()) {
for (RefinedAttributeDefinition rAttrDef: _this.getAttributeDefinitions()) {
sb.append("\n");
sb.append(rAttrDef.debugDump(indent + 1, layer));
}
Expand All @@ -1080,7 +1077,7 @@ public String debugDump(int indent, LayerType layer, String debugDumpClassName)
/**
* Return a human readable name of this class suitable for logs.
*/
protected String getDebugDumpClassName() {
public String getDebugDumpClassName() {
return "rOCD";
}

Expand All @@ -1090,10 +1087,8 @@ public String getHumanReadableName() {
return getDisplayName();
} else if (getKind() != null) {
return getKind()+":"+getIntent();
} else if (getTypeName() != null) {
return getTypeName().getLocalPart();
} else {
return "null";
return getTypeName().getLocalPart();
}
}

Expand Down
Expand Up @@ -534,8 +534,8 @@ public <C extends Containerable> ComplexTypeDefinition findComplexTypeDefinition

@Override
@Nullable
public ComplexTypeDefinition findComplexTypeDefinitionByType(@NotNull QName typeName) {
return originalResourceSchema.findComplexTypeDefinitionByType(typeName);
public <TD extends TypeDefinition> TD findTypeDefinitionByType(@NotNull QName typeName, @NotNull Class<TD> definitionClass) {
return originalResourceSchema.findTypeDefinitionByType(typeName, definitionClass);
}

@Override
Expand Down
Expand Up @@ -31,7 +31,7 @@
* @author semancik
* @author mederly
*/
public interface ComplexTypeDefinition extends Definition, LocalDefinitionStore {
public interface ComplexTypeDefinition extends TypeDefinition, LocalDefinitionStore {

/**
* Returns definitions for all inner items.
Expand All @@ -46,12 +46,6 @@ public interface ComplexTypeDefinition extends Definition, LocalDefinitionStore
@NotNull
List<? extends ItemDefinition> getDefinitions();

/**
* Returns compile-time class, if this type has any. For example, UserType.class, ObjectType.class, ExtensionType.class.
*/
@Nullable
Class<?> getCompileTimeClass();

/**
* If not null, indicates that this type defines the structure of 'extension' element of a given type.
* E.g. getExtensionForType() == c:UserType means that this complex type defines structure of
Expand Down Expand Up @@ -98,14 +92,6 @@ public interface ComplexTypeDefinition extends Definition, LocalDefinitionStore
@NotNull
List<String> getIgnoredNamespaces();

/**
* Name of super type of this complex type definition. E.g. c:ObjectType is a super type for
* c:FocusType which is a super type for c:UserType. Or (more complex example) ri:ShadowAttributesType
* is a super type of ri:AccountObjectClass. (TODO is this really true?)
*/
@Nullable
QName getSuperType();

/**
* Copies cloned definitions from the other type definition into this one.
* (TODO remove from the interface?)
Expand Down
Expand Up @@ -38,16 +38,14 @@
* @author Radovan Semancik
*
*/
public class ComplexTypeDefinitionImpl extends DefinitionImpl implements ComplexTypeDefinition {
public class ComplexTypeDefinitionImpl extends TypeDefinitionImpl implements ComplexTypeDefinition {

private static final long serialVersionUID = 2655797837209175037L;
@NotNull private final List<ItemDefinition> itemDefinitions = new ArrayList<>();
private QName superType;
private boolean containerMarker;
private boolean objectMarker;
private boolean xsdAnyMarker;
private QName extensionForType;
private Class<?> compileTimeClass;

private String defaultNamespace;

Expand Down Expand Up @@ -80,15 +78,6 @@ public void add(ItemDefinition<?> definition) {
itemDefinitions.add(definition);
}

@Override
public Class<?> getCompileTimeClass() {
return compileTimeClass;
}

public void setCompileTimeClass(Class<?> compileTimeClass) {
this.compileTimeClass = compileTimeClass;
}

@Override
public QName getExtensionForType() {
return extensionForType;
Expand Down Expand Up @@ -140,15 +129,6 @@ public void setIgnoredNamespaces(@NotNull List<String> ignoredNamespaces) {
this.ignoredNamespaces = ignoredNamespaces;
}

@Override
public QName getSuperType() {
return superType;
}

public void setSuperType(QName superType) {
this.superType = superType;
}

public void setObjectMarker(boolean objectMarker) {
this.objectMarker = objectMarker;
}
Expand Down Expand Up @@ -303,12 +283,10 @@ public ComplexTypeDefinition deepClone(Map<QName, ComplexTypeDefinition> ctdMap)

protected void copyDefinitionData(ComplexTypeDefinitionImpl clone) {
super.copyDefinitionData(clone);
clone.superType = this.superType;
clone.containerMarker = this.containerMarker;
clone.objectMarker = this.objectMarker;
clone.xsdAnyMarker = this.xsdAnyMarker;
clone.extensionForType = this.extensionForType;
clone.compileTimeClass = this.compileTimeClass;
clone.defaultNamespace = this.defaultNamespace;
clone.ignoredNamespaces = this.ignoredNamespaces;
clone.itemDefinitions.addAll(this.itemDefinitions);
Expand Down Expand Up @@ -337,12 +315,10 @@ public void replaceDefinition(QName propertyName, ItemDefinition newDefinition)
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((compileTimeClass == null) ? 0 : compileTimeClass.hashCode());
result = prime * result + (containerMarker ? 1231 : 1237);
result = prime * result + ((extensionForType == null) ? 0 : extensionForType.hashCode());
result = prime * result + ((itemDefinitions == null) ? 0 : itemDefinitions.hashCode());
result = prime * result + (objectMarker ? 1231 : 1237);
result = prime * result + ((superType == null) ? 0 : superType.hashCode());
result = prime * result + (xsdAnyMarker ? 1231 : 1237);
return result;
}
Expand All @@ -359,13 +335,6 @@ public boolean equals(Object obj) {
return false;
}
ComplexTypeDefinitionImpl other = (ComplexTypeDefinitionImpl) obj;
if (compileTimeClass == null) {
if (other.compileTimeClass != null) {
return false;
}
} else if (!compileTimeClass.equals(other.compileTimeClass)) {
return false;
}
if (containerMarker != other.containerMarker) {
return false;
}
Expand All @@ -376,23 +345,12 @@ public boolean equals(Object obj) {
} else if (!extensionForType.equals(other.extensionForType)) {
return false;
}
if (itemDefinitions == null) {
if (other.itemDefinitions != null) {
return false;
}
} else if (!itemDefinitions.equals(other.itemDefinitions)) {
if (!itemDefinitions.equals(other.itemDefinitions)) {
return false;
}
if (objectMarker != other.objectMarker) {
return false;
}
if (superType == null) {
if (other.superType != null) {
return false;
}
} else if (!superType.equals(other.superType)) {
return false;
}
if (xsdAnyMarker != other.xsdAnyMarker) {
return false;
}
Expand Down

0 comments on commit 1b9f611

Please sign in to comment.