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

📄 leaserequestmsg.java

📁 JXTA&#8482 is a set of open, generalized peer-to-peer (P2P) protocols that allow any networked devi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                ;            } else {                if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                    LOG.warning("Unhandled Attribute: " + aLeaseReqAttr.getName());                }            }        }                Enumeration elements = doc.getChildren();                while (elements.hasMoreElements()) {            XMLElement elem = (XMLElement) elements.nextElement();                        if (!handleElement(elem)) {                if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                    LOG.warning("Unhandled Element: " + elem.toString());                }            }        }                // Sanity Check!!!                if (null == getClientID()) {            throw new IllegalArgumentException("Missing client ID value.");        }                if ((getRequestedLease() < 0) && (getRequestedLease() != Long.MIN_VALUE)) {            throw new IllegalArgumentException("Invalid requested lease duration.");        }                if ((getReferralAdvs() < 0) && (getReferralAdvs() != Integer.MIN_VALUE)) {            throw new IllegalArgumentException("Invalid referral advertisements request value.");        }    }        /**     *  {@inheritDoc}     */    @Override    public Object clone() throws CloneNotSupportedException {        LeaseRequestMsg clone = (LeaseRequestMsg) super.clone();        clone.setClientID(getClientID());        clone.setServerAdvGen(getServerAdvGen());        clone.setRequestedLease(getRequestedLease());        clone.setReferralAdvs(getReferralAdvs());        clone.setCredential(getCredential());        return clone;    }        /**     *  Returns the ID of the client making this request.     *     *  @return ID of the client.     */    public ID getClientID() {        return clientID;    }        /**     *  Sets the ID of the client making this request.     *     *  @param clientID ID of the client.     */    public void setClientID(ID clientID) {        this.clientID = clientID;    }        /**     *  Returns the advertisement generation of the server advertisement which     *  is known to the client. May be {@code null} to indicate that the client     *  does not have a previous version of the server advertisement.     *     *  @return The server advertisement generation.     */    public UUID getServerAdvGen() {        return serverAdvGen;    }        /**     *  Sets the advertisement generation of the server advertisement which is     *  known to the client. May be {@code null} to indicate that the client     *  does not have a previous version of the server advertisement.     *     *  @param serverAdvGen The server advertisement generation.     */    public void setServerAdvGen(UUID serverAdvGen) {        this.serverAdvGen = serverAdvGen;    }        /**     *  Return the duration of the lease being requested. The duration must be     *  a positive integer or {@code Long.MIN_VALUE} which indicates that no     *  lease is being requested.     *     *  @return The duration of the lease being requested.     */    public long getRequestedLease() {        return requestedLease;    }        /**     *  Set the duration of the lease being requested. The duration must be     *  a positive integer or {@code Long.MIN_VALUE} which indicates that no     *  lease is being requested.     *     *  @param requestedLease The duration of the lease being requested.     */    public void setRequestedLease(long requestedLease) {        this.requestedLease = requestedLease;    }        /**     *  Returns the number of referral advertisements requested by the client.     *  Must be a positive integer or {@code Integer.MIN_VALUE} which indicates     *  that the default number is requested.     * @return the number of referral advertisements requested by the client.     */    public int getReferralAdvs() {        return referralAdvs;    }        /**     *  Sets the number of referral advertisements requested by the client.     *  Must be a positive integer or {@code Integer.MIN_VALUE} which indicates     *  that the default number is requested.     *     *  @param referralAdvs The number of referral advertisements requested.     */    public void setReferralAdvs(int referralAdvs) {        this.referralAdvs = referralAdvs;    }        /**     *  Returns the credential of the client making this request in XML format.     *     *  @return The credential associated with this request if any. May be     *  {@code null} to indicate that no credential was provided.     */    public XMLElement getCredential() {        return (XMLElement) ((null != credential) ? StructuredDocumentUtils.copyAsDocument(credential) : null);    }        /**     *  Sets the credential of the client making this request in XML format.     *     *  @param newCred The credential associated with this request if any. May     *  be {@code null} to indicate that no credential is being provided.     */    public void setCredential(XMLElement newCred) {        this.credential = (XMLElement) ((null != newCred) ? StructuredDocumentUtils.copyAsDocument(newCred) : null);    }        /**     *  Our DOCTYPE     *     *  @return the type of this message.     **/    public static String getMessageType() {        return "jxta:LeaseRequestMsg";    }        protected boolean handleElement(XMLElement elem) {                if (CLIENT_CRED_TAG.equals(elem.getName())) {            credential = (XMLElement) StructuredDocumentUtils.copyAsDocument(elem);                        return true;        }                String value = elem.getTextValue();                if (null != value) {            value = value.trim();                        if (0 == value.length()) {                value = null;            }        }                if (null == value) {            return false;        }                return false;    }        /**     *  {@inheritDoc}     **/    public Document getDocument(MimeMediaType mediaType) {                if (null == getClientID()) {            throw new IllegalStateException("Missing client ID value.");        }                if ((getRequestedLease() < 0) && (getRequestedLease() != Long.MIN_VALUE)) {            throw new IllegalStateException("Invalid requested lease duration.");        }                if ((getReferralAdvs() < 0) && (getReferralAdvs() != Integer.MIN_VALUE)) {            throw new IllegalStateException("Invalid referral advertisements request value.");        }                StructuredDocument msg = StructuredDocumentFactory.newStructuredDocument(mediaType, getMessageType());                if (!(msg instanceof Attributable)) {            throw new UnsupportedOperationException("Only 'Attributable' document types are supported.");        }                if (msg instanceof XMLDocument) {            ((XMLDocument) msg).addAttribute("xmlns:jxta", "http://jxta.org");        }                ((Attributable) msg).addAttribute(CLIENT_ID_ATTR, getClientID().toString());                if (Long.MIN_VALUE != getRequestedLease()) {            ((Attributable) msg).addAttribute(REQUESTED_LEASE_ATTR, Long.toString(getRequestedLease()));        }                if (null != getServerAdvGen()) {            ((Attributable) msg).addAttribute(SERVER_ADV_GEN_ATTR, getServerAdvGen().toString());        }                if (null != credential) {            StructuredDocumentUtils.copyElements(msg, msg, credential, CLIENT_CRED_TAG);        }                return msg;    }}

⌨️ 快捷键说明

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