public class HdxResourceType extends Object
To add an extension class, which registers a new HdxResourceType, you must do two things:
newHdxResourceType(java.lang.String)
, in a static initialiser.
my.new.type
, and if
there is an `Hdx property'
HdxResourceType.load.my.new.type
with the value
true
(or anything which the Boolean
class
evaluates to true), then the specified class is loaded during
initialization of this HdxResourceType
class. This is an
`Hdx property', which means that it may be specified as either a
System property, or in an Hdx property file as described in HdxProperties
.
Alternatively, you may register the type by explicitly loading
and initialising the class (and thus executing its static
initialiser). This can happen as a result of a call to some static
method in the class, or explicitly via
java.lang.Class.forName
.
The structure of the elements within the HDX namespace is as follows: XXX ADD STRUCTURE DEFINITION -- WHAT FORMAT?
There is no DTD which corresponds to this document structure.
The method which checks this is isValidHdx(Document)
,
which is equivalent to a call to isValid(Element)
on
object HDX
.
Modifier and Type | Field and Description |
---|---|
static HdxResourceType |
HDX
The overall container of HDX objects
|
static String |
HDX_NAMESPACE
The namespace for HDX
|
static HdxResourceType |
NONE
Not a HDX-registered object, used as error/unknown type.
|
static HdxResourceType |
TITLE
A generic type for titles of HDX objects
|
Modifier and Type | Method and Description |
---|---|
static Iterator |
getAllTypes()
Obtains an iterator containing all the
HdxResourceType types which are defined. |
Class |
getConstructedClass()
Obtains the expected Java type corresponding to this Hdx type.
|
String |
getHoistAttribute()
Retrieves the value of the `hoist' attribute.
|
boolean |
isValid(Element el)
Tests whether the given element is a valid instance of this
type.
|
static boolean |
isValidHdx(Document doc)
Checks that the Document is valid HDX.
|
static HdxResourceType |
match(Element el)
Returns a HdxResourceType object which matches the specified
Element.
|
static HdxResourceType |
match(String gi)
Returns a HdxResourceType object which matches the specified
element name.
|
static HdxResourceType |
newHdxResourceType(String name)
Creates and returns a new resource type.
|
void |
registerHdxResourceFactory(HdxResourceFactory factory)
Registers a handler for this type.
|
void |
setConstructedClass(Class c)
Sets the class or interface which constructed objects of this
type must be assignable to.
|
void |
setConstructedClass(String classname)
Sets the class of interface which constructed objects of this
type must be assignable to.
|
void |
setElementValidator(ElementValidator validator)
Registers an instance of the
ElementValidator type,
which will do the work of validating this type of resource. |
void |
setHoistAttribute(String s)
Defines the `hoist' attribute.
|
String |
toString()
Returns a printable version of the resource type
|
String |
xmlName()
Gives the XML element name corresponding to the resource type.
|
public static final String HDX_NAMESPACE
public static HdxResourceType HDX
public static HdxResourceType TITLE
public static HdxResourceType NONE
public static HdxResourceType newHdxResourceType(String name)
name
- The name of the new resource type, which will also
become its XML element name. It is an error for this resource
type to already exist.public String toString()
public String xmlName()
public String getHoistAttribute()
setHoistAttribute(java.lang.String)
public void setHoistAttribute(String s)
For example if the <mytype>
type has a
hoist attribute of value
, then the XML
<mytype> something </mytype>
is deemed
equivalent to <mytype value="something"/>
.
This is never put in element content when objects are written
to XML, but is only used when objects are constructed from
`foreign' DOMs. If this is null, no attribute is defaulted.
public void setConstructedClass(Class c)
c
- a class which constructed objects must match. This
may be null to turn off such verification, but that is probably
a bad idea.setConstructedClass(String)
public void setConstructedClass(String classname) throws HdxException
classname
- the name of a class which constructed objects
must match. This may be null to turn off such verification,
but that is probably a bad idea.HdxException
- if the specified class cannot be foundsetConstructedClass(Class)
public Class getConstructedClass()
If no such type has been registered, this returns the class
object for the Object
class,
Object.class
. You may compare the result of this
method for equality with Object.class
to determine
if a type was registered, or use it directly, since
Object.class.isInstance(obj)
is true for any Java object.
setConstructedClass(java.lang.Class)
, or Object.class
if no type
was so registeredpublic static boolean isValidHdx(Document doc)
This allows the following assertions for the Document
doc
, and any node n
immediately
contained within it
assert doc.getDocumentElement().getTagName .equals(HdxResourceType.HDX.xmlName()); assert n.getNodeType() == Node.ELEMENT_NODE; // only text nodes assert HdxResourceType.match(n) != HdxResourceType.NONE; // all registeredThere are other constraints which you might want to check: if they are violated, you might want to throw an exception, but until they are checked in this method, and the appropriate assertion listed above, they should not be checked in
assert
statements.isValid(Element)
public boolean isValid(Element el)
ElementValidator
instance registered with method setElementValidator(uk.ac.starlink.hdx.ElementValidator)
.el
- an element to be validated.public void setElementValidator(ElementValidator validator)
ElementValidator
type,
which will do the work of validating this type of resource.public void registerHdxResourceFactory(HdxResourceFactory factory)
public static HdxResourceType match(Element el)
This matches only elements which are in no namespace. That is, if the given element is in any namespace, including the HDX namespace, this does not match it.
match(String)
public static HdxResourceType match(String gi)
gi
- an element name. This may be null, in which case
this `matches' type NONE.public static Iterator getAllTypes()
HdxResourceType
types which are defined. The list
does not include type NONE
, and is in an arbitrary order.Copyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.