/*
 *  Copyright (C) 2011 The Animo Project
 *  http://animotron.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 3
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.animotron.exist.interpreter;

/**
 * @author <a href="mailto:shabanovd@gmail.com">Dmitriy Shabanov</a>
 *
 */
public class Controller {

}

@@ -844,113 +844,1294 @@
 r;%0A%0A
-/**%0A * @author %3Ca href=%22mailto:shabanovd@gmail.com%22%3EDmitriy Shabanov%3C/a%3E%0A *%0A */%0Apublic class Controller %7B%0A
+import org.animotron.exist.index.AnimoIndex;%0Aimport org.animotron.exist.index.AnimoIndexWorker;%0Aimport org.exist.Database;%0Aimport org.exist.dom.NewArrayNodeSet;%0Aimport org.exist.dom.NodeProxy;%0Aimport org.exist.dom.NodeSet;%0A%0A/**%0A * @author %3Ca href=%22mailto:shabanovd@gmail.com%22%3EDmitriy Shabanov%3C/a%3E%0A *%0A */%0Apublic class Controller %7B%0A%0A%09private Database db;%0A%09%0A%09public Controller(Database db) %7B%0A%09%09this.db = db;%0A%09%7D%0A%09%0A%09public AnimoIndexWorker getIndexWorker() %7B%0A        return (AnimoIndexWorker) db.getActiveBroker().getIndexController().getWorkerByIndexId(AnimoIndex.ID);%0A%09%7D%0A%0A%09public NodeSet getUse(NodeSet set) %7B%0A%09%09//XXX: code%0A//      let $query := concat(%22unordered($CONTEXT/%22, local:name-sequence($is, %22descendant-or-self::use%22), %22)%22)%0A//      let $use   := local:eval-query($query, (), $context, ())%0A%09%09return set;%0A%09%7D%0A%09%0A%09//TODO: write tests%0A%09public NodeSet preferedUse(NodeSet is) %7B%0A%09%09if (is.isEmpty())%0A%09%09%09return NodeSet.EMPTY_SET;%0A%09%09%0A%09%09NodeSet result = new NewArrayNodeSet();%0A%09%09%0A%09%09NodeSet use = getUse(is);%0A%09%09for (NodeProxy node : use) %7B%0A%09%09%09NodeSet useIS = getIndexWorker().resolveDownIsLogic(node);%0A%0A%09%09%09if (useIS.isEmpty())%0A%09%09%09%09continue;%0A%09%09%09%0A%09%09%09NodeSet res = use.intersection(useIS);%0A%09%09%09%0A%09%09%09if (res.isEmpty())%0A%09%09%09%09result.add(node);%0A%09%09%09else%0A%09%09%09%09result.addAll(res);%0A%09%09%7D%0A%09%09%0A%09%09return result;%0A%09%7D
 %0A%7D%0A

implement "preferedUse"