Example usage for org.apache.commons.jxpath AbstractFactory AbstractFactory

List of usage examples for org.apache.commons.jxpath AbstractFactory AbstractFactory

Introduction

In this page you can find the example usage for org.apache.commons.jxpath AbstractFactory AbstractFactory.

Prototype

AbstractFactory

Source Link

Usage

From source file:org.dcm4che3.conf.core.util.ConfigNodeUtil.java

public static void replaceNode(Object rootConfigNode, String path, Object replacementConfigNode) {

    JXPathContext jxPathContext = JXPathContext.newContext(rootConfigNode);
    jxPathContext.setFactory(new AbstractFactory() {
        @Override//from   ww  w  .j ava 2s  .  c  om
        public boolean createObject(JXPathContext context, Pointer pointer, Object parent, String name,
                int index) {
            if (parent instanceof Map) {
                ((Map<String, Object>) parent).put(name, new TreeMap<String, Object>());
                return true;
            }
            return false;
        }

        @Override
        public boolean declareVariable(JXPathContext context, String name) {
            return super.declareVariable(context, name);
        }
    });
    jxPathContext.createPathAndSetValue(path, replacementConfigNode);
}