public Object replace(String uri, Object newTarget) throws Exception {
        if (uri == null) {
            // exact match
            if (starTarget == null) {
                if (target == null) {
                    throw new Exception("No target to replace at given node");
                }
                Object oldTarget = target;
                target = newTarget;
                return oldTarget;
            }
        } else {
            // skip the initial /
            int index = uri.indexOf('/', 1);
            String childName;
            String remainder = null;
            ClauseNode node;
            if (index == -1) {
                // we need to remove a leaf node
                childName = uri.substring(1);
            } else {
                // node to be removed is not a leaf node, hence propagate the call
                childName = uri.substring(1, index);
                remainder = uri.substring(index);
            }

            if (childName.equals(starString)) {
                if (starTarget == null) {
                    throw new Exception("No target to replace at given node");
                }

                Object oldTarget = target;
                target = newTarget;
                starTarget = newTarget;
                return oldTarget;
            } else {
                node = traverse(childName);
                if (node != null) {
                    return node.replace(remainder, newTarget);
                } else {
                    throw new Exception("No exact matching path found to replace");
                }
            }
        }

        return null;
    }
public Object replace ( String uri , Object newTarget ) throws Exception { if ( uri == null ) { if ( starTarget == null ) { if ( target == null ) { throw new Exception ( "No target to replace at given node" ) ; } Object oldTarget = target ; target = newTarget ; return oldTarget ; } } else { int index = uri . indexOf ( '/' , 1 ) ; String childName ; String remainder = null ; ClauseNode node ; if ( index == - 1 ) { childName = uri . substring ( 1 ) ; } else { childName = uri . substring ( 1 , index ) ; remainder = uri . substring ( index ) ; } if ( childName . equals ( starString ) ) { if ( starTarget == null ) { throw new Exception ( "No target to replace at given node" ) ; } Object oldTarget = target ; target = newTarget ; starTarget = newTarget ; return oldTarget ; } else { node = traverse ( childName ) ; if ( node != null ) { return node . replace ( remainder , newTarget ) ; } else { throw new Exception ( "No exact matching path found to replace" ) ; } } } return null ; }
@param uri
@param newTarget
@return