⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profileadv.java

📁 基于jxta的局域网P2P文件共享,可以实现局域网中的文件p2p共享,实现文件快速传输及交流
💻 JAVA
字号:
package connex.core.Presence;


/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */

import org.apache.log4j.Logger;

import net.jxta.document.*;
import net.jxta.id.*;

import net.jxta.peer.*;
import java.net.URI;
import net.jxta.protocol.PeerAdvertisement;
import java.io.Serializable;

public class ProfileAdv extends Advertisement implements Serializable {
    private final static Logger LOG = org.apache.log4j.Logger.getLogger(
            ProfileAdv.class.getName());

    static {
        net.jxta.document.AdvertisementFactory.registerAdvertisementInstance(
                getAdvertisementType(), new ProfileAdv.Instantiator());
    }

    private static final String advertisementType =
            "ConneX:ProfileAdvertisement";
    public static final String nameKey = "name";

    public static final String userIDKey = "userID";
    public static final String emailKey = "email";
    public static final String mobilityKey = "mobility";
    public static final String speedKey = "speed";
    public static final String counteryKey = "countery";
    public static final String cityKey = "city";
    public static final String languageKey = "language";
    public static final String otherKey = "other";
    public static final String[] indexFields = new String[] {userIDKey, emailKey,
                                               nameKey};
    /**
     * Last update to detail presense data
     */
    static final String lastUpdateKey = "lastUpdate";

    //Mobility


    private String name; // name/nickname of the user
    private String email; // An email of the user for validation
    private String userID; // ID in the Workspace.
    private String speed; // fast or dialup
    private String mobility; // desktop, portable
    private String countery; // countery
    private String city;
    private String language;
    private String other; // Misc data
    private String lastUpdate; // long int of date that represents last time a related profile was updated

    public static final class Instantiator implements net.jxta.document.
            AdvertisementFactory.Instantiator {
        /**
         *  {@inheritDoc}
         **/
        public String getAdvertisementType() {
            return ProfileAdv.getAdvertisementType();
        }

        /**
         *  {@inheritDoc}
         **/
        public Advertisement newInstance() {
            return new ProfileAdv();
        }

        /**
         *  {@inheritDoc}
         **/
        public Advertisement newInstance(Element element) {
            ProfileAdv adv = new ProfileAdv();

            Element elem = (Element) element.getChildren(nameKey).nextElement();

            if (elem != null && elem.getValue() != null) {
                adv.setName(elem.getValue().toString());
            }
            elem = (Element) element.getChildren(speedKey).nextElement();
            if (elem != null && elem.getValue() != null) {
                adv.setSpeed(elem.getValue().toString());
            }
            elem = (Element) element.getChildren(mobilityKey).nextElement();
            if (elem != null && elem.getValue() != null) {
                adv.setMobility(elem.getValue().toString());
            }
            elem = (Element) element.getChildren(counteryKey).nextElement();
            if (elem != null && elem.getValue() != null) {
                adv.setCountery(elem.getValue().toString());
            }
            elem = (Element) element.getChildren(languageKey).nextElement();
            if (elem != null && elem.getValue() != null) {
                adv.setLanguage(elem.getValue().toString());
            }

            elem = (Element) element.getChildren(cityKey).nextElement();
            if (elem != null && elem.getValue() != null) {
                adv.setLanguage(elem.getValue().toString());
            }

            elem = (Element) element.getChildren(otherKey).nextElement();
            if (elem != null && elem.getValue() != null) {
                adv.setOther(elem.getValue().toString());
            }
            elem = (Element) element.getChildren(emailKey).nextElement();
            if (elem != null && elem.getValue() != null) {
                adv.setEmail(elem.getValue().toString());
            }
            elem = (Element) element.getChildren(userIDKey).nextElement();
            if (elem != null && elem.getValue() != null) {
                adv.setuserID(elem.getValue().toString());
            }
            /*elem = (Element) element.getChildren(lastUpdateKey).nextElement();
            if (elem != null && elem.getValue() != null) {
                adv.setLastUpdate(elem.getValue().toString());
            }*/
            return adv;
        }

    }


    /** Creates a new instance of ProfileAdv */
    public ProfileAdv() {
        super();
    }


    public void setName(String name) {
        this.name = name;
    }

    /** name associated with this instance of peer */
    public String getName() {
        return name;
    }

    /**Advertisement type*/
    public static String getAdvertisementType() {
        return advertisementType;
    }

    /**
     * {@inheritDoc}
     **/
    public final String getBaseAdvType() {
        return getAdvertisementType();
    }
    /**
        * {@inheritDoc}
     **/
    public Document getDocument(MimeMediaType mimeMediaType) {
        StructuredDocument doc = StructuredDocumentFactory.
                                 newStructuredDocument(mimeMediaType,
                getAdvertisementType());

        Element elem = doc.createElement(userIDKey, userID);
        doc.appendChild(elem);

        elem = doc.createElement(nameKey, name);
        doc.appendChild(elem);

        elem = doc.createElement(emailKey, email);
        doc.appendChild(elem);

        elem = doc.createElement(speedKey, speed);
        doc.appendChild(elem);

        elem = doc.createElement(mobilityKey, mobility);
        doc.appendChild(elem);
        elem = doc.createElement(counteryKey, countery);
        doc.appendChild(elem);
        elem = doc.createElement(languageKey, language);
        doc.appendChild(elem);
        elem = doc.createElement(cityKey, city);
        doc.appendChild(elem);

        elem = doc.createElement(otherKey, other);
        doc.appendChild(elem);

        elem = doc.createElement(lastUpdateKey, lastUpdate);
        doc.appendChild(elem);

        return doc;
    }


    public ID getID() {
        try {
            return (PeerID) IDFactory.fromURI(new URI(userID));
        } catch (Exception e) {
            LOG.error("error converting userID='" + userID + "'", e);
            return null;
        }
    }

    public String[] getIndexFields() {
        return indexFields;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getuserID() {
        return userID;
    }

    public void setuserID(String userID) {
        this.userID = userID;
    }

    public String getSpeed() {
        return speed;
    }

    public void setSpeed(String speed) {
        this.speed = speed;
    }

    public String getMobility() {
        return mobility;
    }

    public void setMobility(String mobility) {
        this.mobility = mobility;
    }

    public void setCountery(String countery) {
        this.countery = countery;
    }

    public String getCountery() {
        return this.countery;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public String getLanguage() {
        return this.language;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCity() {
        return this.city;
    }

    public String getOther() {
        return other;
    }

    public void setOther(String other) {
        this.other = other;
    }

    public String getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(String lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public boolean equals(Object target) {
        if (target instanceof ProfileAdv) {
            return ((ProfileAdv) target).getID().equals(getID());
        } else {
            return false;
        }
    }

    public int hasHcode() {
        return getID().hashCode();
    }

    /**
     * Clone this ModuleImplAdvertisement
     *
     * @return Object an object of class ModuleImplAdvertisement that is a
     * deep-enough copy of this one.
     **/
    public Object clone() {

        // All members are either immutable or never modified nor allowed to
        // be modified: all accessors return clones or immutable objects.
        // IDs are know to be immutable but that could change. Accessors
        // clone() them for safety; their clone method costs nothing.
        try {
            return super.clone();
        } catch (CloneNotSupportedException impossible) {
            return null;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -