Skip to content

Commit

Permalink
Add DOM metadata handling
Browse files Browse the repository at this point in the history
With some code cleanup, e.g. removing deprecated parts of DOM writing.

Relates to MID-6337
  • Loading branch information
mederly committed Jun 25, 2020
1 parent 10e3eb8 commit a43635d
Show file tree
Hide file tree
Showing 19 changed files with 646 additions and 621 deletions.
Expand Up @@ -25,6 +25,4 @@ public interface Hacks {

@VisibleForTesting
<T> void parseProtectedType(ProtectedDataType<T> protectedType, MapXNode xmap, PrismContext prismContext, ParsingContext pc) throws SchemaException;

Element serializeSingleElementMapToElement(MapXNode filterClauseXNode) throws SchemaException;
}
Expand Up @@ -111,7 +111,7 @@ public class PrismConstants {
public static final QName SCHEMA_APP_INFO = new QName(W3C_XML_SCHEMA_NS_URI, "appinfo");

public static final QName A_MAX_OCCURS = new QName(NS_ANNOTATION, "maxOccurs");
public static final String MULTIPLICITY_UNBONUNDED = "unbounded";
public static final String MULTIPLICITY_UNBOUNDED = "unbounded";

public static final QName A_NAMESPACE = new QName(NS_ANNOTATION, "namespace");
public static final String A_NAMESPACE_PREFIX = "prefix";
Expand Down
Expand Up @@ -119,13 +119,6 @@ public RootXNode getFilterClauseAsRootXNode() throws SchemaException {
return clause != null ? clause.getSingleSubEntryAsRoot("getFilterClauseAsRootXNode") : null;
}

public Element getFilterClauseAsElement(@NotNull PrismContext prismContext) throws SchemaException {
if (filterClauseXNode == null) {
return null;
}
return prismContext.hacks().serializeSingleElementMapToElement(filterClauseXNode);
}

public static SearchFilterType createFromParsedXNode(XNode xnode, ParsingContext pc, PrismContext prismContext) throws SchemaException {
SearchFilterType filter = new SearchFilterType();
filter.parseFromXNode(xnode, pc, prismContext);
Expand Down
Expand Up @@ -10,12 +10,10 @@
import javax.xml.namespace.QName;

import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Element;

import com.evolveum.midpoint.prism.Hacks;
import com.evolveum.midpoint.prism.ParsingContext;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.impl.lex.dom.DomLexicalProcessor;
import com.evolveum.midpoint.prism.impl.marshaller.XNodeProcessorUtil;
import com.evolveum.midpoint.prism.impl.xnode.ListXNodeImpl;
import com.evolveum.midpoint.prism.impl.xnode.MapXNodeImpl;
Expand Down Expand Up @@ -58,16 +56,6 @@ public <T> void parseProtectedType(ProtectedDataType<T> protectedType, MapXNode
XNodeProcessorUtil.parseProtectedType(protectedType, (MapXNodeImpl) xmap, prismContext, pc);
}

@Override
public Element serializeSingleElementMapToElement(MapXNode filterClauseXNode) throws SchemaException {
DomLexicalProcessor domParser = getDomParser(prismContext);
return domParser.serializeSingleElementMapToElement(filterClauseXNode);
}

private static DomLexicalProcessor getDomParser(@NotNull PrismContext prismContext) {
return ((PrismContextImpl) prismContext).getParserDom();
}

@Override
public void setXNodeType(XNode node, QName explicitTypeName, boolean explicitTypeDeclaration) {
((XNodeImpl) node).setTypeQName(explicitTypeName);
Expand Down
Expand Up @@ -49,8 +49,8 @@ public DomLexicalProcessor(@NotNull SchemaRegistry schemaRegistry) {
@Override
public RootXNodeImpl read(@NotNull ParserSource source, @NotNull ParsingContext parsingContext) throws SchemaException, IOException {
if (source instanceof ParserElementSource) {
return new DomReader(((ParserElementSource) source).getElement(), schemaRegistry)
.read();
Element root = ((ParserElementSource) source).getElement();
return new DomReader(root, schemaRegistry).read();
} else {
InputStream is = source.getInputStream();
try {
Expand Down Expand Up @@ -103,47 +103,49 @@ public boolean canRead(@NotNull String dataString) {
@NotNull
@Override
public String write(@NotNull XNode xnode, @NotNull QName rootElementName, SerializationContext serializationContext) throws SchemaException {
DomLexicalWriter writer = new DomLexicalWriter(schemaRegistry, serializationContext);
RootXNodeImpl xroot = LexicalUtils.createRootXNode((XNodeImpl) xnode, rootElementName);
Element element = writer.write(xroot);
Element element =
new DomWriter(schemaRegistry, serializationContext)
.writeRoot(xroot);
return DOMUtil.serializeDOMToString(element);
}

@NotNull
@Override
public String write(@NotNull RootXNode xnode, SerializationContext serializationContext) throws SchemaException {
DomLexicalWriter writer = new DomLexicalWriter(schemaRegistry, serializationContext);
Element element = writer.write((RootXNodeImpl) xnode);
Element element =
new DomWriter(schemaRegistry, serializationContext)
.writeRoot(xnode);
return DOMUtil.serializeDOMToString(element);
}

@NotNull
@Override
public String write(@NotNull List<RootXNodeImpl> roots, @Nullable SerializationContext context) throws SchemaException {
Element aggregateElement = writeXRootListToElement(roots);
return DOMUtil.serializeDOMToString(aggregateElement);
Element element = writeXRootListToElement(roots);
return DOMUtil.serializeDOMToString(element);
}

@NotNull
public Element writeXRootListToElement(@NotNull List<RootXNodeImpl> roots) throws SchemaException {
return new DomLexicalWriter(schemaRegistry, null)
.write(roots);
return new DomWriter(schemaRegistry, null)
.writeRoots(roots);
}

/**
* Seems to be used in strange circumstances (called from various hacks).
* To be reconsidered eventually. Avoid using in new code.
*/
@Deprecated
public Element writeXMapToElement(MapXNodeImpl xmap, QName elementName) throws SchemaException {
return new DomLexicalWriter(schemaRegistry, null)
.writeToElement(xmap, elementName);
return new DomWriter(schemaRegistry, null)
.writeMap(xmap, elementName);
}

@NotNull
public Element writeXRootToElement(@NotNull RootXNodeImpl xroot) throws SchemaException {
return new DomLexicalWriter(schemaRegistry, null)
.write(xroot);
}

public Element serializeSingleElementMapToElement(MapXNode map) throws SchemaException {
return new DomLexicalWriter(schemaRegistry, null)
.writeSingleElementMapToElement(map);
return new DomWriter(schemaRegistry, null)
.writeRoot(xroot);
}

// TODO move somewhere
Expand Down

0 comments on commit a43635d

Please sign in to comment.