org.dmg.pmml.adapters.NodeAdapter Maven / Gradle / Ivy
/*
* Copyright (c) 2019 Villu Ruusmann
*/
package org.dmg.pmml.adapters;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.dmg.pmml.tree.ComplexNode;
import org.dmg.pmml.tree.DefaultNodeTransformer;
import org.dmg.pmml.tree.Node;
import org.dmg.pmml.tree.NodeTransformer;
public class NodeAdapter extends XmlAdapter {
@Override
public Node unmarshal(ComplexNode value){
NodeTransformer nodeTransformer = NodeAdapter.NODE_TRANSFORMER_PROVIDER.get();
return nodeTransformer.fromComplexNode(value);
}
@Override
public ComplexNode marshal(Node node){
NodeTransformer nodeTransformer = NodeAdapter.NODE_TRANSFORMER_PROVIDER.get();
return nodeTransformer.toComplexNode(node);
}
public static final ThreadLocal NODE_TRANSFORMER_PROVIDER = new ThreadLocal(){
@Override
protected NodeTransformer initialValue(){
return DefaultNodeTransformer.INSTANCE;
}
};
}