Class URN
- java.lang.Object
- com.iizix.urn.URN
- Direct Known Subclasses:
BarcodeURN
,SVG_URN
,URL_URN
,URNResource
,UserProfileImageURN
,UserProfileStringURN
public abstract class URN extends java.lang.Object
This URN class handles a IIZI Universal Resource Name generated from various{@link NID}
with its required parameters, varying depending on the{@link NID}
. The NID string is case sensitive. the"urn:"
prefix is not case sensitive.IIZI Uniform Resource Names (URN) are using the common standard.
A URN normally looks like below, but you can read more at Uniform Resource Name.
The IIZI implementation for URN's to reference various parts in IIZI is:
"urn:NID:NSS:[?+r-component]][?=q-component][#fragment]".
or, in the form of a syntax diagram, as:
In the IIZI case, the use of the some NID's also requires specifying an environment location (
{@link NIDLocation}
) where the data is stored, e.g. in a database, a server cluster, a server instance (for security), a user (chosen to be identified or not), a user identifier, an application, a specific user session or a specific user client session. In the case a location is used, the resource URL produced from the URN will be private to that particular location, e.g. a server, a user or its application/client session.Luckily, the abstraction of the final naming depends on so many things, but you don't have to worry about it. Just place it in the correct NID (Name space IDentifier) and leave the complexity to the framework.
The IIZI NID's are not registered with IANA, so they are all prefixed with "iz-" in this enum class.
- Author:
- Christopher Mindus
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
urnString
The original URN string.
Constructor Summary
Constructors Modifier Constructor Description protected
URN(java.lang.String urnString)
Constructor.
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description URNResource
asURNResource()
Gets this instance as type.abstract boolean
equals(java.lang.Object obj)
Checks if another URN is equal to this one.static URN
from(java.lang.String urnString)
Helper method that creates aURNResource
from a String.IImageTarget
getImageTarget()
Gets the image target interface for this URN instance, if supported.abstract java.lang.String
getParamString()
Gets the parameter string for thetoString()
method.abstract java.lang.String
getURL()
Gets the URL of this resource relative the current web server.java.lang.String
getURNString()
Gets the original URN unparsed string.abstract int
hashCode()
Gets the hash code of the instance.boolean
isImageTargetSupported()
Checks if this instance supports returning the image target interface{@link IImageTarget}
.boolean
isURNResource()
Checks if this URN instance is a .java.lang.String
toString()
Formats this instance to a String that can be used for debugging.
Method Detail
from
public static URN from(java.lang.String urnString) throws URNException
Helper method that creates aURNResource
from a String.This method calls:
URNFactory.getInstance().from(urnString);
- Parameters:
urnString
- The String to resolve to an URN resource.- Returns:
- The URN instance.
- Throws:
URNException
- For illegal URN's.NIDException
- For exceptions with Naming ID's.UnknownNIDException
- For unknown Naming ID's.java.lang.IllegalArgumentException
- If the implementation encounters illegal characters.
getURL
public abstract java.lang.String getURL() throws java.io.IOException
Gets the URL of this resource relative the current web server.- Returns:
- The URL relative the current server, if based on the current server, otherwise the full URL to the resource, or the data URL as
data:<i>mediatype</i>[;base64],<i>data</i>
. - Throws:
java.io.IOException
- If there was a problem retrieving the file, an SQL error or other I/O error that caused the URL not to be possible to get (e.g. barcode failure).
isURNResource
public boolean isURNResource()
Checks if this URN instance is a .- Returns:
- true if the instance is a , false by default.
asURNResource
public URNResource asURNResource()
Gets this instance as type.- Returns:
- The instance, or
null
if this instance is not aURNResource
(default).
isImageTargetSupported
public boolean isImageTargetSupported()
Checks if this instance supports returning the image target interface{@link IImageTarget}
.- Returns:
true
if the URN supports the image target interface,false
(default) otherwise.
getImageTarget
public IImageTarget getImageTarget()
Gets the image target interface for this URN instance, if supported.- Returns:
- The image target interface, or
null
(default) if not supported.
getURNString
public final java.lang.String getURNString()
Gets the original URN unparsed string.- Returns:
- The string used to parse and build this URN instance.
hashCode
public abstract int hashCode()
Gets the hash code of the instance. The original URN string is not used for this hash code, rather the URN 'NID' and the parameters.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- A hash code value.
equals
public abstract boolean equals(java.lang.Object obj)
Checks if another URN is equal to this one. The original URN string is not used for this comparison, rather the URN 'NID' and the parameters.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- The other object to compare with.- Returns:
- true if the URN's are equal, false otherwise.
getParamString
public abstract java.lang.String getParamString()
Gets the parameter string for thetoString()
method.- Returns:
- The parameter string, always
non-null
.
toString
public final java.lang.String toString()
Formats this instance to a String that can be used for debugging.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The String formatted as "className[param1=value1,param2=value2,originalURNString]".