org.nees.metadata.util
Class EncodedIdFactory

java.lang.Object
  extended byorg.nees.metadata.util.IdFactory
      extended byorg.nees.metadata.util.EncodedIdFactory
Direct Known Subclasses:
Base64IdFactory, HexIdFactory

public abstract class EncodedIdFactory
extends IdFactory

Generates ID's whose local parts are encoded. This is to facilitate using arbitrary octet strings as local parts even if they do not conform to the subset of XML nmtoken supported by NMDS. Also provides the optional convenience of encoding a character string into an octet string.

Subclasses only need to implement encode(byte[]) for whatever kind of encoding they support.


Field Summary
static java.lang.String DEFAULT_STRING_ENCODING
          the encoding to use when computing the digest of the arbitrary strings
 
Constructor Summary
EncodedIdFactory()
           
EncodedIdFactory(java.lang.String namespaceURI)
          Creates a factory that produces Identifiers in a given namespace.
EncodedIdFactory(java.lang.String namespaceURI, java.lang.String prefix)
           
 
Method Summary
abstract  byte[] decode(java.lang.String encoded)
          Subclasses implement this for specific decoding behavior.
 byte[] decodeToOctets(Identifier id)
          Decode this Identifier to octets, using the prefix setting of this factory (i.e., strip this factory's prefix from the id's local part before decoding).
 java.lang.String decodeToString(Identifier id)
          Decode this Identifier to a String, using the prefix setting of this factory (i.e., strip this factory's prefix from the id's local part before decoding).
 java.lang.String decodeToString(Identifier id, java.lang.String charset)
          Decode this Identifier to a String, using the prefix setting of this factory (i.e., strip this factory's prefix from the id's local part before decoding).
abstract  java.lang.String encode(byte[] octets)
          Subclasses implement this for specific encoding behavior.
 java.lang.String getDefaultPrefix()
           
 java.lang.String getPrefix()
          Get the prefix.
 java.lang.String getStringEncoding()
           
 Identifier newId(byte[] octets)
          Encodes the octet string, appends a prefix, and uses that as the local part of the ID.
 Identifier newId(java.lang.String localString)
          Encodes the local string, appends a prefix, and uses that as the local part of the ID.
 Identifier newId(java.lang.String namespaceURI, byte[] octets)
          Encodes the octet string, appends a prefix, and uses that as the local part of the ID.
 Identifier newId(java.lang.String namespaceURI, java.lang.String localString)
          Encodes the local string, appends a prefix, and uses that as the local part of the ID.
 void setPrefix(java.lang.String value)
          Set the prefix.
 void setStringEncoding(java.lang.String e)
           
 
Methods inherited from class org.nees.metadata.util.IdFactory
getFactory, getFactory, getNamespaceURI, newId, newIdPromise, setNamespaceURI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STRING_ENCODING

public static final java.lang.String DEFAULT_STRING_ENCODING
the encoding to use when computing the digest of the arbitrary strings

See Also:
Constant Field Values
Constructor Detail

EncodedIdFactory

public EncodedIdFactory()

EncodedIdFactory

public EncodedIdFactory(java.lang.String namespaceURI)
Creates a factory that produces Identifiers in a given namespace.

Parameters:
namespaceURI - the namespace URI

EncodedIdFactory

public EncodedIdFactory(java.lang.String namespaceURI,
                        java.lang.String prefix)
Parameters:
namespaceURI - the namespace URI
prefix - the prefix to append to the local part
Method Detail

getDefaultPrefix

public java.lang.String getDefaultPrefix()

setStringEncoding

public void setStringEncoding(java.lang.String e)
                       throws java.io.UnsupportedEncodingException
Parameters:
e - the encoding to use to convert the string to bytes
Throws:
java.io.UnsupportedEncodingException

getStringEncoding

public java.lang.String getStringEncoding()

getPrefix

public java.lang.String getPrefix()
Get the prefix.

Returns:
the prefix

setPrefix

public void setPrefix(java.lang.String value)
Set the prefix. The factory will behave unexpectedly if the prefix does not conform to Nmtoken, or contains ".".

Parameters:
value - the new prefix

newId

public Identifier newId(java.lang.String localString)
Encodes the local string, appends a prefix, and uses that as the local part of the ID. Uses the namespace URI set for this factory instance.

Overrides:
newId in class IdFactory
Parameters:
localString - a string to encode and turn into a local part.
Returns:
the Identifier

newId

public Identifier newId(java.lang.String namespaceURI,
                        java.lang.String localString)
Encodes the local string, appends a prefix, and uses that as the local part of the ID.

Overrides:
newId in class IdFactory
Parameters:
namespaceURI - the namespace URI to use.
localString - a string to hex-encode and turn into a local part.
Returns:
the new Identifier

newId

public Identifier newId(byte[] octets)
Encodes the octet string, appends a prefix, and uses that as the local part of the ID. Uses the namespace URI set for this factory instance.

Parameters:
octets - a string to hash and turn into a local part.

newId

public Identifier newId(java.lang.String namespaceURI,
                        byte[] octets)
Encodes the octet string, appends a prefix, and uses that as the local part of the ID.

Parameters:
namespaceURI - the namespace URI to use.
octets - a string to hash and turn into a local part.

encode

public abstract java.lang.String encode(byte[] octets)
Subclasses implement this for specific encoding behavior.

Parameters:
octets - the binary data to encode
Returns:
the String encoding of it

decodeToOctets

public byte[] decodeToOctets(Identifier id)
                      throws EncodingException
Decode this Identifier to octets, using the prefix setting of this factory (i.e., strip this factory's prefix from the id's local part before decoding).

Parameters:
id - the id to decode
Throws:
EncodingException

decodeToString

public java.lang.String decodeToString(Identifier id,
                                       java.lang.String charset)
                                throws EncodingException,
                                       java.io.UnsupportedEncodingException
Decode this Identifier to a String, using the prefix setting of this factory (i.e., strip this factory's prefix from the id's local part before decoding). Convert the decoded octets to a String using the given charset.

Parameters:
id - the id to decode
charset - the charset to use
Throws:
EncodingException
java.io.UnsupportedEncodingException

decodeToString

public java.lang.String decodeToString(Identifier id)
                                throws EncodingException
Decode this Identifier to a String, using the prefix setting of this factory (i.e., strip this factory's prefix from the id's local part before decoding). Convert the decoded octets to a String using the factory's encoding

Parameters:
id - the id to decode
Throws:
EncodingException

decode

public abstract byte[] decode(java.lang.String encoded)
                       throws EncodingException
Subclasses implement this for specific decoding behavior. Throw EncodingException if there's a problem.

Throws:
EncodingException