DLESE Tools
v1.6.0

org.dlese.dpc.ndr.reader
Class NdrObjectReader

java.lang.Object
  extended by org.dlese.dpc.ndr.reader.NdrObjectReader
Direct Known Subclasses:
AgentReader, GroupingObjectReader, MetadataReader

public class NdrObjectReader
extends Object

Base Class for reading NDR responses to GET Requests, used primarily to support NDR Import operations. Extended to read specific types of NDR Objects, such as Metadata and MetadataProvider.

Author:
ostwald

Field Summary
protected  String createdDate
           
protected  Document doc
           
protected  List dsFormats
           
protected  String handle
           
protected  String lastModifiedDate
           
protected  String nativeDataStreamFormat
          Native data stream format for this object
protected  org.jaxen.SimpleNamespaceContext nsContext
          nsContext to support xpath ops
protected  NDRConstants.NDRObjectType objectType
           
 
Constructor Summary
NdrObjectReader(Document response)
          Constructor for the NdrObjectReader object with a XML Document (for testing purposes)
NdrObjectReader(Document ndrResponse, String nativeDataStreamFormat)
          Constructor for the NdrObjectReader object
NdrObjectReader(String handle)
          Constructor for the NdrObjectReader object with ndrHandle
NdrObjectReader(String handle, String nativeDataStreamFormat)
          Constructor for the NdrObjectReader object with ndrHandle and specified nativeDataStreamFormat.
 
Method Summary
 Element getCanonicalNsdlDcDataStream()
          Returns the NON_NATIVE data stream labeled simply as "nsdl_dc" with no version
 Date getCreated()
          Gets the fedora-view:createdDate property of the NdrObject as a Date object
 String getCreatedDate()
          Gets the fedora-view:createdDate property of the NdrObject
 Element getDataStream(String format)
          Gets the dataStream of the NdrObjectReader for specified format.
 Element getDataStream(String format, String version)
          Gets the dataStream matching the provided formatSpec, or null if requested stream is not present.
 Document getDocument()
          Gets the original "get" response for this reader object as a dom4j.Document instance.
 Set getFormats()
          Returns the data stream formats as a Set.
 String getHandle()
          Gets the handle attribute of the NdrObjectReader object.
 Date getLastModified()
          Gets the fedora-view:lastModifiedDate property of the NdrObject as a Date object
 String getLastModifiedDate()
          Gets the fedora-view:lastModifiedDate property of the NdrObject as a string
 Element getNativeDataStream(String format)
          Gets the native dataStream of the NdrObject for the specified native "format".
 Element getNativeDataStream(String format, String version)
          Gets the navite dataStream of the NdrObject for specified format and version.
protected  Node getNode(String xpath)
          Gets a single Node satisfying give XPath.
protected  List getNodes(String path)
          Get all Nodes satisfying the given xpath.
protected  String getNodeText(String xpath)
          Return the Text of a Node satisfying the given XPath.
protected  org.jaxen.SimpleNamespaceContext getNsContext()
          Returns a namespace context instance, containing namespaces occuring in NDR objects, that is used in xpath operations.
 NDRConstants.NDRObjectType getObjectType()
          Gets the objectType property of the NdrObject.
 String getProperty(String prop)
          Gets the specified property of the NdrObjectReader object (returning the first if more than one property is present).
 List getPropertyValues(String name)
          Gets a list of values for the specified property
 String getRelationship(String name)
          Gets the FIRST relationship (there may be more) with specified name, which is assumed to be in "nsdl" namespace if no prefix is present.
 List getRelationshipValues(String name)
          Gets all the relationships for the specified name.
 NDRConstants.ObjectState getState()
          Gets the fedora-model:state property of the NdrObject
protected  XPath getXPath(String path)
          Converts the provided xpath string into an XPath instance using the nsContext (see getNsContext)
protected  void initDataStreams()
          Builds a map containing entries for each datastream format in this object, but does not populate the values of the map until necessary.
protected static void pp(Node node)
          Prints a dom4j.Node as formatted string.
static void setDebug(boolean bool)
          Sets the debug attribute of the NdrObjectReader class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

doc

protected Document doc

dsFormats

protected List dsFormats

handle

protected String handle

objectType

protected NDRConstants.NDRObjectType objectType

lastModifiedDate

protected String lastModifiedDate

createdDate

protected String createdDate

nativeDataStreamFormat

protected String nativeDataStreamFormat
Native data stream format for this object


nsContext

protected org.jaxen.SimpleNamespaceContext nsContext
nsContext to support xpath ops

Constructor Detail

NdrObjectReader

public NdrObjectReader(Document response)
                throws Exception
Constructor for the NdrObjectReader object with a XML Document (for testing purposes)

Parameters:
response - NOT YET DOCUMENTED
Throws:
Exception - NOT YET DOCUMENTED

NdrObjectReader

public NdrObjectReader(String handle)
                throws Exception
Constructor for the NdrObjectReader object with ndrHandle

Parameters:
handle - handle of NDR object to read
Throws:
Exception - if object cannot be read from NDR

NdrObjectReader

public NdrObjectReader(String handle,
                       String nativeDataStreamFormat)
                throws Exception
Constructor for the NdrObjectReader object with ndrHandle and specified nativeDataStreamFormat.

Parameters:
handle - handle of NDR object to read
nativeDataStreamFormat - native metadata format (helps extract native data_stream)
Throws:
Exception - NOT YET DOCUMENTED

NdrObjectReader

public NdrObjectReader(Document ndrResponse,
                       String nativeDataStreamFormat)
                throws Exception
Constructor for the NdrObjectReader object

Parameters:
nativeDataStreamFormat - NOT YET DOCUMENTED
ndrResponse - NOT YET DOCUMENTED
Throws:
Exception - NOT YET DOCUMENTED
Method Detail

getNsContext

protected org.jaxen.SimpleNamespaceContext getNsContext()
Returns a namespace context instance, containing namespaces occuring in NDR objects, that is used in xpath operations.

Returns:
The nsContext value

getDocument

public Document getDocument()
Gets the original "get" response for this reader object as a dom4j.Document instance.

Returns:
The document value

getProperty

public String getProperty(String prop)
Gets the specified property of the NdrObjectReader object (returning the first if more than one property is present). If provide prop is not qualified, a namespace prefix of "nsdl" is assumed. If a namespace prefix is provided (e.g., "ncs:status"), it must be contained in the nameSpace Context for this reader.

Parameters:
prop - Description of the Parameter
Returns:
The property value

getPropertyValues

public List getPropertyValues(String name)
Gets a list of values for the specified property

Parameters:
name - propertyname, qualifed with "nsdl" if no namespace prefix is present.
Returns:
a list of property values for specified property.

getRelationship

public String getRelationship(String name)
Gets the FIRST relationship (there may be more) with specified name, which is assumed to be in "nsdl" namespace if no prefix is present.

Parameters:
name - relationship name ("auth:authorizedToChange")
Returns:
the relationship value (a ndrHandle)

getRelationshipValues

public List getRelationshipValues(String name)
Gets all the relationships for the specified name.

Parameters:
name - Relationship name ("auth:authorizedToChange)
Returns:
List of relationship values (ndr handles) for provided name

getHandle

public String getHandle()
Gets the handle attribute of the NdrObjectReader object.

Returns:
The handle value

getObjectType

public NDRConstants.NDRObjectType getObjectType()
Gets the objectType property of the NdrObject. Can be used as integrity check.

Returns:
The objectType value

getState

public NDRConstants.ObjectState getState()
Gets the fedora-model:state property of the NdrObject

Returns:
The state value

getLastModifiedDate

public String getLastModifiedDate()
Gets the fedora-view:lastModifiedDate property of the NdrObject as a string

Returns:
The lastModifiedDate value

getLastModified

public Date getLastModified()
Gets the fedora-view:lastModifiedDate property of the NdrObject as a Date object

Returns:
The lastModified value

getCreatedDate

public String getCreatedDate()
Gets the fedora-view:createdDate property of the NdrObject

Returns:
The createdDate value

getCreated

public Date getCreated()
Gets the fedora-view:createdDate property of the NdrObject as a Date object

Returns:
The created value

initDataStreams

protected void initDataStreams()
Builds a map containing entries for each datastream format in this object, but does not populate the values of the map until necessary.

NOTE: datastreams ending in "_info" are ignored and therefore not accessible by "getDataStream"

DataStream elements have format attribute named "format_"+DATA_STREAM_FORMAT"


getFormats

public Set getFormats()
Returns the data stream formats as a Set.

Returns:
The formats value

getNativeDataStream

public Element getNativeDataStream(String format)
Gets the native dataStream of the NdrObject for the specified native "format".

Note: this method cannot return a non-native datastream.

Parameters:
format - native datastream format (e.g., "oai_dc")
Returns:
The dataStream value

getNativeDataStream

public Element getNativeDataStream(String format,
                                   String version)
Gets the navite dataStream of the NdrObject for specified format and version. If version is provided, the datastream must exactly match the version.

Note: this method cannot return a non-native datastream.

Parameters:
format - native datastream format (.e.g, "oai_dc")
version - version (e.g., "v1.01")
Returns:
The nativeDataStream value

getDataStream

public Element getDataStream(String format)
Gets the dataStream of the NdrObjectReader for specified format.

Parameters:
format - datastream format (e.g., "nsdl_dc")
Returns:
The dataStream value

getDataStream

public Element getDataStream(String format,
                             String version)
Gets the dataStream matching the provided formatSpec, or null if requested stream is not present. Examples of formatSpec:

Parameters:
format - datastream format (e.g., "nsdl_dc")
version - version (e.g., "v1.01")
Returns:
The dataStream value

getCanonicalNsdlDcDataStream

public Element getCanonicalNsdlDcDataStream()
Returns the NON_NATIVE data stream labeled simply as "nsdl_dc" with no version

Returns:
The canonicalNsdlDcDataStream value

getNodes

protected List getNodes(String path)
Get all Nodes satisfying the given xpath.

Parameters:
path - NOT YET DOCUMENTED
Returns:
a List of all nodes satisfying given XPath, or null if path does not exist.

getXPath

protected XPath getXPath(String path)
Converts the provided xpath string into an XPath instance using the nsContext (see getNsContext)

Parameters:
path - string representation of an xpath
Returns:
The xPath value

getNode

protected Node getNode(String xpath)
Gets a single Node satisfying give XPath. If more than one Node is found, the first is returned (and a msg is printed).

Parameters:
xpath - an XPath
Returns:
a dom4j Node

getNodeText

protected String getNodeText(String xpath)
Return the Text of a Node satisfying the given XPath.

Parameters:
xpath - an XPath
Returns:
Text of Node or empty String if no Node is found

setDebug

public static void setDebug(boolean bool)
Sets the debug attribute of the NdrObjectReader class

Parameters:
bool - The new debug value

pp

protected static void pp(Node node)
Prints a dom4j.Node as formatted string.

Parameters:
node - NOT YET DOCUMENTED

DLESE Tools
v1.6.0