org.dmg.pmml.adapters.NodeAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pmml-model-gwt Show documentation
Show all versions of pmml-model-gwt Show documentation
JPMML GWT compatible class model
/*
* Copyright (c) 2019 Villu Ruusmann
*/
package org.dmg.pmml.adapters;
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import org.dmg.pmml.tree.ComplexNode;
import org.dmg.pmml.tree.Node;
import org.dmg.pmml.tree.NodeTransformer;
import org.dmg.pmml.tree.SimplifyingNodeTransformer;
/**
* @see NodeTransformer
*/
public class NodeAdapter extends XmlAdapter {
@Override
public Node unmarshal(ComplexNode value){
NodeTransformer nodeTransformer = NodeAdapter.NODE_TRANSFORMER_PROVIDER.get();
if(nodeTransformer != null){
return nodeTransformer.fromComplexNode(value);
}
return value;
}
@Override
public ComplexNode marshal(Node node){
NodeTransformer nodeTransformer = NodeAdapter.NODE_TRANSFORMER_PROVIDER.get();
if(nodeTransformer != null){
return nodeTransformer.toComplexNode(node);
}
return node.toComplexNode();
}
public static final ThreadLocal NODE_TRANSFORMER_PROVIDER = new ThreadLocal(){
@Override
public NodeTransformer initialValue(){
return SimplifyingNodeTransformer.INSTANCE;
}
};
}