FileDocCategorySizeDatePackage
Host.javaAPI DocExample4910Sun Jul 07 09:43:06 BST 2002javajaxb.generated.config

Host.java

package javajaxb.generated.config;

import java.io.IOException;
import java.io.InputStream;
import javax.xml.bind.Dispatcher;
import javax.xml.bind.DuplicateAttributeException;
import javax.xml.bind.Element;
import javax.xml.bind.InvalidAttributeException;
import javax.xml.bind.LocalValidationException;
import javax.xml.bind.MarshallableObject;
import javax.xml.bind.Marshaller;
import javax.xml.bind.MissingAttributeException;
import javax.xml.bind.StructureValidationException;
import javax.xml.bind.UnmarshalException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.Validator;
import javax.xml.marshal.XMLScanner;
import javax.xml.marshal.XMLWriter;


public class Host
    extends MarshallableObject
    implements Element
{

    private String _Hostname;
    private String _Port;

    public String getHostname() {
        return _Hostname;
    }

    public void setHostname(String _Hostname) {
        this._Hostname = _Hostname;
        if (_Hostname == null) {
            invalidate();
        }
    }

    public String getPort() {
        return _Port;
    }

    public void setPort(String _Port) {
        this._Port = _Port;
        if (_Port == null) {
            invalidate();
        }
    }

    public void validateThis()
        throws LocalValidationException
    {
        if (_Hostname == null) {
            throw new MissingAttributeException("hostname");
        }
        if (_Port == null) {
            throw new MissingAttributeException("port");
        }
    }

    public void validate(Validator v)
        throws StructureValidationException
    {
    }

    public void marshal(Marshaller m)
        throws IOException
    {
        XMLWriter w = m.writer();
        w.start("host");
        w.attribute("hostname", _Hostname.toString());
        w.attribute("port", _Port.toString());
        w.end("host");
    }

    public void unmarshal(Unmarshaller u)
        throws UnmarshalException
    {
        XMLScanner xs = u.scanner();
        Validator v = u.validator();
        xs.takeStart("host");
        while (xs.atAttribute()) {
            String an = xs.takeAttributeName();
            if (an.equals("hostname")) {
                if (_Hostname!= null) {
                    throw new DuplicateAttributeException(an);
                }
                _Hostname = xs.takeAttributeValue();
                continue;
            }
            if (an.equals("port")) {
                if (_Port!= null) {
                    throw new DuplicateAttributeException(an);
                }
                _Port = xs.takeAttributeValue();
                continue;
            }
            throw new InvalidAttributeException(an);
        }
        xs.takeEnd("host");
    }

    public static Host unmarshal(InputStream in)
        throws UnmarshalException
    {
        return unmarshal(XMLScanner.open(in));
    }

    public static Host unmarshal(XMLScanner xs)
        throws UnmarshalException
    {
        return unmarshal(xs, newDispatcher());
    }

    public static Host unmarshal(XMLScanner xs, Dispatcher d)
        throws UnmarshalException
    {
        return ((Host) d.unmarshal(xs, (Host.class)));
    }

    public boolean equals(Object ob) {
        if (this == ob) {
            return true;
        }
        if (!(ob instanceof Host)) {
            return false;
        }
        Host tob = ((Host) ob);
        if (_Hostname!= null) {
            if (tob._Hostname == null) {
                return false;
            }
            if (!_Hostname.equals(tob._Hostname)) {
                return false;
            }
        } else {
            if (tob._Hostname!= null) {
                return false;
            }
        }
        if (_Port!= null) {
            if (tob._Port == null) {
                return false;
            }
            if (!_Port.equals(tob._Port)) {
                return false;
            }
        } else {
            if (tob._Port!= null) {
                return false;
            }
        }
        return true;
    }

    public int hashCode() {
        int h = 0;
        h = ((127 *h)+((_Hostname!= null)?_Hostname.hashCode(): 0));
        h = ((127 *h)+((_Port!= null)?_Port.hashCode(): 0));
        return h;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer("<<host");
        if (_Hostname!= null) {
            sb.append(" hostname=");
            sb.append(_Hostname.toString());
        }
        if (_Port!= null) {
            sb.append(" port=");
            sb.append(_Port.toString());
        }
        sb.append(">>");
        return sb.toString();
    }

    public static Dispatcher newDispatcher() {
        return Connection.newDispatcher();
    }

}