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

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

/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed 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.
*
* CVS $Id: CreateCollection.java,v 1.6 2004/02/08 02:54:17 vgritsenko Exp $
*/

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

import org.apache.xindice.core.CollectionManager;
import org.apache.xindice.server.rpc.RPCDefaultMessage;
import org.apache.xindice.util.Configuration;
import org.apache.xindice.xml.dom.DOMParser;
import org.apache.xindice.xml.dom.DocumentImpl;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import java.util.Hashtable;

/**
*
* @version CVS $Revision: 1.6 $, $Date: 2004/02/08 02:54:17 $
*/
public class CreateCollection extends RPCDefaultMessage {

    public Hashtable execute(Hashtable message) throws Exception {

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

        if (!message.containsKey(CONFIGURATION) && !message.containsKey(NAME)) {
            throw new Exception(MISSING_CONFIGURATION_PARAM);
        }

        Document doc;
        // Handle the case where we're getting an entire configuration document.
        if (message.containsKey(CONFIGURATION)) {
            doc = DOMParser.toDocument((String) message.get(CONFIGURATION));
            if (doc == null) {
                throw new Exception("Unable to parse Collection configuration");
            }
        }
        // Otherwise we need to build the configuration from the name and pattern.
        else {
            // FIXME Use default config defined somewhere else
            doc = new DocumentImpl();

            Element colEle = doc.createElement("collection");
            colEle.setAttribute("compressed", "true");
            colEle.setAttribute("name", (String) message.get(NAME));
            doc.appendChild(colEle);

            Element filEle = doc.createElement("filer");
            filEle.setAttribute("class", "org.apache.xindice.core.filer.BTreeFiler");
            colEle.appendChild(filEle);
        }

        CollectionManager colman = getCollection((String) message.get(COLLECTION));

        Configuration config = new Configuration(doc.getDocumentElement(), false);
        colman.createCollection((String) message.get(NAME), config);

        Hashtable result = new Hashtable();
        result.put(RESULT, message.get(NAME));
        return result;
    }
}
TOP

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

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.