📄 tag.java
字号:
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) { Encoder encoder; // If type is null and encoder is null, this is a "no value" tlv type. if (type == null) { encoder = new NullEncoder(); } else if (java.lang.Number.class.isAssignableFrom(type)) { encoder = new NumberEncoder(); } else if (java.lang.String.class.isAssignableFrom(type)) { encoder = new StringEncoder(); } else if (java.util.BitSet.class.isAssignableFrom(type)) { encoder = new BitmaskEncoder(); } else if (byte[].class.isAssignableFrom(type)) { encoder = new OctetEncoder(); } else { throw new NoEncoderException(type, "No encoder for class type " + type.getName()); } return encoder; } /** * 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. * * <p><b>WARNING</b> The behaviour of this method may change to returning * <code>null</code> for an undefined tag. It needs to be determined * which behaviour is the best.</p> * * @return The Tag object representing the tag <code>tagValue</code>. * Will never return <code>null</code>. */ public static 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 type which has a fixed length. * @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 Tag defineTag(int tagValue, Class type, Encoder enc, int fixedSize) throws TagDefinedException { return new Tag(tagValue, type, enc, fixedSize); } /** * Define a new tag type with minimum and maximum sizes. * @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 Tag defineTag(int tagValue, Class type, Encoder enc, int minSize, int maxSize) throws TagDefinedException { return new Tag(tagValue, type, enc, minSize, maxSize); } /** * Determine if a tag is defined for a particular tag integer value. * @param tagValue The integer value of the tag. * @return <code>true</code> if the tag is defined, <code>false</code> * otherwise. */ public static boolean isTagDefined(int tagValue) { return tagTable.containsKey(new Integer(tagValue)); } /** * 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 Tag undefineTag(Tag tag) { if (tag == null) { return null; } synchronized (tagTable) { return (Tag) tagTable.remove(tag.tag); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -