All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.addc.commons.slp.messages.ServiceDeregistration Maven / Gradle / Ivy

Go to download

The addc-slp library supplies client classes for registering objects with a Service Location Protocol Daemon and for looking theses objects up later.

There is a newer version: 2.6
Show newest version
package com.addc.commons.slp.messages;

import java.io.DataOutputStream;
import java.io.IOException;

import com.addc.commons.slp.SLPConstants;
import com.addc.commons.slp.ServiceURL;
import com.addc.commons.slp.configuration.SLPConfig;

/**
 * The ServiceDeregistration SLP Message.
 */
public class ServiceDeregistration extends SLPMessage {
    private final ServiceURL serviceUrl;
    private final String scopes;

    /**
     * Create a new ServiceDeregistration
     * 
     * @param config
     *            The configuration to use
     * @param serviceUrl
     *            The ServiceURL to use
     */
    public ServiceDeregistration(SLPConfig config, ServiceURL serviceUrl) {
        super(config, SLPConstants.SRVDEREG);
        this.serviceUrl= serviceUrl;
        this.scopes= config.getScopes();
    }

    @Override
    protected void writeBody(DataOutputStream out) throws IOException {
        out.writeUTF(scopes);
        serviceUrl.writeExternal(out); // url entry
        out.writeShort(0); // length of tag list
    }

    @Override
    public int calcSize() {
        return 4 + scopes.length() + serviceUrl.calcSize();
    }

    @Override
    public int hashCode() {
        final int prime= 31;
        int result= super.hashCode();
        result= prime * result + scopes.hashCode();
        result= prime * result + serviceUrl.hashCode();
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof ServiceDeregistration)) {
            return false;
        }
        ServiceDeregistration other= (ServiceDeregistration) obj;
        return (super.equals(obj) && scopes.equals(other.scopes) && serviceUrl.equals(other.serviceUrl));
    }

    @Override
    public String toString() {
        StringBuilder builder= new StringBuilder();
        builder.append("ServiceDeregistration [");
        builder.append(super.toString());
        builder.append(", serviceUrl=");
        builder.append(serviceUrl);
        builder.append(", scopes=");
        builder.append(scopes);
        builder.append(']');
        return builder.toString();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy