//   Copyright 2012 Georg-August-Universität Göttingen, Germany
//
//   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 de.ugoe.cs.autoquest.plugin.php.eventcore;

import de.ugoe.cs.autoquest.eventcore.IEventTarget;

/**
 * <p>
 * Event target for PHP web requests.
 * </p>
 * 
 * @version $Revision: $ $Date: Aug 16, 2012$
 * @author 2012, last modified by $Author: sherbold$
 */
public class PHPEventTarget implements IEventTarget {

    /**
     * <p>
     * Id for object serialization.
     * </p>
     */
    private static final long serialVersionUID = 1L;

    /**
     * <p>
     * Path of the PHP request.
     * </p>
     */
    private String path;

    /**
     * <p>
     * Constructor. Creates a new PHP event target as the path of the request.
     * </p>
     * 
     * @param path
     *            path of the URI of the event
     */
    public PHPEventTarget(String path) {
        this.path = path;
    }

    /*
     * (non-Javadoc)
     * 
     * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform()
     */
    @Override
    public String getPlatform() {
        return "PHP";
    }

    @Override
    public String getStringIdentifier() {
        return this.toString();
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return path;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#equals()
     */
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof PHPEventTarget) {
            if (path != null) {
                return path.equals(((PHPEventTarget) obj).path);
            }
            else {
                return ((PHPEventTarget) obj).path == null;
            }
        }
        return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        int hash = 3;
        if (path != null) {
            hash = path.hashCode();
        }
        return hash;
    }

}
