org.ceryle.xtm
Class XtmReference

java.lang.Object
  extended by org.ceryle.xtm.XtmNode
      extended by org.ceryle.xtm.XtmReference
All Implemented Interfaces:
Comparable, Iterator, Constants

public class XtmReference
extends XtmNode
implements Comparable

Defines a reference occurring in a topic map.

Instances of this class are objects containing URI references, typed internally as either representations of topicRef, resourceRef, or subjectIndicatorRef elements. This class allows only a subset of URIs, given that it builds the provided string as a java.net.URL, throwing an exception if unable. The internal representation of the URI is also stored as a String value, so if the initial setting throws a MalformedURLException, this can be caught and the String value set directly using the setLinkURI() method, which does not set the URL value.

If this default behaviour is considered annoying, it can be altered by changing the boolean strictURIs to false and recompiling. The URL returned by getLinkURL() will then in all cases return a null value.

Since:
JDK1.3
Version:
$Id: XtmReference.java,v 3.5 2007-06-15 12:10:35 altheim Exp $
Author:
Murray Altheim

Field Summary
protected  String uri
          A String containing the URI reference of this XtmReference.
 
Fields inherited from class org.ceryle.xtm.XtmNode
ASSOCIATION_NODE, BASENAME_NODE, BASENAMESTRING_NODE, COMMENT_NODE, DOCUMENT_NODE, GrpSep, GRPSEP, id, INSTANCEOF_NODE, MEMBER_NODE, MERGEMAP_NODE, NODE, NonType, NONTYPE, OCCURRENCE_NODE, PARAMETERS_NODE, PROCESSING_INSTRUCTION_NODE, RecSep, RECSEP, REFERENCE_NODE, RESOURCEDATA_NODE, RESOURCEREF_NODE, ROLESPEC_NODE, SCOPE_NODE, SUBJECTIDENTITY_NODE, SUBJECTINDICATORREF_NODE, TOPIC_NODE, TOPICMAP_NODE, TOPICREF_NODE, VARIANT_NODE, VARIANTNAME_NODE
 
Fields inherited from interface org.ceryle.util.Constants
Amp, AMP, Apos, APOS, APP_NAME, APP_VERSION_NAME, APP_VERSION_NUMBER, AT, BANG, BAR, BIT_dev, BIT_http, BIT_ignoreCom, BIT_merge, BIT_none, BIT_noPreload, BIT_simple, BIT_ui, BIT_unused1, BIT_unused2, BIT_unused3, BIT_validating, BIT_verbose, BIT_xcatalog, BIT_xlink, BIT_xmlnsAware, BIT_xsd, BROKB, BSlash, BSLASH, CERYLE_CREDITS_FILE, CERYLE_DATA_DIR, CERYLE_HIST_FILE, CERYLE_LICENSE_FILE, CERYLE_PREF_FILE, CERYLE_PROP, CERYLE_PROP_BASE, CERYLE_PROP_FILE, CERYLE_RSRC_DIR, CERYLE_THANKS_FILE, CFLEX, Colon, COLON, Comma, COMMA, CR, CRet, Dash, DASH, DEFAULT_DIRECTORY, DEVELOPER, DOLR, Dot, DOT, EIGHT, Ellip, EOF, EqQuot, EQUAL, Equals, False, FALSE, FileProt, Filesep, FileURL, Five, FIVE, FONTSIZES, Four, FOUR, FSchar, GCOL_PROP, GRAPH_PROP, GRAVE, GT, Hash, HASH, HOME_DIRECTORY, HOME_DIRECTORY_PATH, HOME_DIRECTORY_URL, HTML, HttpProt, HttpURL, INDENT, INDENT_0, INDENT_1, INDENT_10, INDENT_2, INDENT_3, INDENT_4, INDENT_5, INDENT_6, INDENT_7, INDENT_8, INDENT_9, INIT, LCURL, LCurly, LF, LFS, Localhost, LPAR, LParen, LS, LSBrkt, LSBrkt2, LSQB, LT, MT, NBSP, NEL, NINE, NL, NL20x, NLchar, No, Null, NULL, NULL_STATE, NumParams, One, ONE, Pathsep, Percent, PERO, PLUS, Prcnt, PS, QMark, QMARK, Quot, QUOT, RCURL, RCurly, RESOURCE_BUNDLE, RPAR, RParen, RSBrkt, RSBrkt2, RSQB, Semi, SEMI, SEVEN, SIX, Slash, SLASH, SP, SPACE, Stago, Star, STAR, Tab, TAB, Tee, Three, THREE, Tilde, TILDE, TM_PROP, True, TRUE, Two, TWO, Under, UNDER, URI, URL, VBar, WIKI_PROP, XNodePfx, XNodeURL, XtmExt, Yes, Zero, ZERO
 
Constructor Summary
XtmReference(int type, String uri)
          XtmReference constructor with type indicator and URI.
XtmReference(String uri)
          XtmReference constructor URI, which creates a <topicRef> if the URI begins with a "#", otherwise defaults to a <subjectIndicatorRef> reference type.
XtmReference(String id, int type, String uri)
          XtmReference constructor including an ID identifier, type indicator and URI.
 
Method Summary
 int compareTo(Object o)
          Compares the URI of this XtmReference with the provided Object for order.
 String getHash()
          Return a String hashcode generated from this XtmReference's URI.
 String getLinkURI()
          Return XtmReference's link URI as String.
 URL getLinkURL()
          Return XtmReference's URI reference as URL.
 String getName()
          Return a String matching this XtmReference's element type name.
 short getNodeType()
          A short integer indicating what type of node this is.
 int getReferenceType()
          Return an int code (1-3) indicating this XtmReference's element type.
 void setLinkURI(String uri)
          Set XtmReference's URI reference to String uri.
 void setReferenceType(int type)
          Set the type of this XtmReference's element type to the int type.
 XtmTopic sgetTopic(XtmProcessor xtmp, XtmTopic reftopic)
          Returns the XtmTopic to which this XtmReference refers.
 String toString()
          Returns a String suitable as a description of this XtmReference.
 
Methods inherited from class org.ceryle.xtm.XtmNode
addPI, getID, getPI, getPIs, hasNext, next, remove, removePI, setID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

uri

protected String uri
A String containing the URI reference of this XtmReference.

Constructor Detail

XtmReference

public XtmReference(String uri)
XtmReference constructor URI, which creates a <topicRef> if the URI begins with a "#", otherwise defaults to a <subjectIndicatorRef> reference type.

NOTE: So that this can be used in a static context, the XtmReference on setting the URI is suppressed, with only a println indicating such an error occurred.


XtmReference

public XtmReference(int type,
                    String uri)
             throws XtmException
XtmReference constructor with type indicator and URI.

Throws:
XtmException

XtmReference

public XtmReference(String id,
                    int type,
                    String uri)
             throws XtmException
XtmReference constructor including an ID identifier, type indicator and URI.

Throws:
XtmException
Method Detail

getName

public String getName()
Return a String matching this XtmReference's element type name.

Overrides:
getName in class XtmNode

setReferenceType

public void setReferenceType(int type)
Set the type of this XtmReference's element type to the int type. Rather than throw an exception, invalid types are cast as subject indicator references.


getReferenceType

public int getReferenceType()
Return an int code (1-3) indicating this XtmReference's element type.


getNodeType

public short getNodeType()
A short integer indicating what type of node this is. The named constants for this value are defined in the org.ceryle.XtmNode class.

Overrides:
getNodeType in class XtmNode

sgetTopic

public XtmTopic sgetTopic(XtmProcessor xtmp,
                          XtmTopic reftopic)
Returns the XtmTopic to which this XtmReference refers. No, the method name is not misspelled. This method sets the reference of this XtmReference to the provided XtmTopic reftopic if this is non-null, and simply returns reftopic after setting a reference to it here.

Alternately, if reftopic is null and the XtmProcessor xtmp is non-null, it will be used to resolve a topic from this XtmReference's URI. Returns null if unable to resolve, or if the topic is unavailable.

Parameters:
xtmp - the XtmProcessor used for topic resolution
reftopic - the XtmTopic to set as a reference

setLinkURI

public void setLinkURI(String uri)
                throws XtmException
Set XtmReference's URI reference to String uri.

Throws:
XtmException

getHash

public String getHash()
Return a String hashcode generated from this XtmReference's URI. Note that the reference type is prepended to this hashcode, with TOPICREF_NODE and SUBJECTINDICATORREF_NODE being treated as equivalents.


getLinkURI

public String getLinkURI()
Return XtmReference's link URI as String.


getLinkURL

public URL getLinkURL()
Return XtmReference's URI reference as URL. Note that this will be a null value if the String provided as its URI is not a valid URL, or if the compiled-in boolean option strictURIs is false.


compareTo

public int compareTo(Object o)
Compares the URI of this XtmReference with the provided Object for order.

Specified by:
compareTo in interface Comparable

toString

public String toString()
Returns a String suitable as a description of this XtmReference. If this XtmReference points to a known XtmTopic, its label is used.

Overrides:
toString in class Object


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.