Skip to content

Commit

Permalink
Move ParsingContextImpl to prism-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Nov 17, 2018
1 parent 16fc75b commit fcd4faa
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +35,27 @@ public class ParsingContextImpl implements ParsingContext {
ParsingContextImpl() {
}

static ParsingContext allowMissingRefTypes() {
ParsingContextImpl pc = new ParsingContextImpl();
pc.setAllowMissingRefTypes(true);
return pc;
}


public static ParsingContext createForCompatibilityMode() {
return forMode(XNodeProcessorEvaluationMode.COMPAT);
}

static ParsingContext forMode(XNodeProcessorEvaluationMode mode) {
ParsingContextImpl pc = new ParsingContextImpl();
pc.setEvaluationMode(mode);
return pc;
}

public static ParsingContext createDefault() {
return new ParsingContextImpl();
}

@SuppressWarnings("SameParameterValue")
void setAllowMissingRefTypes(boolean allowMissingRefTypes) {
this.allowMissingRefTypes = allowMissingRefTypes;
Expand Down
Expand Up @@ -510,4 +510,19 @@ public boolean relationMatches(QName relationQuery, QName relation) {
public boolean relationMatches(@NotNull List<QName> relationQuery, QName relation) {
return relationQuery.stream().anyMatch(rq -> relationMatches(rq, relation));
}

@Override
public ParsingContext getDefaultParsingContext() {
return ParsingContextImpl.createDefault();
}

@Override
public ParsingContext createParsingContextForAllowMissingRefTypes() {
return ParsingContextImpl.allowMissingRefTypes();
}

@Override
public ParsingContext createParsingContextForCompatibilityMode() {
return ParsingContextImpl.createForCompatibilityMode();
}
}
Expand Up @@ -494,7 +494,7 @@ private <C extends Containerable> RefFilter parseRefFilter(MapXNode clauseXMap,
Item<?,?> item = prismContext.parserFor(valueRoot)
.name(itemName)
.definition(itemDefinition)
.context(ParsingContext.allowMissingRefTypes())
.context(prismContext.createParsingContextForAllowMissingRefTypes())
.parseItem();
if (!(item instanceof PrismReference)) {
throw new IllegalStateException("Expected PrismReference, got " + item);
Expand Down Expand Up @@ -688,7 +688,7 @@ private Item parseItem(RootXNode root, QName itemName, ItemDefinition itemDefini
item = prismContext.parserFor(root)
.name(itemName)
.definition(itemDefinition)
.context(ParsingContext.allowMissingRefTypes())
.context(prismContext.createParsingContextForAllowMissingRefTypes())
.parseItem();

if (item.getValues().size() < 1 ) {
Expand Down
Expand Up @@ -16,11 +16,9 @@

package com.evolveum.midpoint.prism;

import com.evolveum.midpoint.prism.marshaller.XNodeProcessorEvaluationMode;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -30,24 +28,6 @@ public interface ParsingContext extends Cloneable {

boolean isAllowMissingRefTypes();

XNodeProcessorEvaluationMode getEvaluationMode();

static ParsingContext forMode(XNodeProcessorEvaluationMode mode) {
ParsingContextImpl pc = new ParsingContextImpl();
pc.setEvaluationMode(mode);
return pc;
}

static ParsingContext allowMissingRefTypes() {
ParsingContextImpl pc = new ParsingContextImpl();
pc.setAllowMissingRefTypes(true);
return pc;
}

static ParsingContext createDefault() {
return new ParsingContextImpl();
}

boolean isCompat();

boolean isStrict();
Expand Down
Expand Up @@ -291,4 +291,9 @@ <C extends Containerable, O extends Objectable> void adopt(PrismContainerValue<C
*/
boolean relationMatches(@NotNull List<QName> relationQuery, QName relation);

ParsingContext getDefaultParsingContext();

ParsingContext createParsingContextForAllowMissingRefTypes();

ParsingContext createParsingContextForCompatibilityMode();
}
Expand Up @@ -510,7 +510,7 @@ private <T extends ObjectType> PrismObject<T> updateLoadedObject(GetObjectResult
PrismObject<T> prismObject;
try {
// "Postel mode": be tolerant what you read. We need this to tolerate (custom) schema changes
ParsingContext parsingContext = ParsingContext.forMode(XNodeProcessorEvaluationMode.COMPAT);
ParsingContext parsingContext = prismContext.createParsingContextForCompatibilityMode();
prismObject = prismContext.parserFor(xml).context(parsingContext).parse();
if (parsingContext.hasWarnings()) {
LOGGER.warn("Object {} parsed with {} warnings", ObjectTypeUtil.toShortString(prismObject), parsingContext.getWarnings().size());
Expand Down

0 comments on commit fcd4faa

Please sign in to comment.