- Timestamp:
- 03/22/11 12:23:07 (14 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 modified
-
org.bridgedb.bio/resources/org/bridgedb/bio/datasources.xml (added)
-
org.bridgedb.bio/src/org/bridgedb/bio/BioDataSource.java (modified) (3 diffs)
-
org.bridgedb.bio/test/org/bridgedb/bio/Test.java (modified) (1 diff)
-
org.bridgedb/src/org/bridgedb/DataSource.java (modified) (3 diffs)
-
org.bridgedb/src/org/bridgedb/impl/InternalUtils.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.bridgedb.bio/src/org/bridgedb/bio/BioDataSource.java
r471 r509 25 25 import java.util.regex.Pattern; 26 26 27 import javax.xml.parsers.ParserConfigurationException; 28 27 29 import org.bridgedb.DataSource; 28 30 import org.bridgedb.DataSourcePatterns; 31 import org.bridgedb.impl.InternalUtils; 32 import org.xml.sax.InputSource; 33 import org.xml.sax.SAXException; 29 34 30 35 /** … … 532 537 if (fields.length > 8) builder.urnBase(fields[8]); 533 538 } 539 540 InternalUtils.readXmlConfig( 541 new InputSource( 542 BioDataSource.class.getClassLoader().getResourceAsStream( 543 "org/bridgedb/bio/datasources.xml"))); 544 534 545 } 535 546 catch (IOException ex) … … 537 548 throw new Error(ex); 538 549 } 550 catch (ParserConfigurationException e) 551 { 552 throw new Error(e); 553 } 554 catch (SAXException e) 555 { 556 throw new Error(e); 557 } 558 539 559 } 540 541 560 } -
trunk/org.bridgedb.bio/test/org/bridgedb/bio/Test.java
r434 r509 124 124 } 125 125 126 @org.junit.Test 127 public void testAlias() 128 { 129 DataSource ds = DataSource.getByAlias("ensembl_gene_id"); 130 assertSame(ds, BioDataSource.ENSEMBL); 131 } 132 126 133 } -
trunk/org.bridgedb/src/org/bridgedb/DataSource.java
r426 r509 59 59 private static Map<String, DataSource> byFullName = new HashMap<String, DataSource>(); 60 60 private static Set<DataSource> registry = new HashSet<DataSource>(); 61 private static Map<String, DataSource> byAlias = new HashMap<String, DataSource>(); 61 62 62 63 private String sysCode = null; … … 321 322 } 322 323 324 public void registerAlias(String alias) 325 { 326 byAlias.put (alias, this); 327 } 328 323 329 /** 324 330 * Helper method to determine if a String is allowed as key for bySysCode and byFullname hashes. … … 363 369 } 364 370 371 public static DataSource getByAlias(String alias) 372 { 373 return byAlias.get(alias); 374 } 375 365 376 /** 366 377 get all registered datasoures as a set. -
trunk/org.bridgedb/src/org/bridgedb/impl/InternalUtils.java
r409 r509 29 29 import java.util.Set; 30 30 31 import javax.xml.parsers.ParserConfigurationException; 32 import javax.xml.parsers.SAXParser; 33 import javax.xml.parsers.SAXParserFactory; 34 31 35 import org.bridgedb.DataSource; 32 36 import org.bridgedb.IDMapper; 33 37 import org.bridgedb.IDMapperException; 34 38 import org.bridgedb.Xref; 39 import org.xml.sax.Attributes; 40 import org.xml.sax.InputSource; 41 import org.xml.sax.SAXException; 42 import org.xml.sax.XMLReader; 43 import org.xml.sax.helpers.DefaultHandler; 35 44 36 45 /** … … 261 270 } 262 271 272 /** read a configuration file in the bridgedb xml format */ 273 public static void readXmlConfig(InputSource is) throws ParserConfigurationException, SAXException, IOException 274 { 275 SAXParserFactory spf = SAXParserFactory.newInstance(); 276 spf.setNamespaceAware(true); 277 SAXParser saxParser = spf.newSAXParser(); 278 279 XMLReader xmlReader = saxParser.getXMLReader(); 280 xmlReader.setContentHandler(new ConfigXmlHandler()); 281 xmlReader.parse(is); 282 } 283 284 private static class ConfigXmlHandler extends DefaultHandler 285 { 286 DataSource current = null; 287 288 @Override 289 public void startElement(String namespaceURI, String localName, 290 String qName, Attributes atts) 291 throws SAXException 292 { 293 if ("datasource".equals (localName)) 294 { 295 String fullname = atts.getValue("fullname"); 296 if (fullname == null) throw new SAXException ("missing attribute fullname"); 297 current = DataSource.getByFullName(fullname); 298 } 299 300 if ("alias".equals (localName)) 301 { 302 String alias = atts.getValue ("name"); 303 if (alias != null && current != null) 304 current.registerAlias(alias); 305 } 306 } 307 308 @Override 309 public void endElement(String namespaceURI, String localName, String qName) throws SAXException 310 { 311 if ("datasource".equals (localName)) 312 { 313 current = null; 314 } 315 } 316 317 } 318 263 319 }
