Version: 1.1.1

ca.ucalgary.seahawk.services
Class MobyClient

java.lang.Object
  extended by ca.ucalgary.seahawk.services.MobyClient

public class MobyClient
extends Object

The engine that finds MOBY data in unstructured text or DOM of other XML languages according to a rules database. The format of this database is described here. Used in Seahawk to provide the service options popup items.


Field Summary
static String ARTICLENAME_RULE_TAG
           
static String DATA_MAPPING_XML_RESOURCE
           
static String DATATYPE_ATTR
           
static String DATATYPE_RULE_ATTR
           
static String DATATYPE_RULE_TAG
           
static String ENCODING_ATTR
           
static String ENCODING_ATTR_BASE64_VAL
           
static String ENCODING_ATTR_NONE_VAL
           
static String IS_ALIVE_SERVICE_URL
           
static String MEMBER_RULE_ATTR
           
static String MEMBER_RULE_TAG
           
static String MEMBERS_RULE_ATTR
           
static String MEMBERS_RULE_TAG
           
static String NAMESPACE_MODEL_ATTR
           
static String NAMESPACE_RULE_TAG
           
static String NAMESPACE_VALUE_ATTR
           
static String NAMESPACE_VALUE_TAG
           
static String PREFIX_ATTR
           
static String PREFIX_TAG
           
static String REGEX_TAG
           
static String RESOURCE_SYSTEM_PROPERTY
           
static String RULE_NAME_ATTR
           
static String RULE_SET_TAG
           
static String SINGLE_RETURNED_VALUE_KEY
           
static String URL_REGEX_TAG
           
static String WHITESPACE_ATTR
           
static String WHITESPACE_ATTR_KEEP_VAL
           
static String WHITESPACE_ATTR_NORMALIZE_VAL
           
static String WHITESPACE_ATTR_STRIP_FLANKING_VAL
           
static String WHITESPACE_ATTR_STRIP_VAL
           
static String XPATH_TAG
           
 
Constructor Summary
MobyClient()
          Nullary constructor that differs significantly in behaviour from the one-arg c-tor: it uses the registry from SeahawkOptions, or if not available, the RegistryCache default registry.
MobyClient(Registry reg)
          Constructor specifying a particular registry to use.
 
Method Summary
 void addMappingsFromURL(URL u)
          Parses the XML formatted rules from the input stream specified by the URL.
 void addNamespaceContext(String prefix, String nsURI)
           
 void addRegexMapping(String regexp, Map<String,String> nsRules, String mobyDataType, Map<String,String[]> membersMap)
           
 void addRegexMapping(String regexp, Map<String,String> nsRules, String mobyDataType, Map<String,String[]> membersMap, String articleName, String ruleName, String urn)
           
 void addRegexMapping(String regexp, String[] mobyObj)
           
 void addRegexMapping(String regexp, String[] mobyObj, String articleName, String urn)
           
 void addURLRegexMapping(String url_regexp, Map<String,String> url_nsRules, String mobyDataType, Map<String,String[]> membersMap, String articleName, String urn)
           
 void addURLRegexMapping(String url_regexp, String[] mobyObj, String articleName, String urn)
           
 void addXPathMapping(String xpath_exp, Map<String,String> nsRules, String mobyDataType, Map<String,String[]> membersMap, String articleName, String urn)
           
 void addXPathMapping(String xpath_exp, Map<String,String> nsRules, String articleName, String urn)
           
 void addXPathMapping(String xpath, String[] mobyObj)
           
 boolean canProduceDataTypeFromString(MobyDataType targetDataType)
          Indicates whether at least one production rule exists for the data type or one of its children.
 void clear()
          Removes all mapping rules.
 void clearRegexs()
           
 void clearURLRegexs()
           
 void clearXPaths()
           
 MobyComplexBuilder getBuilder(String ruleName)
          If a rule was given this name, or url/lsid, the MOBY object builder for the rule is returned.
 CentralImpl getMobyCentralImpl()
           
 MobyDataInstance getMobyObject(Map<String,byte[]> resultParts, MobyPrimaryData dataTemplate)
          Create a MOBY data instance from a map of name->bytes[] by applying the rules of the given MobyClient.
 MobyDataInstance getMobyObject(Node n, MobyPrimaryData dataTemplate)
          Create a MOBY data instance from a DOM by applying the rules of the given MobyClient (xpaths).
 MobyDataInstance getMobyObject(String s, MobyPrimaryData dataTemplate)
          Create a MOBY data instance from a string by applying the rules of the given MobyClient (regexes).
 MobyDataObject[] getMobyObjects(byte[] rawData, MobyDataType targetDataType)
          Using the regular expression mappings that have been set up, maps a string using rules producing moby objects of the given type.
 MobyDataObject[] getMobyObjects(CharSequence textData)
          Using the regular expression mappings that have been set up, maps a string to moby objects.
 MobyDataObject[] getMobyObjects(CharSequence textData, byte[] bytes)
           
 MobyDataObject[] getMobyObjects(CharSequence textData, MobyDataType targetDataType)
           
 MobyDataObject[] getMobyObjects(CharSequence textData, MobyDataType targetDataType, MobyNamespace targetNS)
          Using the regular expression mappings that have been set up, maps a string using rules producing moby objects of the given type.
 MobyDataObject[] getMobyObjects(Node n)
          Using the XPath mappings that have been set up, maps a DOM node to moby objects.
 MobyDataObject[] getMobyObjects(URL url)
          Using the URL regular expression mappings that have been set up, maps a string to moby objects.
 MobyDataObject[] getMobyObjects(URL url, MobyDataType targetDataType)
           
 MobyDataObject[] getMobyObjects(URL url, String linkText)
           
 MobyDataObject[] getMobyObjects(URL url, String linkText, MobyDataType targetDataType)
           
 Map<String,MobyDataObject[]> getMobyObjectsURNMap(CharSequence textData)
          Same as getMobyObjects(String), but returns only those generated Moby objects that are derived from URN-addressable rules (which are the keys), mostly for provenance and reproducibility purposes.
 Map<String,MobyDataObject[]> getMobyObjectsURNMap(CharSequence textData, byte[] bytes)
           
 Map<String,MobyDataObject[]> getMobyObjectsURNMap(Node n)
          Same as getMobyObjects(Node), but applies only those rules that have a URN associated with them, mainly for provenance and reuse purposes.Map
static MobyPrimaryDataSimple getObjectProduced(URL ruleSource, String ruleURI, Registry reg)
          Convenience method to backtrack from a mapping rule to the Moby datatype it produces.
 Pattern getPattern(String ruleName)
          If a rule was given this name, the regex pattern for the rule is returned.
 Registry getRegistry()
           
 MobyDataServiceAssocInstance getServices(MobyDataObject mdo)
           
 MobyDataServiceAssocInstance[] getServices(MobyDataObject[] mdos)
           
 MobyDataServiceAssocInstance getServices(MobyDataObjectSet mdos)
           
 MobyDataServiceAssocInstance[] getServices(MobyDataObjectSet[] mdoss)
           
 MobyDataServiceAssocInstance[] getServices(Node n)
          Performs the moby object creation and service association together (XPath rules).
 MobyDataServiceAssocInstance[] getServices(String s)
          Performs the moby object creation and service association together (regex rules).
 MobyDataServiceAssocInstance[] getServices(URL u)
          Performs the moby object creation and service association together (url_regex rules).
 boolean isArticleNameRule(Element e)
           
 boolean isDataTypeRule(Element e)
           
 boolean isMapped(Node n)
           
 boolean isMemberRule(Element e)
           
 boolean isMembersRule(Element e)
           
 boolean isNamespaceRule(Element e)
           
 boolean isPrefixRule(Element e)
           
 boolean isPrimitiveDataType(String dataType)
           
 boolean isRegex(Element e)
           
 boolean isURLRegex(Element e)
           
 boolean isXPath(Element e)
           
 void setRequiredServiceLevel(int level)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA_MAPPING_XML_RESOURCE

public static final String DATA_MAPPING_XML_RESOURCE
See Also:
Constant Field Values

RESOURCE_SYSTEM_PROPERTY

public static final String RESOURCE_SYSTEM_PROPERTY
See Also:
Constant Field Values

RULE_SET_TAG

public static final String RULE_SET_TAG
See Also:
Constant Field Values

RULE_NAME_ATTR

public static final String RULE_NAME_ATTR
See Also:
Constant Field Values

PREFIX_TAG

public static final String PREFIX_TAG
See Also:
Constant Field Values

PREFIX_ATTR

public static final String PREFIX_ATTR
See Also:
Constant Field Values

ARTICLENAME_RULE_TAG

public static final String ARTICLENAME_RULE_TAG
See Also:
Constant Field Values

NAMESPACE_RULE_TAG

public static final String NAMESPACE_RULE_TAG
See Also:
Constant Field Values

NAMESPACE_MODEL_ATTR

public static final String NAMESPACE_MODEL_ATTR
See Also:
Constant Field Values

NAMESPACE_VALUE_TAG

public static final String NAMESPACE_VALUE_TAG
See Also:
Constant Field Values

NAMESPACE_VALUE_ATTR

public static final String NAMESPACE_VALUE_ATTR
See Also:
Constant Field Values

DATATYPE_RULE_TAG

public static final String DATATYPE_RULE_TAG
See Also:
Constant Field Values

DATATYPE_RULE_ATTR

public static final String DATATYPE_RULE_ATTR
See Also:
Constant Field Values

MEMBER_RULE_TAG

public static final String MEMBER_RULE_TAG
See Also:
Constant Field Values

MEMBER_RULE_ATTR

public static final String MEMBER_RULE_ATTR
See Also:
Constant Field Values

MEMBERS_RULE_TAG

public static final String MEMBERS_RULE_TAG
See Also:
Constant Field Values

MEMBERS_RULE_ATTR

public static final String MEMBERS_RULE_ATTR
See Also:
Constant Field Values

URL_REGEX_TAG

public static final String URL_REGEX_TAG
See Also:
Constant Field Values

REGEX_TAG

public static final String REGEX_TAG
See Also:
Constant Field Values

XPATH_TAG

public static final String XPATH_TAG
See Also:
Constant Field Values

WHITESPACE_ATTR

public static final String WHITESPACE_ATTR
See Also:
Constant Field Values

WHITESPACE_ATTR_STRIP_VAL

public static final String WHITESPACE_ATTR_STRIP_VAL
See Also:
Constant Field Values

WHITESPACE_ATTR_NORMALIZE_VAL

public static final String WHITESPACE_ATTR_NORMALIZE_VAL
See Also:
Constant Field Values

WHITESPACE_ATTR_STRIP_FLANKING_VAL

public static final String WHITESPACE_ATTR_STRIP_FLANKING_VAL
See Also:
Constant Field Values

WHITESPACE_ATTR_KEEP_VAL

public static final String WHITESPACE_ATTR_KEEP_VAL
See Also:
Constant Field Values

DATATYPE_ATTR

public static final String DATATYPE_ATTR
See Also:
Constant Field Values

ENCODING_ATTR

public static final String ENCODING_ATTR
See Also:
Constant Field Values

ENCODING_ATTR_BASE64_VAL

public static final String ENCODING_ATTR_BASE64_VAL
See Also:
Constant Field Values

ENCODING_ATTR_NONE_VAL

public static final String ENCODING_ATTR_NONE_VAL
See Also:
Constant Field Values

SINGLE_RETURNED_VALUE_KEY

public static final String SINGLE_RETURNED_VALUE_KEY
See Also:
Constant Field Values

IS_ALIVE_SERVICE_URL

public static final String IS_ALIVE_SERVICE_URL
See Also:
Constant Field Values
Constructor Detail

MobyClient

public MobyClient()
           throws MobyException
Nullary constructor that differs significantly in behaviour from the one-arg c-tor: it uses the registry from SeahawkOptions, or if not available, the RegistryCache default registry. If the SeahawkOptions registry choice changes during the life of this object, the new registry will NOT be reflected here.

Throws:
MobyException

MobyClient

public MobyClient(Registry reg)
           throws MobyException
Constructor specifying a particular registry to use.

Parameters:
reg - the registry that will be called to validate ontology terms and determine available services. If null, the default registry will be used.
Throws:
MobyException
Method Detail

getObjectProduced

public static MobyPrimaryDataSimple getObjectProduced(URL ruleSource,
                                                      String ruleURI,
                                                      Registry reg)
                                               throws Exception
Convenience method to backtrack from a mapping rule to the Moby datatype it produces.

Parameters:
ruleSource - where the rule should be loaded from
ruleURI - a unique ID for the rule, in the source XML using Dublin Core
Returns:
a template object with the datatype and namespaces produced by the rule
Throws:
Exception

getRegistry

public Registry getRegistry()

addMappingsFromURL

public void addMappingsFromURL(URL u)
                        throws Exception
Parses the XML formatted rules from the input stream specified by the URL.

Throws:
Exception

addNamespaceContext

public void addNamespaceContext(String prefix,
                                String nsURI)

isPrefixRule

public boolean isPrefixRule(Element e)

isRegex

public boolean isRegex(Element e)

isURLRegex

public boolean isURLRegex(Element e)

isXPath

public boolean isXPath(Element e)

isDataTypeRule

public boolean isDataTypeRule(Element e)

isArticleNameRule

public boolean isArticleNameRule(Element e)

isMemberRule

public boolean isMemberRule(Element e)

isMembersRule

public boolean isMembersRule(Element e)

isNamespaceRule

public boolean isNamespaceRule(Element e)

isPrimitiveDataType

public boolean isPrimitiveDataType(String dataType)

getMobyCentralImpl

public CentralImpl getMobyCentralImpl()

getServices

public MobyDataServiceAssocInstance[] getServices(Node n)
                                           throws MobyException
Performs the moby object creation and service association together (XPath rules).

Throws:
MobyException

getServices

public MobyDataServiceAssocInstance[] getServices(String s)
                                           throws MobyException
Performs the moby object creation and service association together (regex rules).

Throws:
MobyException

getServices

public MobyDataServiceAssocInstance[] getServices(URL u)
                                           throws MobyException
Performs the moby object creation and service association together (url_regex rules).

Throws:
MobyException

getMobyObjects

public MobyDataObject[] getMobyObjects(CharSequence textData,
                                       MobyDataType targetDataType)

getMobyObjects

public MobyDataObject[] getMobyObjects(CharSequence textData,
                                       MobyDataType targetDataType,
                                       MobyNamespace targetNS)
Using the regular expression mappings that have been set up, maps a string using rules producing moby objects of the given type.

Parameters:
targetDataType - matches any data type if null, otherwise restricts returned items to those that are of (or inherit from) the given type

getMobyObject

public MobyDataInstance getMobyObject(Node n,
                                      MobyPrimaryData dataTemplate)
                               throws Exception,
                                      MobyServiceException
Create a MOBY data instance from a DOM by applying the rules of the given MobyClient (xpaths). The creation of a single object or collection is done according to the dataTemplate provided.

Throws:
MobyServiceException - NOTE: these are just warning level exceptions about collection-simple casting that you can add to the service response, or ignore if you like
Exception

getMobyObject

public MobyDataInstance getMobyObject(String s,
                                      MobyPrimaryData dataTemplate)
                               throws Exception,
                                      MobyServiceException
Create a MOBY data instance from a string by applying the rules of the given MobyClient (regexes). The creation of a single object or collection is done according to the dataTemplate provided.

Throws:
MobyServiceException - NOTE: these are just warning level exceptions about collection-simple casting that you can add to the service response, or ignore if you like
Exception

getMobyObject

public MobyDataInstance getMobyObject(Map<String,byte[]> resultParts,
                                      MobyPrimaryData dataTemplate)
                               throws Exception,
                                      MobyServiceException
Create a MOBY data instance from a map of name->bytes[] by applying the rules of the given MobyClient. The creation of a single object or collection is done according to the dataTemplate provided.

Throws:
MobyServiceException - NOTE: these are just warning level exceptions about collection-simple casting that you can add to the service response, or ignore if you like
Exception

getMobyObjects

public MobyDataObject[] getMobyObjects(byte[] rawData,
                                       MobyDataType targetDataType)
Using the regular expression mappings that have been set up, maps a string using rules producing moby objects of the given type. Particularly, the regex is assumed to include only ASCII characters at first, and the byte-translation of it is checked against the raw data's bytes. If no rules match, the raw data is converted to a String, and the regex are tried as normal... The net effect is that you specify magic signatures for file types as regular expression rules, and calling this method will match up the file type by byte-wise comparing the data and pattern.


getMobyObjects

public MobyDataObject[] getMobyObjects(CharSequence textData)
Using the regular expression mappings that have been set up, maps a string to moby objects.


getMobyObjectsURNMap

public Map<String,MobyDataObject[]> getMobyObjectsURNMap(CharSequence textData)
Same as getMobyObjects(String), but returns only those generated Moby objects that are derived from URN-addressable rules (which are the keys), mostly for provenance and reproducibility purposes.


getMobyObjectsURNMap

public Map<String,MobyDataObject[]> getMobyObjectsURNMap(CharSequence textData,
                                                         byte[] bytes)

getMobyObjects

public MobyDataObject[] getMobyObjects(CharSequence textData,
                                       byte[] bytes)

getMobyObjects

public MobyDataObject[] getMobyObjects(URL url)
Using the URL regular expression mappings that have been set up, maps a string to moby objects. URL regexs are special because they are flexible in the order in which query parameters are given. They may also have requirements based on the hypertext linked. This method does not look at the contents of the URL, but rather the URL itself.


getMobyObjects

public MobyDataObject[] getMobyObjects(URL url,
                                       String linkText)

getMobyObjects

public MobyDataObject[] getMobyObjects(URL url,
                                       MobyDataType targetDataType)

getMobyObjects

public MobyDataObject[] getMobyObjects(URL url,
                                       String linkText,
                                       MobyDataType targetDataType)

getMobyObjects

public MobyDataObject[] getMobyObjects(Node n)
Using the XPath mappings that have been set up, maps a DOM node to moby objects.


getMobyObjectsURNMap

public Map<String,MobyDataObject[]> getMobyObjectsURNMap(Node n)
Same as getMobyObjects(Node), but applies only those rules that have a URN associated with them, mainly for provenance and reuse purposes.Map


setRequiredServiceLevel

public void setRequiredServiceLevel(int level)

getServices

public MobyDataServiceAssocInstance getServices(MobyDataObjectSet mdos)
                                         throws MobyException
Throws:
MobyException

getServices

public MobyDataServiceAssocInstance getServices(MobyDataObject mdo)
                                         throws MobyException
Throws:
MobyException

getServices

public MobyDataServiceAssocInstance[] getServices(MobyDataObjectSet[] mdoss)
                                           throws MobyException
Throws:
MobyException

getServices

public MobyDataServiceAssocInstance[] getServices(MobyDataObject[] mdos)
                                           throws MobyException
Throws:
MobyException

isMapped

public boolean isMapped(Node n)

addRegexMapping

public void addRegexMapping(String regexp,
                            String[] mobyObj)

addRegexMapping

public void addRegexMapping(String regexp,
                            String[] mobyObj,
                            String articleName,
                            String urn)

addURLRegexMapping

public void addURLRegexMapping(String url_regexp,
                               String[] mobyObj,
                               String articleName,
                               String urn)

addRegexMapping

public void addRegexMapping(String regexp,
                            Map<String,String> nsRules,
                            String mobyDataType,
                            Map<String,String[]> membersMap)

addRegexMapping

public void addRegexMapping(String regexp,
                            Map<String,String> nsRules,
                            String mobyDataType,
                            Map<String,String[]> membersMap,
                            String articleName,
                            String ruleName,
                            String urn)

addURLRegexMapping

public void addURLRegexMapping(String url_regexp,
                               Map<String,String> url_nsRules,
                               String mobyDataType,
                               Map<String,String[]> membersMap,
                               String articleName,
                               String urn)

addXPathMapping

public void addXPathMapping(String xpath,
                            String[] mobyObj)

addXPathMapping

public void addXPathMapping(String xpath_exp,
                            Map<String,String> nsRules,
                            String articleName,
                            String urn)

addXPathMapping

public void addXPathMapping(String xpath_exp,
                            Map<String,String> nsRules,
                            String mobyDataType,
                            Map<String,String[]> membersMap,
                            String articleName,
                            String urn)

clear

public void clear()
Removes all mapping rules.


clearXPaths

public void clearXPaths()

clearRegexs

public void clearRegexs()

clearURLRegexs

public void clearURLRegexs()

canProduceDataTypeFromString

public boolean canProduceDataTypeFromString(MobyDataType targetDataType)
Indicates whether at least one production rule exists for the data type or one of its children.


getBuilder

public MobyComplexBuilder getBuilder(String ruleName)
If a rule was given this name, or url/lsid, the MOBY object builder for the rule is returned.


getPattern

public Pattern getPattern(String ruleName)
If a rule was given this name, the regex pattern for the rule is returned.


Version: 1.1.1

Submit a bug or feature
Generated: Sat May 29 04:26:35 EDT 2010