[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Mon Dec 17 18:37:55 UTC 2007
gordonp
Mon Dec 17 13:37:55 EST 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services
In directory dev.open-bio.org:/tmp/cvs-serv6019/src/main/ca/ucalgary/seahawk/services
Modified Files:
MobyClient.java
Log Message:
Added support for registry specification, got rid of unchecked type operations
moby-live/Java/src/main/ca/ucalgary/seahawk/services MobyClient.java,1.17,1.18
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyClient.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyClient.java 2007/12/07 20:22:49 1.17
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyClient.java 2007/12/17 18:37:55 1.18
@@ -67,32 +67,46 @@
private NamespaceContextImpl nsContext;
private CentralImpl c;
- private Map isDeadMap;
- private HashMap xpathMap;
- private HashMap urlRegexMap;
- private Map<Pattern,MobyComplexBuilder> regexMap;
- private Map<String,MobyComplexBuilder> builderNameMap;
- private Map<String,Pattern> patternNameMap;
+ private Map<String,String> isDeadMap;
+ private Map<XPath,MobyComplexBuilder> xpathMap;
+ private Map<Pattern,MobyComplexBuilder> urlRegexMap;
+ private Map<Pattern,MobyComplexBuilder> regexMap;
+ private Map<String,MobyComplexBuilder> builderNameMap;
+ private Map<String,Pattern> patternNameMap;
+ private Registry registry;
private URL dataMappingXMLURL;
private DocumentBuilder docBuilder;
private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(MobyClient.class);
private int serviceLevel = MobyService.UNCHECKED;
+ /**
+ * 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.
+ */
public MobyClient() throws MobyException{
- Registry reg = SeahawkOptions.getRegistry();
- if(reg == null){
- reg = RegistryCache.getDefaultRegistry();
- }
+ this(SeahawkOptions.getRegistry() == null ?
+ RegistryCache.getDefaultRegistry() :
+ SeahawkOptions.getRegistry());
+ }
+ /**
+ * Constructor specifying a particular registry to use.
+ *
+ * @param reg the registry that will be called to validate ontology terms and determine available services. If null, the default registry will be used.
+ */
+ public MobyClient(Registry reg) throws MobyException{
+ registry = reg;
if(reg != null && reg.getEndpoint() != null){
c = new CentralCachedCallsImpl(reg.getEndpoint());
}
else{
c = new CentralCachedCallsImpl();
}
- xpathMap = new HashMap();
- urlRegexMap = new HashMap();
+ xpathMap = new HashMap<XPath,MobyComplexBuilder>();
+ urlRegexMap = new HashMap<Pattern,MobyComplexBuilder>();
regexMap = new HashMap<Pattern,MobyComplexBuilder>();
builderNameMap = new HashMap<String,MobyComplexBuilder>();
patternNameMap = new HashMap<String,Pattern>();
@@ -139,6 +153,10 @@
}
}
+ public Registry getRegistry(){
+ return registry;
+ }
+
/**
* Parses the XML formatted rules from the input stream specified by the URL.
*/
@@ -211,9 +229,9 @@
String ruleName = ruleSet.getAttribute(RULE_NAME_ATTR);
- Vector regexStrings = new Vector();
- Vector urlRegexStrings = new Vector();
- Vector xpathStrings = new Vector();
+ Vector<String> regexStrings = new Vector<String>();
+ Vector<String> urlRegexStrings = new Vector<String>();
+ Vector<String> xpathStrings = new Vector<String>();
Map<String,String> namespaceMap = new HashMap<String,String>();
Map<String,String[]> memberMap = new HashMap<String,String[]>();
String dataTypeString = null;
@@ -365,7 +383,7 @@
return dtTag.getAttribute(DATATYPE_RULE_ATTR);
}
- protected String addRegexString(Element regexTag, Vector regexStrings) throws Exception{
+ protected String addRegexString(Element regexTag, Vector<String> regexStrings) throws Exception{
if(!isRegex(regexTag)){
throw new Exception("Element provided to addRegexString (" +
(regexTag == null ? null : regexTag.getLocalName()) +
@@ -383,7 +401,7 @@
return str;
}
- protected String addURLRegexString(Element urlRegexTag, Vector urlRegexStrings) throws Exception{
+ protected String addURLRegexString(Element urlRegexTag, Vector<String> urlRegexStrings) throws Exception{
if(!isRegex(urlRegexTag)){
throw new Exception("Element provided to addURLRegexString (" +
(urlRegexTag == null ? null : urlRegexTag.getLocalName()) +
@@ -401,7 +419,7 @@
return str;
}
- protected String addXPathString(Element xPathTag, Vector xPathStrings) throws Exception{
+ protected String addXPathString(Element xPathTag, Vector<String> xPathStrings) throws Exception{
if(!isXPath(xPathTag)){
throw new Exception("Element provided to addXPathString (" +
(xPathTag == null ? null : xPathTag.getLocalName()) +
@@ -811,7 +829,7 @@
}
// Vector of moby objects we construct based on the regex mappings found
- Vector objectVector = new Vector();
+ Vector<MobyDataObject> objectVector = new Vector<MobyDataObject>();
Iterator regex_keys = regexMap.keySet().iterator();
while(regex_keys.hasNext()){ //map still has untraversed regex entry to test
@@ -863,7 +881,7 @@
}
// Vector of moby objects we construct based on the regex mappings found
- Vector objectVector = new Vector();
+ Vector<MobyDataObject> objectVector = new Vector<MobyDataObject>();
String urlString = url.toString();
Iterator url_regex_keys = urlRegexMap.keySet().iterator();
@@ -914,7 +932,7 @@
PrefixResolver doc_prefix_resolver = new PrefixResolverDefault(current_node);
// Vector of moby objects we construct based on the xpath mappings found
- Vector objectVector = new Vector();
+ Vector<MobyDataObject> objectVector = new Vector<MobyDataObject>();
Iterator xpath_keys = xpathMap.keySet().iterator();
while(xpath_keys.hasNext()){ //map still has untraversed xpath entry to test
@@ -1018,15 +1036,13 @@
templateServices.setCategory("");
MobyService[] mService = c.findService(templateServices);
- Vector<MobyService> filteredServices = new Vector();
+ Vector<MobyService> filteredServices = new Vector<MobyService>();
// Let's make sure all of the services have their service type properly instantiated
// for ontology checks later on
for(int j = 0; j < mService.length; j++){
mService[j].setStatus(MobyService.ALIVE, isServiceAlive(mService[j]));
mService[j].setServiceType(MobyServiceType.getServiceType(mService[j].getServiceType().getName(),
- SeahawkOptions.getRegistry()));
- //System.err.println("Service type is "+mService[j].getServiceType()+" registry="+SeahawkOptions.getRegistry());
- //System.err.println(mService[j].getServiceType().getParent());
+ getRegistry()));
if(serviceLevel != MobyService.UNCHECKED){
int serviceStatus = mService[j].getStatus();
//System.err.println("Service " + mService[j].getName() + " has status " + serviceStatus);
@@ -1082,7 +1098,7 @@
return;
}
- Map url_nsRules = new HashMap();
+ Map<String,String> url_nsRules = new HashMap<String,String>();
// Default the rule to take the first saved grouping of the regex (whole URL won't be a good ID)
for(int i = 0; i < mobyObj.length; i++){
url_nsRules.put(mobyObj[i], "$1");
@@ -1173,13 +1189,13 @@
addRegexMapping(regexp, nsRules, (String) null, (Map<String,String[]>) null, articleName, null);
}
- protected void addURLRegexMapping(String url_regexp, Map url_nsRules, String articleName){ //nsRules = Map<String ns, String regex_replacement>
+ protected void addURLRegexMapping(String url_regexp, Map<String,String> url_nsRules, String articleName){ //nsRules = Map<String ns, String regex_replacement>
if(url_nsRules == null || url_nsRules.size() == 0){
System.err.println("Ignoring empty namespace-only url regex rule mappings");
return;
}
- addURLRegexMapping(url_regexp, url_nsRules, (String) null, (Map) null, articleName);
+ addURLRegexMapping(url_regexp, url_nsRules, (String) null, (Map<String,String[]>) null, articleName);
}
public void addRegexMapping(String regexp, Map<String,String> nsRules,
@@ -1204,7 +1220,7 @@
//System.err.println("Got null data type for regex "+regexp);
return regexp; //must be a base object
}
- MobyDataType dataType = MobyDataType.getDataType(mobyDataType, SeahawkOptions.getRegistry());
+ MobyDataType dataType = MobyDataType.getDataType(mobyDataType, getRegistry());
if(dataType == null){
throw new Exception("Cannot find definition of data type "+mobyDataType+
" in the ontology, therefore the rule cannot be properly parsed");
@@ -1313,7 +1329,7 @@
}
}
- public void addURLRegexMapping(String url_regexp, Map url_nsRules,
+ public void addURLRegexMapping(String url_regexp, Map<String,String> url_nsRules,
String mobyDataType, Map<String,String[]> membersMap, String articleName){ //mobyObj<--mobyNamespaces
//System.out.println("url regex addMapping: " + url_regexp);
try{
@@ -1348,7 +1364,7 @@
return;
}
- Map nsRules = new HashMap();
+ Map<String,String> nsRules = new HashMap<String,String>();
// Defautl the rule to taking the whole matched expression ($0)
for(int i = 0; i < mobyObj.length; i++){
nsRules.put(mobyObj[i], ".");
@@ -1356,11 +1372,11 @@
addXPathMapping(xpath, nsRules, null);
}
- public void addXPathMapping(String xpath_exp, Map nsRules, String articleName){ //mobyObj<--mobyNamespaces
- addXPathMapping(xpath_exp, nsRules, (String) null, (Map) null, articleName);
+ public void addXPathMapping(String xpath_exp, Map<String,String> nsRules, String articleName){ //mobyObj<--mobyNamespaces
+ addXPathMapping(xpath_exp, nsRules, (String) null, (Map<String,String[]>) null, articleName);
}
- public void addXPathMapping(String xpath_exp, Map nsRules, String mobyDataType,
+ public void addXPathMapping(String xpath_exp, Map<String,String> nsRules, String mobyDataType,
Map<String,String[]> membersMap, String articleName){ //mobyObj<--mobyNamespaces
//System.out.println("xpath addMapping: " + xpath_exp);
try{
@@ -1450,7 +1466,7 @@
private boolean isServiceAlive(MobyService service){
// first time method is called
if(isDeadMap == null){
- isDeadMap = new HashMap(); // keys are authority:serviceName
+ isDeadMap = new HashMap<String,String>(); // keys are authority:serviceName
try{
// Note, since it's not part of the standard API, this only
// works for services listed in the default Central
More information about the MOBY-guts
mailing list