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

📄 tag.java

📁 开放源码的smpp协议开发包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *            The maximum length allowed for the value.     * @throws ie.omk.smpp.message.tlv.TagDefinedException     *             If a tag with integer value <code>tag</code> has already     *             been defined.     */    private Tag(int tag, Class type, Encoder enc, int minLength, int maxLength)            throws TagDefinedException {        this.tag = new Integer(tag);        this.type = type;        this.minLength = minLength;        this.maxLength = maxLength;        if (enc == null)            this.encoder = getEncoderForType(type);        else            this.encoder = enc;        synchronized (tagTable) {            if (tagTable.containsKey(this.tag))                throw new TagDefinedException(tag, "Tag 0x"                        + Integer.toHexString(tag) + " is already defined.");            tagTable.put(this.tag, this);        }    }    /**     * Get an <code>Encoder</code> for a particular Java type.     *      * @param type     *            The Java type to get an encoder for.     * @return The encoder/decoder for Java type <code>type</code>.     */    private Encoder getEncoderForType(Class type) {        // If type is null and encoder is null, this is a "no value" tlv type.        if (type == null)            return (NullEncoder.getInstance());        if (java.lang.Number.class.isAssignableFrom(type))            return (NumberEncoder.getInstance());        else if (java.lang.String.class.isAssignableFrom(type))            return (StringEncoder.getInstance());        else if (java.util.BitSet.class.isAssignableFrom(type))            return (BitmaskEncoder.getInstance());        else if (byte[].class.isAssignableFrom(type))            return (OctetEncoder.getInstance());        else            throw new NoEncoderException(type, "No encoder for class type "                    + type.getName());    }    /**     * Get the integer value of this tag.     *      * @return the integer value of this tag.     */    public int intValue() {        return (tag.intValue());    }    /**     * Get the allowed length of a value of this tag type.     *      * @return The allowed length, or the maximum length if a range is set.     */    public int getLength() {        return (maxLength < 0 ? minLength : maxLength);    }    /**     * Get the minimum length of a value of this tag type.     *      * @return the minimum length of a value of this tag type.     */    public int getMinLength() {        return (minLength);    }    /**     * Get the maximum length of a value of this tag type.     *      * @return the maximum length of a value of this tag type.     */    public int getMaxLength() {        return (maxLength);    }    /**     * Get the Java type of values of this tag type.     *      * @return the Java type of values of this tag type.     */    public Class getType() {        return (type);    }    /**     * Test for equality. Two tags are equal if their integer values are     * equivalent.     *      * @return true if <code>obj</code> is Tag and has the same tag value.     */    public boolean equals(Object obj) {        if (obj instanceof Tag)            return (((Tag) obj).tag.equals(this.tag));        else            return (false);    }    /**     * Test for equality against an integer.     *      * @return true if this Tag's integer value is equal to <code>tag</code>.     */    public boolean equals(int tag) {        return (tag == this.tag.intValue());    }    /**     * Get the hashCode for this Tag. The hashCode for a Tag is the same as:     * <br>     * <code>new Integer(tag.tagValue()).hashCode()</code>     *      * @return A hash code for this tag.     */    public int hashCode() {        return (tag.hashCode());    }    /**     * Convert this tag to a String. This returns a decimal representation of     * the tag's integer value in a String.     *      * @return This tag's string value.     */    public String toString() {        return (tag.toString());    }    /**     * Convert this tag to a String. This returns a hex representation of the     * tag's integer value in a String.     *      * @return This tag's hexadecimal representation.     */    public String toHexString() {        return (Integer.toHexString(tag.intValue()));    }    /**     * Get the encoder used to encode values of this tag type.     *      * @return the encoder used to encode values of this tag type.     */    public Encoder getEncoder() {        return (encoder);    }    /**     * Get the Tag object that represents tag <code>tagValue</code>. If the     * tag is known then the static Tag object representing the tag is returned.     * If the tag is not known, a fresh instance of Tag will be returned which     * uses an octet-string type.     *      * @return The Tag object representing the tag <code>tagValue</code>.     *         Will never return <code>null</code>.     */    public static final Tag getTag(int tagValue) {        Tag t = (Tag) tagTable.get(new Integer(tagValue));        if (t == null) {            return (Tag.defineTag(tagValue, byte[].class, null, -1, -1));        } else {            return (t);        }    }    /**     * Define a new tag value type. This method adds a new tag type to the     * internal tag table.     *      * @param tagValue     *            the integer value of the tag.     * @param type     *            the parameter type.     * @param enc     *            the encoder used to serialize and deserialize. This may be     *            null to use the API's default internally defined encoders.     * @param fixedSize     *            the defined size of the parameter.     * @throws ie.omk.smpp.message.tlv.TagDefinedException     *             if an attempt is made to define a tag with a integer value     *             equivalent to an already defined tag.     * @see Encoder     */    public static final Tag defineTag(int tagValue, Class type, Encoder enc,            int fixedSize) throws TagDefinedException {        return (new Tag(tagValue, type, enc, fixedSize));    }    /**     * Define a new tag value type. This method adds a new tag type to the     * internal tag table.     *      * @param tagValue     *            the integer value of the tag.     * @param type     *            the parameter type.     * @param enc     *            the encoder used to serialize and deserialize. This may be     *            null to use the API's default internally defined encoders.     * @param minSize     *            the minimum size of the parameter.     * @param maxSize     *            the maximum size of the parameter.     * @throws ie.omk.smpp.message.tlv.TagDefinedException     *             if an attempt is made to define a tag with a integer value     *             equivalent to an already defined tag.     * @see Encoder     */    public static final Tag defineTag(int tagValue, Class type, Encoder enc,            int minSize, int maxSize) throws TagDefinedException {        return (new Tag(tagValue, type, enc, minSize, maxSize));    }    /**     * Undefine a tag. This removes all knoweledge of this tag type from the     * internal tables. If there is no such tag defined already, this method     * will do nothing.     *      * @param tag     *            The tag to undefine. null if there was no tag defined already.     * @return The Tag object that has been undefined.     */    public static final Tag undefineTag(Tag tag) {        if (tag == null)            return (null);        synchronized (tagTable) {            return ((Tag) tagTable.remove(tag));        }    }    // XXX defineTags method that can read definitions from a properties file}

⌨️ 快捷键说明

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