Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/mid-9278-an…
Browse files Browse the repository at this point in the history
…notations-review
  • Loading branch information
1azyman committed Nov 3, 2023
2 parents 5a16026 + bdcbea9 commit b99ea91
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ public static <T> boolean containsValue(
return false;
}

public static <T> Collection<PrismPropertyValue<T>> createCollection(PrismContext prismContext,
Collection<T> realValueCollection) {
public static <T> Collection<PrismPropertyValue<T>> createCollection(Collection<T> realValueCollection) {
Collection<PrismPropertyValue<T>> pvalCol = new ArrayList<>(realValueCollection.size());
for (T realValue: realValueCollection) {
pvalCol.add(prismContext.itemFactory().createPropertyValue(realValue));
pvalCol.add(PrismContext.get().itemFactory().createPropertyValue(realValue));
}
return pvalCol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ class DomToSchemaPostProcessor {

private static final Trace LOGGER = TraceManager.getTrace(DomToSchemaPostProcessor.class);


private static final String ENUMERATION = "enumeration";


private final XSSchemaSet xsSchemaSet;
private final PrismContext prismContext;
private MutablePrismSchema schema;
Expand Down Expand Up @@ -89,7 +87,9 @@ private boolean isMyNamespace(QName qname) {
/**
* Main entry point.
*/
void postprocessSchema(MutablePrismSchema prismSchema, boolean isRuntime, boolean allowDelayedItemDefinitions, String shortDescription) throws SchemaException {
void postprocessSchema(
MutablePrismSchema prismSchema, boolean isRuntime, boolean allowDelayedItemDefinitions, String shortDescription)
throws SchemaException {
this.schema = prismSchema;
this.isRuntime = isRuntime;
this.allowDelayedItemDefinitions = allowDelayedItemDefinitions;
Expand Down Expand Up @@ -153,25 +153,22 @@ private ComplexTypeDefinition processComplexTypeDefinition(XSComplexType complex
throws SchemaException {

SchemaDefinitionFactory definitionFactory = getDefinitionFactory();
MutableComplexTypeDefinition ctd = definitionFactory.createComplexTypeDefinition(complexType, prismContext, complexType.getAnnotation());
MutableComplexTypeDefinition ctd = definitionFactory.createComplexTypeDefinition(
complexType, prismContext, complexType.getAnnotation());

ComplexTypeDefinition existingComplexTypeDefinition = schema.findComplexTypeDefinitionByType(ctd.getTypeName());
if (existingComplexTypeDefinition != null) {
// We already have this in schema. So avoid redundant work and
// infinite loops;
// We already have this in schema. So avoid redundant work and infinite loops.
return existingComplexTypeDefinition;
}
// Add to the schema right now to avoid loops - even if it is not
// complete yet
// The definition may reference itself
// Add to the schema right now to avoid loops - even if it is not complete yet. The definition may reference itself.
schema.add(ctd);

XSContentType content = complexType.getContentType();
XSContentType explicitContent = complexType.getExplicitContent();
if (content != null) {
XSParticle particle = content.asParticle();


// We need this in order for properly distinguish between containers and plain complex types
if (isPropertyContainer(complexType)) {
ctd.setContainerMarker(true);
Expand All @@ -192,11 +189,11 @@ private ComplexTypeDefinition processComplexTypeDefinition(XSComplexType complex
XSAnnotation annotation = complexType.getAnnotation();
Element extensionAnnotationElement = SchemaProcessorUtil.getAnnotationElement(annotation, A_EXTENSION);
if (extensionAnnotationElement != null) {
QName extensionType = DOMUtil.getQNameAttribute(extensionAnnotationElement,
A_EXTENSION_REF.getLocalPart());
QName extensionType = DOMUtil.getQNameAttribute(extensionAnnotationElement, A_EXTENSION_REF.getLocalPart());
if (extensionType == null) {
throw new SchemaException("The " + A_EXTENSION + "annotation on " + ctd.getTypeName()
+ " complex type does not have " + A_EXTENSION_REF.getLocalPart() + " attribute",
throw new SchemaException(
"The %s annotation on %s complex type does not have %s attribute".formatted(
A_EXTENSION, ctd.getTypeName(), A_EXTENSION_REF.getLocalPart()),
A_EXTENSION_REF);
}
ctd.setContainerMarker(true);
Expand Down Expand Up @@ -236,7 +233,6 @@ private ComplexTypeDefinition processComplexTypeDefinition(XSComplexType complex
if (isAny(complexType, Optional.of(XSWildcard.STRTICT))) {
ctd.setStrictAnyMarker(true);
}

}

if (isList(complexType)) {
Expand All @@ -249,42 +245,28 @@ private ComplexTypeDefinition processComplexTypeDefinition(XSComplexType complex
ctd.setCompileTimeClass(compileTimeClass);
schema.registerCompileTimeClass(compileTimeClass, ctd);

definitionFactory.finishComplexTypeDefinition(ctd, complexType, prismContext,
complexType.getAnnotation());

// Attempt to create object or container definition from this complex
// type

PrismContainerDefinition<?> defFromComplexType = getDefinitionFactory()
.createExtraDefinitionFromComplexType(complexType, ctd, prismContext,
complexType.getAnnotation());

if (defFromComplexType != null) {
markRuntime(defFromComplexType);
schema.add(defFromComplexType);
}
definitionFactory.finishComplexTypeDefinition(
ctd, complexType, prismContext, complexType.getAnnotation());

parseAttributes(ctd, complexType);

return ctd;

}

private void parseAttributes(MutableComplexTypeDefinition ctd, XSComplexType complexType) throws SchemaException {
// TODO Auto-generated method stub
List<PrismPropertyDefinition<?>> definitions = new ArrayList<>();
for(XSAttributeUse attributeUse : complexType.getAttributeUses()) {
for (XSAttributeUse attributeUse : complexType.getAttributeUses()) {

var attributeDecl = attributeUse.getDecl();
ItemName name = new ItemName(ctd.getTypeName().getNamespaceURI(), attributeDecl.getName());
QName type = getType(attributeDecl.getType());
var attributeDef = getDefinitionFactory().createPropertyDefinition(name, type, null, prismContext, null, null);
var attributeDef = getDefinitionFactory().createPropertyDefinition(
name, type, null, prismContext, null, null);
attributeDef.toMutable().setMinOccurs(0);
attributeDef.toMutable().setMaxOccurs(1);
definitions.add(attributeDef);
}
ctd.setAttributeDefinitions(definitions);

}

private void setInstantiationOrder(MutableTypeDefinition typeDefinition, XSAnnotation annotation) throws SchemaException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ class DomToSchemaProcessor {
/**
* Parses single schema.
*/
void parseSchema(@NotNull PrismSchemaImpl prismSchema, @NotNull Element xsdSchema, boolean isRuntime,
boolean allowDelayedItemDefinitions, String shortDescription) throws SchemaException {
void parseSchema(
@NotNull PrismSchemaImpl prismSchema,
@NotNull Element xsdSchema,
boolean isRuntime,
boolean allowDelayedItemDefinitions,
String shortDescription) throws SchemaException {
this.shortDescription = shortDescription;
XSSchemaSet xsSchemaSet = parseSchema(xsdSchema);
if (xsSchemaSet == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,14 @@ public void parseThis(Element element, boolean isRuntime, String shortDescriptio
parse(element, ((PrismContextImpl) prismContext).getEntityResolver(), this, isRuntime, shortDescription, false, prismContext);
}

private static PrismSchema parse(Element element, EntityResolver resolver, PrismSchemaImpl schema, boolean isRuntime,
String shortDescription, boolean allowDelayedItemDefinitions, PrismContext prismContext) throws SchemaException {
private static PrismSchema parse(
Element element,
EntityResolver resolver,
PrismSchemaImpl schema,
boolean isRuntime,
String shortDescription,
boolean allowDelayedItemDefinitions,
PrismContext prismContext) throws SchemaException {
if (element == null) {
throw new IllegalArgumentException("Schema element must not be null in " + shortDescription);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,6 @@ public <T extends Objectable> PrismObjectDefinitionImpl<T> createObjectDefinitio
return new PrismObjectDefinitionImpl<>(elementName, complexTypeDefinition, compileTimeClass);
}

/**
* Create optional extra definition form a top-level complex type definition.
* This is used e.g. to create object class definitions in midPoint
*/
public <C extends Containerable> PrismContainerDefinition<C> createExtraDefinitionFromComplexType(XSComplexType complexType,
ComplexTypeDefinition complexTypeDefinition, PrismContext prismContext,
XSAnnotation annotation) throws SchemaException {
// Create nothing by default
return null;
}

/**
* Called after the complex type definition is filled with items. It may be used to finish building
* the definition, e.g. by adding data that depends on existing internal definitions.
Expand Down
10 changes: 10 additions & 0 deletions infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,16 @@ public static <T> T getFirstNonNull(T... values) {
return null;
}

@SafeVarargs
public static @NotNull <T> T getFirstNonNullRequired(T... values) {
for (T value : values) {
if (value != null) {
return value;
}
}
throw new IllegalStateException("All values are null");
}

// TODO better name
public static <T> T getFirstNonNullFromList(List<T> values) {
for (T value : values) {
Expand Down

0 comments on commit b99ea91

Please sign in to comment.