/** 
 * 
 * Copyright 2004 Hiram Chirino
 * 
 * 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. 
 * 
 **/
package org.activemq.ra;

import javax.resource.spi.ConnectionRequestInfo;
import java.io.Serializable;


/**
 * @version $Revision: 1.1.1.1 $
 * 
 * Must override equals and hashCode (JCA spec 16.4)
 */
public class ActiveMQConnectionRequestInfo implements ConnectionRequestInfo, Serializable, Cloneable {

    private static final long serialVersionUID = -5754338187296859149L;

    private String userName;
    private String password;
    private String serverUrl;
    private String clientid;
    private boolean useEmbeddedBroker = false;
    private String brokerXmlConfig;

    public ActiveMQConnectionRequestInfo copy() {
        try {
            return (ActiveMQConnectionRequestInfo) clone();
        }
        catch (CloneNotSupportedException e) {
            throw new RuntimeException("Could not clone: ", e);
        }
    }


    /**
     * @see javax.resource.spi.ConnectionRequestInfo#hashCode()
     */
    public int hashCode() {
        int rc = Boolean.valueOf(useEmbeddedBroker).hashCode();
//        if (userName != null) {
//            rc ^= userName.hashCode();
//        }
        if (serverUrl != null) {
            rc ^= serverUrl.hashCode();
        }
//        if (clientid != null) {
//            rc ^= clientid.hashCode();
//        }
        if (brokerXmlConfig != null) {
            rc ^= brokerXmlConfig.hashCode();
        }
        return rc;
    }


    /**
     * @see javax.resource.spi.ConnectionRequestInfo#equals(java.lang.Object)
     */
    public boolean equals(Object o) {
        if (o == null) {
            return false;
        }
        if (!getClass().equals(o.getClass())) {
            return false;
        }
        ActiveMQConnectionRequestInfo i = (ActiveMQConnectionRequestInfo) o;
//        if (userName == null ^ i.userName == null) {
//            return false;
//        }
//        if (userName != null && !userName.equals(i.userName)) {
//            return false;
//        }
        if (serverUrl == null ^ i.serverUrl == null) {
            return false;
        }
        if (serverUrl != null && !serverUrl.equals(i.serverUrl)) {
            return false;
        }
//        if (clientid == null ^ i.clientid == null) {
//            return false;
//        }
//        if (clientid != null && !clientid.equals(i.clientid)) {
//            return false;
//        }
        if (brokerXmlConfig == null ^ i.brokerXmlConfig == null) {
            return false;
        }
        if (brokerXmlConfig != null && !brokerXmlConfig.equals(i.brokerXmlConfig)) {
            return false;
        }
        if (useEmbeddedBroker != i.useEmbeddedBroker) {
            return false;
        }
        return true;
    }

    /**
     * @return Returns the url.
     */
    public String getServerUrl() {
        return serverUrl;
    }

    /**
     * @param url The url to set.
     */
    public void setServerUrl(String url) {
        this.serverUrl = url;
    }

    /**
     * @return Returns the password.
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password The password to set.
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return Returns the userid.
     */
    public String getUserName() {
        return userName;
    }

    /**
     * @param userid The userid to set.
     */
    public void setUserName(String userid) {
        this.userName = userid;
    }

    /**
     * @return Returns the clientid.
     */
    public String getClientid() {
        return clientid;
    }

    /**
     * @param clientid The clientid to set.
     */
    public void setClientid(String clientid) {
        this.clientid = clientid;
    }

    /**
     * @return Returns the name of the brokerXMLConfig file 
     */ 
    public String getBrokerXmlConfig() {
        return brokerXmlConfig;
    }

    /**
     * @param brokerXmlConfig the file name of the brokerXMLConfig file to use
     */ 
    public void setBrokerXmlConfig(String brokerXmlConfig) {
        this.brokerXmlConfig = brokerXmlConfig;
    }

    public boolean isUseEmbeddedBroker() {
        return useEmbeddedBroker;
    }

    public void setUseEmbeddedBroker(boolean useEmbeddedBroker) {
        this.useEmbeddedBroker = useEmbeddedBroker;
    }

    public String toString() {
        return "ActiveMQConnectionRequestInfo{ " +
                "brokerXmlConfig = '" + brokerXmlConfig + "' " +
                ", userName = '" + userName + "' " +
                ", serverUrl = '" + serverUrl + "' " +
                ", clientid = '" + clientid + "' " +
                ", useEmbeddedBroker = " + useEmbeddedBroker +
                " }";
    }
}
