Package org.apache.xindice.server.rpc.messages

Source Code of org.apache.xindice.server.rpc.messages.Query

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: Query.java 513096 2007-03-01 01:41:53Z vgritsenko $
*/

package org.apache.xindice.server.rpc.messages;

import org.apache.xindice.core.Collection;
import org.apache.xindice.core.data.NodeSet;
import org.apache.xindice.core.query.QueryUtil;
import org.apache.xindice.server.rpc.RPCDefaultMessage;
import org.apache.xindice.xml.NamespaceMap;

import java.util.Hashtable;

/**
* Executes a query against a document or collection
*
* @version $Revision: 513096 $, $Date: 2007-02-28 20:41:53 -0500 (Wed, 28 Feb 2007) $
*/
public class Query extends RPCDefaultMessage {

    public Hashtable execute(Hashtable message) throws Exception {

        if (!message.containsKey(COLLECTION)) {
            throw new Exception(MISSING_COLLECTION_PARAM);
        }

        final String type = (String) message.get(TYPE);
        if (type == null) {
            throw new Exception(MISSING_TYPE_PARAM);
        }

        final String query = (String) message.get(QUERY);
        if (query == null) {
            throw new Exception(MISSING_QUERY_PARAM);
        }

        Collection col = getCollection((String) message.get(COLLECTION));
        NamespaceMap nsMap = QueryUtil.mapNamespaces((Hashtable) message.get(NAMESPACES));

        NodeSet ns;
        if (message.containsKey(NAME)) {
            ns = col.queryDocument(type, query, nsMap, message.get(NAME));
        } else {
            ns = col.queryCollection(type, query, nsMap);
        }

        Hashtable result = new Hashtable();
        result.put(RESULT, QueryUtil.queryResultsToString(ns));
        return result;
    }
}
TOP

Related Classes of org.apache.xindice.server.rpc.messages.Query

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.