/* $Id: RabbitmqConfig.java 988245 2010-08-23 18:39:35Z kwright $ */

/**
 * 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.
 */
package org.apache.manifoldcf.agents.output.rabbitmq;

import org.apache.manifoldcf.core.interfaces.ConfigParams;
import org.apache.manifoldcf.core.interfaces.IPostParameters;
import org.apache.manifoldcf.agents.system.Logging;

public class RabbitmqConfig {
    public static final String hostParameter = "host";
    public static final String portParameter = "port";
    public static final String queueParameter = "queue";
    public static final String durableParameter = "durable";
    public static final String autoDeleteParameter = "autodelete";
    public static final String exclusiveParameter = "exclusive";
    public static final String transactionParameter = "transaction";

    private String queueName = "manifoldcf";
    private String host = "localhost";
    private int port = 5672;

    private boolean durable = true;
    private boolean exclusive = false;
    private boolean autoDelete = false;
    private boolean useTransactions = false;


    RabbitmqConfig(ConfigParams configParams) {
        this.host = configParams.getParameter(hostParameter);
        // TODO: this.port = configParams.get
        this.queueName = configParams.getParameter(queueParameter);
        extractAutoDeleteParameter(configParams);
        extractExclusiveParameter(configParams);
        extractDurableParameter(configParams);
    }

    public static void contextToConfig(IPostParameters variableContext, ConfigParams parameters) {

        String host = variableContext.getParameter(hostParameter);

        if (host != null) {
            parameters.setParameter(hostParameter, host);
        }

        String port = variableContext.getParameter(portParameter);

        if (port != null) {
            parameters.setParameter(portParameter, port);
        }

        String queue = variableContext.getParameter(queueParameter);

        if (queue != null) {
            parameters.setParameter(queueParameter, queue);
        }

        String _autodelete = variableContext.getParameter(autoDeleteParameter);

        if (_autodelete != null) {
            parameters.setParameter(autoDeleteParameter, _autodelete);
        }

        String _durable = variableContext.getParameter(durableParameter);

        if (_durable != null) {
            parameters.setParameter(durableParameter, _durable);
        }

        String _exclusive = variableContext.getParameter(_durable);

        if (_exclusive != null) {
            parameters.setParameter(exclusiveParameter, _exclusive);
        }
    }

    private void extractAutoDeleteParameter(ConfigParams variableContext) {

        String _active = variableContext.getParameter(autoDeleteParameter);

        if (_active != null) {
            this.autoDelete = Boolean.parseBoolean(_active);
            Logging.connectors.debug("Channel parameter active set to " + this.autoDelete);
        }
        else {
            this.autoDelete = false;

            Logging.connectors.debug("Channel parameter active parameter not set, defaults to " + this.autoDelete);
        }
    }

    private void extractDurableParameter(ConfigParams variableContext) {

        String _durable = variableContext.getParameter(durableParameter);

        if (_durable != null) {
            this.durable = Boolean.parseBoolean(_durable);
            Logging.connectors.debug("Channel parameter durable set to " + this.durable);
        }
        else {
            this.autoDelete = true;

            Logging.connectors.debug("Channel parameter durable parameter not set, defaults to " + this.durable);
        }
    }

    private void extractExclusiveParameter(ConfigParams variableContext) {

        String _exclusive = variableContext.getParameter(exclusiveParameter);

        if (_exclusive != null) {
            this.exclusive = Boolean.parseBoolean(_exclusive);

            Logging.connectors.debug("Channel parameter exclusive set to " + this.exclusive);
        }
        else {
            this.exclusive = false;

            Logging.connectors.debug("Channel parameter exclusive parameter not set, defaults to " + this.exclusive);
        }
    }

    public String getQueueName() {
        return queueName;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public boolean isDurable() {
        return durable;
    }

    public boolean isExclusive() {
        return exclusive;
    }

    public boolean isAutoDelete() {
        return autoDelete;
    }

    public boolean isUseTransactions() {
        return useTransactions;
    }
}

@@ -1065,22 +1065,23 @@
 ifoldcf.
-agents
+crawler
 .system.

fix logging problem