javax.microedition.contactless.ndef
Class NDEFRecordType

java.lang.Object
  extended by javax.microedition.contactless.ndef.NDEFRecordType

public class NDEFRecordType
extends java.lang.Object

This class encapsulates the type of an NDEF record. It stores the name and format of the record type name. Possible name formats are provided as constants in this class. Record type names used in this class and in the API must follow the rules defined by the NFC Forum RTDs and the RFCs.

The record type name format defines the structure and the format for the record type name. Possible formats are MIME media types defined in RFC 2046, absolute URIs defined in RFC 3986, NFC Forum well-known types, defined in the NFC Forum RTDs, NFC Forum external types and unknown. The application developer may also define own record type names using naming conventions of NFC Forum RTDs. These record type names are categorized as NFC Forum external types.

The responsibility of the character encodings used in the record type names are left to the application. The API implementation must use US-ASCII character encoding with the record type names. This class also provides a convenience method to compare record types. The comparison rules for record type names are defined in equals method.

The implementation of this class must remove the prefix urn:nfc:wkt: from the NFC Forum RTD names and the prefix urn:nfc:ext: from the NFC Forum external record type names. This means that the getName() method must return the record type name without any prefixes.


Field Summary
static int EMPTY
          Record type name format identifier for the empty record.
static int EXTERNAL_RTD
          Record type name format identifier for application specific record type names that follow the NFC Forum naming conventions.
static int MIME
          Record type name format identifier for the MIME type defined in the RFC 2046.
static int NFC_FORUM_RTD
          Record type name format identifier for the NFC Forum Record Type Description.
static int UNKNOWN
          Record type name format identifier for the unknown record type.
static int URI
          Record type name format identifier for the URI type defined in the RFC 3986.
 
Constructor Summary
NDEFRecordType(int format, java.lang.String name)
          Creates a new record type object.
 
Method Summary
 boolean equals(java.lang.Object recordType)
          This method compares two record type objects.
 int getFormat()
          Returns the format of the record type name.
 java.lang.String getName()
          Returns the name of the NDEF record without any prefixes defined in the NFC Forum.
 byte[] getNameAsBytes()
          Returns the name of the NDEF record without any prefixes defined in the NFC Forum.
 int hashCode()
          Returns a hash code value for the record type object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY

public static final int EMPTY

Record type name format identifier for the empty record. This format indicates there is no type name associated with this record. When this format is used, the record type name is omitted. The only valid value for the record type name with this EMPTY record type is null.

See Also:
Constant Field Values

NFC_FORUM_RTD

public static final int NFC_FORUM_RTD

Record type name format identifier for the NFC Forum Record Type Description.

See Also:
Constant Field Values

MIME

public static final int MIME

Record type name format identifier for the MIME type defined in the RFC 2046.

See Also:
Constant Field Values

URI

public static final int URI

Record type name format identifier for the URI type defined in the RFC 3986.

See Also:
Constant Field Values

EXTERNAL_RTD

public static final int EXTERNAL_RTD

Record type name format identifier for application specific record type names that follow the NFC Forum naming conventions.

See Also:
Constant Field Values

UNKNOWN

public static final int UNKNOWN

Record type name format identifier for the unknown record type. This format indicates that the type of the payload is unknown. The only valid values for the record type name with this UNKNOWN record type is null.

See Also:
Constant Field Values
Constructor Detail

NDEFRecordType

public NDEFRecordType(int format,
                      java.lang.String name)

Creates a new record type object. The format must be one of the constants defined in this class. If the format is EMPTY or UNKNOWN the name must be null. The record type names of NFC_FORUM_RTD and EXTERNAL_RTD record types must follow the naming rules defined in the NFC Forum RTD specification. The record type name must only contain characters in the US_ASCII character set.

If the record type format is URI the URI should be percent-encoded and the percent-encoded URIs must be normalized to upper-case letters.

Parameters:
format - record type format
name - record type name
Throws:
java.lang.IllegalArgumentException - if format is not one of the constants defined in this class or the type format is EMPTY or UNKNOWN and the type name is not null or the type name is not valid NFC_FORUM_RTD or EXTERNAL_RTD name or name contains characters outside US_ASCII character set
Method Detail

getName

public java.lang.String getName()

Returns the name of the NDEF record without any prefixes defined in the NFC Forum. If the format of the record is EMPTY or UNKNOWN, this method must return null. If the format of the record is URI the method must return the name in same format as it was given in the constructor (with or without percent-encoding). The record type name is character encoded using US_ASCII character set.

Returns:
the record type name of the NDEF record, null if record type is EMPTY or UNKNOWN

getNameAsBytes

public byte[] getNameAsBytes()

Returns the name of the NDEF record without any prefixes defined in the NFC Forum. If the type of the record is EMPTY or UNKNOWN, this method must return null. The character encoding is left to the application.

Returns:
the record type name of the NDEF record as byte array, null if record type is EMPTY or UNKNOWN

getFormat

public int getFormat()

Returns the format of the record type name. Possible return values are defined as constants in this class.

Returns:
record type name format

equals

public boolean equals(java.lang.Object recordType)

This method compares two record type objects. They are equal if both the record type format and record type name are equal and they both use the same character encoding. The following table defines the comparison rules for different record type name formats.

Comparison rules
Record type format Comparison rule for record type name
MIME Comparison character-by-character in case-insensitive manner up to the first ";".
URI Reserved characters must be percent-encoded and the hexadecimal digits in those normalized to upper-case letters. The scheme and host parts of the URI must be normalized to lower-case. After this the URIs are compared in the character-by-character in case-sensitive manner.
NFC_FORUM_RTD Comparison character-by-character in case-sensitive manner.
EXTERNAL_RTD Comparison character-by-character in case-insensitive manner.
UNKNOWN Both record type names must be null.
EMPTY Both record type names must be null.

Overrides:
equals in class java.lang.Object
Parameters:
recordType - record type that this record type is compared to
Returns:
true if record types are equal, else false

hashCode

public int hashCode()

Returns a hash code value for the record type object. Two object that refer to the same NDEFRecordType must have the same hash code. For more information see java.lang.Object.hashCode() method.

Overrides:
hashCode in class java.lang.Object
Returns:
hash value of the record type


Copyright © 2004-2009 Nokia Corporation. All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.